diff --git a/memory.c b/memory.c index ac423d0..ddfb593 100644 --- a/memory.c +++ b/memory.c @@ -16,6 +16,17 @@ void *memory_map(size_t size) { 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 ret = munmap(ptr, size); if (unlikely(ret) && errno != ENOMEM) { diff --git a/memory.h b/memory.h index 76c0c71..5a3273d 100644 --- a/memory.h +++ b/memory.h @@ -4,6 +4,7 @@ #include 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_protect_rw(void *ptr, size_t size); int memory_protect_ro(void *ptr, size_t size);