diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-05-05 13:49:06 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-05-05 13:49:06 +0200 |
| commit | 49dfbee2119ce52600f7acbf61af690d6c9ef16c (patch) | |
| tree | 5cc28c28631fe8ac7736eea8a95223a0814ebcae /src/custommem.c | |
| parent | 3fc3875e82402f788c85db9de16851570d69346f (diff) | |
| download | box64-49dfbee2119ce52600f7acbf61af690d6c9ef16c.tar.gz box64-49dfbee2119ce52600f7acbf61af690d6c9ef16c.zip | |
Improved handling of x86_64 47bits memory (should help #763)
Diffstat (limited to 'src/custommem.c')
| -rw-r--r-- | src/custommem.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/custommem.c b/src/custommem.c index f77b005c..7214aa8c 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -1364,6 +1364,30 @@ static void atfork_child_custommem(void) init_mutexes(); } +void reserveHighMem() +{ + intptr_t cur = 1LL<<47; + mapmem_t* m = mapmem; + while(m && (m->end<cur)) { + m = m->next; + } + while (m) { + uintptr_t addr = 0, end = 0; + if(m->begin>cur) { + void* ret = mmap64((void*)cur, m->begin-cur, 0, MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE|MAP_NORESERVE, -1, 0); + printf_log(LOG_DEBUG, "Reserve %p(0x%zx) => %p (%s)\n", (void*)cur, m->begin-cur, ret, strerror(errno)); + if(ret!=(void*)-1) { + addr = cur; + end = m->begin; + } + } + cur = m->end + 1; + m = m->next; + if(addr) + addMapMem(addr, end); + } +} + void init_custommem_helper(box64context_t* ctx) { (void)ctx; @@ -1392,6 +1416,7 @@ void init_custommem_helper(box64context_t* ctx) mapmem->begin = 0x0; mapmem->end = (uintptr_t)LOWEST - 1; loadProtectionFromMap(); + reserveHighMem(); // check if PageSize is correctly defined if(box64_pagesize != (1<<MEMPROT_SHIFT)) { printf_log(LOG_NONE, "Error: PageSize configuration is wrong: configured with %d, but got %zd\n", 1<<MEMPROT_SHIFT, box64_pagesize); |