qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Li-Wen Hsu" <lwhsu@freebsd.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	qemu-arm@nongnu.org, "Alexandre Iooss" <erdnaxe@crans.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Riku Voipio" <riku.voipio@iki.fi>,
	"Warner Losh" <imp@bsdimp.com>,
	"Brian Cain" <brian.cain@oss.qualcomm.com>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Kyle Evans" <kevans@freebsd.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Ed Maste" <emaste@freebsd.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>
Subject: [PATCH v2 26/32] plugins/api: split out binary path/start/end/entry code
Date: Tue,  4 Mar 2025 22:24:33 +0000	[thread overview]
Message-ID: <20250304222439.2035603-27-alex.bennee@linaro.org> (raw)
In-Reply-To: <20250304222439.2035603-1-alex.bennee@linaro.org>

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.

While using the plugin-api.c.inc trick means we build for both
linux-user and bsd-user the BSD user-mode command line is still
missing -plugin. This can be enabled once we have reliable check-tcg
tests working for the BSDs.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Message-Id: <20250226140343.3907080-22-alex.bennee@linaro.org>

---
v2
  - use common-user/plugin-api.c.inc instead
  - add commentary about state of plugins for BSD user
v3
  - add missing osdep include
---
 bsd-user/plugin-api.c        | 15 +++++++++++++
 linux-user/plugin-api.c      | 15 +++++++++++++
 plugins/api-system.c         | 39 ++++++++++++++++++++++++++++++++
 plugins/api.c                | 43 ------------------------------------
 common-user/plugin-api.c.inc | 43 ++++++++++++++++++++++++++++++++++++
 bsd-user/meson.build         |  1 +
 linux-user/meson.build       |  1 +
 plugins/meson.build          |  2 +-
 8 files changed, 115 insertions(+), 44 deletions(-)
 create mode 100644 bsd-user/plugin-api.c
 create mode 100644 linux-user/plugin-api.c
 create mode 100644 plugins/api-system.c
 create mode 100644 common-user/plugin-api.c.inc

diff --git a/bsd-user/plugin-api.c b/bsd-user/plugin-api.c
new file mode 100644
index 0000000000..6ccef7eaa0
--- /dev/null
+++ b/bsd-user/plugin-api.c
@@ -0,0 +1,15 @@
+/*
+ * QEMU Plugin API - bsd-user-mode only implementations
+ *
+ * Common user-mode only APIs are in plugins/api-user. These helpers
+ * are only specific to bsd-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.h"
+#include "common-user/plugin-api.c.inc"
diff --git a/linux-user/plugin-api.c b/linux-user/plugin-api.c
new file mode 100644
index 0000000000..66755df526
--- /dev/null
+++ b/linux-user/plugin-api.c
@@ -0,0 +1,15 @@
+/*
+ * 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.h"
+#include "common-user/plugin-api.c.inc"
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 c3ba1e98e8..ffccd71e4b 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -471,49 +471,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/common-user/plugin-api.c.inc b/common-user/plugin-api.c.inc
new file mode 100644
index 0000000000..5b8a1396b6
--- /dev/null
+++ b/common-user/plugin-api.c.inc
@@ -0,0 +1,43 @@
+/*
+ * QEMU Plugin API - *-user-mode only implementations
+ *
+ * Common user-mode only APIs are in plugins/api-user. These helpers
+ * are only specific to the *-user frontends.
+ *
+ * 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/bsd-user/meson.build b/bsd-user/meson.build
index 39bad0ae33..37b7cd6de8 100644
--- a/bsd-user/meson.build
+++ b/bsd-user/meson.build
@@ -13,6 +13,7 @@ bsd_user_ss.add(files(
   'elfload.c',
   'main.c',
   'mmap.c',
+  'plugin-api.c',
   'signal.c',
   'strace.c',
   'uaccess.c',
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



  parent reply	other threads:[~2025-03-04 22:33 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 22:24 [PATCH v2 00/32] maintainer updates for 10.0 softfreeze (gpu/tcg tests, plugins, MAINTAINERS) pre-PR Alex Bennée
2025-03-04 22:24 ` [PATCH v2 01/32] tests/functional: move aarch64 GPU test into own file Alex Bennée
2025-03-05  8:17   ` Thomas Huth
2025-03-04 22:24 ` [PATCH v2 02/32] tests/functional: factor out common code in gpu test Alex Bennée
2025-03-05  8:29   ` Thomas Huth
2025-03-04 22:24 ` [PATCH v2 03/32] tests/functional: ensure we have a GPU device for tests Alex Bennée
2025-03-04 22:24 ` [PATCH v2 04/32] tests/functional: bail early if vkmark hangs Alex Bennée
2025-03-05  8:30   ` Thomas Huth
2025-03-04 22:24 ` [PATCH v2 05/32] tests/functional: skip vulkan tests with nVidia Alex Bennée
2025-03-04 22:24 ` [PATCH v2 06/32] tests/functional: expand tests to cover virgl Alex Bennée
2025-03-04 22:24 ` [PATCH v2 07/32] tests/functional: update the aarch64_virg_gpu images Alex Bennée
2025-03-05  8:35   ` Thomas Huth
2025-03-05 16:58     ` Alex Bennée
2025-03-04 22:24 ` [PATCH v2 08/32] plugins: add explicit dependency in functional tests Alex Bennée
2025-03-04 22:24 ` [PATCH v2 09/32] tests/functional: Introduce the dso_suffix() helper Alex Bennée
2025-03-04 22:24 ` [PATCH v2 10/32] tests/functional: Allow running TCG plugins tests on non-Linux/BSD hosts Alex Bennée
2025-03-04 22:24 ` [PATCH v2 11/32] libvirt-ci: bump to latest for vulkan-tools Alex Bennée
2025-03-04 22:24 ` [PATCH v2 12/32] tests/vm: bump timeout for shutdown Alex Bennée
2025-03-04 22:24 ` [PATCH v2 13/32] tests/tcg: mark test-vma as a linux-only test Alex Bennée
2025-03-04 22:49   ` Richard Henderson
2025-03-04 22:24 ` [PATCH v2 14/32] tests/tcg: add message to _Static_assert in test-avx Alex Bennée
2025-03-04 22:48   ` Richard Henderson
2025-03-04 22:24 ` [PATCH v2 15/32] tests/tcg: fix constraints in test-i386-adcox Alex Bennée
2025-03-04 22:45   ` Richard Henderson
2025-03-04 22:24 ` [PATCH v2 16/32] tests/tcg: enable -fwrapv for test-i386-bmi Alex Bennée
2025-03-04 22:24 ` [PATCH v2 17/32] tests/tcg: Suppress compiler false-positive warning on sha1.c Alex Bennée
2025-03-04 22:24 ` [PATCH v2 18/32] gitlab: add a new build_unit job to track build size Alex Bennée
2025-03-04 22:24 ` [PATCH v2 19/32] tests/functional: add boot error detection for RME tests Alex Bennée
2025-03-04 22:24 ` [PATCH v2 20/32] plugins/api: use qemu_target_page_mask() to get value Alex Bennée
2025-03-04 22:24 ` [PATCH v2 21/32] plugins/loader: populate target_name with target_name() Alex Bennée
2025-03-05  0:01   ` Philippe Mathieu-Daudé
2025-03-05  6:57     ` Alex Bennée
2025-03-04 22:24 ` [PATCH v2 22/32] include/qemu: plugin-memory.h doesn't need cpu-defs.h Alex Bennée
2025-03-04 22:24 ` [PATCH v2 23/32] plugins/api: clean-up the includes Alex Bennée
2025-03-04 22:24 ` [PATCH v2 24/32] plugins/plugin.h: include queue.h Alex Bennée
2025-03-04 22:24 ` [PATCH v2 25/32] plugins/loader: compile loader only once Alex Bennée
2025-03-04 22:24 ` Alex Bennée [this message]
2025-03-04 22:24 ` [PATCH v2 27/32] plugins/api: split out the vaddr/hwaddr helpers Alex Bennée
2025-03-04 22:24 ` [PATCH v2 28/32] plugins/api: split out time control helpers Alex Bennée
2025-03-04 22:24 ` [PATCH v2 29/32] plugins/api: build only once Alex Bennée
2025-03-04 22:24 ` [PATCH v2 30/32] plugins/core: make a single build unit Alex Bennée
2025-03-04 22:54   ` Richard Henderson
2025-03-04 22:24 ` [PATCH v2 31/32] MAINTAINERS: remove widely sanctioned entities Alex Bennée
2025-03-04 22:24 ` [PATCH v2 32/32] meson.build: default to -gsplit-dwarf for debug info Alex Bennée
2025-03-04 23:05   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250304222439.2035603-27-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=brian.cain@oss.qualcomm.com \
    --cc=eduardo@habkost.net \
    --cc=emaste@freebsd.org \
    --cc=erdnaxe@crans.org \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=laurent@vivier.eu \
    --cc=lwhsu@freebsd.org \
    --cc=ma.mandourr@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=riku.voipio@iki.fi \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).