On Tue, Jun 21, 2022 at 02:59:11PM +0200, Luc Michel wrote: > Add the semihosting_exit_request function to be used by targets when > handling an `exit' semihosted syscall. This function calls gdb_exit to > close existing GDB connections, and qemu_system_shutdown_request with > the new `guest-semi-exit' exit reason. It sets the QEMU exit status > given by the exit syscall parameter. Finally it stops the CPU to prevent > further execution, and exit the CPU loop as the syscall caller expects > this syscall to not return. > > This function is meant to be used in place of a raw exit() call when > handling semihosted `exit' syscalls. Such a call is not safe because > it does not allow other CPU threads to exit properly, leading to e.g. > at_exit callbacks being called while other CPUs still run. This can lead > to strange bugs, especially in plugins with a registered at_exit function. > > Signed-off-by: Luc Michel <lmic...@kalray.eu> > --- > qapi/run-state.json | 4 +++- > include/semihosting/semihost.h | 5 +++++ > semihosting/config.c | 16 ++++++++++++++++ > 3 files changed, 24 insertions(+), 1 deletion(-) > > diff --git a/qapi/run-state.json b/qapi/run-state.json > index 6e2162d7b3..a4f08dd32e 100644 > --- a/qapi/run-state.json > +++ b/qapi/run-state.json > @@ -80,20 +80,22 @@ > # @guest-reset: Guest reset request, and command line turns that into > # a shutdown > # > # @guest-panic: Guest panicked, and command line turns that into a shutdown > # > +# @guest-semi-exit: Guest exit request via a semi-hosted exit syscall
Should include a '(since 7.1)' notation. > +# > # @subsystem-reset: Partial guest reset that does not trigger QMP events and > # ignores --no-reboot. This is useful for sanitizing > # hypercalls on s390 that are used during kexec/kdump/boot > # > ## As it is, the overall enum is missing a 'Since: 1.0' section. > { 'enum': 'ShutdownCause', > # Beware, shutdown_caused_by_guest() depends on enumeration order > 'data': [ 'none', 'host-error', 'host-qmp-quit', 'host-qmp-system-reset', > 'host-signal', 'host-ui', 'guest-shutdown', 'guest-reset', > - 'guest-panic', 'subsystem-reset'] } > + 'guest-panic', 'guest-semi-exit', 'subsystem-reset'] } > > ## > # @StatusInfo: > # > # Information about VCPU run state -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org