From 52e91260999fc662eea5faa96c2665dd82e26cd6 Mon Sep 17 00:00:00 2001 From: Andrew Fasano Date: Sat, 17 Feb 2024 18:11:47 -0500 Subject: [PATCH] CallstackInstr: switch to SBE/EBE callbacks The old logic would miss many calls if tb_chaining was enabled (which is is by default). Since this plugin did not disable tb_chaining, many calls would be missed if a user didn't disable chaining or load another plugin that disabled chaining. This commit updates the plugin to use start_block_exec and end_block_exec which work even with tb_chaining enabled. --- panda/plugins/callstack_instr/callstack_instr.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/panda/plugins/callstack_instr/callstack_instr.cpp b/panda/plugins/callstack_instr/callstack_instr.cpp index 62380b8b1db..40f3e090695 100644 --- a/panda/plugins/callstack_instr/callstack_instr.cpp +++ b/panda/plugins/callstack_instr/callstack_instr.cpp @@ -55,10 +55,8 @@ extern "C" { #include "panda/plog.h" #include "callstack_instr_int_fns.h" -bool translate_callback(CPUState* cpu, target_ulong pc); -int exec_callback(CPUState* cpu, target_ulong pc); -void before_block_exec(CPUState* cpu, TranslationBlock *tb); -void after_block_exec(CPUState* cpu, TranslationBlock *tb, uint8_t exitCode); +void start_block_exec(CPUState* cpu, TranslationBlock *tb); +void end_block_exec(CPUState* cpu, TranslationBlock *tb, uint8_t exitCode); void after_block_translate(CPUState* cpu, TranslationBlock *tb); bool init_plugin(void *); @@ -322,7 +320,7 @@ void after_block_translate(CPUState *cpu, TranslationBlock *tb) { return; } -void before_block_exec(CPUState *cpu, TranslationBlock *tb) { +void start_block_exec(CPUState *cpu, TranslationBlock *tb) { // if the block a call returns to was interrupted before it completed, this // function will be called twice - only want to remove the return value from // the stack once @@ -366,7 +364,7 @@ void before_block_exec(CPUState *cpu, TranslationBlock *tb) { } } -void after_block_exec(CPUState* cpu, TranslationBlock *tb, uint8_t exitCode) { +void end_block_exec(CPUState* cpu, TranslationBlock *tb, uint8_t exitCode) { target_ulong pc = 0x0; target_ulong cs_base = 0x0; uint32_t flags = 0x0; @@ -611,9 +609,9 @@ bool init_plugin(void *self) { pcb.after_block_translate = after_block_translate; panda_register_callback(self, PANDA_CB_AFTER_BLOCK_TRANSLATE, pcb); - pcb.after_block_exec = after_block_exec; + pcb.end_block_exec = end_block_exec; panda_register_callback(self, PANDA_CB_AFTER_BLOCK_EXEC, pcb); - pcb.before_block_exec = before_block_exec; + pcb.start_block_exec = start_block_exec; panda_register_callback(self, PANDA_CB_BEFORE_BLOCK_EXEC, pcb); bool setup_ok = true;