add mmap MAP_FIXED wrapper for dropping slabs
parent
0e2f3d1015
commit
00b2613e16
11
memory.c
11
memory.c
|
@ -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) {
|
||||||
|
|
1
memory.h
1
memory.h
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue