Browse Source

tests/tcg/plugins/mem.c: remove dependency on qemu headers

This plugin uses endianness conversion primitives from QEMU headers. As
next commit will strongly isolate plugins code from those headers, those
primitives can't be used anymore.

glib.h provides such primitives:
https://docs.gtk.org/glib/conversion-macros.html#byte-order-conversion

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/qemu-devel/20260124182921.531562-6-pierrick.bouvier@linaro.org
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
pull/319/head
Pierrick Bouvier 7 months ago
parent
commit
eb3f69cac6
  1. 59
      tests/tcg/plugins/mem.c

59
tests/tcg/plugins/mem.c

@ -12,16 +12,7 @@
#include <stdio.h>
#include <glib.h>
/*
* plugins should not include anything from QEMU aside from the
* API header. However as this is a test plugin to exercise the
* internals of QEMU and we want to avoid needless code duplication we
* do so here. bswap.h is pretty self-contained although it needs a
* few things provided by compiler.h.
*/
#include <compiler.h>
#include <stdbool.h>
#include <bswap.h>
#include <qemu-plugin.h>
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
@ -152,56 +143,52 @@ static void update_region_info(uint64_t region, uint64_t offset,
ri->reads++;
}
void *ri_data = &ri->data[offset];
switch (value.type) {
case QEMU_PLUGIN_MEM_VALUE_U8:
{
uint8_t val = value.data.u8;
uint8_t *p = ri_data;
if (is_store) {
ri->data[offset] = value.data.u8;
} else if (ri->data[offset] != value.data.u8) {
unseen_data = true;
*p = val;
} else {
unseen_data = *p != val;
}
break;
}
case QEMU_PLUGIN_MEM_VALUE_U16:
{
uint16_t *p = (uint16_t *) &ri->data[offset];
uint16_t val = be ? GUINT16_FROM_BE(value.data.u16) :
GUINT16_FROM_LE(value.data.u16);
uint16_t *p = ri_data;
if (is_store) {
if (be) {
stw_be_p(p, value.data.u16);
} else {
stw_le_p(p, value.data.u16);
}
*p = val;
} else {
uint16_t val = be ? lduw_be_p(p) : lduw_le_p(p);
unseen_data = val != value.data.u16;
unseen_data = *p != val;
}
break;
}
case QEMU_PLUGIN_MEM_VALUE_U32:
{
uint32_t *p = (uint32_t *) &ri->data[offset];
uint32_t val = be ? GUINT32_FROM_BE(value.data.u32) :
GUINT32_FROM_LE(value.data.u32);
uint32_t *p = ri_data;
if (is_store) {
if (be) {
stl_be_p(p, value.data.u32);
} else {
stl_le_p(p, value.data.u32);
}
*p = val;
} else {
uint32_t val = be ? ldl_be_p(p) : ldl_le_p(p);
unseen_data = val != value.data.u32;
unseen_data = *p != val;
}
break;
}
case QEMU_PLUGIN_MEM_VALUE_U64:
{
uint64_t *p = (uint64_t *) &ri->data[offset];
uint64_t val = be ? GUINT64_FROM_BE(value.data.u64) :
GUINT64_FROM_LE(value.data.u64);
uint64_t *p = ri_data;
if (is_store) {
if (be) {
stq_be_p(p, value.data.u64);
} else {
stq_le_p(p, value.data.u64);
}
*p = val;
} else {
uint64_t val = be ? ldq_be_p(p) : ldq_le_p(p);
unseen_data = val != value.data.u64;
unseen_data = *p != val;
}
break;
}

Loading…
Cancel
Save