add mmap MAP_FIXED wrapper for dropping slabs

This commit is contained in:
Daniel Micay 2018-08-29 13:04:52 -04:00
parent 0e2f3d1015
commit 00b2613e16
2 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,17 @@ void *memory_map(size_t size) {
return p; return p;
} }
int memory_map_fixed(void *ptr, size_t size) {
void *p = mmap(ptr, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, -1, 0);
if (unlikely(p == MAP_FAILED)) {
if (errno != ENOMEM) {
fatal_error("non-ENOMEM mmap failure");
}
return 1;
}
return 0;
}
int memory_unmap(void *ptr, size_t size) { int memory_unmap(void *ptr, size_t size) {
int ret = munmap(ptr, size); int ret = munmap(ptr, size);
if (unlikely(ret) && errno != ENOMEM) { if (unlikely(ret) && errno != ENOMEM) {

View File

@ -4,6 +4,7 @@
#include <stddef.h> #include <stddef.h>
void *memory_map(size_t size); void *memory_map(size_t size);
int memory_map_fixed(void *ptr, size_t size);
int memory_unmap(void *ptr, size_t size); int memory_unmap(void *ptr, size_t size);
int memory_protect_rw(void *ptr, size_t size); int memory_protect_rw(void *ptr, size_t size);
int memory_protect_ro(void *ptr, size_t size); int memory_protect_ro(void *ptr, size_t size);