void pmem_add(phys_addr_t start, size_t length) { pmem_region_t* reg; recheck: reg = pmem_region_head; while(reg) { if(start >= reg->start && start < (reg->start + reg->length)) { /* start within this region */ if((start + length) <= (reg->start + reg->length)) { /* end withing this section, so completely with us already */ return; } length -= (reg->start + reg->length) - start; start = reg->start + reg->length; goto recheck; } if((start + length) > reg->start && (start + length) < (reg->start + reg->length)) { /* end within this region */ if(start >= reg->start) { /* start too, so no more left over. */ return; } length = (reg->start - start); goto recheck; } reg = reg->next; } /* we have a checked region here, with correct start and end. * now allocate the required management structures, etc. */ pmem_region_t* region = (pmem_region_t*)kheap_alloc(sizeof(pmem_region_t)); bitmap_t* bmap = bmap_new(PMEM_PAGES(length)); if(!region || !bmap) { error("not enough memory to allocate memory management structures!\n"); if(region) kheap_free(region); if(bmap) kheap_free(bmap); return; } region->start = start; region->length = length; region->bmap = bmap; region->next = NULL; pmem_region_tail->next = region; pmem_region_tail = region; }
thread_t* thr_delete(thread_t* thr) { if(thr->context) { kheap_free(thr->context); } if(thr->stack) { stka_free(thr->parent->stka, thr->stack); } if(thr) { kheap_free(thr); } return NULL; }
/* deallocate a chunk of memory */ void nf_free(void *ptr) { kheap_free(ptr); }