@@ -437,6 +437,10 @@ int qemu_plugin_read_register(struct
qemu_plugin_register *reg, GByteArray *buf)
{
g_assert(current_cpu);
+ if (qemu_plugin_get_cb_flags() == QEMU_PLUGIN_CB_NO_REGS) {
+ return -1;
+ }
+
return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg)
- 1);
}
@@ -445,6 +449,10 @@ int qemu_plugin_write_register(struct
qemu_plugin_register *reg,
{
g_assert(current_cpu);
+ if (buf->len == 0 || qemu_plugin_get_cb_flags() !=
QEMU_PLUGIN_CB_RW_REGS) {
+ return 0;
+ }
+
Would it be better to return -1 for "qemu_plugin_get_cb_flags() !=
QEMU_PLUGIN_CB_RW_REGS", so user can notice there is something wrong
with flags?
Sure would, typo on my part here.
return gdb_write_register(current_cpu, buf->data,
GPOINTER_TO_INT(reg) - 1);
}
diff --git a/plugins/core.c b/plugins/core.c
index eb9281fe54..34bddb6c1c 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -364,14 +364,15 @@ void plugin_register_dyn_cb__udata(GArray **arr,
enum qemu_plugin_cb_flags flags,
void *udata)
{
- static TCGHelperInfo info[3] = {
+ static TCGHelperInfo info[4] = {
[QEMU_PLUGIN_CB_NO_REGS].flags = TCG_CALL_NO_RWG,
[QEMU_PLUGIN_CB_R_REGS].flags = TCG_CALL_NO_WG,
+ [QEMU_PLUGIN_CB_RW_REGS].flags = 0,
/*
* Match qemu_plugin_vcpu_udata_cb_t:
* void (*)(uint32_t, void *)
*/
- [0 ... 2].typemask = (dh_typemask(void, 0) |
+ [0 ... 3].typemask = (dh_typemask(void, 0) |
dh_typemask(i32, 1) |
dh_typemask(ptr, 2))
};
[QEMU_PLUGIN_CB_RW_REGS].flags = 0 was already set implicitly, as all
elements not explicit set are initialized to 0.
As you can see, [0 ... 2].typemask was set, which shows we initialized
the third element.
Adding [QEMU_PLUGIN_CB_RW_REGS].flags = 0 does not hurt, and is more
explicit, but you don't need to increase array size.
This static array is used to set info field in callback struct, as
.info = &info[flags]. Flags being an enum qemu_plugin_cb_flags, its
value is 0,1 or 2, so adding one entry is useless.
Got it, for some reason I assumed this array needed a sentinel value and
simultaneously didn't recognize the [0 ... n] sytnax was inclusive.
Thanks for pointing that out!
I'll make these two changes.