2 * Plugin Shared Internal Functions
4 * Copyright (C) 2019, Linaro
6 * License: GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef _PLUGIN_INTERNAL_H_
13 #define _PLUGIN_INTERNAL_H_
18 struct qemu_plugin_state
{
19 QTAILQ_HEAD(, qemu_plugin_ctx
) ctxs
;
20 QLIST_HEAD(, qemu_plugin_cb
) cb_lists
[QEMU_PLUGIN_EV_MAX
];
22 * Use the HT as a hash map by inserting k == v, which saves memory as
23 * documented by GLib. The parent struct is obtained with container_of().
27 * Use the HT as a hash map. Note that we could use a list here,
28 * but with the HT we avoid adding a field to CPUState.
31 DECLARE_BITMAP(mask
, QEMU_PLUGIN_EV_MAX
);
33 * @lock protects the struct as well as ctx->uninstalling.
34 * The lock must be acquired by all API ops.
35 * The lock is recursive, which greatly simplifies things, e.g.
36 * callback registration from qemu_plugin_vcpu_for_each().
40 * HT of callbacks invoked from helpers. All entries are freed when
41 * the code cache is flushed.
43 struct qht dyn_cb_arr_ht
;
47 struct qemu_plugin_ctx
{
50 struct qemu_plugin_cb
*callbacks
[QEMU_PLUGIN_EV_MAX
];
51 QTAILQ_ENTRY(qemu_plugin_ctx
) entry
;
53 * keep a reference to @desc until uninstall, so that plugins do not have
54 * to strdup plugin args.
56 struct qemu_plugin_desc
*desc
;
62 struct qemu_plugin_ctx
*plugin_id_to_ctx_locked(qemu_plugin_id_t id
);
64 void plugin_register_inline_op(GArray
**arr
,
65 enum qemu_plugin_mem_rw rw
,
66 enum qemu_plugin_op op
, void *ptr
,
69 void plugin_reset_uninstall(qemu_plugin_id_t id
,
70 qemu_plugin_simple_cb_t cb
,
73 void plugin_register_cb(qemu_plugin_id_t id
, enum qemu_plugin_event ev
,
76 void plugin_unregister_cb__locked(struct qemu_plugin_ctx
*ctx
,
77 enum qemu_plugin_event ev
);
80 plugin_register_cb_udata(qemu_plugin_id_t id
, enum qemu_plugin_event ev
,
81 void *func
, void *udata
);
84 plugin_register_dyn_cb__udata(GArray
**arr
,
85 qemu_plugin_vcpu_udata_cb_t cb
,
86 enum qemu_plugin_cb_flags flags
, void *udata
);
89 void plugin_register_vcpu_mem_cb(GArray
**arr
,
91 enum qemu_plugin_cb_flags flags
,
92 enum qemu_plugin_mem_rw rw
,
95 void exec_inline_op(struct qemu_plugin_dyn_cb
*cb
);
97 #endif /* _PLUGIN_INTERNAL_H_ */