/* align start of data portion by rounding up */
addr = (uintptr)b;
addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
b->base = (uchar*)addr;
/* align end of data portion by rounding down */
b->lim = (uchar*)b + msize(b);
addr = (uintptr)b->lim;
addr &= ~(BLOCKALIGN-1);
b->lim = (uchar*)addr;
/*
* Check in a process and wait until successful.
* Can still error out of here, though.
*/
if(up == nil)
panic("ucallocb without up: %#p", getcallerpc(&size));
if((b = _ucallocb(size)) == nil)
panic("ucallocb: no memory for %d bytes", size);
setmalloctag(b, getcallerpc(&size));
/*
* drivers which perform non cache coherent DMA manage their own buffer
* pool of uncached buffers and provide their own free routine.
*/
if(b->free != nil) {
b->free(b);
return;
}
if(b->flag & BINTR) {
ilock(&ucialloc);
ucialloc.bytes -= b->lim - b->base;
iunlock(&ucialloc);
}
/* poison the block in case someone is still holding onto it */
b->next = dead;
b->rp = dead;
b->wp = dead;
b->lim = dead;
b->base = dead;