arm tcg cpus: Fix Lesser GPL version number
[qemu.git] / plugins / plugin.h
1 /*
2 * Plugin Shared Internal Functions
3 *
4 * Copyright (C) 2019, Linaro
5 *
6 * License: GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12 #ifndef _PLUGIN_INTERNAL_H_
13 #define _PLUGIN_INTERNAL_H_
14
15 #include <gmodule.h>
16
17 #define QEMU_PLUGIN_MIN_VERSION 0
18
19 /* global state */
20 struct qemu_plugin_state {
21 QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
22 QLIST_HEAD(, qemu_plugin_cb) cb_lists[QEMU_PLUGIN_EV_MAX];
23 /*
24 * Use the HT as a hash map by inserting k == v, which saves memory as
25 * documented by GLib. The parent struct is obtained with container_of().
26 */
27 GHashTable *id_ht;
28 /*
29 * Use the HT as a hash map. Note that we could use a list here,
30 * but with the HT we avoid adding a field to CPUState.
31 */
32 GHashTable *cpu_ht;
33 DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX);
34 /*
35 * @lock protects the struct as well as ctx->uninstalling.
36 * The lock must be acquired by all API ops.
37 * The lock is recursive, which greatly simplifies things, e.g.
38 * callback registration from qemu_plugin_vcpu_for_each().
39 */
40 QemuRecMutex lock;
41 /*
42 * HT of callbacks invoked from helpers. All entries are freed when
43 * the code cache is flushed.
44 */
45 struct qht dyn_cb_arr_ht;
46 };
47
48
49 struct qemu_plugin_ctx {
50 GModule *handle;
51 qemu_plugin_id_t id;
52 struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX];
53 QTAILQ_ENTRY(qemu_plugin_ctx) entry;
54 /*
55 * keep a reference to @desc until uninstall, so that plugins do not have
56 * to strdup plugin args.
57 */
58 struct qemu_plugin_desc *desc;
59 bool installing;
60 bool uninstalling;
61 bool resetting;
62 };
63
64 struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id);
65
66 void plugin_register_inline_op(GArray **arr,
67 enum qemu_plugin_mem_rw rw,
68 enum qemu_plugin_op op, void *ptr,
69 uint64_t imm);
70
71 void plugin_reset_uninstall(qemu_plugin_id_t id,
72 qemu_plugin_simple_cb_t cb,
73 bool reset);
74
75 void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev,
76 void *func);
77
78 void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx,
79 enum qemu_plugin_event ev);
80
81 void
82 plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev,
83 void *func, void *udata);
84
85 void
86 plugin_register_dyn_cb__udata(GArray **arr,
87 qemu_plugin_vcpu_udata_cb_t cb,
88 enum qemu_plugin_cb_flags flags, void *udata);
89
90
91 void plugin_register_vcpu_mem_cb(GArray **arr,
92 void *cb,
93 enum qemu_plugin_cb_flags flags,
94 enum qemu_plugin_mem_rw rw,
95 void *udata);
96
97 void exec_inline_op(struct qemu_plugin_dyn_cb *cb);
98
99 #endif /* _PLUGIN_INTERNAL_H_ */