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_
17 #define QEMU_PLUGIN_MIN_VERSION 0
20 struct qemu_plugin_state
{
21 QTAILQ_HEAD(, qemu_plugin_ctx
) ctxs
;
22 QLIST_HEAD(, qemu_plugin_cb
) cb_lists
[QEMU_PLUGIN_EV_MAX
];
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().
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.
33 DECLARE_BITMAP(mask
, QEMU_PLUGIN_EV_MAX
);
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().
42 * HT of callbacks invoked from helpers. All entries are freed when
43 * the code cache is flushed.
45 struct qht dyn_cb_arr_ht
;
49 struct qemu_plugin_ctx
{
52 struct qemu_plugin_cb
*callbacks
[QEMU_PLUGIN_EV_MAX
];
53 QTAILQ_ENTRY(qemu_plugin_ctx
) entry
;
55 * keep a reference to @desc until uninstall, so that plugins do not have
56 * to strdup plugin args.
58 struct qemu_plugin_desc
*desc
;
64 struct qemu_plugin_ctx
*plugin_id_to_ctx_locked(qemu_plugin_id_t id
);
66 void plugin_register_inline_op(GArray
**arr
,
67 enum qemu_plugin_mem_rw rw
,
68 enum qemu_plugin_op op
, void *ptr
,
71 void plugin_reset_uninstall(qemu_plugin_id_t id
,
72 qemu_plugin_simple_cb_t cb
,
75 void plugin_register_cb(qemu_plugin_id_t id
, enum qemu_plugin_event ev
,
78 void plugin_unregister_cb__locked(struct qemu_plugin_ctx
*ctx
,
79 enum qemu_plugin_event ev
);
82 plugin_register_cb_udata(qemu_plugin_id_t id
, enum qemu_plugin_event ev
,
83 void *func
, void *udata
);
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
);
91 void plugin_register_vcpu_mem_cb(GArray
**arr
,
93 enum qemu_plugin_cb_flags flags
,
94 enum qemu_plugin_mem_rw rw
,
97 void exec_inline_op(struct qemu_plugin_dyn_cb
*cb
);
99 #endif /* _PLUGIN_INTERNAL_H_ */