mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-07 07:38:04 -04:00
retry with mmap when mremap fails
This commit is contained in:
parent
e7f580052c
commit
448ec62f85
1 changed files with 12 additions and 2 deletions
14
linux/plat.c
14
linux/plat.c
|
@ -216,8 +216,18 @@ void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
|
ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
|
||||||
if (ret == MAP_FAILED)
|
if (ret == MAP_FAILED) {
|
||||||
return NULL;
|
fprintf(stderr, "mremap %p %zd %zd: ",
|
||||||
|
ptr, oldsize, newsize);
|
||||||
|
perror(NULL);
|
||||||
|
// might be because huge pages can't be remapped,
|
||||||
|
// just make a new mapping
|
||||||
|
ret = plat_mmap(0, newsize, 0, 0);
|
||||||
|
if (ret == MAP_FAILED)
|
||||||
|
return NULL;
|
||||||
|
memcpy(ret, ptr, oldsize);
|
||||||
|
munmap(ptr, oldsize);
|
||||||
|
}
|
||||||
if (ret != ptr)
|
if (ret != ptr)
|
||||||
printf("warning: mremap moved: %p -> %p\n", ptr, ret);
|
printf("warning: mremap moved: %p -> %p\n", ptr, ret);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue