mirror of
https://github.com/jrcutler/threadless.io.git
synced 2024-07-07 10:35:49 +00:00
Update mmap_allocate() to shrink mappings with munmap() (when mremap() doesn't exist)
This commit is contained in:
parent
b66c589d85
commit
31633b0b49
@ -57,6 +57,7 @@ static void *do_mremap(void *memory, size_t old_size, size_t new_size)
|
|||||||
#ifdef HAVE_MREMAP
|
#ifdef HAVE_MREMAP
|
||||||
new_memory = mremap(memory, old_size, new_size, MREMAP_MAYMOVE);
|
new_memory = mremap(memory, old_size, new_size, MREMAP_MAYMOVE);
|
||||||
#else
|
#else
|
||||||
|
if (old_size < new_size) {
|
||||||
/* slow remap: mmap + copy + munmap */
|
/* slow remap: mmap + copy + munmap */
|
||||||
size_t copy_size = (new_size < old_size) ? new_size : old_size;
|
size_t copy_size = (new_size < old_size) ? new_size : old_size;
|
||||||
new_memory = do_mmap(new_size);
|
new_memory = do_mmap(new_size);
|
||||||
@ -64,6 +65,11 @@ static void *do_mremap(void *memory, size_t old_size, size_t new_size)
|
|||||||
memcpy(new_memory, memory, copy_size);
|
memcpy(new_memory, memory, copy_size);
|
||||||
(void) munmap(memory, old_size);
|
(void) munmap(memory, old_size);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* shrink via munmap */
|
||||||
|
(void) munmap((char *)memory + new_size, old_size - new_size);
|
||||||
|
new_memory = memory;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return new_memory;
|
return new_memory;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user