On Sat, Nov 7, 2026 at 1:44 AM Pierrick Bouvier
<[email protected]> wrote:
>
> On 11/5/2026 11:03 AM, Yonggang Luo wrote:
> > Return the QEMU_ARCH_* mask of the selected target. System mode
> > returns QEMU_ARCH_ALL until a target is selected. User mode returns
> > that target's bit. Tools return 0.
> >
> > Signed-off-by: Yonggang Luo <[email protected]>
> > ---
> > include/qemu/target-info-init.h | 15 ++++++++++-----
> > include/qemu/target-info.h | 9 +++++++++
> > stubs/meson.build | 1 +
> > stubs/target-mask-selected.c | 13 +++++++++++++
> > target-info-def.c | 3 +++
> > target-info-qom.c | 10 ++++++++++
> > 6 files changed, 46 insertions(+), 5 deletions(-)
> > create mode 100644 stubs/target-mask-selected.c
> >
> > diff --git a/include/qemu/target-info-init.h
> > b/include/qemu/target-info-init.h
> > index b7024c9fae..8492986832 100644
> > --- a/include/qemu/target-info-init.h
> > +++ b/include/qemu/target-info-init.h
> > @@ -24,12 +24,17 @@ module_init(do_qemu_init_target_info,
> > MODULE_INIT_TARGET_INFO)
> >
> > /*
> > * User mode does not support multiple targets in the same binary, so just
> > - * define target_info().
> > + * define target_info() and target_mask_selected(). The target is always
> > + * selected.
> > */
> > -#define target_info_init(ti_var) \
> > -const TargetInfo *target_info(void) \
> > -{ \
> > - return &ti_var; \
> > +#define target_info_init(ti_var) \
> > +const TargetInfo *target_info(void) \
> > +{ \
> > + return &ti_var; \
> > +} \
> > +uint64_t target_mask_selected(void) \
> > +{ \
> > + return QEMU_ARCH_BIT((ti_var).target_arch); \
> > }
> >
> > #else /* CONFIG_USER_ONLY */
> > diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
> > index 2cd4cc5671..5673d10eba 100644
> > --- a/include/qemu/target-info.h
> > +++ b/include/qemu/target-info.h
> > @@ -134,4 +134,13 @@ bool target_base_riscv(void);
> > */
> > bool target_riscv64(void);
> >
> > +/**
> > + * target_mask_selected:
> > + *
> > + * Returns the QEMU_ARCH_* mask of the selected target. System mode
> > + * returns QEMU_ARCH_ALL until a target is selected. User mode returns
> > + * that target's bit. Tools return 0.
> > + */
> > +uint64_t target_mask_selected(void);
> > +
> > #endif
> > diff --git a/stubs/meson.build b/stubs/meson.build
> > index 744fb759a2..49cede8582 100644
> > --- a/stubs/meson.build
> > +++ b/stubs/meson.build
> > @@ -12,6 +12,7 @@ stub_ss.add(files('monitor-hmp.c'))
> > stub_ss.add(files('qapi-event-emit.c'))
> > stub_ss.add(files('replay-mode.c'))
> > stub_ss.add(files('trace-control.c'))
> > +stub_ss.add(files('target-mask-selected.c'))
> >
>
> For which configs is the stub required?
> target-info-def will always be present.
For tools
>
> > if have_block
> > stub_ss.add(files('bdrv-next-monitor-owned.c'))
> > diff --git a/stubs/target-mask-selected.c b/stubs/target-mask-selected.c
> > new file mode 100644
> > index 0000000000..510a515851
> > --- /dev/null
> > +++ b/stubs/target-mask-selected.c
> > @@ -0,0 +1,13 @@
> > +/*
> > + * Tools have no selected target.
> > + *
> > + * SPDX-License-Identifier: GPL-2.0-or-later
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu/target-info.h"
> > +
> > +uint64_t target_mask_selected(void)
> > +{
> > + return 0;
> > +}
> > diff --git a/target-info-def.c b/target-info-def.c
> > index bcf9cfe1e4..a992019626 100644
> > --- a/target-info-def.c
> > +++ b/target-info-def.c
> > @@ -9,6 +9,9 @@
> > #include "qemu/osdep.h"
> > #include "qemu/target-info.h"
> > #include "qemu/target-info-def.h"
> > +#ifdef CONFIG_USER_ONLY
> > +#include "qemu/base-arch-defs.h"
> > +#endif
> > #include "qemu/target-info-init.h"
> > #include "hw/core/boards.h"
> > #include "cpu.h"
> > diff --git a/target-info-qom.c b/target-info-qom.c
> > index aeeedb7e81..fb4c9835e5 100644
> > --- a/target-info-qom.c
> > +++ b/target-info-qom.c
> > @@ -9,6 +9,8 @@
> > #include "qemu/osdep.h"
> > #include "qapi/error.h"
> > #include "qom/object.h"
> > +#include "qemu/base-arch-defs.h"
> > +#include "qemu/target-info.h"
> > #include "qemu/target-info-def.h"
> > #include "qemu/target-info-init.h"
> > #include "qemu/target-info-qom.h"
> > @@ -40,6 +42,14 @@ const TargetInfo *target_info(void)
> > return target_info_ptr;
> > }
> >
> > +uint64_t target_mask_selected(void)
> > +{
> > + if (!target_info_ptr) {
> > + return QEMU_ARCH_ALL;
> > + }
> > + return QEMU_ARCH_BIT(target_info_ptr->target_arch);
> > +}
> > +
> > void target_info_qom_set_target(void)
> > {
> > g_autoptr(GSList) targets = object_class_get_list(TYPE_TARGET_INFO,
> > false);
>
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo