add wrapper for mremap with sanity check

This commit is contained in:
Daniel Micay 2018-08-29 10:43:54 -04:00
parent 5bc6820c24
commit 1cb28531a8
3 changed files with 14 additions and 2 deletions

View file

@ -31,3 +31,14 @@ int memory_protect(void *ptr, size_t size, int prot) {
}
return ret;
}
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)) {
if (errno != ENOMEM) {
fatal_error("non-ENOMEM mremap failure");
}
return 1;
}
return 0;
}