ulib Add umallocbig() and ufreebig() for non-fragmented allocations
This commit is contained in:
@ -148,3 +148,18 @@ void *urealloc(void *ptr, size_t newsize) {
|
||||
err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *umallocbig(size_t size) {
|
||||
size_t allocsz = ALIGN_UP(size, 4096);
|
||||
uint8_t *out;
|
||||
int32_t ret = mman_map(NULL, allocsz, MMAN_MAP_PF_RW, 0, &out);
|
||||
if (out == NULL || ret != E_OK) {
|
||||
return NULL;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void ufreebig(void *addr) {
|
||||
if (addr != NULL)
|
||||
mman_unmap(addr);
|
||||
}
|
||||
|
||||
@ -7,5 +7,7 @@
|
||||
void *umalloc(size_t size);
|
||||
void ufree(void *ptr_);
|
||||
void *urealloc(void *ptr, size_t newsize);
|
||||
void *umallocbig(size_t size);
|
||||
void ufreebig(void *addr);
|
||||
|
||||
#endif // ULIB_UMALLOC_UMALLOC_H_
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
(_a > _b ? _a : _b); \
|
||||
})
|
||||
|
||||
#define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
|
||||
|
||||
void quit(void);
|
||||
|
||||
#endif // ULIB_UTIL_UTIL_H_
|
||||
|
||||
Reference in New Issue
Block a user