qga/qapi-schema: Move error documentation to new "Errors" sections
[qemu/armbru.git] / plugins / plugin.h
blob00b3509f7082216ebf512849f9fb53562af48324
1 /*
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_H
13 #define PLUGIN_H
15 #include <gmodule.h>
16 #include "qemu/qht.h"
18 #define QEMU_PLUGIN_MIN_VERSION 2
20 /* global state */
21 struct qemu_plugin_state {
22 QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
23 QLIST_HEAD(, qemu_plugin_cb) cb_lists[QEMU_PLUGIN_EV_MAX];
25 * Use the HT as a hash map by inserting k == v, which saves memory as
26 * documented by GLib. The parent struct is obtained with container_of().
28 GHashTable *id_ht;
30 * Use the HT as a hash map. Note that we could use a list here,
31 * but with the HT we avoid adding a field to CPUState.
33 GHashTable *cpu_ht;
34 DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX);
36 * @lock protects the struct as well as ctx->uninstalling.
37 * The lock must be acquired by all API ops.
38 * The lock is recursive, which greatly simplifies things, e.g.
39 * callback registration from qemu_plugin_vcpu_for_each().
41 QemuRecMutex lock;
43 * HT of callbacks invoked from helpers. All entries are freed when
44 * the code cache is flushed.
46 struct qht dyn_cb_arr_ht;
47 /* How many vcpus were started */
48 int num_vcpus;
52 struct qemu_plugin_ctx {
53 GModule *handle;
54 qemu_plugin_id_t id;
55 struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX];
56 QTAILQ_ENTRY(qemu_plugin_ctx) entry;
58 * keep a reference to @desc until uninstall, so that plugins do not have
59 * to strdup plugin args.
61 struct qemu_plugin_desc *desc;
62 bool installing;
63 bool uninstalling;
64 bool resetting;
67 struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id);
69 void plugin_register_inline_op(GArray **arr,
70 enum qemu_plugin_mem_rw rw,
71 enum qemu_plugin_op op, void *ptr,
72 uint64_t imm);
74 void plugin_reset_uninstall(qemu_plugin_id_t id,
75 qemu_plugin_simple_cb_t cb,
76 bool reset);
78 void plugin_register_cb(qemu_plugin_id_t id, enum qemu_plugin_event ev,
79 void *func);
81 void plugin_unregister_cb__locked(struct qemu_plugin_ctx *ctx,
82 enum qemu_plugin_event ev);
84 void
85 plugin_register_cb_udata(qemu_plugin_id_t id, enum qemu_plugin_event ev,
86 void *func, void *udata);
88 void
89 plugin_register_dyn_cb__udata(GArray **arr,
90 qemu_plugin_vcpu_udata_cb_t cb,
91 enum qemu_plugin_cb_flags flags, void *udata);
94 void plugin_register_vcpu_mem_cb(GArray **arr,
95 void *cb,
96 enum qemu_plugin_cb_flags flags,
97 enum qemu_plugin_mem_rw rw,
98 void *udata);
100 void exec_inline_op(struct qemu_plugin_dyn_cb *cb);
102 int plugin_num_vcpus(void);
104 #endif /* PLUGIN_H */