On 6/3/2026 1:51 PM, Pierrick Bouvier wrote:
> A coworker recently wrote a C++ plugin, and noticed interesting limitations of
> current API. Basically, the biggest issue is that the only way to maintain
> state
> in a plugin is by using global variables. The root cause is that some
> callback types can't transfer user data.
>
> Also, he asked why some callbacks have a qemu_plugin_id_t, and some other
> don't.
> This excellent question exposed that we don't need this most of the time. And
> if
> needed, we can rely on user data instead.
>
> For functional programmers here, it allows to have something similar to
> continuation-passing style, with all callbacks carrying data to next one.
>
> This series modifies our callback types to make sure they all have a userdata,
> and none have a qemu_plugin_id. Existing C plugins don't need to change, and
> global variables can still exist.
>
> After all those changes, we can finally implement a C++ plugin without any
> static variable (well, out of qemu_plugin_version), using an object and
> lambdas. This act as a demonstration of how we could write future plugins, and
> also, how we are finally on the edge to offer a proper native interface
> in Rust using closures.
>
> Pierrick Bouvier (25):
> plugins: bump version
> plugins: add userdata for qemu_plugin_{uninstall, reset}
> plugins: add userdata to qemu_plugin_register_flush_cb
> plugins: remove type qemu_plugin_simple_cb_t
> plugins: remove qemu_plugin_id_t from qemu_plugin_udata_cb_t
> plugins: remove qemu_plugin_id_t from qemu_plugin_vcpu_simple_cb_t
> plugins: add userdata to qemu_plugin_register_vcpu_init_cb
> plugins: add userdata to qemu_plugin_register_vcpu_exit_cb
> plugins: add userdata to qemu_plugin_register_vcpu_idle_cb
> plugins: add userdata to qemu_plugin_register_vcpu_resume_cb
> plugins: add userdata to qemu_plugin_vcpu_for_each
> plugins: remove type qemu_plugin_vcpu_simple_cb_t
> plugins: add userdata to qemu_plugin_register_vcpu_discon_cb
> plugins: remove qemu_plugin_id from qemu_plugin_vcpu_discon_cb_t
> plugins: remove qemu_plugin_id from qemu_plugin_vcpu_tb_trans_cb_t
> plugins: add userdata to qemu_plugin_vcpu_tb_trans_cb_t
> plugins: remove qemu_plugin_id from qemu_plugin_vcpu_syscall_cb_t
> plugins: add userdata to qemu_plugin_register_vcpu_syscall_cb
> plugins: remove qemu_plugin_id from
> qemu_plugin_vcpu_syscall_filter_cb_t
> plugins: add userdata to qemu_plugin_register_vcpu_syscall_filter_cb
> plugins: remove qemu_plugin_id from qemu_plugin_vcpu_syscall_ret_cb_t
> plugins: add userdata to qemu_plugin_register_vcpu_syscall_ret_cb
> scripts/checkpatch: ignore spaces required around some operators in
> C++
> scripts/checkpatch: remove check on forbidden space before '[' in C++
> plugins/cpp: register callbacks using captureless lambda
>
> contrib/plugins/bbv.c | 10 +--
> contrib/plugins/cache.c | 6 +-
> contrib/plugins/cflow.c | 6 +-
> contrib/plugins/cpp.cpp | 89 +++++++++++++++++++++++++-
> contrib/plugins/drcov.c | 6 +-
> contrib/plugins/execlog.c | 10 +--
> contrib/plugins/hotblocks.c | 6 +-
> contrib/plugins/hotpages.c | 6 +-
> contrib/plugins/howvec.c | 6 +-
> contrib/plugins/hwprofile.c | 6 +-
> contrib/plugins/ips.c | 14 ++---
> contrib/plugins/lockstep.c | 18 +++---
> contrib/plugins/stoptrigger.c | 6 +-
> contrib/plugins/traps.c | 9 +--
> contrib/plugins/uftrace.c | 10 +--
> include/plugins/qemu-plugin.h | 114 +++++++++++++++++++---------------
> include/qemu/plugin.h | 2 -
> plugins/api.c | 40 +++++++-----
> plugins/core.c | 94 +++++++++++-----------------
> plugins/loader.c | 13 ++--
> plugins/plugin.h | 5 +-
> scripts/checkpatch.pl | 20 +++++-
> tests/tcg/plugins/bb.c | 10 +--
> tests/tcg/plugins/discons.c | 10 +--
> tests/tcg/plugins/empty.c | 4 +-
> tests/tcg/plugins/inline.c | 6 +-
> tests/tcg/plugins/insn.c | 10 +--
> tests/tcg/plugins/mem.c | 6 +-
> tests/tcg/plugins/patch.c | 4 +-
> tests/tcg/plugins/registers.c | 4 +-
> tests/tcg/plugins/reset.c | 17 ++---
> tests/tcg/plugins/setpc.c | 10 +--
> tests/tcg/plugins/syscall.c | 22 ++++---
> 33 files changed, 354 insertions(+), 245 deletions(-)
>
sent v2:
https://lore.kernel.org/qemu-devel/[email protected]/T/#
Regards,
Pierrick