wrap more memory mapping implementation details

This commit is contained in:
Daniel Micay
2018-08-29 10:52:10 -04:00
parent 1cb28531a8
commit d779d41721
3 changed files with 17 additions and 9 deletions

View File

@ -24,7 +24,7 @@ int memory_unmap(void *ptr, size_t size) {
return ret;
}
int memory_protect(void *ptr, size_t size, int prot) {
static int memory_protect_prot(void *ptr, size_t size, int prot) {
int ret = mprotect(ptr, size, prot);
if (unlikely(ret) && errno != ENOMEM) {
fatal_error("non-ENOMEM mprotect failure");
@ -32,6 +32,14 @@ int memory_protect(void *ptr, size_t size, int prot) {
return ret;
}
int memory_protect_rw(void *ptr, size_t size) {
return memory_protect_prot(ptr, size, PROT_READ|PROT_WRITE);
}
int memory_protect_ro(void *ptr, size_t size) {
return memory_protect_prot(ptr, size, PROT_READ);
}
int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size) {
void *ptr = mremap(old, old_size, new_size, MREMAP_MAYMOVE|MREMAP_FIXED, new);
if (unlikely(ptr == MAP_FAILED)) {