Skip to content

Commit 903e870

Browse files
committed
plugins/api: split out binary path/start/end/entry code
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. Reviewed-by: Richard Henderson <[email protected]> Reviewed-by: Warner Losh <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent 8c15f6e commit 903e870

File tree

8 files changed

+115
-44
lines changed

8 files changed

+115
-44
lines changed

bsd-user/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bsd_user_ss.add(files(
1313
'elfload.c',
1414
'main.c',
1515
'mmap.c',
16+
'plugin-api.c',
1617
'signal.c',
1718
'strace.c',
1819
'uaccess.c',

bsd-user/plugin-api.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* QEMU Plugin API - bsd-user-mode only implementations
3+
*
4+
* Common user-mode only APIs are in plugins/api-user. These helpers
5+
* are only specific to bsd-user.
6+
*
7+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
8+
* Copyright (C) 2019-2025, Linaro
9+
*
10+
* SPDX-License-Identifier: GPL-2.0-or-later
11+
*/
12+
13+
#include "qemu/osdep.h"
14+
#include "qemu.h"
15+
#include "common-user/plugin-api.c.inc"

common-user/plugin-api.c.inc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* QEMU Plugin API - *-user-mode only implementations
3+
*
4+
* Common user-mode only APIs are in plugins/api-user. These helpers
5+
* are only specific to the *-user frontends.
6+
*
7+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
8+
* Copyright (C) 2019-2025, Linaro
9+
*
10+
* SPDX-License-Identifier: GPL-2.0-or-later
11+
*/
12+
13+
#include "qemu/osdep.h"
14+
#include "qemu/main-loop.h"
15+
#include "qemu/plugin.h"
16+
#include "qemu.h"
17+
18+
/*
19+
* Binary path, start and end locations. Host specific due to TaskState.
20+
*/
21+
const char *qemu_plugin_path_to_binary(void)
22+
{
23+
TaskState *ts = get_task_state(current_cpu);
24+
return g_strdup(ts->bprm->filename);
25+
}
26+
27+
uint64_t qemu_plugin_start_code(void)
28+
{
29+
TaskState *ts = get_task_state(current_cpu);
30+
return ts->info->start_code;
31+
}
32+
33+
uint64_t qemu_plugin_end_code(void)
34+
{
35+
TaskState *ts = get_task_state(current_cpu);
36+
return ts->info->end_code;
37+
}
38+
39+
uint64_t qemu_plugin_entry_code(void)
40+
{
41+
TaskState *ts = get_task_state(current_cpu);
42+
return ts->info->entry;
43+
}

linux-user/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ linux_user_ss.add(libdw)
2727
linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c'))
2828
linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c'))
2929
linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('semihost.c'))
30+
linux_user_ss.add(when: 'CONFIG_TCG_PLUGINS', if_true: files('plugin-api.c'))
3031

3132
syscall_nr_generators = {}
3233

linux-user/plugin-api.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* QEMU Plugin API - linux-user-mode only implementations
3+
*
4+
* Common user-mode only APIs are in plugins/api-user. These helpers
5+
* are only specific to linux-user.
6+
*
7+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
8+
* Copyright (C) 2019-2025, Linaro
9+
*
10+
* SPDX-License-Identifier: GPL-2.0-or-later
11+
*/
12+
13+
#include "qemu/osdep.h"
14+
#include "qemu.h"
15+
#include "common-user/plugin-api.c.inc"

plugins/api-system.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* QEMU Plugin API - System specific implementations
3+
*
4+
* This provides the APIs that have a specific system implementation
5+
* or are only relevant to system-mode.
6+
*
7+
* Copyright (C) 2017, Emilio G. Cota <[email protected]>
8+
* Copyright (C) 2019-2025, Linaro
9+
*
10+
* SPDX-License-Identifier: GPL-2.0-or-later
11+
*/
12+
13+
#include "qemu/osdep.h"
14+
#include "qemu/main-loop.h"
15+
#include "qemu/plugin.h"
16+
17+
/*
18+
* In system mode we cannot trace the binary being executed so the
19+
* helpers all return NULL/0.
20+
*/
21+
const char *qemu_plugin_path_to_binary(void)
22+
{
23+
return NULL;
24+
}
25+
26+
uint64_t qemu_plugin_start_code(void)
27+
{
28+
return 0;
29+
}
30+
31+
uint64_t qemu_plugin_end_code(void)
32+
{
33+
return 0;
34+
}
35+
36+
uint64_t qemu_plugin_entry_code(void)
37+
{
38+
return 0;
39+
}

plugins/api.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -471,49 +471,6 @@ bool qemu_plugin_bool_parse(const char *name, const char *value, bool *ret)
471471
return name && value && qapi_bool_parse(name, value, ret, NULL);
472472
}
473473

474-
/*
475-
* Binary path, start and end locations
476-
*/
477-
const char *qemu_plugin_path_to_binary(void)
478-
{
479-
char *path = NULL;
480-
#ifdef CONFIG_USER_ONLY
481-
TaskState *ts = get_task_state(current_cpu);
482-
path = g_strdup(ts->bprm->filename);
483-
#endif
484-
return path;
485-
}
486-
487-
uint64_t qemu_plugin_start_code(void)
488-
{
489-
uint64_t start = 0;
490-
#ifdef CONFIG_USER_ONLY
491-
TaskState *ts = get_task_state(current_cpu);
492-
start = ts->info->start_code;
493-
#endif
494-
return start;
495-
}
496-
497-
uint64_t qemu_plugin_end_code(void)
498-
{
499-
uint64_t end = 0;
500-
#ifdef CONFIG_USER_ONLY
501-
TaskState *ts = get_task_state(current_cpu);
502-
end = ts->info->end_code;
503-
#endif
504-
return end;
505-
}
506-
507-
uint64_t qemu_plugin_entry_code(void)
508-
{
509-
uint64_t entry = 0;
510-
#ifdef CONFIG_USER_ONLY
511-
TaskState *ts = get_task_state(current_cpu);
512-
entry = ts->info->entry;
513-
#endif
514-
return entry;
515-
}
516-
517474
/*
518475
* Create register handles.
519476
*

plugins/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if host_os == 'windows'
5959
endif
6060

6161
user_ss.add(files('user.c'))
62-
system_ss.add(files('system.c'))
62+
system_ss.add(files('system.c', 'api-system.c'))
6363

6464
common_ss.add(files('loader.c'))
6565

0 commit comments

Comments
 (0)