Changeset 186 for trunk


Ignore:
Timestamp:
04/19/10 17:55:26 (14 years ago)
Author:
tim
Message:

minor changes based on suggestions from Michael Cohen

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r185 r186  
    716716   * the file offset while another thread is in the middle of a multi-read
    717717   * parsing transaction */
    718   pthread_mutex_t* cb_lock;
     718  pthread_mutex_t cb_lock;
    719719
    720720  /* For sanity checking (not part of the registry header) */
     
    725725
    726726  /* Multiple read access allowed, write access is exclusive */
    727   pthread_rwlock_t* hbins_lock;
     727  pthread_rwlock_t hbins_lock;
    728728
    729729  /* SK record cached since they're repeatedly reused */
     
    731731
    732732  /* Need exclusive access for LRUs, since lookups make changes */
    733   pthread_mutex_t* sk_lock;
     733  pthread_mutex_t sk_lock;
    734734
    735735  /* Data parsed from file header */
  • trunk/lib/regfi.c

    r185 r186  
    806806  bool recursive_type;
    807807
    808   if(!regfi_lock(file, file->cb_lock, "regfi_parse_subkeylist"))
     808  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_subkeylist"))
    809809     goto fail;
    810810
     
    882882    goto fail_locked;
    883883
    884   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_subkeylist"))
     884  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_subkeylist"))
    885885     goto fail;
    886886
     
    906906
    907907 fail_locked:
    908   regfi_unlock(file, file->cb_lock, "regfi_parse_subkeylist");
     908  regfi_unlock(file, &file->cb_lock, "regfi_parse_subkeylist");
    909909 fail:
    910910  if(elements != NULL)
     
    982982  bool unalloc = false;
    983983
    984   if(!regfi_lock(file, file->cb_lock, "regfi_parse_sk"))
     984  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_sk"))
    985985     goto fail;
    986986
     
    10601060  }
    10611061
    1062   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_sk"))
     1062  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_sk"))
    10631063     goto fail;
    10641064
     
    10761076
    10771077 fail_locked:
    1078   regfi_unlock(file, file->cb_lock, "regfi_parse_sk");
     1078  regfi_unlock(file, &file->cb_lock, "regfi_parse_sk");
    10791079 fail:
    10801080  if(sec_desc_buf != NULL)
     
    10921092  bool unalloc;
    10931093
    1094   if(!regfi_lock(file, file->cb_lock, "regfi_parse_valuelist"))
     1094  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_valuelist"))
    10951095     goto fail;
    10961096
     
    11401140  }
    11411141 
    1142   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_valuelist"))
     1142  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_valuelist"))
    11431143     goto fail;
    11441144
     
    11671167
    11681168 fail_locked:
    1169   regfi_unlock(file, file->cb_lock, "regfi_parse_valuelist");
     1169  regfi_unlock(file, &file->cb_lock, "regfi_parse_valuelist");
    11701170 fail:
    11711171  talloc_free(ret_val);
     
    14231423    return regfi_parse_sk(file, offset, max_size, strict);
    14241424
    1425   if(!regfi_lock(file, file->sk_lock, "regfi_load_sk"))
     1425  if(!regfi_lock(file, &file->sk_lock, "regfi_load_sk"))
    14261426    return NULL;
    14271427
     
    14501450  }
    14511451
    1452   if(!regfi_unlock(file, file->sk_lock, "regfi_load_sk"))
     1452  if(!regfi_unlock(file, &file->sk_lock, "regfi_load_sk"))
    14531453  {
    14541454    talloc_unlink(NULL, ret_val);
     
    14751475  {
    14761476
    1477     if(!regfi_lock(file, file->cb_lock, "regfi_find_root_nk"))
     1477    if(!regfi_lock(file, &file->cb_lock, "regfi_find_root_nk"))
    14781478      return NULL;
    14791479
     
    14851485    }
    14861486
    1487     if(!regfi_unlock(file, file->cb_lock, "regfi_find_root_nk"))
     1487    if(!regfi_unlock(file, &file->cb_lock, "regfi_find_root_nk"))
    14881488      return NULL;
    14891489
     
    15391539
    15401540
    1541 
     1541/******************************************************************************
     1542 ******************************************************************************/
     1543int regfi_free_cb(void* f)
     1544{
     1545  REGFI_FILE* file = (REGFI_FILE*)f;
     1546
     1547  pthread_mutex_destroy(&file->cb_lock);
     1548  pthread_rwlock_destroy(&file->hbins_lock);
     1549  pthread_mutex_destroy(&file->sk_lock);
     1550
     1551  return 0;
     1552}
     1553
     1554
     1555/******************************************************************************
     1556 ******************************************************************************/
    15421557REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb)
    15431558{
     
    15681583  rb->file_length = file_length; 
    15691584  rb->cb = file_cb;
    1570   rb->cb_lock = NULL;
    1571   rb->hbins_lock = NULL;
    1572   rb->sk_lock = NULL;
    1573 
    1574   rb->cb_lock = talloc(rb, pthread_mutex_t);
    1575   if(rb->cb_lock == NULL || pthread_mutex_init(rb->cb_lock, NULL) != 0)
     1585
     1586  if(pthread_mutex_init(&rb->cb_lock, NULL) != 0)
    15761587  {
    15771588    regfi_log_add(REGFI_LOG_ERROR, "Failed to create cb_lock mutex.");
     
    15791590  }
    15801591
    1581   rb->hbins_lock = talloc(rb, pthread_rwlock_t);
    1582   if(rb->hbins_lock == NULL || pthread_rwlock_init(rb->hbins_lock, NULL) != 0)
     1592  if(pthread_rwlock_init(&rb->hbins_lock, NULL) != 0)
    15831593  {
    15841594    regfi_log_add(REGFI_LOG_ERROR, "Failed to create hbins_lock rwlock.");
     
    15861596  }
    15871597
    1588   rb->sk_lock = talloc(rb, pthread_mutex_t);
    1589   if(rb->sk_lock == NULL || pthread_mutex_init(rb->sk_lock, NULL) != 0)
     1598  if(pthread_mutex_init(&rb->sk_lock, NULL) != 0)
    15901599  {
    15911600    regfi_log_add(REGFI_LOG_ERROR, "Failed to create sk_lock mutex.");
     
    16261635
    16271636  /* success */
     1637  talloc_set_destructor(rb, regfi_free_cb);
    16281638  return rb;
    16291639
    16301640 fail:
    1631   if(rb->cb_lock != NULL)
    1632     pthread_mutex_destroy(rb->cb_lock);
    1633   if(rb->hbins_lock != NULL)
    1634     pthread_rwlock_destroy(rb->hbins_lock);
    1635   if(rb->sk_lock != NULL)
    1636     pthread_mutex_destroy(rb->sk_lock);
     1641  pthread_mutex_destroy(&rb->cb_lock);
     1642  pthread_rwlock_destroy(&rb->hbins_lock);
     1643  pthread_mutex_destroy(&rb->sk_lock);
    16371644
    16381645  range_list_free(rb->hbins);
    1639   talloc_free(rb->cb_lock);
    1640   talloc_free(rb->hbins_lock);
    16411646  talloc_free(rb);
    16421647  return NULL;
     
    16461651/******************************************************************************
    16471652 ******************************************************************************/
    1648 void regfi_free(REGFI_FILE *file)
    1649 {
    1650   pthread_mutex_destroy(file->cb_lock);
    1651   pthread_rwlock_destroy(file->hbins_lock);
    1652   pthread_mutex_destroy(file->sk_lock);
     1653void regfi_free(REGFI_FILE* file)
     1654{
     1655  /* Callback handles cleanup side effects */
    16531656  talloc_free(file);
    16541657}
     
    16841687   */
    16851688 
    1686   if(!regfi_read_lock(file, file->hbins_lock, "regfi_rootkey"))
     1689  if(!regfi_read_lock(file, &file->hbins_lock, "regfi_rootkey"))
    16871690    return NULL;
    16881691
     
    16941697  }
    16951698
    1696   if(!regfi_rw_unlock(file, file->hbins_lock, "regfi_rootkey"))
     1699  if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_rootkey"))
    16971700    return NULL;
    16981701
     
    24982501    goto fail;
    24992502 
    2500   if(!regfi_lock(file, file->cb_lock, "regfi_parse_hbin"))
     2503  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_hbin"))
    25012504    goto fail;
    25022505
     
    25172520  }
    25182521
    2519   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_hbin"))
     2522  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_hbin"))
    25202523    goto fail;
    25212524
     
    25622565
    25632566 fail_locked:
    2564   regfi_unlock(file, file->cb_lock, "regfi_parse_hbin");
     2567  regfi_unlock(file, &file->cb_lock, "regfi_parse_hbin");
    25652568 fail:
    25662569  talloc_free(hbin);
     
    25872590  }
    25882591
    2589   if(!regfi_lock(file, file->cb_lock, "regfi_parse_nk"))
     2592  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_nk"))
    25902593    goto fail;
    25912594
     
    27002703  }
    27012704
    2702   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_nk"))
     2705  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_nk"))
    27032706    goto fail;
    27042707
     
    27062709
    27072710 fail_locked:
    2708   regfi_unlock(file, file->cb_lock, "regfi_parse_nk");
     2711  regfi_unlock(file, &file->cb_lock, "regfi_parse_nk");
    27092712 fail:
    27102713  talloc_free(ret_val);
     
    27252728  { goto fail; }
    27262729
    2727   if(!regfi_lock(file, file->cb_lock, "regfi_parse_classname"))
     2730  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_classname"))
    27282731    goto fail;
    27292732
     
    27752778  }
    27762779
    2777   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_classname"))
     2780  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_classname"))
    27782781    goto fail;
    27792782
     
    27812784
    27822785 fail_locked:
    2783   regfi_unlock(file, file->cb_lock, "regfi_parse_classname");
     2786  regfi_unlock(file, &file->cb_lock, "regfi_parse_classname");
    27842787 fail:
    27852788  talloc_free(ret_val);
     
    28022805    goto fail;
    28032806
    2804   if(!regfi_lock(file, file->cb_lock, "regfi_parse_nk"))
     2807  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_nk"))
    28052808    goto fail;
    28062809
     
    28872890    cell_length = REGFI_VK_MIN_LENGTH + 4;
    28882891
    2889   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_nk"))
     2892  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_nk"))
    28902893    goto fail;
    28912894
     
    29002903 
    29012904 fail_locked:
    2902   regfi_unlock(file, file->cb_lock, "regfi_parse_vk");
     2905  regfi_unlock(file, &file->cb_lock, "regfi_parse_vk");
    29032906 fail:
    29042907  talloc_free(ret_val);
     
    29522955    }
    29532956   
    2954     if(!regfi_lock(file, file->cb_lock, "regfi_load_data"))
     2957    if(!regfi_lock(file, &file->cb_lock, "regfi_load_data"))
    29552958      goto fail;
    29562959
     
    29632966    }
    29642967
    2965     if(!regfi_unlock(file, file->cb_lock, "regfi_load_data"))
     2968    if(!regfi_unlock(file, &file->cb_lock, "regfi_load_data"))
    29662969      goto fail;
    29672970
     
    30133016
    30143017 fail_locked:
    3015   regfi_unlock(file, file->cb_lock, "regfi_load_data");
     3018  regfi_unlock(file, &file->cb_lock, "regfi_load_data");
    30163019 fail:
    30173020  ret_val.buf = NULL;
     
    30373040  ret_val.len = length;
    30383041
    3039   if(!regfi_lock(file, file->cb_lock, "regfi_parse_data"))
     3042  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_data"))
    30403043    goto fail;
    30413044
     
    30563059  }
    30573060
    3058   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_data"))
     3061  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_data"))
    30593062    goto fail;
    30603063
     
    30623065
    30633066 fail_locked:
    3064   regfi_unlock(file, file->cb_lock, "regfi_parse_data");
     3067  regfi_unlock(file, &file->cb_lock, "regfi_parse_data");
    30653068 fail:
    30663069  talloc_free(ret_val.buf);
     
    31233126  }
    31243127
    3125   if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_header"))
     3128  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_header"))
    31263129    goto fail;
    31273130
     
    31353138  }
    31363139
    3137   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_header"))
     3140  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_header"))
    31383141    goto fail;
    31393142
     
    31513154
    31523155 fail_locked:
    3153   regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_header");
     3156  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_header");
    31543157 fail:
    31553158  talloc_free(ret_val.buf);
     
    31833186    goto fail;
    31843187
    3185   if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_indirect"))
     3188  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_indirect"))
    31863189    goto fail;
    31873190
     
    31963199  }
    31973200
    3198   if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_indirect"))
     3201  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_indirect"))
    31993202    goto fail;
    32003203
     
    32103213
    32113214 fail_locked:
    3212   regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_indirect");
     3215  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_indirect");
    32133216 fail:
    32143217  talloc_free(ret_val);
     
    32443247  for(i=0; i<num_chunks; i++)
    32453248  {
    3246     if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_cells"))
     3249    if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_cells"))
    32473250      goto fail;
    32483251
     
    32573260    }
    32583261
    3259     if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_cells"))
     3262    if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_cells"))
    32603263      goto fail;
    32613264
     
    32673270
    32683271 fail_locked:
    3269   regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_cells");
     3272  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_cells");
    32703273 fail:
    32713274  if(ret_val != NULL)
     
    33613364    }
    33623365
    3363     if(!regfi_lock(file, file->cb_lock, "regfi_load_big_data"))
     3366    if(!regfi_lock(file, &file->cb_lock, "regfi_load_big_data"))
    33643367      goto fail;
    33653368
     
    33823385    }
    33833386
    3384     if(!regfi_unlock(file, file->cb_lock, "regfi_load_big_data"))
     3387    if(!regfi_unlock(file, &file->cb_lock, "regfi_load_big_data"))
    33853388      goto fail;
    33863389
     
    33973400
    33983401 fail_locked:
    3399   regfi_unlock(file, file->cb_lock, "regfi_load_big_data");
     3402  regfi_unlock(file, &file->cb_lock, "regfi_load_big_data");
    34003403 fail:
    34013404  talloc_free(ret_val.buf);
     
    34213424    return NULL;
    34223425
    3423   if(!regfi_read_lock(file, file->hbins_lock, "regfi_parse_unalloc_cells"))
     3426  if(!regfi_read_lock(file, &file->hbins_lock, "regfi_parse_unalloc_cells"))
    34243427  {
    34253428    range_list_free(ret_val);
     
    34383441    while(curr_off < hbin->block_size)
    34393442    {
    3440       if(!regfi_lock(file, file->cb_lock, "regfi_parse_unalloc_cells"))
     3443      if(!regfi_lock(file, &file->cb_lock, "regfi_parse_unalloc_cells"))
    34413444        break;
    34423445
     
    34443447                           &cell_len, &is_unalloc))
    34453448      {
    3446         regfi_unlock(file, file->cb_lock, "regfi_parse_unalloc_cells");
     3449        regfi_unlock(file, &file->cb_lock, "regfi_parse_unalloc_cells");
    34473450        break;
    34483451      }
    34493452
    3450       if(!regfi_unlock(file, file->cb_lock, "regfi_parse_unalloc_cells"))
     3453      if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_unalloc_cells"))
    34513454        break;
    34523455
     
    34743477  }
    34753478
    3476   if(!regfi_rw_unlock(file, file->hbins_lock, "regfi_parse_unalloc_cells"))
     3479  if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_parse_unalloc_cells"))
    34773480  {
    34783481    range_list_free(ret_val);
  • trunk/src/common.c

    r185 r186  
    4848void bailOut(int code, char* message)
    4949{
    50   fprintf(stderr, message);
     50  fprintf(stderr, "%s", message);
    5151  exit(code);
    5252}
Note: See TracChangeset for help on using the changeset viewer.