From 5d073d3f400fef9fcd7a7fab40eaccd7e2cb7d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Wed, 29 Aug 2018 17:48:11 +0200 Subject: [PATCH] vrclient: Add CFI directives to asm functions. Fixes backtraces. --- vrclient_x64/gen_wrapper.py | 2 ++ vrclient_x64/vrclient_x64/cxx.h | 2 ++ vrclient_x64/vrclient_x64/flatapi.c | 36 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/vrclient_x64/gen_wrapper.py b/vrclient_x64/gen_wrapper.py index ac74f2fd..6a4f71b1 100755 --- a/vrclient_x64/gen_wrapper.py +++ b/vrclient_x64/gen_wrapper.py @@ -664,6 +664,7 @@ def generate_x64_call_flat_method(cfile, param_count, has_floats, is_4th_float): l(r"__ASM_GLOBAL_FUNC(%s," % name) l(r' "subq $0x%x, %%rsp\n\t"' % stack_space); + l(r' __ASM_CFI(".cfi_adjust_cfa_offset %d\n\t")' % stack_space) if is_4th_float: l(r' "movq %%xmm3, 0x%x(%%rsp)\n\t"' % dst_offset) @@ -689,6 +690,7 @@ def generate_x64_call_flat_method(cfile, param_count, has_floats, is_4th_float): l(r' "call *%r11\n\t"') l(r' "addq $0x%x, %%rsp\n\t"' % stack_space); + l(r' __ASM_CFI(".cfi_adjust_cfa_offset -%d\n\t")' % stack_space) l(r' "ret");') l(r'extern void %s(void);' % name); diff --git a/vrclient_x64/vrclient_x64/cxx.h b/vrclient_x64/vrclient_x64/cxx.h index 322cdec4..ef46ded9 100644 --- a/vrclient_x64/vrclient_x64/cxx.h +++ b/vrclient_x64/vrclient_x64/cxx.h @@ -19,6 +19,8 @@ /* Copied from dlls/msvcrt/cxx.h */ #undef __thiscall +#define __ASM_CFI(str) str + #ifdef __APPLE__ # define __ASM_NAME(name) "_" name # define FORCE_ALIGN diff --git a/vrclient_x64/vrclient_x64/flatapi.c b/vrclient_x64/vrclient_x64/flatapi.c index d91604b5..f7e4d510 100644 --- a/vrclient_x64/vrclient_x64/flatapi.c +++ b/vrclient_x64/vrclient_x64/flatapi.c @@ -37,6 +37,7 @@ extern void call_flat_method_f(void); __ASM_GLOBAL_FUNC(call_flat_method4, "subq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 40\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq %r8, %r9\n\t" // shift over arguments "movq %rdx, %r8\n\t" @@ -44,11 +45,13 @@ __ASM_GLOBAL_FUNC(call_flat_method4, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -40\n\t") "ret"); extern void call_flat_method4(void); __ASM_GLOBAL_FUNC(call_flat_method5, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -58,11 +61,13 @@ __ASM_GLOBAL_FUNC(call_flat_method5, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method5(void); __ASM_GLOBAL_FUNC(call_flat_method6, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -74,11 +79,13 @@ __ASM_GLOBAL_FUNC(call_flat_method6, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method6(void); __ASM_GLOBAL_FUNC(call_flat_method7, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -92,11 +99,13 @@ __ASM_GLOBAL_FUNC(call_flat_method7, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method7(void); __ASM_GLOBAL_FUNC(call_flat_method8, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -112,11 +121,13 @@ __ASM_GLOBAL_FUNC(call_flat_method8, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method8(void); __ASM_GLOBAL_FUNC(call_flat_method9, "subq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 88\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x80(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -134,11 +145,13 @@ __ASM_GLOBAL_FUNC(call_flat_method9, "movq %r10, %rcx\n\t" // add This pointer "call *%r11\n\t" "addq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -88\n\t") "ret"); extern void call_flat_method9(void); __ASM_GLOBAL_FUNC(call_flat_method4_f, "subq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 40\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq %r8, %r9\n\t" // shift over arguments "movq %rdx, %r8\n\t" @@ -149,11 +162,13 @@ __ASM_GLOBAL_FUNC(call_flat_method4_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -40\n\t") "ret"); extern void call_flat_method4_f(void); __ASM_GLOBAL_FUNC(call_flat_method4_f_f, "subq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 40\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq %r8, %r9\n\t" // shift over arguments "movq %rdx, %r8\n\t" @@ -164,11 +179,13 @@ __ASM_GLOBAL_FUNC(call_flat_method4_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x28, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -40\n\t") "ret"); extern void call_flat_method4_f_f(void); __ASM_GLOBAL_FUNC(call_flat_method5_f, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -181,11 +198,13 @@ __ASM_GLOBAL_FUNC(call_flat_method5_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method5_f(void); __ASM_GLOBAL_FUNC(call_flat_method5_f_f, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -198,11 +217,13 @@ __ASM_GLOBAL_FUNC(call_flat_method5_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method5_f_f(void); __ASM_GLOBAL_FUNC(call_flat_method6_f, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -217,11 +238,13 @@ __ASM_GLOBAL_FUNC(call_flat_method6_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method6_f(void); __ASM_GLOBAL_FUNC(call_flat_method6_f_f, "subq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 56\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq 0x60(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -236,11 +259,13 @@ __ASM_GLOBAL_FUNC(call_flat_method6_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x38, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -56\n\t") "ret"); extern void call_flat_method6_f_f(void); __ASM_GLOBAL_FUNC(call_flat_method7_f, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -257,11 +282,13 @@ __ASM_GLOBAL_FUNC(call_flat_method7_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method7_f(void); __ASM_GLOBAL_FUNC(call_flat_method7_f_f, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -278,11 +305,13 @@ __ASM_GLOBAL_FUNC(call_flat_method7_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method7_f_f(void); __ASM_GLOBAL_FUNC(call_flat_method8_f, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -301,11 +330,13 @@ __ASM_GLOBAL_FUNC(call_flat_method8_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method8_f(void); __ASM_GLOBAL_FUNC(call_flat_method8_f_f, "subq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 72\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq 0x70(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -324,11 +355,13 @@ __ASM_GLOBAL_FUNC(call_flat_method8_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x48, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -72\n\t") "ret"); extern void call_flat_method8_f_f(void); __ASM_GLOBAL_FUNC(call_flat_method9_f, "subq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 88\n\t") "movq %r9, 0x20(%rsp)\n\t" "movq 0x80(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -349,11 +382,13 @@ __ASM_GLOBAL_FUNC(call_flat_method9_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -88\n\t") "ret"); extern void call_flat_method9_f(void); __ASM_GLOBAL_FUNC(call_flat_method9_f_f, "subq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 88\n\t") "movq %xmm3, 0x20(%rsp)\n\t" "movq 0x80(%rsp), %rax\n\t" // copy parameter "movq %rax, 0x28(%rsp)\n\t" @@ -374,6 +409,7 @@ __ASM_GLOBAL_FUNC(call_flat_method9_f_f, "movaps %xmm0, %xmm1\n\t" "call *%r11\n\t" "addq $0x58, %rsp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset -88\n\t") "ret"); extern void call_flat_method9_f_f(void);