From 95839d4cbb322ae7cf03d2452a3f1917cc49a985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 24 May 2024 14:42:02 +0200 Subject: [PATCH] interceptor: Simplify the x86 enter thunk logic --- gum/backend-x86/guminterceptor-x86.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gum/backend-x86/guminterceptor-x86.c b/gum/backend-x86/guminterceptor-x86.c index ebe1b19b6..975f7dab0 100644 --- a/gum/backend-x86/guminterceptor-x86.c +++ b/gum/backend-x86/guminterceptor-x86.c @@ -346,7 +346,6 @@ gum_emit_enter_thunk (GumX86Writer * cw) { const gssize return_address_stack_displacement = 0; const gchar * prepare_trap_on_leave = "prepare_trap_on_leave"; - gpointer epilog; gum_emit_prolog (cw, return_address_stack_displacement); @@ -366,24 +365,25 @@ gum_emit_enter_thunk (GumX86Writer * cw) if ((cw->cpu_features & GUM_CPU_CET_SS) != 0) { + gpointer epilog; + gum_x86_writer_put_test_reg_reg (cw, GUM_X86_EAX, GUM_X86_EAX); gum_x86_writer_put_jcc_short_label (cw, X86_INS_JNE, prepare_trap_on_leave, GUM_NO_HINT); epilog = gum_x86_writer_cur (cw); - } - - gum_emit_epilog (cw, GUM_POINT_ENTER); + gum_emit_epilog (cw, GUM_POINT_ENTER); - if ((cw->cpu_features & GUM_CPU_CET_SS) != 0) - { gum_x86_writer_put_label (cw, prepare_trap_on_leave); - gum_x86_writer_put_mov_reg_address (cw, GUM_X86_XAX, GUM_ADDRESS (epilog)); gum_x86_writer_put_jmp_reg_offset_ptr (cw, GUM_X86_XBX, G_STRUCT_OFFSET (GumFunctionContext, backend_data) + G_STRUCT_OFFSET (GumX86FunctionContextData, push_to_shadow_stack)); } + else + { + gum_emit_epilog (cw, GUM_POINT_ENTER); + } } static void