From 9638ce9ec6865137b60ed6d8c3169e34f384019c Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 20 Oct 2015 05:39:02 +0200 Subject: [PATCH] ntdll-Consolidation_Callback: Do not add CFI rules for volatile registers, some other cleanup. --- ...r-function-for-consolidation-callbac.patch | 46 ++++++------------- patches/patchinstall.sh | 2 +- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/patches/ntdll-Consolidation_Callback/0001-ntdll-Use-wrapper-function-for-consolidation-callbac.patch b/patches/ntdll-Consolidation_Callback/0001-ntdll-Use-wrapper-function-for-consolidation-callbac.patch index 2e98127b..3984ed0b 100644 --- a/patches/ntdll-Consolidation_Callback/0001-ntdll-Use-wrapper-function-for-consolidation-callbac.patch +++ b/patches/ntdll-Consolidation_Callback/0001-ntdll-Use-wrapper-function-for-consolidation-callbac.patch @@ -1,33 +1,33 @@ -From dc6ca8f416c82692552e757d045017d72d5b1e9e Mon Sep 17 00:00:00 2001 +From cea14f59b480bf408af07081dba8300cd62efbfd Mon Sep 17 00:00:00 2001 From: Sebastian Lackner -Date: Tue, 20 Oct 2015 02:08:12 +0200 -Subject: ntdll: Use wrapper function for consolidation callback during - unwinding. +Date: Tue, 20 Oct 2015 05:53:46 +0200 +Subject: ntdll: Use wrapper function for consolidate callback on x86_64. +Signed-off-by: Sebastian Lackner --- - dlls/ntdll/signal_x86_64.c | 81 ++++++++++++++++++++++++++++++++++++++++++++-- - 1 file changed, 79 insertions(+), 2 deletions(-) + dlls/ntdll/signal_x86_64.c | 63 ++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c -index 575a770..0211eda 100644 +index 575a770..524de68 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c -@@ -3288,6 +3288,82 @@ static void call_teb_unwind_handler( EXCEPTION_RECORD *rec, DISPATCHER_CONTEXT * +@@ -3288,6 +3288,64 @@ static void call_teb_unwind_handler( EXCEPTION_RECORD *rec, DISPATCHER_CONTEXT * } +/********************************************************************** + * call_consolidate_callback + * -+ * Wrapper function to call a consolidate callback from a fake unwind frame. ++ * Wrapper function to call a consolidate callback from a fake frame. + * If the callback executes RtlUnwindEx (like for example done in C++ handlers), + * we have to skip all frames which were already processed. To do that we + * trick the unwinding functions into thinking the call came from somewhere -+ * else. All CFA instructions are either DW_CFA_def_cfa_expression or ++ * else. All CFI instructions are either DW_CFA_def_cfa_expression or + * DW_CFA_expression, and the expressions have the following format: + * + * DW_OP_breg6; sleb128 0x10 | Load %rbp + 0x10 -+ * DW_OP_deref | Calculate *(%rbp + 0x10) == context ++ * DW_OP_deref | Get *(%rbp + 0x10) == context + * DW_OP_plus_uconst; uleb128 | Add offset to get struct member + * [DW_OP_deref] | Dereference, only for CFA + */ @@ -42,27 +42,17 @@ index 575a770..0211eda 100644 + __ASM_CFI(".cfi_def_cfa_register %rbp\n\t") + "subq $0x20,%rsp\n\t" + "movq %rcx,0x10(%rbp)\n\t" -+ __ASM_CFI(".cfi_escape 0x0a\n\t") /* DW_CFA_remember_state */ -+ /* FIXME: should we also restore %rax, %rcx, %rdx and %r8 ? */ ++ __ASM_CFI(".cfi_remember_state\n\t") + __ASM_CFI(".cfi_escape 0x0f,0x07,0x76,0x10,0x06,0x23,0x98,0x01,0x06\n\t") /* CFA */ + __ASM_CFI(".cfi_escape 0x10,0x03,0x06,0x76,0x10,0x06,0x23,0x90,0x01\n\t") /* %rbx */ + __ASM_CFI(".cfi_escape 0x10,0x04,0x06,0x76,0x10,0x06,0x23,0xa8,0x01\n\t") /* %rsi */ + __ASM_CFI(".cfi_escape 0x10,0x05,0x06,0x76,0x10,0x06,0x23,0xb0,0x01\n\t") /* %rdi */ + __ASM_CFI(".cfi_escape 0x10,0x06,0x06,0x76,0x10,0x06,0x23,0xa0,0x01\n\t") /* %rbp */ -+ __ASM_CFI(".cfi_escape 0x10,0x09,0x06,0x76,0x10,0x06,0x23,0xc0,0x01\n\t") /* %r9 */ -+ __ASM_CFI(".cfi_escape 0x10,0x0a,0x06,0x76,0x10,0x06,0x23,0xc8,0x01\n\t") /* %r10 */ -+ __ASM_CFI(".cfi_escape 0x10,0x0b,0x06,0x76,0x10,0x06,0x23,0xd0,0x01\n\t") /* %r11 */ + __ASM_CFI(".cfi_escape 0x10,0x0c,0x06,0x76,0x10,0x06,0x23,0xd8,0x01\n\t") /* %r12 */ + __ASM_CFI(".cfi_escape 0x10,0x0d,0x06,0x76,0x10,0x06,0x23,0xe0,0x01\n\t") /* %r13 */ + __ASM_CFI(".cfi_escape 0x10,0x0e,0x06,0x76,0x10,0x06,0x23,0xe8,0x01\n\t") /* %r14 */ + __ASM_CFI(".cfi_escape 0x10,0x0f,0x06,0x76,0x10,0x06,0x23,0xf0,0x01\n\t") /* %r15 */ + __ASM_CFI(".cfi_escape 0x10,0x10,0x06,0x76,0x10,0x06,0x23,0xf8,0x01\n\t") /* %rip */ -+ __ASM_CFI(".cfi_escape 0x10,0x11,0x06,0x76,0x10,0x06,0x23,0xa0,0x03\n\t") /* %xmm0 */ -+ __ASM_CFI(".cfi_escape 0x10,0x12,0x06,0x76,0x10,0x06,0x23,0xb0,0x03\n\t") /* %xmm1 */ -+ __ASM_CFI(".cfi_escape 0x10,0x13,0x06,0x76,0x10,0x06,0x23,0xc0,0x03\n\t") /* %xmm2 */ -+ __ASM_CFI(".cfi_escape 0x10,0x14,0x06,0x76,0x10,0x06,0x23,0xd0,0x03\n\t") /* %xmm3 */ -+ __ASM_CFI(".cfi_escape 0x10,0x15,0x06,0x76,0x10,0x06,0x23,0xe0,0x03\n\t") /* %xmm4 */ -+ __ASM_CFI(".cfi_escape 0x10,0x16,0x06,0x76,0x10,0x06,0x23,0xf0,0x03\n\t") /* %xmm5 */ + __ASM_CFI(".cfi_escape 0x10,0x17,0x06,0x76,0x10,0x06,0x23,0x80,0x04\n\t") /* %xmm6 */ + __ASM_CFI(".cfi_escape 0x10,0x18,0x06,0x76,0x10,0x06,0x23,0x90,0x04\n\t") /* %xmm7 */ + __ASM_CFI(".cfi_escape 0x10,0x19,0x06,0x76,0x10,0x06,0x23,0xa0,0x04\n\t") /* %xmm8 */ @@ -73,17 +63,9 @@ index 575a770..0211eda 100644 + __ASM_CFI(".cfi_escape 0x10,0x1e,0x06,0x76,0x10,0x06,0x23,0xf0,0x04\n\t") /* %xmm13 */ + __ASM_CFI(".cfi_escape 0x10,0x1f,0x06,0x76,0x10,0x06,0x23,0x80,0x05\n\t") /* %xmm14 */ + __ASM_CFI(".cfi_escape 0x10,0x20,0x06,0x76,0x10,0x06,0x23,0x90,0x05\n\t") /* %xmm15 */ -+ __ASM_CFI(".cfi_escape 0x10,0x21,0x06,0x76,0x10,0x06,0x23,0xa0,0x02\n\t") /* %st0 */ -+ __ASM_CFI(".cfi_escape 0x10,0x22,0x06,0x76,0x10,0x06,0x23,0xb0,0x02\n\t") /* %st1 */ -+ __ASM_CFI(".cfi_escape 0x10,0x23,0x06,0x76,0x10,0x06,0x23,0xc0,0x02\n\t") /* %st2 */ -+ __ASM_CFI(".cfi_escape 0x10,0x24,0x06,0x76,0x10,0x06,0x23,0xd0,0x02\n\t") /* %st3 */ -+ __ASM_CFI(".cfi_escape 0x10,0x25,0x06,0x76,0x10,0x06,0x23,0xe0,0x02\n\t") /* %st4 */ -+ __ASM_CFI(".cfi_escape 0x10,0x26,0x06,0x76,0x10,0x06,0x23,0xf0,0x02\n\t") /* %st5 */ -+ __ASM_CFI(".cfi_escape 0x10,0x27,0x06,0x76,0x10,0x06,0x23,0x80,0x03\n\t") /* %st6 */ -+ __ASM_CFI(".cfi_escape 0x10,0x28,0x06,0x76,0x10,0x06,0x23,0x90,0x03\n\t") /* %st7 */ + "movq %r8,%rcx\n\t" + "callq *%rdx\n\t" -+ __ASM_CFI(".cfi_escape 0x0b\n\t") /* DW_CFA_restore_state */ ++ __ASM_CFI(".cfi_restore_state\n\t") + "movq %rbp,%rsp\n\t" + __ASM_CFI(".cfi_def_cfa_register %rsp\n\t") + "popq %rbp\n\t" @@ -95,7 +77,7 @@ index 575a770..0211eda 100644 /******************************************************************* * RtlUnwindEx (NTDLL.@) */ -@@ -3474,8 +3550,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec +@@ -3474,8 +3532,9 @@ void WINAPI RtlUnwindEx( PVOID end_frame, PVOID target_ip, EXCEPTION_RECORD *rec else if (rec->ExceptionCode == STATUS_UNWIND_CONSOLIDATE && rec->NumberParameters >= 1) { PVOID (CALLBACK *consolidate)(EXCEPTION_RECORD *) = (void *)rec->ExceptionInformation[0]; diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index d2676d07..b1fcbecb 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -3932,7 +3932,7 @@ fi if test "$enable_ntdll_Consolidation_Callback" -eq 1; then patch_apply ntdll-Consolidation_Callback/0001-ntdll-Use-wrapper-function-for-consolidation-callbac.patch ( - echo '+ { "Sebastian Lackner", "ntdll: Use wrapper function for consolidation callback during unwinding.", 1 },'; + echo '+ { "Sebastian Lackner", "ntdll: Use wrapper function for consolidate callback on x86_64.", 1 },'; ) >> "$patchlist" fi