diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-10-13 11:20:25 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-10-13 11:20:25 +0200 |
| commit | d31b9c9caa6b28e5c9246dcffc88367ef9d4e8f6 (patch) | |
| tree | 6bd6fcabb367ee7979ddf1fa0422f0609c81d10a /src | |
| parent | 2670d37542ddb7b03cc4e12b610f2b686562ee58 (diff) | |
| download | box64-d31b9c9caa6b28e5c9246dcffc88367ef9d4e8f6.tar.gz box64-d31b9c9caa6b28e5c9246dcffc88367ef9d4e8f6.zip | |
[BOX32] Allow internal memory to be in 32bits space if needed
Diffstat (limited to 'src')
| -rw-r--r-- | src/emu/x64emu.c | 6 | ||||
| -rw-r--r-- | src/include/debug.h | 26 | ||||
| -rw-r--r-- | src/libtools/libc_net32.c | 4 | ||||
| -rwxr-xr-x | src/libtools/myalign32.c | 4 | ||||
| -rw-r--r-- | src/mallochook.c | 13 |
5 files changed, 33 insertions, 20 deletions
diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c index e6487d5d..26184ea2 100644 --- a/src/emu/x64emu.c +++ b/src/emu/x64emu.c @@ -97,7 +97,7 @@ x64emu_t *NewX64Emu(box64context_t *context, uintptr_t start, uintptr_t stack, i { printf_log(LOG_DEBUG, "Allocate a new X86_64 Emu, with %cIP=%p and Stack=%p/0x%X\n", box64_is32bits?'E':'R', (void*)start, (void*)stack, stacksize); - x64emu_t *emu = (x64emu_t*)box_calloc(1, sizeof(x64emu_t)); + x64emu_t *emu = (x64emu_t*)actual_calloc(1, sizeof(x64emu_t)); internalX64Setup(emu, context, start, stack, stacksize, ownstack); @@ -215,12 +215,12 @@ void FreeX64Emu(x64emu_t **emu) if((*emu)->test.emu) { internalFreeX64((*emu)->test.emu); - box_free((*emu)->test.emu); + actual_free((*emu)->test.emu); (*emu)->test.emu = NULL; } internalFreeX64(*emu); - box_free(*emu); + actual_free(*emu); *emu = NULL; } diff --git a/src/include/debug.h b/src/include/debug.h index a17e76a4..9fb183b4 100644 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -177,4 +177,30 @@ extern char* box_strdup(const char* s); extern char* box_realpath(const char* path, char* ret); #endif +//use actual_XXXX for internal memory that should be in 32bits space when box32 is active +//use box_XXX for internal memory that doesn't need anything special +#ifdef BOX32 +int isCustomAddr(void* p); +void* box32_calloc(size_t n, size_t s); +void* box32_malloc(size_t s); +void* box32_realloc(void* p, size_t s); +void box32_free(void* p); +void* box32_memalign(size_t align, size_t s); +size_t box32_malloc_usable_size(void* p); + +#define actual_calloc(A, B) (box64_is32bits?box32_calloc(A, B):box_calloc(A, B)) +#define actual_malloc(A) (box64_is32bits?box32_malloc(A):box_malloc(A)) +#define actual_realloc(A, B) (box64_is32bits?box32_realloc(A, B):box_realloc(A, B)) +#define actual_free(A) (box64_is32bits?box32_free(A):box_free(A)) +#define actual_memalign(A, B) (box64_is32bits?box32_memalign(A, B):box_memalign(A, B)) +#define actual_malloc_usable_size(A) (box64_is32bits?box32_malloc_usable_size(A):box_malloc_usable_size(A)) +#else +#define actual_calloc(A, B) box_calloc(A, B) +#define actual_malloc(A) box_malloc(A) +#define actual_realloc(A, B) box_realloc(A, B) +#define actual_free(A) box_free(A) +#define actual_memalign(A, B) box_memalign(A, B) +#define actual_malloc_usable_size(A) box_malloc_usable_size(A) +#endif + #endif //__DEBUG_H_ diff --git a/src/libtools/libc_net32.c b/src/libtools/libc_net32.c index 35e1e6a4..c06472fc 100644 --- a/src/libtools/libc_net32.c +++ b/src/libtools/libc_net32.c @@ -84,7 +84,7 @@ EXPORT int my32_getaddrinfo(x64emu_t* emu, void* node, void* service, struct i38 int idx = 0; while(p2) {++idx; p2 = p2->ai_next;} // doing the malloc! - void* r = box_malloc(idx*sizeof(struct i386_addrinfo)+sizeof(void*)); + void* r = actual_malloc(idx*sizeof(struct i386_addrinfo)+sizeof(void*)); ptr_t p3 = to_ptrv(r); *res = p3; p2 = p; @@ -114,7 +114,7 @@ EXPORT void my32_freeaddrinfo(x64emu_t* emu, void* a) { if(!a) return; void* orig = *(void**)(a+sizeof(struct i386_addrinfo)); freeaddrinfo(orig); - box_free(a); + actual_free(a); } EXPORT void* my32_gethostbyname(x64emu_t* emu, const char* a) diff --git a/src/libtools/myalign32.c b/src/libtools/myalign32.c index d16b8f28..7f41aa68 100755 --- a/src/libtools/myalign32.c +++ b/src/libtools/myalign32.c @@ -1494,7 +1494,7 @@ void AlignMsgHdr_32(void* dest, void* dest_iov, void* dest_cmsg, void* source, i struct i386_cmsghdr* cmsg = from_ptrv(s->msg_control); struct cmsghdr* dcmsg = dest_cmsg; while(cmsg) { - dcmsg->cmsg_len = to_ulong(cmsg->cmsg_len); + dcmsg->cmsg_len = from_ulong(cmsg->cmsg_len); dcmsg->cmsg_level = cmsg->cmsg_level; dcmsg->cmsg_type = cmsg->cmsg_type; if(cmsg->cmsg_len) { @@ -1533,7 +1533,7 @@ void UnalignMsgHdr_32(void* dest, void* source) struct i386_cmsghdr* dcmsg = from_ptrv(d->msg_control); struct cmsghdr* scmsg = s->msg_control; while(scmsg) { - dcmsg->cmsg_len = from_ulong(scmsg->cmsg_len); + dcmsg->cmsg_len = to_ulong(scmsg->cmsg_len); dcmsg->cmsg_level = scmsg->cmsg_level; dcmsg->cmsg_type = scmsg->cmsg_type; if(dcmsg->cmsg_len) { diff --git a/src/mallochook.c b/src/mallochook.c index 2aae5ec0..474972ee 100644 --- a/src/mallochook.c +++ b/src/mallochook.c @@ -231,19 +231,6 @@ size_t box32_malloc_usable_size(void* p) else return box_malloc_usable_size(p); } -#define actual_calloc(A, B) box64_is32bits?box32_calloc(A, B):box_calloc(A, B) -#define actual_malloc(A) box64_is32bits?box32_malloc(A):box_malloc(A) -#define actual_realloc(A, B) box64_is32bits?box32_realloc(A, B):box_realloc(A, B) -#define actual_free(A) box64_is32bits?box32_free(A):box_free(A) -#define actual_memalign(A, B) box64_is32bits?box32_memalign(A, B):box_memalign(A, B) -#define actual_malloc_usable_size(A) box64_is32bits?box32_malloc_usable_size(A):box_malloc_usable_size(A) -#else -#define actual_calloc(A, B) box_calloc(A, B) -#define actual_malloc(A) box_malloc(A) -#define actual_realloc(A, B) box_realloc(A, B) -#define actual_free(A) box_free(A) -#define actual_memalign(A, B) box_memalign(A, B) -#define actual_malloc_usable_size(A) box_malloc_usable_size(A) #endif // redefining all libc memory allocation routines |