Background
Qemu version 4.2.0, released Dec '19, included a new functionality for something called TCG Plugins. They have a few examples in the tests/plugins directory, and the API is more or less defined in qemu-plugin.h.
This file defines two enumerated types, qemu_plugin_cb_flags and qemu_plugin_mem_rw, which are passed into functions that register callbacks. These enums seem to indicate whether the callbacks will read or write CPU registers or memory. However, all of the example plugins use QEMU_PLUGIN_CB_NO_REGS, and only 2 of the plugins use the memory access enum. hotpages.c and mem.c use QEMU_PLUGIN_MEM_RW as the default for registering a memory callback (qemu_plugin_register_vcpu_mem_cb). mem.c has an argument when the plugin is loaded to choose if it's read or write, however, it doesn't seem to make any difference in the callback function.
Question
My question is, how do I access the guest memory and registers from the plugin callback function? The API seems to indicate that it is possible, since the callback registering requires you to say if you will access them, and if it's RW or just read.
Are there any examples of using this part of the API? I realize this is a very new part of Qemu functionality.
Code
When you register a callback on an instruction, like in insn.c, you can get the virtual address of the instruction.
uint64_t insn_vaddr = qemu_plugin_insn_vaddr(insn);
I am running a baremetal ARM program, and this virtual address seems to correlate to the address of the instruction in the ELF file.
Inside memory callback functions, you can call qemu_plugin_get_hwaddr to get the hardware address of the memory access, but I'm not sure exactly what that struct represents.
Related
This answer is 7 years old, and suggests using the GDB interface. My question is specifically related to using the TCG plugin functionality.