4242#include "internal-common.h"
4343#include "internal-target.h"
4444
45+ //// --- Begin LibAFL code ---
46+ #include "libafl/exit.h"
47+ #include "libafl/tcg.h"
48+
49+ #include "libafl/hooks/tcg/block.h"
50+ //// --- End LibAFL code ---
51+
4552/* -icount align implementation. */
4653
4754typedef struct SyncClocks {
@@ -286,6 +293,14 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, vaddr pc,
286293 return tb ;
287294}
288295
296+ //// --- Begin LibAFL code ---
297+ TranslationBlock * libafl_tb_lookup (CPUState * cpu , vaddr pc ,
298+ uint64_t cs_base , uint32_t flags ,
299+ uint32_t cflags ) {
300+ return tb_lookup (cpu , pc , cs_base , flags , cflags );
301+ }
302+ //// --- End LibAFL code ---
303+
289304static void log_cpu_exec (vaddr pc , CPUState * cpu ,
290305 const TranslationBlock * tb )
291306{
@@ -674,6 +689,13 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
674689 return ;
675690}
676691
692+ //// --- Begin LibAFL code ---
693+ void libafl_tb_add_jump (TranslationBlock * tb , int n ,
694+ TranslationBlock * tb_next ) {
695+ tb_add_jump (tb , n , tb_next );
696+ }
697+ //// --- End LibAFL code ---
698+
677699static inline bool cpu_handle_halt (CPUState * cpu )
678700{
679701#ifndef CONFIG_USER_ONLY
@@ -708,12 +730,6 @@ static inline void cpu_handle_debug_exception(CPUState *cpu)
708730 }
709731}
710732
711- //// --- Begin LibAFL code ---
712-
713- #include "libafl/exit.h"
714-
715- //// --- End LibAFL code ---
716-
717733static inline bool cpu_handle_exception (CPUState * cpu , int * ret )
718734{
719735 //// --- Begin LibAFL code ---
@@ -1017,6 +1033,23 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
10171033
10181034 mmap_lock ();
10191035 tb = tb_gen_code (cpu , pc , cs_base , flags , cflags );
1036+
1037+ //// --- Begin LibAFL code ---
1038+ #ifndef CONFIG_USER_ONLY
1039+ /*
1040+ * We don't take care of direct jumps when address mapping
1041+ * changes in system emulation. So it's not safe to make a
1042+ * direct jump to a TB spanning two pages because the mapping
1043+ * for the second page can change.
1044+ */
1045+ if (tb_page_addr1 (tb ) != -1 ) {
1046+ last_tb = NULL ;
1047+ }
1048+ #endif
1049+ libafl_qemu_hook_block_post_run (tb , last_tb , pc , tb_exit );
1050+
1051+ //// --- End LibAFL code ---
1052+
10201053 mmap_unlock ();
10211054
10221055 /*
@@ -1028,18 +1061,23 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
10281061 jc -> array [h ].pc = pc ;
10291062 qatomic_set (& jc -> array [h ].tb , tb );
10301063 }
1031-
1064+ //// --- Begin LibAFL code ---
1065+ else {
1066+ //// --- End LibAFL code ---
10321067#ifndef CONFIG_USER_ONLY
1033- /*
1034- * We don't take care of direct jumps when address mapping
1035- * changes in system emulation. So it's not safe to make a
1036- * direct jump to a TB spanning two pages because the mapping
1037- * for the second page can change.
1038- */
1039- if (tb_page_addr1 (tb ) != -1 ) {
1040- last_tb = NULL ;
1041- }
1068+ /*
1069+ * We don't take care of direct jumps when address mapping
1070+ * changes in system emulation. So it's not safe to make a
1071+ * direct jump to a TB spanning two pages because the mapping
1072+ * for the second page can change.
1073+ */
1074+ if (tb_page_addr1 (tb ) != -1 ) {
1075+ last_tb = NULL ;
1076+ }
10421077#endif
1078+ //// --- Begin LibAFL code ---
1079+ }
1080+ //// --- End LibAFL code ---
10431081
10441082 //// --- Begin LibAFL code ---
10451083
0 commit comments