* only adjust the stack pointer of the signal context if it's aligned (it

may still be unaligned in case the signal got raised in a leaf function)

git-svn-id: trunk@40771 -
This commit is contained in:
Jonas Maebe 2019-01-05 16:26:26 +00:00
parent e3126bdf3d
commit f20e7bc193

View File

@ -80,9 +80,11 @@ begin
sigcontext^.uc_mcontext^.ts.rdi:=res;
sigcontext^.uc_mcontext^.ts.rsi:=sigcontext^.uc_mcontext^.ts.rip;
sigcontext^.uc_mcontext^.ts.rdx:=sigcontext^.uc_mcontext^.ts.rbp;
{ the ABI expects the stack pointer to be 4 bytes off alignment }
{ due to the return address which has been pushed }
dec(sigcontext^.uc_mcontext^.ts.rsp,sizeof(pointer));
{ the ABI expects the stack pointer to be 8 bytes off alignment
due to the return address which has been pushed -- but take into account
that rsp may already unaligned in case of a leaf routine }
if (sigcontext^.uc_mcontext^.ts.rsp and 15)=0 then
dec(sigcontext^.uc_mcontext^.ts.rsp,sizeof(pointer));
{ return to run time error handler }
sigcontext^.uc_mcontext^.ts.rip:=ptruint(@HandleErrorAddrFrame);
{$else cpu64}
@ -90,9 +92,11 @@ begin
sigcontext^.uc_mcontext^.ts.eax:=res;
sigcontext^.uc_mcontext^.ts.edx:=sigcontext^.uc_mcontext^.ts.eip;
sigcontext^.uc_mcontext^.ts.ecx:=sigcontext^.uc_mcontext^.ts.ebp;
{ the ABI expects the stack pointer to be 8 bytes off alignment }
{ due to the return address which has been pushed }
dec(sigcontext^.uc_mcontext^.ts.esp,sizeof(pointer));
{ the ABI expects the stack pointer to be 4 bytes off alignment }
{ due to the return address which has been pushed -- but take into account
that esp may already unaligned in case of a leaf routine }
if (sigcontext^.uc_mcontext^.ts.rsp and 15)=0 then
dec(sigcontext^.uc_mcontext^.ts.esp,sizeof(pointer));
{ return to run time error handler }
sigcontext^.uc_mcontext^.ts.eip:=ptruint(@HandleErrorAddrFrame);
{$endif cpu64}