void umm_extend(FAR void *mem, size_t size, int region) { mm_extend(USR_HEAP, mem, size, region); }
FAR void *mm_sbrk(FAR struct mm_heap_s *heap, intptr_t incr, uintptr_t maxbreak) { uintptr_t brkaddr; uintptr_t allocbase; unsigned int pgincr; size_t bytesize; int err; DEBUGASSERT(incr >= 0); if (incr < 0) { err = ENOSYS; goto errout; } /* Get the current break address (NOTE: assumes region 0). If * the memory manager is uninitialized, mm_brkaddr() will return * zero. */ brkaddr = (uintptr_t)mm_brkaddr(heap, 0); if (incr > 0) { /* Convert the increment to multiples of the page size */ pgincr = MM_NPAGES(incr); /* Check if this increment would exceed the maximum break value */ if ((brkaddr > 0) && ((maxbreak - brkaddr) < (pgincr << MM_PGSHIFT))) { err = ENOMEM; goto errout; } /* Allocate the requested number of pages and map them to the * break address. If we provide a zero brkaddr to pgalloc(), it * will create the first block in the correct virtual address * space and return the start address of that block. */ allocbase = pgalloc(brkaddr, pgincr); if (allocbase == 0) { err = EAGAIN; goto errout; } /* Has the been been initialized? brkaddr will be zero if the * memory manager has not yet been initialized. */ bytesize = pgincr << MM_PGSHIFT; if (brkaddr != 0) { /* No... then initialize it now */ mm_initialize(heap, (FAR void *)allocbase, bytesize); } else { /* Extend the heap (region 0) */ mm_extend(heap, (FAR void *)allocbase, bytesize, 0); } } return (FAR void *)brkaddr; errout: set_errno(err); return (FAR void *)-1; }
void kmm_extend(FAR void *mem, size_t size, int region) { mm_extend(&g_kmmheap, mem, size, region); }