diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2025-09-10 11:28:59 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2025-09-10 11:28:59 +0200 |
| commit | d509261f81553a6b09ea219e1dbde9775df9a63e (patch) | |
| tree | 1dcb50b1230d1eb7b742dbcb85366b859d225c99 | |
| parent | 7862e8a3d55e201d2410edc68f1abad6bc586cbd (diff) | |
| download | box64-d509261f81553a6b09ea219e1dbde9775df9a63e.tar.gz box64-d509261f81553a6b09ea219e1dbde9775df9a63e.zip | |
[BOX32] Some improvment to box32 memory managment and thread handling
| -rw-r--r-- | src/custommem.c | 15 | ||||
| -rwxr-xr-x | src/libtools/threads32.c | 12 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/custommem.c b/src/custommem.c index 60e0549e..38caaa03 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -420,6 +420,7 @@ void testAllBlocks() // just silently skip blocks with 0 size, as they are not finished and so might be not coherent if(p_blocks[i].size) { int is32bits = p_blocks[i].is32bits; + if(box64_is32bits && !is32bits && p_blocks[i].block<(void*)0x100000000LL) printf_log(LOG_NONE, "Warning, p_block[%d] is 64bits but in 32bits address space: %p (type=%d)\n", i, p_blocks[i].block, p_blocks[i].type); if(is32bits) ++n_blocks32; if((p_blocks[i].type==BTYPE_LIST) && !printBlockCoherent(i)) printBlock(p_blocks[i].block, p_blocks[i].first, p_blocks[i].size); @@ -1148,6 +1149,7 @@ void* internal_customMemAligned(size_t align, size_t size, int is32bits) #ifdef TRACE_MEMSTAT printf_log(LOG_INFO, "Custommem: Failed to aligned alloc 32bits: allocation %p-%p for LIST Alloc p_blocks[%d]\n", p, p+allocsize, i); #endif + p_blocks[i].is32bits = 0; p_blocks[i].maxfree = allocsize - sizeof(blockmark_t)*2; return NULL; } @@ -1251,7 +1253,7 @@ void* box32_dynarec_mmap(size_t size, int fd, off_t offset) uint32_t map_flags = ((fd==-1)?MAP_ANONYMOUS:0) | MAP_PRIVATE; //printf_log(LOG_INFO, "BOX32: Error allocating Dynarec memory: %s\n", "fallback to internal mmap"); void* ret = InternalMmap(box64_isAddressSpace32?NULL:(void*)0x100000000ULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, map_flags, fd, offset); - printf_log(LOG_INFO, "fallback on box32_dynarec_mmap: %p\n", ret); + //printf_log(LOG_INFO, "fallback on box32_dynarec_mmap: %p\n", ret); return ret; } @@ -2427,7 +2429,18 @@ void loadProtectionFromMap() (void)ret; char r, w, x; uintptr_t s, e; + uintptr_t prev = 0; if(sscanf(buf, "%lx-%lx %c%c%c", &s, &e, &r, &w, &x)==5) { + uint32_t val; + uintptr_t endb; + if(prev!=s && rb_get_end(mapallmem, prev, &val, &endb)) { + if(endb>s) endb = s; + if(val==MEM_EXTERNAL) { + // free the place, it's not longer taken + rb_unset(mapallmem, prev, endb); + } + } + prev = e; int prot = ((r=='r')?PROT_READ:0)|((w=='w')?PROT_WRITE:0)|((x=='x')?PROT_EXEC:0); allocProtection(s, e-s, prot); if(!pbrk && strstr(buf, "[heap]")) diff --git a/src/libtools/threads32.c b/src/libtools/threads32.c index 318db0d2..2c36a532 100755 --- a/src/libtools/threads32.c +++ b/src/libtools/threads32.c @@ -181,6 +181,8 @@ EXPORT int my32_pthread_create(x64emu_t *emu, void* t, void* attr, void* start_r size_t attr_stacksize; int own; void* stack = NULL; + pthread_attr_t* my_attr = NULL; + pthread_attr_t actual_attr; if(attr) { size_t stsize; @@ -193,6 +195,12 @@ EXPORT int my32_pthread_create(x64emu_t *emu, void* t, void* attr, void* start_r stacksize = stsize; if(stacksize<minsize) // emu and all needs some stack space, don't go too low pthread_attr_setstacksize(get_attr(attr), minsize); + if(stacksize>1*1024*1024) + pthread_attr_setstacksize(get_attr(attr), 1*1024*1024); + } else { + my_attr = &actual_attr; + pthread_attr_init(my_attr); + pthread_attr_setstacksize(my_attr, 1*1024*1024); } if(GetStackSize((uintptr_t)attr, &attr_stack, &attr_stacksize)) { @@ -242,8 +250,10 @@ EXPORT int my32_pthread_create(x64emu_t *emu, void* t, void* attr, void* start_r } #endif // create thread - return pthread_create((pthread_t*)t, get_attr(attr), + int ret = pthread_create((pthread_t*)t, my_attr?my_attr:get_attr(attr), pthread_routine, et); + if(my_attr) pthread_attr_destroy(my_attr); + return ret; } EXPORT int my32_pthread_detach(x64emu_t* emu, pthread_t p) |