Warner's v3:
20211113045603.60391-1-imp@bsdimp.com/" rel="noreferrer" target="_blank">https://patchew.org/QEMU/20211113045603.60391-1-imp@bsdimp.com/
Changes for v4:
* Move errno handling into the assembly. While returning the
raw -errno is handy for x86 linux (and a few others), it is
in fact more complex for other hosts that return a separate
error indicator. At which point we wind up jumping through
hoops to return -errno, only to have the caller put it right
back into +errno with -1 result, just like syscall(3).
Pass in &errno, because the method of calculating this
varies wildly between glibc, musl, etc. This means that
the assembly need only store to a provided pointer.
* Add mips and sparc safe-syscall implementations.
Both of which, btw, have separate error indicators. ;-)
* All hosts now have it, so remove HAVE_SAFE_SYSCALL.
* Add meson.build rules for common-user/safe-syscall.S, so
that we don't have to have weird includes from *-user.
I'll note that this last patch will at present break bsd-user,
because TARGET_ERESTARTSYS and the header from whence it comes
is currently missing there.
In addition, I think that this should be reorganized further
so that TARGET_ERESTARTSYS is (1) renamed because in *this*
context it is pretending to be a host errno, and (2) placed
in a file of its own under include/user/. At which point,
meson.build could be simplified further so that safe-syscall.S
is compiled once, not per target.
Anyway, the final patch needs some bsd-user changes sorted first.
I've got bsd-user to compile with these changes by creating bsd-user/target_errno_defs.h that was just #include "errno_defs.h", which suggests a simple rename and #include adjustment in bsd-user/syscall_defs.h would also work. On *BSD, the errno namespace is the same for all architectures since they never followed the rather divergent System V ABIs that Linux follows (or at least did for the early ports).
I've noted a couple of other tweaks I needed as well, but there seemed to be no good place to share this.
I'd be happy to change these vague descriptions into actual code I can push to gitlab that you can pull into the patch series as well (or I can send them to the list, I'm not sure about this finer point of qemu and want to fit in).
Thanks for expanding my start at this.
Warner
r~
Richard Henderson (4):
common-user: Move syscall error detection into safe_syscall_base
common-user/host/mips: Add safe-syscall.inc.S
common-user/host/sparc64: Add safe-syscall.inc.S
linux-user: Remove HAVE_SAFE_SYSCALL and hostdep.h
Warner Losh (5):
linux-user: Add host_signal_set_pc to set pc in mcontext
linux-user/signal.c: Create a common rewind_if_in_safe_syscall
linux-user/safe-syscall.inc.S: Move to common-user
common-user: Adjust system call return on FreeBSD
common-user: Move safe-syscall.* from *-user
meson.build | 9 +-
{linux-user => include/user}/safe-syscall.h | 31 ++--
linux-user/host/aarch64/host-signal.h | 5 +
linux-user/host/aarch64/hostdep.h | 38 -----
linux-user/host/alpha/host-signal.h | 5 +
linux-user/host/arm/host-signal.h | 5 +
linux-user/host/arm/hostdep.h | 38 -----
linux-user/host/i386/host-signal.h | 5 +
linux-user/host/i386/hostdep.h | 38 -----
linux-user/host/ia64/hostdep.h | 15 --
linux-user/host/mips/host-signal.h | 5 +
linux-user/host/mips/hostdep.h | 15 --
linux-user/host/ppc/host-signal.h | 5 +
linux-user/host/ppc/hostdep.h | 15 --
linux-user/host/ppc64/hostdep.h | 38 -----
linux-user/host/riscv/host-signal.h | 5 +
linux-user/host/riscv/hostdep.h | 34 -----
linux-user/host/s390/host-signal.h | 5 +
linux-user/host/s390/hostdep.h | 15 --
linux-user/host/s390x/hostdep.h | 38 -----
linux-user/host/sparc/host-signal.h | 9 ++
linux-user/host/sparc/hostdep.h | 15 --
linux-user/host/sparc64/hostdep.h | 15 --
linux-user/host/x32/hostdep.h | 15 --
linux-user/host/x86_64/host-signal.h | 5 +
linux-user/host/x86_64/hostdep.h | 38 -----
linux-user/user-internals.h | 1 -
linux-user/signal.c | 13 +-
linux-user/syscall.c | 2 +-
.../host/aarch64/safe-syscall.inc.S | 65 ++++++---
.../host/arm/safe-syscall.inc.S | 69 ++++++---
.../host/i386/safe-syscall.inc.S | 61 +++++---
common-user/host/mips/safe-syscall.inc.S | 135 ++++++++++++++++++
.../host/ppc64/safe-syscall.inc.S | 63 ++++----
.../host/riscv/safe-syscall.inc.S | 50 ++++---
.../host/s390x/safe-syscall.inc.S | 50 ++++---
common-user/host/sparc64/safe-syscall.inc.S | 91 ++++++++++++
.../host/x86_64/safe-syscall.inc.S | 80 +++++++----
common-user/meson.build | 2 +
{linux-user => common-user}/safe-syscall.S | 3 -
linux-user/meson.build | 1 -
41 files changed, 585 insertions(+), 562 deletions(-)
rename {linux-user => include/user}/safe-syscall.h (85%)
delete mode 100644 linux-user/host/aarch64/hostdep.h
delete mode 100644 linux-user/host/arm/hostdep.h
delete mode 100644 linux-user/host/i386/hostdep.h
delete mode 100644 linux-user/host/ia64/hostdep.h
delete mode 100644 linux-user/host/mips/hostdep.h
delete mode 100644 linux-user/host/ppc/hostdep.h
delete mode 100644 linux-user/host/ppc64/hostdep.h
delete mode 100644 linux-user/host/riscv/hostdep.h
delete mode 100644 linux-user/host/s390/hostdep.h
delete mode 100644 linux-user/host/s390x/hostdep.h
delete mode 100644 linux-user/host/sparc/hostdep.h
delete mode 100644 linux-user/host/sparc64/hostdep.h
delete mode 100644 linux-user/host/x32/hostdep.h
delete mode 100644 linux-user/host/x86_64/hostdep.h
rename {linux-user => common-user}/host/aarch64/safe-syscall.inc.S (64%)
rename {linux-user => common-user}/host/arm/safe-syscall.inc.S (64%)
rename {linux-user => common-user}/host/i386/safe-syscall.inc.S (71%)
create mode 100644 common-user/host/mips/safe-syscall.inc.S
rename {linux-user => common-user}/host/ppc64/safe-syscall.inc.S (68%)
rename {linux-user => common-user}/host/riscv/safe-syscall.inc.S (77%)
rename {linux-user => common-user}/host/s390x/safe-syscall.inc.S (71%)
create mode 100644 common-user/host/sparc64/safe-syscall.inc.S
rename {linux-user => common-user}/host/x86_64/safe-syscall.inc.S (64%)
create mode 100644 common-user/meson.build
rename {linux-user => common-user}/safe-syscall.S (94%)
--
2.25.1