implement in-place growth of large allocations

This commit is contained in:
Daniel Micay 2018-10-06 10:40:55 -04:00
parent 3a936295f8
commit eb7ced7781
3 changed files with 36 additions and 3 deletions

View file

@ -51,6 +51,17 @@ int memory_protect_ro(void *ptr, size_t size) {
return memory_protect_prot(ptr, size, PROT_READ);
}
int memory_remap(void *old, size_t old_size, size_t new_size) {
void *ptr = mremap(old, old_size, new_size, 0);
if (unlikely(ptr == MAP_FAILED)) {
if (errno != ENOMEM) {
fatal_error("non-ENOMEM mremap failure");
}
return 1;
}
return 0;
}
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)) {