]>
Commit | Line | Data |
---|---|---|
975c4553 EC |
1 | /* |
2 | * Copyright (C) 2017, Emilio G. Cota <cota@braap.org> | |
3 | * Copyright (C) 2019, Linaro | |
4 | * | |
5 | * License: GNU GPL, version 2 or later. | |
6 | * See the COPYING file in the top-level directory. | |
7 | * | |
8 | * SPDX-License-Identifier: GPL-2.0-or-later | |
9 | */ | |
52581c71 MA |
10 | |
11 | #ifndef QEMU_QEMU_PLUGIN_H | |
12 | #define QEMU_QEMU_PLUGIN_H | |
975c4553 EC |
13 | |
14 | #include <inttypes.h> | |
15 | #include <stdbool.h> | |
02324a47 | 16 | #include <stddef.h> |
975c4553 EC |
17 | |
18 | /* | |
19 | * For best performance, build the plugin with -fvisibility=hidden so that | |
20 | * QEMU_PLUGIN_LOCAL is implicit. Then, just mark qemu_plugin_install with | |
21 | * QEMU_PLUGIN_EXPORT. For more info, see | |
22 | * https://gcc.gnu.org/wiki/Visibility | |
23 | */ | |
24 | #if defined _WIN32 || defined __CYGWIN__ | |
fb691b8c | 25 | #ifdef CONFIG_PLUGIN |
975c4553 | 26 | #define QEMU_PLUGIN_EXPORT __declspec(dllimport) |
fb691b8c GM |
27 | #define QEMU_PLUGIN_API __declspec(dllexport) |
28 | #else | |
29 | #define QEMU_PLUGIN_EXPORT __declspec(dllexport) | |
30 | #define QEMU_PLUGIN_API __declspec(dllimport) | |
975c4553 EC |
31 | #endif |
32 | #define QEMU_PLUGIN_LOCAL | |
33 | #else | |
53b5d954 MAL |
34 | #define QEMU_PLUGIN_EXPORT __attribute__((visibility("default"))) |
35 | #define QEMU_PLUGIN_LOCAL __attribute__((visibility("hidden"))) | |
fb691b8c | 36 | #define QEMU_PLUGIN_API |
975c4553 EC |
37 | #endif |
38 | ||
fd6744a4 AB |
39 | /** |
40 | * typedef qemu_plugin_id_t - Unique plugin ID | |
41 | */ | |
975c4553 EC |
42 | typedef uint64_t qemu_plugin_id_t; |
43 | ||
3fb356cc AB |
44 | /* |
45 | * Versioning plugins: | |
46 | * | |
47 | * The plugin API will pass a minimum and current API version that | |
48 | * QEMU currently supports. The minimum API will be incremented if an | |
49 | * API needs to be deprecated. | |
50 | * | |
51 | * The plugins export the API they were built against by exposing the | |
52 | * symbol qemu_plugin_version which can be checked. | |
53 | */ | |
54 | ||
55 | extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; | |
56 | ||
787148bf | 57 | #define QEMU_PLUGIN_VERSION 1 |
3fb356cc | 58 | |
841dcc08 AB |
59 | /** |
60 | * struct qemu_info_t - system information for plugins | |
61 | * | |
62 | * This structure provides for some limited information about the | |
63 | * system to allow the plugin to make decisions on how to proceed. For | |
64 | * example it might only be suitable for running on some guest | |
65 | * architectures or when under full system emulation. | |
66 | */ | |
67 | typedef struct qemu_info_t { | |
68 | /** @target_name: string describing architecture */ | |
5901b2e1 | 69 | const char *target_name; |
841dcc08 | 70 | /** @version: minimum and current plugin API level */ |
3fb356cc AB |
71 | struct { |
72 | int min; | |
73 | int cur; | |
74 | } version; | |
841dcc08 | 75 | /** @system_emulation: is this a full system emulation? */ |
5901b2e1 AB |
76 | bool system_emulation; |
77 | union { | |
841dcc08 | 78 | /** @system: information relevant to system emulation */ |
5901b2e1 | 79 | struct { |
841dcc08 | 80 | /** @system.smp_vcpus: initial number of vCPUs */ |
5901b2e1 | 81 | int smp_vcpus; |
841dcc08 | 82 | /** @system.max_vcpus: maximum possible number of vCPUs */ |
5901b2e1 AB |
83 | int max_vcpus; |
84 | } system; | |
85 | }; | |
86 | } qemu_info_t; | |
87 | ||
975c4553 EC |
88 | /** |
89 | * qemu_plugin_install() - Install a plugin | |
90 | * @id: this plugin's opaque ID | |
5901b2e1 | 91 | * @info: a block describing some details about the guest |
975c4553 EC |
92 | * @argc: number of arguments |
93 | * @argv: array of arguments (@argc elements) | |
94 | * | |
1caa8d9f AB |
95 | * All plugins must export this symbol which is called when the plugin |
96 | * is first loaded. Calling qemu_plugin_uninstall() from this function | |
97 | * is a bug. | |
975c4553 | 98 | * |
5901b2e1 | 99 | * Note: @info is only live during the call. Copy any information we |
1caa8d9f AB |
100 | * want to keep. @argv remains valid throughout the lifetime of the |
101 | * loaded plugin. | |
5901b2e1 | 102 | * |
1caa8d9f | 103 | * Return: 0 on successful loading, !0 for an error. |
975c4553 | 104 | */ |
5901b2e1 AB |
105 | QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, |
106 | const qemu_info_t *info, | |
107 | int argc, char **argv); | |
975c4553 | 108 | |
c4f19122 AB |
109 | /** |
110 | * typedef qemu_plugin_simple_cb_t - simple callback | |
111 | * @id: the unique qemu_plugin_id_t | |
112 | * | |
83b9c2bf | 113 | * This callback passes no information aside from the unique @id. |
975c4553 EC |
114 | */ |
115 | typedef void (*qemu_plugin_simple_cb_t)(qemu_plugin_id_t id); | |
116 | ||
c4f19122 AB |
117 | /** |
118 | * typedef qemu_plugin_udata_cb_t - callback with user data | |
119 | * @id: the unique qemu_plugin_id_t | |
83b9c2bf | 120 | * @userdata: a pointer to some user data supplied when the callback |
c4f19122 AB |
121 | * was registered. |
122 | */ | |
975c4553 EC |
123 | typedef void (*qemu_plugin_udata_cb_t)(qemu_plugin_id_t id, void *userdata); |
124 | ||
c4f19122 AB |
125 | /** |
126 | * typedef qemu_plugin_vcpu_simple_cb_t - vcpu callback | |
127 | * @id: the unique qemu_plugin_id_t | |
128 | * @vcpu_index: the current vcpu context | |
129 | */ | |
975c4553 EC |
130 | typedef void (*qemu_plugin_vcpu_simple_cb_t)(qemu_plugin_id_t id, |
131 | unsigned int vcpu_index); | |
132 | ||
c4f19122 AB |
133 | /** |
134 | * typedef qemu_plugin_vcpu_udata_cb_t - vcpu callback | |
135 | * @vcpu_index: the current vcpu context | |
83b9c2bf | 136 | * @userdata: a pointer to some user data supplied when the callback |
c4f19122 AB |
137 | * was registered. |
138 | */ | |
975c4553 EC |
139 | typedef void (*qemu_plugin_vcpu_udata_cb_t)(unsigned int vcpu_index, |
140 | void *userdata); | |
141 | ||
142 | /** | |
143 | * qemu_plugin_uninstall() - Uninstall a plugin | |
144 | * @id: this plugin's opaque ID | |
145 | * @cb: callback to be called once the plugin has been removed | |
146 | * | |
147 | * Do NOT assume that the plugin has been uninstalled once this function | |
148 | * returns. Plugins are uninstalled asynchronously, and therefore the given | |
149 | * plugin receives callbacks until @cb is called. | |
150 | * | |
151 | * Note: Calling this function from qemu_plugin_install() is a bug. | |
152 | */ | |
fb691b8c | 153 | QEMU_PLUGIN_API |
975c4553 EC |
154 | void qemu_plugin_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb); |
155 | ||
156 | /** | |
157 | * qemu_plugin_reset() - Reset a plugin | |
158 | * @id: this plugin's opaque ID | |
159 | * @cb: callback to be called once the plugin has been reset | |
160 | * | |
161 | * Unregisters all callbacks for the plugin given by @id. | |
162 | * | |
163 | * Do NOT assume that the plugin has been reset once this function returns. | |
164 | * Plugins are reset asynchronously, and therefore the given plugin receives | |
165 | * callbacks until @cb is called. | |
166 | */ | |
fb691b8c | 167 | QEMU_PLUGIN_API |
975c4553 EC |
168 | void qemu_plugin_reset(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb); |
169 | ||
170 | /** | |
171 | * qemu_plugin_register_vcpu_init_cb() - register a vCPU initialization callback | |
172 | * @id: plugin ID | |
173 | * @cb: callback function | |
174 | * | |
175 | * The @cb function is called every time a vCPU is initialized. | |
176 | * | |
177 | * See also: qemu_plugin_register_vcpu_exit_cb() | |
178 | */ | |
fb691b8c | 179 | QEMU_PLUGIN_API |
975c4553 EC |
180 | void qemu_plugin_register_vcpu_init_cb(qemu_plugin_id_t id, |
181 | qemu_plugin_vcpu_simple_cb_t cb); | |
182 | ||
183 | /** | |
184 | * qemu_plugin_register_vcpu_exit_cb() - register a vCPU exit callback | |
185 | * @id: plugin ID | |
186 | * @cb: callback function | |
187 | * | |
188 | * The @cb function is called every time a vCPU exits. | |
189 | * | |
190 | * See also: qemu_plugin_register_vcpu_init_cb() | |
191 | */ | |
fb691b8c | 192 | QEMU_PLUGIN_API |
975c4553 EC |
193 | void qemu_plugin_register_vcpu_exit_cb(qemu_plugin_id_t id, |
194 | qemu_plugin_vcpu_simple_cb_t cb); | |
195 | ||
196 | /** | |
197 | * qemu_plugin_register_vcpu_idle_cb() - register a vCPU idle callback | |
198 | * @id: plugin ID | |
199 | * @cb: callback function | |
200 | * | |
201 | * The @cb function is called every time a vCPU idles. | |
202 | */ | |
fb691b8c | 203 | QEMU_PLUGIN_API |
975c4553 EC |
204 | void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id, |
205 | qemu_plugin_vcpu_simple_cb_t cb); | |
206 | ||
207 | /** | |
208 | * qemu_plugin_register_vcpu_resume_cb() - register a vCPU resume callback | |
209 | * @id: plugin ID | |
210 | * @cb: callback function | |
211 | * | |
212 | * The @cb function is called every time a vCPU resumes execution. | |
213 | */ | |
fb691b8c | 214 | QEMU_PLUGIN_API |
975c4553 EC |
215 | void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, |
216 | qemu_plugin_vcpu_simple_cb_t cb); | |
217 | ||
83b9c2bf | 218 | /** struct qemu_plugin_tb - Opaque handle for a translation block */ |
975c4553 | 219 | struct qemu_plugin_tb; |
83b9c2bf | 220 | /** struct qemu_plugin_insn - Opaque handle for a translated instruction */ |
975c4553 EC |
221 | struct qemu_plugin_insn; |
222 | ||
a40d3819 AB |
223 | /** |
224 | * enum qemu_plugin_cb_flags - type of callback | |
225 | * | |
226 | * @QEMU_PLUGIN_CB_NO_REGS: callback does not access the CPU's regs | |
227 | * @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs | |
228 | * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs | |
229 | * | |
230 | * Note: currently unused, plugins cannot read or change system | |
231 | * register state. | |
232 | */ | |
975c4553 | 233 | enum qemu_plugin_cb_flags { |
a40d3819 AB |
234 | QEMU_PLUGIN_CB_NO_REGS, |
235 | QEMU_PLUGIN_CB_R_REGS, | |
236 | QEMU_PLUGIN_CB_RW_REGS, | |
975c4553 EC |
237 | }; |
238 | ||
239 | enum qemu_plugin_mem_rw { | |
240 | QEMU_PLUGIN_MEM_R = 1, | |
241 | QEMU_PLUGIN_MEM_W, | |
242 | QEMU_PLUGIN_MEM_RW, | |
243 | }; | |
244 | ||
83b9c2bf AB |
245 | /** |
246 | * typedef qemu_plugin_vcpu_tb_trans_cb_t - translation callback | |
247 | * @id: unique plugin id | |
248 | * @tb: opaque handle used for querying and instrumenting a block. | |
249 | */ | |
250 | typedef void (*qemu_plugin_vcpu_tb_trans_cb_t)(qemu_plugin_id_t id, | |
251 | struct qemu_plugin_tb *tb); | |
252 | ||
975c4553 EC |
253 | /** |
254 | * qemu_plugin_register_vcpu_tb_trans_cb() - register a translate cb | |
255 | * @id: plugin ID | |
256 | * @cb: callback function | |
257 | * | |
258 | * The @cb function is called every time a translation occurs. The @cb | |
259 | * function is passed an opaque qemu_plugin_type which it can query | |
260 | * for additional information including the list of translated | |
261 | * instructions. At this point the plugin can register further | |
262 | * callbacks to be triggered when the block or individual instruction | |
263 | * executes. | |
264 | */ | |
fb691b8c | 265 | QEMU_PLUGIN_API |
975c4553 EC |
266 | void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, |
267 | qemu_plugin_vcpu_tb_trans_cb_t cb); | |
268 | ||
269 | /** | |
38c4101d | 270 | * qemu_plugin_register_vcpu_tb_exec_cb() - register execution callback |
975c4553 EC |
271 | * @tb: the opaque qemu_plugin_tb handle for the translation |
272 | * @cb: callback function | |
273 | * @flags: does the plugin read or write the CPU's registers? | |
274 | * @userdata: any plugin data to pass to the @cb? | |
275 | * | |
276 | * The @cb function is called every time a translated unit executes. | |
277 | */ | |
fb691b8c | 278 | QEMU_PLUGIN_API |
975c4553 EC |
279 | void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, |
280 | qemu_plugin_vcpu_udata_cb_t cb, | |
281 | enum qemu_plugin_cb_flags flags, | |
282 | void *userdata); | |
283 | ||
8bc9a4d4 AB |
284 | /** |
285 | * enum qemu_plugin_op - describes an inline op | |
286 | * | |
287 | * @QEMU_PLUGIN_INLINE_ADD_U64: add an immediate value uint64_t | |
288 | * | |
289 | * Note: currently only a single inline op is supported. | |
290 | */ | |
291 | ||
975c4553 EC |
292 | enum qemu_plugin_op { |
293 | QEMU_PLUGIN_INLINE_ADD_U64, | |
294 | }; | |
295 | ||
296 | /** | |
38c4101d | 297 | * qemu_plugin_register_vcpu_tb_exec_inline() - execution inline op |
975c4553 EC |
298 | * @tb: the opaque qemu_plugin_tb handle for the translation |
299 | * @op: the type of qemu_plugin_op (e.g. ADD_U64) | |
300 | * @ptr: the target memory location for the op | |
301 | * @imm: the op data (e.g. 1) | |
302 | * | |
303 | * Insert an inline op to every time a translated unit executes. | |
304 | * Useful if you just want to increment a single counter somewhere in | |
305 | * memory. | |
8bc9a4d4 AB |
306 | * |
307 | * Note: ops are not atomic so in multi-threaded/multi-smp situations | |
308 | * you will get inexact results. | |
975c4553 | 309 | */ |
fb691b8c | 310 | QEMU_PLUGIN_API |
975c4553 EC |
311 | void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, |
312 | enum qemu_plugin_op op, | |
313 | void *ptr, uint64_t imm); | |
314 | ||
315 | /** | |
316 | * qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb | |
317 | * @insn: the opaque qemu_plugin_insn handle for an instruction | |
318 | * @cb: callback function | |
319 | * @flags: does the plugin read or write the CPU's registers? | |
320 | * @userdata: any plugin data to pass to the @cb? | |
321 | * | |
322 | * The @cb function is called every time an instruction is executed | |
323 | */ | |
fb691b8c | 324 | QEMU_PLUGIN_API |
975c4553 EC |
325 | void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, |
326 | qemu_plugin_vcpu_udata_cb_t cb, | |
327 | enum qemu_plugin_cb_flags flags, | |
328 | void *userdata); | |
329 | ||
330 | /** | |
331 | * qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op | |
332 | * @insn: the opaque qemu_plugin_insn handle for an instruction | |
975c4553 EC |
333 | * @op: the type of qemu_plugin_op (e.g. ADD_U64) |
334 | * @ptr: the target memory location for the op | |
335 | * @imm: the op data (e.g. 1) | |
336 | * | |
337 | * Insert an inline op to every time an instruction executes. Useful | |
338 | * if you just want to increment a single counter somewhere in memory. | |
339 | */ | |
fb691b8c | 340 | QEMU_PLUGIN_API |
975c4553 EC |
341 | void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, |
342 | enum qemu_plugin_op op, | |
343 | void *ptr, uint64_t imm); | |
344 | ||
8affbacb AB |
345 | /** |
346 | * qemu_plugin_tb_n_insns() - query helper for number of insns in TB | |
347 | * @tb: opaque handle to TB passed to callback | |
348 | * | |
349 | * Returns: number of instructions in this block | |
975c4553 | 350 | */ |
fb691b8c | 351 | QEMU_PLUGIN_API |
975c4553 EC |
352 | size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb); |
353 | ||
8affbacb AB |
354 | /** |
355 | * qemu_plugin_tb_vaddr() - query helper for vaddr of TB start | |
356 | * @tb: opaque handle to TB passed to callback | |
357 | * | |
358 | * Returns: virtual address of block start | |
359 | */ | |
fb691b8c | 360 | QEMU_PLUGIN_API |
975c4553 EC |
361 | uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb); |
362 | ||
8affbacb AB |
363 | /** |
364 | * qemu_plugin_tb_get_insn() - retrieve handle for instruction | |
365 | * @tb: opaque handle to TB passed to callback | |
366 | * @idx: instruction number, 0 indexed | |
367 | * | |
368 | * The returned handle can be used in follow up helper queries as well | |
369 | * as when instrumenting an instruction. It is only valid for the | |
370 | * lifetime of the callback. | |
371 | * | |
372 | * Returns: opaque handle to instruction | |
373 | */ | |
fb691b8c | 374 | QEMU_PLUGIN_API |
975c4553 EC |
375 | struct qemu_plugin_insn * |
376 | qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx); | |
377 | ||
8affbacb AB |
378 | /** |
379 | * qemu_plugin_insn_data() - return ptr to instruction data | |
380 | * @insn: opaque instruction handle from qemu_plugin_tb_get_insn() | |
381 | * | |
382 | * Note: data is only valid for duration of callback. See | |
383 | * qemu_plugin_insn_size() to calculate size of stream. | |
384 | * | |
385 | * Returns: pointer to a stream of bytes containing the value of this | |
386 | * instructions opcode. | |
387 | */ | |
fb691b8c | 388 | QEMU_PLUGIN_API |
975c4553 EC |
389 | const void *qemu_plugin_insn_data(const struct qemu_plugin_insn *insn); |
390 | ||
8affbacb AB |
391 | /** |
392 | * qemu_plugin_insn_size() - return size of instruction | |
393 | * @insn: opaque instruction handle from qemu_plugin_tb_get_insn() | |
394 | * | |
395 | * Returns: size of instruction in bytes | |
396 | */ | |
fb691b8c | 397 | QEMU_PLUGIN_API |
975c4553 EC |
398 | size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn); |
399 | ||
8affbacb AB |
400 | /** |
401 | * qemu_plugin_insn_vaddr() - return vaddr of instruction | |
402 | * @insn: opaque instruction handle from qemu_plugin_tb_get_insn() | |
403 | * | |
404 | * Returns: virtual address of instruction | |
405 | */ | |
fb691b8c | 406 | QEMU_PLUGIN_API |
975c4553 | 407 | uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn); |
8affbacb AB |
408 | |
409 | /** | |
410 | * qemu_plugin_insn_haddr() - return hardware addr of instruction | |
411 | * @insn: opaque instruction handle from qemu_plugin_tb_get_insn() | |
412 | * | |
413 | * Returns: hardware (physical) target address of instruction | |
414 | */ | |
fb691b8c | 415 | QEMU_PLUGIN_API |
975c4553 EC |
416 | void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn); |
417 | ||
fc292a7e AB |
418 | /** |
419 | * typedef qemu_plugin_meminfo_t - opaque memory transaction handle | |
975c4553 | 420 | * |
fc292a7e AB |
421 | * This can be further queried using the qemu_plugin_mem_* query |
422 | * functions. | |
975c4553 EC |
423 | */ |
424 | typedef uint32_t qemu_plugin_meminfo_t; | |
fc292a7e | 425 | /** struct qemu_plugin_hwaddr - opaque hw address handle */ |
975c4553 EC |
426 | struct qemu_plugin_hwaddr; |
427 | ||
fc292a7e AB |
428 | /** |
429 | * qemu_plugin_mem_size_shift() - get size of access | |
430 | * @info: opaque memory transaction handle | |
431 | * | |
432 | * Returns: size of access in ^2 (0=byte, 1=16bit, 2=32bit etc...) | |
433 | */ | |
fb691b8c | 434 | QEMU_PLUGIN_API |
975c4553 | 435 | unsigned int qemu_plugin_mem_size_shift(qemu_plugin_meminfo_t info); |
fc292a7e AB |
436 | /** |
437 | * qemu_plugin_mem_is_sign_extended() - was the access sign extended | |
438 | * @info: opaque memory transaction handle | |
439 | * | |
440 | * Returns: true if it was, otherwise false | |
441 | */ | |
fb691b8c | 442 | QEMU_PLUGIN_API |
975c4553 | 443 | bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info); |
fc292a7e AB |
444 | /** |
445 | * qemu_plugin_mem_is_big_endian() - was the access big endian | |
446 | * @info: opaque memory transaction handle | |
447 | * | |
448 | * Returns: true if it was, otherwise false | |
449 | */ | |
fb691b8c | 450 | QEMU_PLUGIN_API |
975c4553 | 451 | bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info); |
fc292a7e AB |
452 | /** |
453 | * qemu_plugin_mem_is_store() - was the access a store | |
454 | * @info: opaque memory transaction handle | |
455 | * | |
456 | * Returns: true if it was, otherwise false | |
457 | */ | |
fb691b8c | 458 | QEMU_PLUGIN_API |
975c4553 EC |
459 | bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info); |
460 | ||
787148bf AL |
461 | /** |
462 | * qemu_plugin_get_hwaddr() - return handle for memory operation | |
fc292a7e | 463 | * @info: opaque memory info structure |
975c4553 EC |
464 | * @vaddr: the virtual address of the memory operation |
465 | * | |
466 | * For system emulation returns a qemu_plugin_hwaddr handle to query | |
467 | * details about the actual physical address backing the virtual | |
468 | * address. For linux-user guests it just returns NULL. | |
469 | * | |
470 | * This handle is *only* valid for the duration of the callback. Any | |
471 | * information about the handle should be recovered before the | |
472 | * callback returns. | |
473 | */ | |
fb691b8c | 474 | QEMU_PLUGIN_API |
975c4553 EC |
475 | struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info, |
476 | uint64_t vaddr); | |
477 | ||
235537fa | 478 | /* |
787148bf AL |
479 | * The following additional queries can be run on the hwaddr structure to |
480 | * return information about it - namely whether it is for an IO access and the | |
481 | * physical address associated with the access. | |
482 | */ | |
483 | ||
484 | /** | |
485 | * qemu_plugin_hwaddr_is_io() - query whether memory operation is IO | |
486 | * @haddr: address handle from qemu_plugin_get_hwaddr() | |
487 | * | |
488 | * Returns true if the handle's memory operation is to memory-mapped IO, or | |
489 | * false if it is to RAM | |
235537fa | 490 | */ |
fb691b8c | 491 | QEMU_PLUGIN_API |
308e7549 | 492 | bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr); |
787148bf AL |
493 | |
494 | /** | |
495 | * qemu_plugin_hwaddr_phys_addr() - query physical address for memory operation | |
496 | * @haddr: address handle from qemu_plugin_get_hwaddr() | |
497 | * | |
498 | * Returns the physical address associated with the memory operation | |
499 | * | |
500 | * Note that the returned physical address may not be unique if you are dealing | |
501 | * with multiple address spaces. | |
502 | */ | |
fb691b8c | 503 | QEMU_PLUGIN_API |
787148bf | 504 | uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr); |
235537fa | 505 | |
b853a79f AB |
506 | /* |
507 | * Returns a string representing the device. The string is valid for | |
508 | * the lifetime of the plugin. | |
509 | */ | |
fb691b8c | 510 | QEMU_PLUGIN_API |
b853a79f AB |
511 | const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h); |
512 | ||
32ba75ad AB |
513 | /** |
514 | * typedef qemu_plugin_vcpu_mem_cb_t - memory callback function type | |
515 | * @vcpu_index: the executing vCPU | |
516 | * @info: an opaque handle for further queries about the memory | |
517 | * @vaddr: the virtual address of the transaction | |
518 | * @userdata: any user data attached to the callback | |
519 | */ | |
520 | typedef void (*qemu_plugin_vcpu_mem_cb_t) (unsigned int vcpu_index, | |
521 | qemu_plugin_meminfo_t info, | |
522 | uint64_t vaddr, | |
523 | void *userdata); | |
975c4553 | 524 | |
32ba75ad AB |
525 | /** |
526 | * qemu_plugin_register_vcpu_mem_cb() - register memory access callback | |
527 | * @insn: handle for instruction to instrument | |
528 | * @cb: callback of type qemu_plugin_vcpu_mem_cb_t | |
529 | * @flags: (currently unused) callback flags | |
530 | * @rw: monitor reads, writes or both | |
531 | * @userdata: opaque pointer for userdata | |
532 | * | |
533 | * This registers a full callback for every memory access generated by | |
534 | * an instruction. If the instruction doesn't access memory no | |
535 | * callback will be made. | |
536 | * | |
537 | * The callback reports the vCPU the access took place on, the virtual | |
538 | * address of the access and a handle for further queries. The user | |
539 | * can attach some userdata to the callback for additional purposes. | |
540 | * | |
541 | * Other execution threads will continue to execute during the | |
542 | * callback so the plugin is responsible for ensuring it doesn't get | |
543 | * confused by making appropriate use of locking if required. | |
544 | */ | |
fb691b8c | 545 | QEMU_PLUGIN_API |
975c4553 EC |
546 | void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, |
547 | qemu_plugin_vcpu_mem_cb_t cb, | |
548 | enum qemu_plugin_cb_flags flags, | |
549 | enum qemu_plugin_mem_rw rw, | |
550 | void *userdata); | |
551 | ||
32ba75ad AB |
552 | /** |
553 | * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any memory access | |
554 | * @insn: handle for instruction to instrument | |
555 | * @rw: apply to reads, writes or both | |
556 | * @op: the op, of type qemu_plugin_op | |
557 | * @ptr: pointer memory for the op | |
558 | * @imm: immediate data for @op | |
559 | * | |
560 | * This registers a inline op every memory access generated by the | |
561 | * instruction. This provides for a lightweight but not thread-safe | |
562 | * way of counting the number of operations done. | |
563 | */ | |
fb691b8c | 564 | QEMU_PLUGIN_API |
975c4553 EC |
565 | void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, |
566 | enum qemu_plugin_mem_rw rw, | |
567 | enum qemu_plugin_op op, void *ptr, | |
568 | uint64_t imm); | |
569 | ||
570 | ||
571 | ||
572 | typedef void | |
573 | (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, | |
574 | int64_t num, uint64_t a1, uint64_t a2, | |
575 | uint64_t a3, uint64_t a4, uint64_t a5, | |
576 | uint64_t a6, uint64_t a7, uint64_t a8); | |
577 | ||
fb691b8c | 578 | QEMU_PLUGIN_API |
975c4553 EC |
579 | void qemu_plugin_register_vcpu_syscall_cb(qemu_plugin_id_t id, |
580 | qemu_plugin_vcpu_syscall_cb_t cb); | |
581 | ||
582 | typedef void | |
583 | (*qemu_plugin_vcpu_syscall_ret_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_idx, | |
584 | int64_t num, int64_t ret); | |
585 | ||
fb691b8c | 586 | QEMU_PLUGIN_API |
975c4553 EC |
587 | void |
588 | qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, | |
589 | qemu_plugin_vcpu_syscall_ret_cb_t cb); | |
590 | ||
591 | ||
cbafa236 AB |
592 | /** |
593 | * qemu_plugin_insn_disas() - return disassembly string for instruction | |
594 | * @insn: instruction reference | |
595 | * | |
596 | * Returns an allocated string containing the disassembly | |
597 | */ | |
598 | ||
fb691b8c | 599 | QEMU_PLUGIN_API |
cbafa236 AB |
600 | char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn); |
601 | ||
7c4ab60f AB |
602 | /** |
603 | * qemu_plugin_insn_symbol() - best effort symbol lookup | |
604 | * @insn: instruction reference | |
605 | * | |
606 | * Return a static string referring to the symbol. This is dependent | |
607 | * on the binary QEMU is running having provided a symbol table. | |
608 | */ | |
fb691b8c | 609 | QEMU_PLUGIN_API |
7c4ab60f AB |
610 | const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn); |
611 | ||
975c4553 EC |
612 | /** |
613 | * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU | |
614 | * @id: plugin ID | |
615 | * @cb: callback function | |
616 | * | |
617 | * The @cb function is called once for each existing vCPU. | |
618 | * | |
619 | * See also: qemu_plugin_register_vcpu_init_cb() | |
620 | */ | |
fb691b8c | 621 | QEMU_PLUGIN_API |
975c4553 EC |
622 | void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id, |
623 | qemu_plugin_vcpu_simple_cb_t cb); | |
624 | ||
fb691b8c | 625 | QEMU_PLUGIN_API |
975c4553 EC |
626 | void qemu_plugin_register_flush_cb(qemu_plugin_id_t id, |
627 | qemu_plugin_simple_cb_t cb); | |
628 | ||
f7e68c9c AB |
629 | /** |
630 | * qemu_plugin_register_atexit_cb() - register exit callback | |
631 | * @id: plugin ID | |
632 | * @cb: callback | |
633 | * @userdata: user data for callback | |
634 | * | |
635 | * The @cb function is called once execution has finished. Plugins | |
636 | * should be able to free all their resources at this point much like | |
637 | * after a reset/uninstall callback is called. | |
638 | * | |
639 | * In user-mode it is possible a few un-instrumented instructions from | |
640 | * child threads may run before the host kernel reaps the threads. | |
641 | */ | |
fb691b8c | 642 | QEMU_PLUGIN_API |
975c4553 EC |
643 | void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id, |
644 | qemu_plugin_udata_cb_t cb, void *userdata); | |
645 | ||
646 | /* returns -1 in user-mode */ | |
647 | int qemu_plugin_n_vcpus(void); | |
648 | ||
649 | /* returns -1 in user-mode */ | |
650 | int qemu_plugin_n_max_vcpus(void); | |
651 | ||
ca76a669 AB |
652 | /** |
653 | * qemu_plugin_outs() - output string via QEMU's logging system | |
654 | * @string: a string | |
655 | */ | |
fb691b8c | 656 | QEMU_PLUGIN_API |
ca76a669 AB |
657 | void qemu_plugin_outs(const char *string); |
658 | ||
6a9e8a08 MM |
659 | /** |
660 | * qemu_plugin_bool_parse() - parses a boolean argument in the form of | |
661 | * "<argname>=[on|yes|true|off|no|false]" | |
662 | * | |
663 | * @name: argument name, the part before the equals sign | |
664 | * @val: argument value, what's after the equals sign | |
665 | * @ret: output return value | |
666 | * | |
667 | * returns true if the combination @name=@val parses correctly to a boolean | |
668 | * argument, and false otherwise | |
669 | */ | |
fb691b8c | 670 | QEMU_PLUGIN_API |
6a9e8a08 MM |
671 | bool qemu_plugin_bool_parse(const char *name, const char *val, bool *ret); |
672 | ||
91d40327 IA |
673 | /** |
674 | * qemu_plugin_path_to_binary() - path to binary file being executed | |
675 | * | |
676 | * Return a string representing the path to the binary. For user-mode | |
677 | * this is the main executable. For system emulation we currently | |
678 | * return NULL. The user should g_free() the string once no longer | |
679 | * needed. | |
680 | */ | |
fb691b8c | 681 | QEMU_PLUGIN_API |
91d40327 IA |
682 | const char *qemu_plugin_path_to_binary(void); |
683 | ||
684 | /** | |
685 | * qemu_plugin_start_code() - returns start of text segment | |
686 | * | |
687 | * Returns the nominal start address of the main text segment in | |
688 | * user-mode. Currently returns 0 for system emulation. | |
689 | */ | |
fb691b8c | 690 | QEMU_PLUGIN_API |
91d40327 IA |
691 | uint64_t qemu_plugin_start_code(void); |
692 | ||
693 | /** | |
694 | * qemu_plugin_end_code() - returns end of text segment | |
695 | * | |
696 | * Returns the nominal end address of the main text segment in | |
697 | * user-mode. Currently returns 0 for system emulation. | |
698 | */ | |
fb691b8c | 699 | QEMU_PLUGIN_API |
91d40327 IA |
700 | uint64_t qemu_plugin_end_code(void); |
701 | ||
702 | /** | |
703 | * qemu_plugin_entry_code() - returns start address for module | |
704 | * | |
705 | * Returns the nominal entry address of the main text segment in | |
706 | * user-mode. Currently returns 0 for system emulation. | |
707 | */ | |
fb691b8c | 708 | QEMU_PLUGIN_API |
91d40327 IA |
709 | uint64_t qemu_plugin_entry_code(void); |
710 | ||
52581c71 | 711 | #endif /* QEMU_QEMU_PLUGIN_H */ |