1 other thing to try is the pop's, try:
etc
if all else fails you can always manually solve this by replacing the pop's with something like
Code:
mov rdi, dword ptr [rsp+4]
mov rsi, dword ptr [rsp]
add rsp, 8
EDIT
but actually hehe, i'm tired, anyways you just need to keep edi etc so in this case we can solve it easily..
your code:
Code:
asm
push esi
push edi
sub esp, StkUsage // make room on stack
mov edi, esp // set destination of mem copy, it is the stack
mov esi, StkAdr // set source of mem copy, it is Addr(ExtStk)
mov ecx, StkUsage // prepare ecx to copy StkUsage bytes
shr ecx, 2 // divide by 4 to perform DWORD-copy (is faster)
//add edi, StkUsage;
//sub edi,4
//add esi, StkUsage;
//sub esi,4
cld // choose copy direction
rep movsd // do DWORD-copy
cmp RegCall, true
jnz @@EXEC
mov EAX, _EAX
mov EDX, _EDX
mov ECX, _ECX
@@EXEC:
call Adr // execute the external function
// esp is restored by the external function
// (except for cdecl-convention)
pop edi // restore edi...
pop esi // ...and esi
mov _EAX,eax
end; // asm
so try this:
Code:
asm
push rsi
push rdi
sub rsp, StkUsage // make room on stack
mov rdi, rsp // set destination of mem copy, it is the stack
mov rsi, StkAdr // set source of mem copy, it is Addr(ExtStk)
mov rcx, StkUsage // prepare ecx to copy StkUsage bytes
shr rcx, 4 // divide by 8 to perform QWORD-copy (is faster)
cld // choose copy direction
rep movsq // do QWORD-copy
cmp RegCall, true
jnz @@EXEC
mov RAX, dword _EAX
mov RDX, dword _EDX
mov RCX, dword _ECX
@@EXEC:
call Adr // execute the external function
// esp is restored by the external function
// (except for cdecl-convention)
pop rdi // restore edi...
pop rsi // ...and esi
mov _EAX,eax
end; // asm
for 64-bit you want to change _EAX etc to int64 and then remove dword casts. Note that this is only valid for fastcall, stdcall would be a big trouble for stack alignment across 32/64 bit
Bookmarks