xref: /qemu/include/qemu/qemu-plugin.h (revision 5db05230)
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  */
10 
11 #ifndef QEMU_QEMU_PLUGIN_H
12 #define QEMU_QEMU_PLUGIN_H
13 
14 #include <inttypes.h>
15 #include <stdbool.h>
16 #include <stddef.h>
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__
25   #ifdef CONFIG_PLUGIN
26     #define QEMU_PLUGIN_EXPORT __declspec(dllimport)
27     #define QEMU_PLUGIN_API __declspec(dllexport)
28   #else
29     #define QEMU_PLUGIN_EXPORT __declspec(dllexport)
30     #define QEMU_PLUGIN_API __declspec(dllimport)
31   #endif
32   #define QEMU_PLUGIN_LOCAL
33 #else
34   #define QEMU_PLUGIN_EXPORT __attribute__((visibility("default")))
35   #define QEMU_PLUGIN_LOCAL  __attribute__((visibility("hidden")))
36   #define QEMU_PLUGIN_API
37 #endif
38 
39 /**
40  * typedef qemu_plugin_id_t - Unique plugin ID
41  */
42 typedef uint64_t qemu_plugin_id_t;
43 
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 
57 #define QEMU_PLUGIN_VERSION 1
58 
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 */
69     const char *target_name;
70     /** @version: minimum and current plugin API level */
71     struct {
72         int min;
73         int cur;
74     } version;
75     /** @system_emulation: is this a full system emulation? */
76     bool system_emulation;
77     union {
78         /** @system: information relevant to system emulation */
79         struct {
80             /** @system.smp_vcpus: initial number of vCPUs */
81             int smp_vcpus;
82             /** @system.max_vcpus: maximum possible number of vCPUs */
83             int max_vcpus;
84         } system;
85     };
86 } qemu_info_t;
87 
88 /**
89  * qemu_plugin_install() - Install a plugin
90  * @id: this plugin's opaque ID
91  * @info: a block describing some details about the guest
92  * @argc: number of arguments
93  * @argv: array of arguments (@argc elements)
94  *
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.
98  *
99  * Note: @info is only live during the call. Copy any information we
100  * want to keep. @argv remains valid throughout the lifetime of the
101  * loaded plugin.
102  *
103  * Return: 0 on successful loading, !0 for an error.
104  */
105 QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
106                                            const qemu_info_t *info,
107                                            int argc, char **argv);
108 
109 /**
110  * typedef qemu_plugin_simple_cb_t - simple callback
111  * @id: the unique qemu_plugin_id_t
112  *
113  * This callback passes no information aside from the unique @id.
114  */
115 typedef void (*qemu_plugin_simple_cb_t)(qemu_plugin_id_t id);
116 
117 /**
118  * typedef qemu_plugin_udata_cb_t - callback with user data
119  * @id: the unique qemu_plugin_id_t
120  * @userdata: a pointer to some user data supplied when the callback
121  * was registered.
122  */
123 typedef void (*qemu_plugin_udata_cb_t)(qemu_plugin_id_t id, void *userdata);
124 
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  */
130 typedef void (*qemu_plugin_vcpu_simple_cb_t)(qemu_plugin_id_t id,
131                                              unsigned int vcpu_index);
132 
133 /**
134  * typedef qemu_plugin_vcpu_udata_cb_t - vcpu callback
135  * @vcpu_index: the current vcpu context
136  * @userdata: a pointer to some user data supplied when the callback
137  * was registered.
138  */
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  */
153 QEMU_PLUGIN_API
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  */
167 QEMU_PLUGIN_API
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  */
179 QEMU_PLUGIN_API
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  */
192 QEMU_PLUGIN_API
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  */
203 QEMU_PLUGIN_API
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  */
214 QEMU_PLUGIN_API
215 void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id,
216                                          qemu_plugin_vcpu_simple_cb_t cb);
217 
218 /** struct qemu_plugin_tb - Opaque handle for a translation block */
219 struct qemu_plugin_tb;
220 /** struct qemu_plugin_insn - Opaque handle for a translated instruction */
221 struct qemu_plugin_insn;
222 
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  */
233 enum qemu_plugin_cb_flags {
234     QEMU_PLUGIN_CB_NO_REGS,
235     QEMU_PLUGIN_CB_R_REGS,
236     QEMU_PLUGIN_CB_RW_REGS,
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 
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 
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  */
265 QEMU_PLUGIN_API
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 /**
270  * qemu_plugin_register_vcpu_tb_exec_cb() - register execution callback
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  */
278 QEMU_PLUGIN_API
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 
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 
292 enum qemu_plugin_op {
293     QEMU_PLUGIN_INLINE_ADD_U64,
294 };
295 
296 /**
297  * qemu_plugin_register_vcpu_tb_exec_inline() - execution inline op
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.
306  *
307  * Note: ops are not atomic so in multi-threaded/multi-smp situations
308  * you will get inexact results.
309  */
310 QEMU_PLUGIN_API
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  */
324 QEMU_PLUGIN_API
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
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  */
340 QEMU_PLUGIN_API
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 
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
350  */
351 QEMU_PLUGIN_API
352 size_t qemu_plugin_tb_n_insns(const struct qemu_plugin_tb *tb);
353 
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  */
360 QEMU_PLUGIN_API
361 uint64_t qemu_plugin_tb_vaddr(const struct qemu_plugin_tb *tb);
362 
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  */
374 QEMU_PLUGIN_API
375 struct qemu_plugin_insn *
376 qemu_plugin_tb_get_insn(const struct qemu_plugin_tb *tb, size_t idx);
377 
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  */
388 QEMU_PLUGIN_API
389 const void *qemu_plugin_insn_data(const struct qemu_plugin_insn *insn);
390 
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  */
397 QEMU_PLUGIN_API
398 size_t qemu_plugin_insn_size(const struct qemu_plugin_insn *insn);
399 
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  */
406 QEMU_PLUGIN_API
407 uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn);
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  */
415 QEMU_PLUGIN_API
416 void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn);
417 
418 /**
419  * typedef qemu_plugin_meminfo_t - opaque memory transaction handle
420  *
421  * This can be further queried using the qemu_plugin_mem_* query
422  * functions.
423  */
424 typedef uint32_t qemu_plugin_meminfo_t;
425 /** struct qemu_plugin_hwaddr - opaque hw address handle */
426 struct qemu_plugin_hwaddr;
427 
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  */
434 QEMU_PLUGIN_API
435 unsigned int qemu_plugin_mem_size_shift(qemu_plugin_meminfo_t info);
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  */
442 QEMU_PLUGIN_API
443 bool qemu_plugin_mem_is_sign_extended(qemu_plugin_meminfo_t info);
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  */
450 QEMU_PLUGIN_API
451 bool qemu_plugin_mem_is_big_endian(qemu_plugin_meminfo_t info);
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  */
458 QEMU_PLUGIN_API
459 bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info);
460 
461 /**
462  * qemu_plugin_get_hwaddr() - return handle for memory operation
463  * @info: opaque memory info structure
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  */
474 QEMU_PLUGIN_API
475 struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
476                                                   uint64_t vaddr);
477 
478 /*
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
490  */
491 QEMU_PLUGIN_API
492 bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr);
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  */
503 QEMU_PLUGIN_API
504 uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr);
505 
506 /*
507  * Returns a string representing the device. The string is valid for
508  * the lifetime of the plugin.
509  */
510 QEMU_PLUGIN_API
511 const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h);
512 
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);
524 
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  */
545 QEMU_PLUGIN_API
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 
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  */
564 QEMU_PLUGIN_API
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 
578 QEMU_PLUGIN_API
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 
586 QEMU_PLUGIN_API
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 
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 
599 QEMU_PLUGIN_API
600 char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);
601 
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  */
609 QEMU_PLUGIN_API
610 const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn);
611 
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  */
621 QEMU_PLUGIN_API
622 void qemu_plugin_vcpu_for_each(qemu_plugin_id_t id,
623                                qemu_plugin_vcpu_simple_cb_t cb);
624 
625 QEMU_PLUGIN_API
626 void qemu_plugin_register_flush_cb(qemu_plugin_id_t id,
627                                    qemu_plugin_simple_cb_t cb);
628 
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  */
642 QEMU_PLUGIN_API
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 
652 /**
653  * qemu_plugin_outs() - output string via QEMU's logging system
654  * @string: a string
655  */
656 QEMU_PLUGIN_API
657 void qemu_plugin_outs(const char *string);
658 
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  */
670 QEMU_PLUGIN_API
671 bool qemu_plugin_bool_parse(const char *name, const char *val, bool *ret);
672 
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  */
681 QEMU_PLUGIN_API
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  */
690 QEMU_PLUGIN_API
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  */
699 QEMU_PLUGIN_API
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  */
708 QEMU_PLUGIN_API
709 uint64_t qemu_plugin_entry_code(void);
710 
711 #endif /* QEMU_QEMU_PLUGIN_H */
712