int coded_unit_dup(coded_unit *dst, coded_unit *src) { assert(dst != NULL); assert(src != NULL); assert(src->data_len != 0); dst->data = (u_char*)block_alloc(src->data_len); dst->data_len = src->data_len; memcpy(dst->data, src->data, src->data_len); if (src->state_len != 0) { dst->state = (u_char*)block_alloc(src->state_len); dst->state_len = src->state_len; memcpy(dst->state, src->state, src->state_len); } else { dst->state = NULL; dst->state_len = 0; } dst->id = src->id; return TRUE; }
int media_data_create(media_data **ppmd, int nrep) { media_data *pmd; int i; *ppmd = NULL; pmd = (media_data*)block_alloc(sizeof(media_data)); if (pmd) { memset(pmd, 0, sizeof(media_data)); for(i = 0; i < nrep; i++) { pmd->rep[i] = block_alloc(sizeof(coded_unit)); if (pmd->rep[i] == NULL) { pmd->nrep = i; media_data_destroy(&pmd, sizeof(media_data)); return FALSE; } memset(pmd->rep[i], 0, sizeof(coded_unit)); } pmd->nrep = nrep; *ppmd = pmd; return TRUE; } return FALSE; }
static tree_node_t *create_node(struct strings *strings, uint32_t hash, const char *string) { tree_node_t *node = block_alloc(strings->index, sizeof(*node)); if (!node) { return NULL; } node->hash = hash; node->next = NULL; node->id = strings->total + 1; if (node->id == id_overflow) { return NULL; } size_t size = strlen(string) + 1; #ifdef ALIGNMENT size = size + ALIGNMENT - (size % ALIGNMENT); #endif void *string_ptr = block_alloc(strings->strings, size); if (!string_ptr) { return NULL; } memcpy(string_ptr, string, size); node->string = (const char *)string_ptr; uint32_t *hash_ptr = block_alloc(strings->hashes, sizeof(*hash_ptr)); if (!hash_ptr) { return NULL; } *hash_ptr = hash; strings->total++; return node; }
static void sinc_init_filter(filter_state_t *fs, const converter_fmt_t *cfmt) { if (cfmt->src_freq < cfmt->dst_freq) { assert(cfmt->dst_freq / cfmt->src_freq < SINC_MAX_CHANGE); fs->scale = cfmt->dst_freq/cfmt->src_freq; fs->filter = upfilter[fs->scale]; fs->taps = 2 * SINC_CYCLES * (cfmt->dst_freq/cfmt->src_freq) + 1; fs->hold_bytes = fs->taps * cfmt->src_channels * sizeof(sample); fs->hold_buf = (sample*)block_alloc(fs->hold_bytes); switch(cfmt->src_channels) { case 1: fs->fn = sinc_upsample_mono; break; case 2: fs->fn = sinc_upsample_stereo; break; default: abort(); } } else if (cfmt->src_freq > cfmt->dst_freq) { assert(cfmt->src_freq / cfmt->dst_freq < SINC_MAX_CHANGE); fs->scale = cfmt->src_freq/cfmt->dst_freq; fs->filter = downfilter[fs->scale]; fs->taps = 2 * SINC_CYCLES * (cfmt->src_freq/cfmt->dst_freq) + 1; fs->hold_bytes = fs->taps * cfmt->src_channels * sizeof(sample); fs->hold_buf = (sample*)block_alloc(fs->hold_bytes); switch(cfmt->src_channels) { case 1: fs->fn = sinc_downsample_mono; break; case 2: fs->fn = sinc_downsample_stereo; break; default: abort(); } } memset(fs->hold_buf, 0, fs->hold_bytes); }
static tree_node_t *create_node(struct strings *strings, uint32_t hash, const char *string) { tree_node_t *node = block_alloc(strings->index, sizeof(*node)); if (!node) { return NULL; } node->hash = hash; node->next = NULL; node->id = strings->total + 1; if (node->id == id_overflow) { return NULL; } size_t len = strlen(string); void *string_ptr = block_alloc(strings->strings, len + 1); if (!string_ptr) { return NULL; } memcpy(string_ptr, string, len + 1); node->string = (const char *)string_ptr; uint32_t *hash_ptr = block_alloc(strings->hashes, sizeof(*hash_ptr)); if (!hash_ptr) { return NULL; } *hash_ptr = hash; strings->total++; return node; }
void coded_unit_layer_split(coded_unit *in, coded_unit *out, uint8_t layer, uint8_t *layer_markers) { uint16_t tmp_datalen; uint8_t i; tmp_datalen = (uint16_t)(layer_markers[layer] - layer_markers[layer-1]); out->data = (u_char*)block_alloc(tmp_datalen); out->data_len = tmp_datalen; for(i=layer_markers[layer-1];i<layer_markers[layer];i++) { out->data[i-layer_markers[layer-1]] = in->data[i]; } if (in->state_len != 0) { out->state = (u_char*)block_alloc(in->state_len); out->state_len = in->state_len; memcpy(out->state, in->state, in->state_len); } else { in->state = NULL; in->state_len = 0; } out->id = in->id; }
/* * pad a block to the front (or the back if size is negative) */ struct block *padblock(struct block *bp, int size) { int n; struct block *nbp; uint8_t bcksum = bp->flag & BCKSUM_FLAGS; uint16_t checksum_start = bp->checksum_start; uint16_t checksum_offset = bp->checksum_offset; uint16_t mss = bp->mss; QDEBUG checkb(bp, "padblock 1"); if (size >= 0) { if (bp->rp - bp->base >= size) { bp->checksum_start += size; bp->rp -= size; return bp; } PANIC_EXTRA(bp); if (bp->next) panic("padblock %p", getcallerpc(&bp)); n = BLEN(bp); padblockcnt++; nbp = block_alloc(size + n, MEM_WAIT); nbp->rp += size; nbp->wp = nbp->rp; memmove(nbp->wp, bp->rp, n); nbp->wp += n; freeb(bp); nbp->rp -= size; } else { size = -size; PANIC_EXTRA(bp); if (bp->next) panic("padblock %p", getcallerpc(&bp)); if (bp->lim - bp->wp >= size) return bp; n = BLEN(bp); padblockcnt++; nbp = block_alloc(size + n, MEM_WAIT); memmove(nbp->wp, bp->rp, n); nbp->wp += n; freeb(bp); } if (bcksum) { nbp->flag |= bcksum; nbp->checksum_start = checksum_start; nbp->checksum_offset = checksum_offset; nbp->mss = mss; } QDEBUG checkb(nbp, "padblock 1"); return nbp; }
static void print_heap() { int i, block_count; unsigned *list_p; void *bp; size_t size, alloc; if (DEBUG_CHECKHEAP) { printf("\n----- arrays -----\n"); list_p = (unsigned *)heap_head; for (i = 0; i <= 4; i++) { printf("0x%lx: [%d, %d] -> %x\n", (long)list_p, i + 4, i + 4, (unsigned)*list_p); list_p++; } for (; i < ARRAYSIZE; i++) { printf("0x%lx: [%d, %d] -> %x\n", (long)list_p, (1 << (i - 2)) + 1, 1 << (i - 1), (unsigned)*list_p); list_p++; } printf("----- blocks -----\n"); bp = data_head + 4 * WSIZE; size = block_size(bp); alloc = block_alloc(bp); block_count = 0; while (!size == 0) { printf("\n----- block %d -----\n", block_count); block_count++; printf("bp: 0x%lx\n", (long)bp); printf("--- header ---\n"); printf("size: %d\n", (int)size); printf("prev alloc: %d\n", (int)block_prev_alloc(bp)); printf("alloc: %d\n", (int)alloc); printf("--- data ---\n"); if (alloc == 0) { // free block printf("- pointer -\n"); printf("pred: 0x%lx -> 0x%x\n", (long)bp, *(unsigned *)bp); printf("succ: 0x%lx -> 0x%x\n", (long)(bp + WSIZE), *((unsigned *)bp + 1)); } else { // allocated block /*for (i = 0; i < size - DSIZE; i += WSIZE) { printf("data[%d] = %d\n", i / WSIZE, *((int *)(bp + i))); }*/ printf("data[%d~%d]\n", 0, (int)size / WSIZE - 2); } /* printf("--- footer ---\n"); printf("size: %d\n", (int)size); printf("prev alloc: %d\n", (int)block_prev_alloc(bp)); printf("alloc: %d\n", (int)alloc); */ bp = next_block(bp); size = block_size(bp); alloc = block_alloc(bp); } printf("last_block: %lx\n\n\n", (long)last_block); } }
void * block_copy_construct(void *inp) { block * x = (block *) inp; block * y = block_alloc(x->vec->size); block_copy(x, y); return y; }
/* Helper and front-end for __try_qbread: extracts and returns a list of blocks * containing up to len bytes. It may contain less than len even if q has more * data. * * Returns 0 if the q is closed or would require blocking and !CAN_BLOCK. * * Technically, there's a weird corner case with !Qcoalesce and Qmsg where you * could get a zero length block back. */ static struct block *__qbread(struct queue *q, size_t len, int qio_flags, int mem_flags) { struct block *ret = 0; struct block *spare = 0; while (1) { switch (__try_qbread(q, len, qio_flags, &ret, spare)) { case QBR_OK: case QBR_FAIL: if (spare && (ret != spare)) freeb(spare); return ret; case QBR_SPARE: assert(!spare); /* Due to some nastiness, we need a fresh block so we can read out * anything from the queue. 'len' seems like a reasonable amount. * Maybe we can get away with less. */ spare = block_alloc(len, mem_flags); if (!spare) return 0; break; case QBR_AGAIN: /* if the first block is 0 and we are Qcoalesce, then we'll need to * try again. We bounce out of __try so we can perform the "is * there a block" logic again from the top. */ break; } } }
/** * @brief Create an indirect block. * * @details Creates a indirect block and saves in @param dest. * * @param dest Destination buffer, It is the corresponding disk block to be changed. * @param ip File to use. * @param offset Offset to be calculated the block. * @param creat If 1, creates an block, otherwise, just return this value. * * @returns If successful, the block number created / obtained, otherwise BLOCK_NULL is * returned. * * @note @p ip must be locked. */ PUBLIC block_t create_indirect_block (struct buffer *dest, struct inode *ip, off_t offset, int create) { block_t phys; /* Physical block number. */ if (((block_t *)buffer_data(dest))[offset] == BLOCK_NULL && create) { /* Allocate an block. */ superblock_lock(ip->sb); phys = block_alloc(ip->sb); superblock_unlock(ip->sb); if (phys != BLOCK_NULL) { ((block_t *)buffer_data(dest))[offset] = phys; buffer_dirty(dest, 1); inode_touch(ip); brelse(dest); return (phys); } else { brelse(dest); return (phys); } } else { brelse(dest); return ((block_t *)buffer_data(dest))[offset]; } }
/* * copy 'count' bytes into a new block */ struct block *copyblock(struct block *bp, int count) { int l; struct block *nbp; QDEBUG checkb(bp, "copyblock 0"); nbp = block_alloc(count, MEM_WAIT); if (bp->flag & BCKSUM_FLAGS) { nbp->flag |= (bp->flag & BCKSUM_FLAGS); nbp->checksum_start = bp->checksum_start; nbp->checksum_offset = bp->checksum_offset; nbp->mss = bp->mss; } PANIC_EXTRA(bp); for (; count > 0 && bp != 0; bp = bp->next) { l = BLEN(bp); if (l > count) l = count; memmove(nbp->wp, bp->rp, l); nbp->wp += l; count -= l; } if (count > 0) { memset(nbp->wp, 0, count); nbp->wp += count; } copyblockcnt++; QDEBUG checkb(nbp, "copyblock 1"); return nbp; }
struct packet *command_packet(unsigned short sessid, char *c, int len) { struct packet *ret = packet_alloc(); ret->family = 0xf1; ret->unk1 = 0xe0; ret->dir = 0x02; ret->pltype = 0x00; ret->connid = 0; ret->subseq = 0; ret->unk2 = 0; ret->sessid = sessid; ret->tail = 0; ret->data = block_alloc(); ret->data->id = 4; ret->data->data = NULL; ret->data->nchildren = 0; unsigned char xxx[1024]; xxx[0] = 0x04; block_addchild(ret->data, "1", xxx, 1); *(unsigned short *)(xxx) = htons(0); *(unsigned short *)(xxx+2) = htons(0); // job nr. *(unsigned short *)(xxx+4) = htons(0); *(unsigned short *)(xxx+6) = htons(0); xxx[8] = 0; block_addchild(ret->data, "2", xxx, 0x09); block_addchild(ret->data, "6-1", (unsigned char *)c, len); return ret; }
static int cmd_endremapblock(const char *args) { int ret = ERR_BLOCK_TOO_LARGE; unsigned int i, x; struct block *block; (void)args; block = block_alloc(); if (!block) goto ret; fill_block_header(block); block_append(block, current_layer); block_append(block, (unsigned char)pair_lists[REMAP_LIST].len); for (i = 0; i < pair_lists[REMAP_LIST].len; i++) { x = pair_lists[REMAP_LIST].list[i]; block_append(block, (unsigned char)(x >> 8)); block_append(block, (unsigned char)(x & 0xff)); } block->bytes[0] = block->len; block_list_append(block); free(block); pair_list_clear(REMAP_LIST); block_type = BLOCK_NONE; ret = 0; ret: return ret; }
struct packet *command_cancel_packet(unsigned short connid, unsigned short sessid, unsigned char tail, unsigned short jobnr) { struct packet *ret = packet_alloc(); ret->family = 0xf1; ret->unk1 = 0xe0; ret->dir = 0x03; ret->pltype = 0x01; ret->connid = connid; ret->subseq = 0; ret->unk2 = 0; ret->sessid = sessid; ret->tail = tail; ret->data = block_alloc(); ret->data->id = 0x0a; ret->data->data = NULL; ret->data->nchildren = 0; unsigned char xxx[1024]; xxx[0] = 0x05; block_addchild(ret->data, "1", xxx, 1); *(unsigned short *)(xxx) = htons(0); *(unsigned short *)(xxx+2) = htons(jobnr); *(unsigned short *)(xxx+4) = htons(0); *(unsigned short *)(xxx+6) = htons(0); *(unsigned short *)(xxx+8) = htons(0); block_addchild(ret->data, "2", xxx, 0x0a); return ret; }
struct packet *command_confirmation_packet(unsigned short connid, unsigned short sessid, unsigned char tail, char *c, int len) { struct packet *ret = packet_alloc(); ret->family = 0xf1; ret->unk1 = 0xe0; ret->dir = 0x03; ret->pltype = 0x01; ret->connid = connid; ret->subseq = 0; ret->unk2 = 0; ret->sessid = sessid; ret->tail = tail; ret->data = block_alloc(); ret->data->id = 8; ret->data->data = NULL; ret->data->nchildren = 0; unsigned char xxx[1024]; xxx[0] = 0x04; block_addchild(ret->data, "1", xxx, 1); *(unsigned short *)(xxx) = htons(0); *(unsigned short *)(xxx+2) = htons(0); *(unsigned short *)(xxx+4) = htons(0); *(unsigned short *)(xxx+6) = htons(0); *(unsigned short *)(xxx+8) = htons(0); block_addchild(ret->data, "2", xxx, 0x0a); block_addchild(ret->data, "6-1", (unsigned char *)c, len); return ret; }
void *_dbg_realloc(void *oldp, size_t size) { u8_t *newp; struct block *oldblock, *newblock; LOG(("_dbg_realloc; oldp=0x%x; size=0x%x\n", oldp, size)); assert(oldp); /* enforced by regular realloc */ assert(size > 0); /* enforced by regular realloc */ /* always allocate new block */ newblock = block_alloc(size); if (!newblock) return NULL; /* copy the data */ oldblock = block_find(oldp); memcpy(block_get_dataptr(newblock), block_get_dataptr(oldblock), MIN(newblock->size, oldblock->size)); /* deallocate old block */ block_free(oldblock); newp = block_get_dataptr(newblock); LOG(("_dbg_realloc; newp=0x%x\n", newp)); return newp; }
/* Decoder related ***********************************************************/ int codec_decoder_create(codec_id_t id, codec_state **cs) { if (codec_id_is_valid(id)) { uint16_t ifs, fmt; *cs = (codec_state*)block_alloc(sizeof(codec_state)); if (!cs) { *cs = NULL; return 0; } (*cs)->state = NULL; (*cs)->id = id; ifs = CODEC_GET_IFS_INDEX(id); fmt = CODEC_GET_FMT_INDEX(id); if (codec_table[ifs].cx_decoder_create) { /* Must also have a destructor */ assert(codec_table[ifs].cx_decoder_destroy != NULL); codec_table[ifs].cx_decoder_create(fmt, &(*cs)->state); } return TRUE; } else { debug_msg("Attempting to initiate invalid codec\n"); abort(); } return 0; }
struct packet *logout_packet(unsigned short sessid) { struct packet *ret = packet_alloc(); ret->family = 0xf1; ret->unk1 = 0xe0; ret->dir = 0x0e; ret->pltype = 0x00; ret->connid = 0; ret->subseq = 0; ret->unk2 = 0; ret->sessid = sessid; ret->tail = 0; ret->data = block_alloc(); ret->data->id = 0x0b; ret->data->data = NULL; ret->data->nchildren = 0; unsigned char xxx[1024]; xxx[0] = 0x04; block_addchild(ret->data, "1", xxx, 1); *(unsigned short *)(xxx) = htons(0); *(unsigned short *)(xxx+2) = htons(0); // job nr. *(unsigned short *)(xxx+4) = htons(sessid); *(unsigned short *)(xxx+6) = htons(0); *(unsigned short *)(xxx+8) = htons(0); block_addchild(ret->data, "2", xxx, 0x0a); return ret; }
/* Returns a block with the remaining contents of b all in the main body of the * returned block. Replace old references to b with the returned value (which * may still be 'b', if no change was needed. */ struct block *linearizeblock(struct block *b) { struct block *newb; size_t len; struct extra_bdata *ebd; if (!b->extra_len) return b; newb = block_alloc(BLEN(b), MEM_WAIT); len = BHLEN(b); memcpy(newb->wp, b->rp, len); newb->wp += len; len = b->extra_len; for (int i = 0; (i < b->nr_extra_bufs) && len; i++) { ebd = &b->extra_data[i]; if (!ebd->base || !ebd->len) continue; memcpy(newb->wp, (void*)(ebd->base + ebd->off), ebd->len); newb->wp += ebd->len; len -= ebd->len; } /* TODO: any other flags that need copied over? */ if (b->flag & BCKSUM_FLAGS) { newb->flag |= (b->flag & BCKSUM_FLAGS); newb->checksum_start = b->checksum_start; newb->checksum_offset = b->checksum_offset; newb->mss = b->mss; } freeb(b); return newb; }
/* * copy the contents of memory into a string of blocks. * return NULL on error. */ struct block *mem2bl(uint8_t * p, int len) { ERRSTACK(1); int n; struct block *b, *first, **l; first = NULL; l = &first; if (waserror()) { freeblist(first); nexterror(); } do { n = len; if (n > Maxatomic) n = Maxatomic; *l = b = block_alloc(n, MEM_WAIT); /* TODO consider extra_data */ memmove(b->wp, p, n); b->wp += n; p += n; len -= n; l = &b->next; } while (len > 0); poperror(); return first; }
int lpc_repair (uint16_t idx, u_char *state, uint16_t consec_lost, coded_unit *prev, coded_unit *missing, coded_unit *next) { lpc_txstate_t *lps; assert(prev); assert(missing); if (missing->data) { debug_msg("lpc_repair: missing unit had data!\n"); block_free(missing->data, missing->data_len); } missing->data = (u_char*)block_alloc(LPCTXSIZE); missing->data_len = LPCTXSIZE; assert(prev->data); assert(prev->data_len == LPCTXSIZE); memcpy(missing->data, prev->data, LPCTXSIZE); lps = (lpc_txstate_t*)missing->data; lps->gain = (u_char)((float)lps->gain * 0.8f); UNUSED(next); UNUSED(consec_lost); UNUSED(state); UNUSED(idx); return TRUE; }
static HANDLE open_dsp(Devtab_t* dp, Pfd_t* fdp, Path_t *ip, int oflags, HANDLE *extra) { HANDLE hp; int blkno, minor = ip->name[1]; Pdev_t *pdev; unsigned short *blocks = devtab_ptr(Share->chardev_index, AUDIO_MAJOR); if(load_audio()) { /* If the device is already opened */ if(blkno = blocks[minor]) { logerr(LOG_DEV+5, "Device Busy"); errno = EBUSY; return 0; } else { WAVEFORMATEX *wp; if((blkno = block_alloc(BLK_PDEV)) == 0) return(0); pdev = dev_ptr(blkno); wp = (WAVEFORMATEX*)(pdev+1); ZeroMemory((void *)pdev, BLOCK_SIZE-1); /* Initialising the wave format sturcture */ wp->wFormatTag=WAVE_FORMAT_PCM; wp->nChannels=CHANNELS; wp->nSamplesPerSec=SAMPLES_PER_SEC; if(minor&1) wp->nSamplesPerSec *= 2; wp->wBitsPerSample=BITS_PER_SAMPLE; wp->nBlockAlign=(wp->wBitsPerSample*CHANNELS)/8 ; wp->nAvgBytesPerSec=wp->nSamplesPerSec*wp->nBlockAlign; wp->cbSize=EXTRA_FORMAT_SIZE; if(!audio_open(pdev,1)) { logerr(LOG_DEV+5, "waveOutOpen"); block_free((unsigned short)blkno); return 0; } hp = AUDIO_HANDLE; pdev->major=AUDIO_MAJOR; pdev->minor = minor; uwin_pathmap(ip->path, pdev->devname, sizeof(pdev->devname), UWIN_W2U); fdp->devno = blkno; blocks[minor] = blkno; pdev->devpid = P_CP->pid; } return hp; } else { logerr(0, "audio functions not supported"); return 0; } }
void sinc_convert (const converter_fmt_t *cfmt, u_char *state, sample* src_buf, int src_len, sample *dst_buf, int dst_len) { sinc_state_t *s; int channels; sample *tmp_buf; int tmp_len; channels = cfmt->src_channels; s = (sinc_state_t*)state; if (cfmt->src_channels == 2 && cfmt->dst_channels == 1) { /* stereo->mono then sample rate change */ if (s->steps) { /* inplace conversion needed */ converter_change_channels(src_buf, src_len, 2, src_buf, src_len / 2, 1); src_len /= 2; } else { /* this is only conversion */ converter_change_channels(src_buf, src_len, 2, dst_buf, dst_len, 1); return; } channels = 1; } else if (cfmt->src_channels == 1 && cfmt->dst_channels == 2) { dst_len /= 2; } switch(s->steps) { case 1: assert(s->fs[0].fn); s->fs[0].fn(&s->fs[0], src_buf, src_len, dst_buf, dst_len); break; case 2: /* first step is downsampling */ tmp_len = src_len / s->fs[0].scale; tmp_buf = (sample*)block_alloc(sizeof(sample) * tmp_len); assert(s->fs[0].fn); assert(s->fs[1].fn); s->fs[0].fn(&s->fs[0], src_buf, src_len, tmp_buf, tmp_len); s->fs[1].fn(&s->fs[1], tmp_buf, tmp_len, dst_buf, dst_len); block_free(tmp_buf, tmp_len * sizeof(sample)); } if (cfmt->src_channels == 1 && cfmt->dst_channels == 2) { /* sample rate change before mono-> stereo */ if (s->steps) { /* in place needed */ converter_change_channels(dst_buf, dst_len, 1, dst_buf, dst_len * 2, 2); } else { /* this is our only conversion here */ converter_change_channels(src_buf, src_len, 1, dst_buf, dst_len * 2, 2); } } }
static void sinc_downsample_mono(struct s_filter_state *fs, sample *src, int src_len, sample *dst, int dst_len) { int32_t *hc, *he, t, work_len; sample *work_buf, *ss, *sc, *de, *d; work_len = src_len + fs->taps; work_buf = (sample*)block_alloc(work_len * sizeof(sample)); /* Get samples into work_buf */ memcpy(work_buf, fs->hold_buf, fs->hold_bytes); memcpy(work_buf + fs->hold_bytes / sizeof(sample), src, src_len * sizeof(sample)); /* Save last samples in src into hold_buf for next time */ if (src_len >= (int)(fs->hold_bytes / sizeof(sample))) { memcpy(fs->hold_buf, src + src_len - fs->hold_bytes / sizeof(sample), fs->hold_bytes); } else { /* incoming chunk was shorter than hold buffer */ memmove(fs->hold_buf, fs->hold_buf + src_len, fs->hold_bytes - src_len * sizeof(sample)); memcpy(fs->hold_buf + fs->hold_bytes / sizeof(sample) - src_len, src, src_len * sizeof(sample)); } d = dst; de = dst + dst_len; sc = ss = work_buf; he = fs->filter + fs->taps; while (d != de) { t = 0; hc = fs->filter; while(hc < he) { t += (*sc) * (*hc); sc++; hc++; } t = t / SINC_SCALE; clip16(t); *d = (sample) t; d++; ss += fs->scale; sc = ss; } assert(d == dst + dst_len); block_free(work_buf, work_len * sizeof(sample)); xmemchk(); }
/* * free - free a allocated block */ void free(void *bp) { if (bp == NULL) { return; } dbg_printf("want to free %d size block in address 0x%lx\n", (int)block_size(bp), (long)bp); print_heap(); if (block_alloc(bp) == 0) { return; } if (heap_head == NULL) { mm_init(); } mark(bp, block_size(bp), block_prev_alloc(bp), 0); mark(next_block(bp), block_size(next_block(bp)), 0, block_alloc(next_block(bp))); insert_to_list(bp); bp = coalesce(bp); dbg_printf("want return from free %d size block in address 0x%lx\n", (int)block_size(bp), (long)bp); print_heap(); }
static Block block_find(const char *file, int line) { for (Block b = block_list; b; b = b->next) { if (b->line == line && !strcmp(b->file, file) ) { return b; } } return block_alloc(file, line); }
/* * Add a number of blocks to an inode. */ Uint32 increase_inode_size (struct ext2_filesystem_context *context, struct ext2_inode *fp, Uint32 nbytes) { Uint32 block_size = get_block_size( context->sb ); Uint32 initial_size = fp->size; Uint32 logical_block_idx = initial_size / block_size; Uint32 blocks_allocated = 0; Uint32 total_bytes_to_alloc = nbytes; // Account for unused space in the last block. if( initial_size % block_size ) { nbytes -= block_size - (initial_size % block_size); } // Allocate at least nbytes worth of blocks. Because it needs to be // aligned, we'll always round up. Uint32 num_blocks_to_alloc = nbytes / block_size; if( nbytes % block_size ) { num_blocks_to_alloc += 1; } BlockNumber last_block_allocked = 0; for( Uint i = 0; i < num_blocks_to_alloc; ++i ) { last_block_allocked = block_alloc( context ); // Was the alloc successful? if( last_block_allocked ) { blocks_allocated++; Uint32 *inode_block = get_inode_block( fp, logical_block_idx ); *inode_block = last_block_allocked; } else { break; } } // Record the new size of the inode if( blocks_allocated == num_blocks_to_alloc ) { fp->size += total_bytes_to_alloc; } else { fp->size += total_bytes_to_alloc - ((num_blocks_to_alloc - blocks_allocated) * block_size); } return blocks_allocated; }
PUBLIC void * Slab_cache::alloc() // request initialized member from cache { void *unused_block = 0; void *ret; { auto guard = lock_guard(lock); Slab *s = get_available_locked(); if (EXPECT_FALSE(!s)) { guard.reset(); char *m = (char*)block_alloc(_slab_size, _slab_size); Slab *new_slab = 0; if (m) new_slab = new (m + _slab_size - sizeof(Slab)) Slab(_elem_num, _entry_size, m); guard.lock(&lock); // retry gettin a slab that might be allocated by a different // CPU meanwhile s = get_available_locked(); if (!s) { // real OOM if (!m) return 0; _partial.add(new_slab); s = new_slab; } else unused_block = m; } ret = s->alloc(); assert(ret); if (s->is_full()) { cxx::H_list<Slab>::remove(s); _full.add(s); } } if (unused_block) block_free(unused_block, _slab_size); return ret; }
static void vanilla_decoder_output(channel_unit *cu, struct s_pb *out, timestamp_t playout) { const codec_format_t *cf; codec_id_t id; uint32_t data_len; u_char *p, *end; media_data *m; timestamp_t unit_dur; id = codec_get_by_payload(cu->pt); cf = codec_get_format(id); unit_dur = ts_map32(cf->format.sample_rate, codec_get_samples_per_frame(id)); p = cu->data; end = cu->data + cu->data_len; while(p < end) { media_data_create(&m, 1); m->rep[0]->id = id; if (p == cu->data && cf->mean_per_packet_state_size) { /* First unit out of packet may have state */ m->rep[0]->state_len = cf->mean_per_packet_state_size; m->rep[0]->state = (u_char*)block_alloc(m->rep[0]->state_len); memcpy(m->rep[0]->state, p, cf->mean_per_packet_state_size); p += cf->mean_per_packet_state_size; } /* Now do data section */ data_len = codec_peek_frame_size(id, p, (uint16_t)(end - p)); m->rep[0]->data = (u_char*)block_alloc(data_len); m->rep[0]->data_len = (uint16_t)data_len; memcpy(m->rep[0]->data, p, data_len); if (pb_add(out, (u_char *)m, sizeof(media_data), playout) == FALSE) { debug_msg("Vanilla decode failed\n"); media_data_destroy(&m, sizeof(media_data)); return; } p += data_len; playout = ts_add(playout, unit_dur); } assert(p == end); }