/* find_block -- find a free block of specified size */ static header *find_block(unsigned size, unsigned objsize) { header *h = NULL, *h2; int i = min(size/GC_PAGESIZE, BIG_BLOCK); ASSERT(size % GC_PAGESIZE == 0); do { for (headers(h2, free_list[i])) { /* This always succeeds for small blocks, and gives first-fit allocation for big blocks. */ if (size <= h2->h_size) { h = h2; break; } } i++; } while (h == NULL && i <= BIG_BLOCK); if (h == NULL) { /* No suitable block was found. Get a big chunk. */ unsigned chunk = max(size, CHUNK_SIZE); GC_TRACE("[ex]"); ASSERT(chunk % GC_PAGESIZE == 0); h = alloc_header(); h->h_memory = (uchar *) get_memory(chunk); h->h_size = chunk; /* Add to the free list for merging and page table setup */ h = free_block(h, FALSE); } ASSERT(h->h_memory != NULL && h->h_size >= size); unlink(h); if (size < h->h_size) { /* Split the block, and return the waste to the free list. It's best to use header h for the waste: that way, we don't have to reset lots of page table entries when we chip a small piece off a big block. */ h2 = alloc_header(); h2->h_memory = h->h_memory; h2->h_size = size; page_setup(h2->h_memory, size, h2); h->h_memory += size; h->h_size -= size; make_free(h); h = h2; } h->h_objsize = objsize; h->h_epoch = gencount; return h; }
int thforce_datainit(thforce_data *arg, int id, int start, int num, int comb, int len, int set_len, pheader *header, int iv_mode, int chain_mode, char *crypt_disk, int fast_check, char *set, int keyslot, int *progress, char *win_pwd){ arg->id=id; arg->start=start; arg->num=num; arg->len=len; arg->set_len=set_len; arg->comb=comb; arg->iv_mode=iv_mode; arg->chain_mode=chain_mode; arg->fast_check=fast_check; arg->keyslot=keyslot; arg->progress=progress; arg->win_pwd=win_pwd; /* create a copy of the header for the current thread */ if(!alloc_header(&(arg->header))){ errprint("alloc_header error!\n"); return 0; } memcpy(&(arg->header), header, sizeof(pheader)); /* print_header(&(arg->header));*/ /* create a copy of the encrypted disk for the current thread */ if((arg->crypt_disk = calloc(32,sizeof(char *)))==NULL){ errprint("malloc error\n"); return 0; } memcpy(arg->crypt_disk, crypt_disk, 32); /* create a copy of the set for the current thread */ if((arg->set = calloc(set_len,sizeof(char *)))==NULL){ errprint("malloc error\n"); return 0; } memcpy(arg->set, set, set_len); /* set the correct pbk_hash */ if(strcmp(header->hash_spec, "sha1")==0){ arg->pbk_hash=SHA_ONE; }else if(strcmp(header->hash_spec, "sha256")==0){ arg->pbk_hash=SHA_TWO_FIVE_SIX; }else if(strcmp(header->hash_spec, "sha512")==0){ arg->pbk_hash=SHA_FIVE_ONE_TWO; }else if(strcmp(header->hash_spec, "ripemd160")==0){ arg->pbk_hash=RIPEMD; }else{ errprint("Unsupported hash function\n"); return 0; } return 1; }
int thlist_datainit(thlist_data *arg, int id, char **list, int num, pheader *header, int iv_mode, int chain_mode, char *crypt_disk, int fast_check,int max_l, int keyslot, int *progress, char *win_pwd){ int i,l; arg->id=id; arg->num=num; arg->iv_mode=iv_mode; arg->chain_mode=chain_mode; arg->fast_check=fast_check; arg->max_l=max_l; arg->keyslot=keyslot; arg->progress=progress; arg->win_pwd=win_pwd; /* set the list of password for the curent thread */ if((arg->list = calloc(num,sizeof(char *)))==NULL){ errprint("malloc error\n"); return 0; } for(i=0;i<num;i++){ l=strlen(list[i]); if((arg->list[i]=calloc(l,sizeof(char)))==NULL){ errprint("malloc error!\n"); return 0; } memcpy(arg->list[i],list[i],l); } /* create a copy of the header for the current thread */ if(!alloc_header(&(arg->header))){ errprint("alloc_header error!\n"); return 0; } memcpy(&(arg->header), header, sizeof(pheader)); /* create a copy of the encrypted disk for the current thread */ if((arg->crypt_disk = calloc(32,sizeof(char *)))==NULL){ errprint("malloc error\n"); return 0; } memcpy(arg->crypt_disk, crypt_disk, 32); /* set the correct pbk_hash */ if(strcmp(header->hash_spec, "sha1")==0){ arg->pbk_hash=SHA_ONE; }else if(strcmp(header->hash_spec, "sha256")==0){ arg->pbk_hash=SHA_TWO_FIVE_SIX; }else if(strcmp(header->hash_spec, "sha512")==0){ arg->pbk_hash=SHA_FIVE_ONE_TWO; }else if(strcmp(header->hash_spec, "ripemd160")==0){ arg->pbk_hash=RIPEMD; }else{ errprint("Unsupported hash function\n"); return 0; } return 1; }
static header *new_list(void) { header *h = alloc_header(); h->h_next = h->h_prev = h; return h; }