To move the main api.c to a single build compilation object we need to
start splitting out user and system specific code. As we need to grob
around host headers we move these particular helpers into the *-user
mode directories.
The binary/start/end/entry helpers are all NOPs for system mode.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
linux-user/plugin-api.c | 43 +++++++++++++++++++++++++++++++++++++++++
plugins/api-system.c | 39 +++++++++++++++++++++++++++++++++++++
plugins/api.c | 43 -----------------------------------------
linux-user/meson.build | 1 +
plugins/meson.build | 2 +-
5 files changed, 84 insertions(+), 44 deletions(-)
create mode 100644 linux-user/plugin-api.c
create mode 100644 plugins/api-system.c
diff --git a/linux-user/plugin-api.c b/linux-user/plugin-api.c
new file mode 100644
index 0000000000..42e977c339
--- /dev/null
+++ b/linux-user/plugin-api.c
@@ -0,0 +1,43 @@
+/*
+ * QEMU Plugin API - linux-user-mode only implementations
+ *
+ * Common user-mode only APIs are in plugins/api-user. These helpers
+ * are only specific to linux-user.
+ *
+ * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
+ * Copyright (C) 2019-2025, Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+#include "qemu/plugin.h"
+#include "qemu.h"
+
+/*
+ * Binary path, start and end locations. Host specific due to TaskState.
+ */
+const char *qemu_plugin_path_to_binary(void)
+{
+ TaskState *ts = get_task_state(current_cpu);
+ return g_strdup(ts->bprm->filename);
+}
+
+uint64_t qemu_plugin_start_code(void)
+{
+ TaskState *ts = get_task_state(current_cpu);
+ return ts->info->start_code;
+}
+
+uint64_t qemu_plugin_end_code(void)
+{
+ TaskState *ts = get_task_state(current_cpu);
+ return ts->info->end_code;
+}
+
+uint64_t qemu_plugin_entry_code(void)
+{
+ TaskState *ts = get_task_state(current_cpu);
+ return ts->info->entry;
+}
diff --git a/plugins/api-system.c b/plugins/api-system.c
new file mode 100644
index 0000000000..cb0dd8f730
--- /dev/null
+++ b/plugins/api-system.c
@@ -0,0 +1,39 @@
+/*
+ * QEMU Plugin API - System specific implementations
+ *
+ * This provides the APIs that have a specific system implementation
+ * or are only relevant to system-mode.
+ *
+ * Copyright (C) 2017, Emilio G. Cota <cota@braap.org>
+ * Copyright (C) 2019-2025, Linaro
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+#include "qemu/plugin.h"
+
+/*
+ * In system mode we cannot trace the binary being executed so the
+ * helpers all return NULL/0.
+ */
+const char *qemu_plugin_path_to_binary(void)
+{
+ return NULL;
+}
+
+uint64_t qemu_plugin_start_code(void)
+{
+ return 0;
+}
+
+uint64_t qemu_plugin_end_code(void)
+{
+ return 0;
+}
+
+uint64_t qemu_plugin_entry_code(void)
+{
+ return 0;
+}
diff --git a/plugins/api.c b/plugins/api.c
index 3e1aac7bfb..12a3b6a66d 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -470,49 +470,6 @@ bool qemu_plugin_bool_parse(const char *name, const char *value, bool *ret)
return name && value && qapi_bool_parse(name, value, ret, NULL);
}
-/*
- * Binary path, start and end locations
- */
-const char *qemu_plugin_path_to_binary(void)
-{
- char *path = NULL;
-#ifdef CONFIG_USER_ONLY
- TaskState *ts = get_task_state(current_cpu);
- path = g_strdup(ts->bprm->filename);
-#endif
- return path;
-}
-
-uint64_t qemu_plugin_start_code(void)
-{
- uint64_t start = 0;
-#ifdef CONFIG_USER_ONLY
- TaskState *ts = get_task_state(current_cpu);
- start = ts->info->start_code;
-#endif
- return start;
-}
-
-uint64_t qemu_plugin_end_code(void)
-{
- uint64_t end = 0;
-#ifdef CONFIG_USER_ONLY
- TaskState *ts = get_task_state(current_cpu);
- end = ts->info->end_code;
-#endif
- return end;
-}
-
-uint64_t qemu_plugin_entry_code(void)
-{
- uint64_t entry = 0;
-#ifdef CONFIG_USER_ONLY
- TaskState *ts = get_task_state(current_cpu);
- entry = ts->info->entry;
-#endif
- return entry;
-}
-
/*
* Create register handles.
*
diff --git a/linux-user/meson.build b/linux-user/meson.build
index f75b4fe0e3..f47a213ca3 100644
--- a/linux-user/meson.build
+++ b/linux-user/meson.build
@@ -27,6 +27,7 @@ linux_user_ss.add(libdw)
linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c'))
linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c'))
linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('semihost.c'))
+linux_user_ss.add(when: 'CONFIG_TCG_PLUGINS', if_true: files('plugin-api.c'))
syscall_nr_generators = {}
diff --git a/plugins/meson.build b/plugins/meson.build
index f7820806d3..9c9bc9e5bb 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -59,7 +59,7 @@ if host_os == 'windows'
endif
user_ss.add(files('user.c'))
-system_ss.add(files('system.c'))
+system_ss.add(files('system.c', 'api-system.c'))
common_ss.add(files('loader.c'))
--
2.39.5
On 2/25/25 03:08, Alex Bennée wrote:
> To move the main api.c to a single build compilation object we need to
> start splitting out user and system specific code. As we need to grob
> around host headers we move these particular helpers into the *-user
> mode directories.
>
> The binary/start/end/entry helpers are all NOPs for system mode.
>
> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
> ---
> linux-user/plugin-api.c | 43 +++++++++++++++++++++++++++++++++++++++++
> plugins/api-system.c | 39 +++++++++++++++++++++++++++++++++++++
> plugins/api.c | 43 -----------------------------------------
> linux-user/meson.build | 1 +
> plugins/meson.build | 2 +-
> 5 files changed, 84 insertions(+), 44 deletions(-)
> create mode 100644 linux-user/plugin-api.c
> create mode 100644 plugins/api-system.c
Surely this breaks bsd-user.
Ideally this would go in common-user, but I think you'd need to move structures out of
{bsd,linux}-user/qemu.h into include/user/.
In the very short term you could put plugin-api.c.inc in common-user, and
#include "qemu.h"
#include "common-user/plugin-api.c.inc"
in both linux-user and bsd-user.
r~
Richard Henderson <richard.henderson@linaro.org> writes:
> On 2/25/25 03:08, Alex Bennée wrote:
>> To move the main api.c to a single build compilation object we need to
>> start splitting out user and system specific code. As we need to grob
>> around host headers we move these particular helpers into the *-user
>> mode directories.
>> The binary/start/end/entry helpers are all NOPs for system mode.
>> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
>> ---
>> linux-user/plugin-api.c | 43 +++++++++++++++++++++++++++++++++++++++++
>> plugins/api-system.c | 39 +++++++++++++++++++++++++++++++++++++
>> plugins/api.c | 43 -----------------------------------------
>> linux-user/meson.build | 1 +
>> plugins/meson.build | 2 +-
>> 5 files changed, 84 insertions(+), 44 deletions(-)
>> create mode 100644 linux-user/plugin-api.c
>> create mode 100644 plugins/api-system.c
>
> Surely this breaks bsd-user.
It didn't seem to - but my local building isn't working so maybe CI
disables plugins.
>
> Ideally this would go in common-user, but I think you'd need to move
> structures out of {bsd,linux}-user/qemu.h into include/user/.
>
> In the very short term you could put plugin-api.c.inc in common-user, and
>
>
> #include "qemu.h"
> #include "common-user/plugin-api.c.inc"
>
>
> in both linux-user and bsd-user.
>
>
> r~
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
© 2016 - 2026 Red Hat, Inc.