From: Andrew Wesie Subject: [07/23] ntdll: Save rdi and rsi registers in raise_func_trampoline. Message-Id: <1479062123-21238-8-git-send-email-awesie@gmail.com> Date: Sun, 13 Nov 2016 12:35:07 -0600 In-Reply-To: <1479062123-21238-1-git-send-email-awesie@gmail.com> References: <1479062123-21238-1-git-send-email-awesie@gmail.com> On Windows, RDI and RSI are callee-saved registers, but on Linux they are caller-saved registers. Fix raise_func_trampoline and setup_exception to properly save them. Signed-off-by: Andrew Wesie --- dlls/ntdll/signal_x86_64.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index e2440a6..d493027 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -2067,9 +2067,11 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) extern void raise_func_trampoline( EXCEPTION_RECORD *rec, CONTEXT *context, raise_func func ); __ASM_GLOBAL_FUNC( raise_func_trampoline, __ASM_CFI(".cfi_signal_frame\n\t") - __ASM_CFI(".cfi_def_cfa %rbp,144\n\t") /* red zone + rip + rbp */ - __ASM_CFI(".cfi_rel_offset %rip,8\n\t") - __ASM_CFI(".cfi_rel_offset %rbp,0\n\t") + __ASM_CFI(".cfi_def_cfa %rbp,160\n\t") /* red zone + rip + rbp + rdi + rsi */ + __ASM_CFI(".cfi_rel_offset %rip,24\n\t") + __ASM_CFI(".cfi_rel_offset %rbp,16\n\t") + __ASM_CFI(".cfi_rel_offset %rdi,8\n\t") + __ASM_CFI(".cfi_rel_offset %rsi,0\n\t") "call *%rdx\n\t" "int $3") @@ -2086,6 +2088,8 @@ static EXCEPTION_RECORD *setup_exception( ucontext_t *sigcontext, raise_func fun { CONTEXT context; EXCEPTION_RECORD rec; + ULONG64 rsi; + ULONG64 rdi; ULONG64 rbp; ULONG64 rip; ULONG64 red_zone[16]; @@ -2155,6 +2159,8 @@ static EXCEPTION_RECORD *setup_exception( ucontext_t *sigcontext, raise_func fun rsp_ptr = (ULONG64 *)RSP_sig(sigcontext) - 16; *(--rsp_ptr) = RIP_sig(sigcontext); *(--rsp_ptr) = RBP_sig(sigcontext); + *(--rsp_ptr) = RDI_sig(sigcontext); + *(--rsp_ptr) = RSI_sig(sigcontext); /* now modify the sigcontext to return to the raise function */ RIP_sig(sigcontext) = (ULONG_PTR)raise_func_trampoline; -- 2.7.4