summary refs log tree commit diff stats
path: root/plugins/api.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2024-04-03 09:54:43 -1000
committerRichard Henderson <richard.henderson@linaro.org>2024-05-15 08:55:18 +0200
commitd3ace105900c43d1eb034b81ce0951e6110ab990 (patch)
tree180f5fe787b3da20b8bd262ee4c1392d16c62eab /plugins/api.c
parente501325991815e09297a048ffb0be81411bbe34a (diff)
downloadfocaccia-qemu-d3ace105900c43d1eb034b81ce0951e6110ab990.tar.gz
focaccia-qemu-d3ace105900c43d1eb034b81ce0951e6110ab990.zip
plugins: Use DisasContextBase for qemu_plugin_insn_haddr
We can delay the computation of haddr until the plugin
actually requests it.

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'plugins/api.c')
-rw-r--r--plugins/api.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/plugins/api.c b/plugins/api.c
index 9e4aa9d2d9..0ae19774df 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -242,7 +242,30 @@ uint64_t qemu_plugin_insn_vaddr(const struct qemu_plugin_insn *insn)
 
 void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn)
 {
-    return insn->haddr;
+    const DisasContextBase *db = tcg_ctx->plugin_db;
+    vaddr page0_last = db->pc_first | ~TARGET_PAGE_MASK;
+
+    if (db->fake_insn) {
+        return NULL;
+    }
+
+    /*
+     * ??? The return value is not intended for use of host memory,
+     * but as a proxy for address space and physical address.
+     * Thus we are only interested in the first byte and do not
+     * care about spanning pages.
+     */
+    if (insn->vaddr <= page0_last) {
+        if (db->host_addr[0] == NULL) {
+            return NULL;
+        }
+        return db->host_addr[0] + insn->vaddr - db->pc_first;
+    } else {
+        if (db->host_addr[1] == NULL) {
+            return NULL;
+        }
+        return db->host_addr[1] + insn->vaddr - (page0_last + 1);
+    }
 }
 
 char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn)