From 617fd69bcc04eedef76b41e5dba68e9c1e54f890 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 13 Oct 2024 11:19:19 +0200 Subject: [BOX32] Reworked alignment for 32bits stacks --- src/libtools/threads32.c | 1 + src/tools/callback.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libtools/threads32.c b/src/libtools/threads32.c index 0ba81b77..067a4861 100755 --- a/src/libtools/threads32.c +++ b/src/libtools/threads32.c @@ -140,6 +140,7 @@ static void* pthread_routine(void* p) R_EBP = R_ESP; // MOV BP, SP R_ESP -= 32; // guard area R_ESP &=~15; + R_ESP -= 3*4; // prepare alignment Push_32(emu, to_ptrv(et->arg)); PushExit_32(emu); R_EIP = to_ptr(et->fnc); diff --git a/src/tools/callback.c b/src/tools/callback.c index e0df5cfc..3c58bc6e 100644 --- a/src/tools/callback.c +++ b/src/tools/callback.c @@ -25,7 +25,7 @@ uint64_t RunFunction(uintptr_t fnc, int nargs, ...) Push_32(emu, R_RBP); // push ebp R_RBP = R_ESP; // mov ebp, esp - R_ESP -= nargs*4; // need to push in reverse order + R_ESP -= nargs*4+(4-(nargs&3))*4; // need to push in reverse order ptr_t *p = (ptr_t*)from_ptrv(R_ESP); @@ -141,6 +141,7 @@ uint64_t RunFunctionFmt(uintptr_t fnc, const char* fmt, ...) Push_32(emu, R_EBP); // push ebp R_RBP = R_ESP; // mov ebp, esp sizeof_ptr = sizeof(ptr_t); + align = (4-(nargs&3))&3; } else #endif { @@ -336,7 +337,7 @@ uint64_t RunFunctionWithEmu(x64emu_t *emu, int QuitOnLongJump, uintptr_t fnc, in Push_32(emu, R_RBP); // push ebp R_RBP = R_ESP; // mov ebp, esp - R_ESP -= nargs*4; // need to push in reverse order + R_ESP -= nargs*4 + ((4-(nargs&3))&3)*4; // need to push in reverse order ptr_t *p = (ptr_t*)from_ptrv(R_ESP); -- cgit 1.4.1