xref: /qemu/include/exec/plugin-gen.h (revision 727385c4)
1 /*
2  * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
3  *
4  * License: GNU GPL, version 2 or later.
5  *   See the COPYING file in the top-level directory.
6  *
7  * plugin-gen.h - TCG-dependent definitions for generating plugin code
8  *
9  * This header should be included only from plugin.c and C files that emit
10  * TCG code.
11  */
12 #ifndef QEMU_PLUGIN_GEN_H
13 #define QEMU_PLUGIN_GEN_H
14 
15 #include "qemu/plugin.h"
16 #include "tcg/tcg.h"
17 
18 struct DisasContextBase;
19 
20 #ifdef CONFIG_PLUGIN
21 
22 bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool supress);
23 void plugin_gen_tb_end(CPUState *cpu);
24 void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
25 void plugin_gen_insn_end(void);
26 
27 void plugin_gen_disable_mem_helpers(void);
28 void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info);
29 
30 static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
31 {
32     struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
33     abi_ptr off;
34 
35     if (insn == NULL) {
36         return;
37     }
38     off = pc - insn->vaddr;
39     if (off < insn->data->len) {
40         g_byte_array_set_size(insn->data, off);
41     } else if (off > insn->data->len) {
42         /* we have an unexpected gap */
43         g_assert_not_reached();
44     }
45 
46     insn->data = g_byte_array_append(insn->data, from, size);
47 }
48 
49 #else /* !CONFIG_PLUGIN */
50 
51 static inline
52 bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool supress)
53 {
54     return false;
55 }
56 
57 static inline
58 void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db)
59 { }
60 
61 static inline void plugin_gen_insn_end(void)
62 { }
63 
64 static inline void plugin_gen_tb_end(CPUState *cpu)
65 { }
66 
67 static inline void plugin_gen_disable_mem_helpers(void)
68 { }
69 
70 static inline void plugin_gen_empty_mem_callback(TCGv addr, uint32_t info)
71 { }
72 
73 static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
74 { }
75 
76 #endif /* CONFIG_PLUGIN */
77 
78 #endif /* QEMU_PLUGIN_GEN_H */
79 
80