[PATCH v2 00/40] bsd-user: upstream our signal implementation

Warner Losh posted 40 patches 2 years, 2 months ago
Failed in applying to current master (apply log)
MAINTAINERS                           |    1 +
bsd-user/arm/signal.c                 |   58 +-
bsd-user/arm/target_arch_cpu.h        |  101 +--
bsd-user/freebsd/target_os_siginfo.h  |   15 +-
bsd-user/freebsd/target_os_signal.h   |    3 +
bsd-user/freebsd/target_os_ucontext.h |    6 +-
bsd-user/host/arm/host-signal.h       |   35 +
bsd-user/host/i386/host-signal.h      |   37 +
bsd-user/host/x86_64/host-signal.h    |   37 +
bsd-user/i386/signal.c                |   13 +
bsd-user/i386/target_arch_cpu.h       |    4 +-
bsd-user/main.c                       |   14 +-
bsd-user/meson.build                  |    1 +
bsd-user/qemu.h                       |   62 +-
bsd-user/signal-common.h              |   70 ++
bsd-user/signal.c                     | 1001 ++++++++++++++++++++++++-
bsd-user/strace.c                     |   97 +++
bsd-user/syscall_defs.h               |    1 +
bsd-user/trace-events                 |   11 +
bsd-user/trace.h                      |    1 +
bsd-user/x86_64/signal.c              |   13 +
bsd-user/x86_64/target_arch_cpu.h     |    4 +-
meson.build                           |    6 +-
23 files changed, 1477 insertions(+), 114 deletions(-)
create mode 100644 bsd-user/host/arm/host-signal.h
create mode 100644 bsd-user/host/i386/host-signal.h
create mode 100644 bsd-user/host/x86_64/host-signal.h
create mode 100644 bsd-user/signal-common.h
create mode 100644 bsd-user/trace-events
create mode 100644 bsd-user/trace.h
[PATCH v2 00/40] bsd-user: upstream our signal implementation
Posted by Warner Losh 2 years, 2 months ago
Upstream the bsd-user fork signal implementation, for the most part.  This
series of commits represents nearly all of the infrastructure that surround
signals, except the actual system call glue (that was also reworked in the
fork and needs its own series). In addition, this adds the sigsegv and sigbus
code to arm. Even in the fork, we don't have good x86 signal implementation,
so there's little to upstream for that at the moment.

bsd-user's signal implementation is similar to linux-user's. However, all
signals are always queued for batch processing (except synchronous ones that
kill the process). The full context can be found in the fork's 'blitz branch'
at https://github.com/qemu-bsd-user/qemu-bsd-user/tree/blitz which shows how
these are used to implement various system calls. Since this was built from
linux-user's stack stuff, evolved for BSD with the passage of a few years,
it no-doubt missed some bug fixes from linux-user (though nothing obvious
stood out in the quick comparison I made).

I lumped thinks slightly larger than past patch sets, but none of the patches
should exceed about 100 lines of diffs (there is one that clocks in at 166
though, but I had trouble splitting it smaller). With over 30k lines of diffs
between the two repos, I need to find more efficient ways of getting things
reviewed and each extra chunk takes time to curate so I'm searching for a good
happy medium.

New in version 2:

Lots of changes based on feedback garnered in v1. The patch numbers are only
loosely related as some were dropped or merged and others were added. I've
not rebased this yet to a newer revision due to the volume of changes.

o Removed an unnecessary memset for the signal table, it's already all 0's.
o Fixed a number of comments as suggested in the first round of review.
o yoda speak removed have I.
o added a path to the MAINTAINERS entry for bsd related VMs
o removed MIPS code from trapframe construction
o Add si_code call to queue_signal
o Remove final remnants of signal queueing on BSD
o Add documentation of fields of the task structure
o Remove a bunch of comments that are no longer correct or turned out to
  be false...
o Get FSR directly from the siginfo rather than doing crazy things to
  find it.
o Move target_sigaltstack_used to ts->sigaltstack_used and adjust all
  references to be per-stack.
o rename force_sig to dump_core_and_abort
o Create a new setup_sigframe_arch to save/restore context. Most
  architectures this is just get_mcontext, but arm needs special
  setup.
o Move to generating SIGILL when we can't write the signal trap frame.
o Add comments about a few extreme edge cases for SIGILL instructions
o rewrite arm's host_signal_write to use the trap frame it needs to
  get the data rather than the prior bogus assumptions.
o Add more comments to the signal related Task elements, cribbed from
  linux-user
o Move to storing QEMU supecific signal si_code, stored in the top
  8 bits of si_code. BSD uses bit 16 to indicate the code is 'generic'
  and not tied to a specific signal type, so we have to preserve that
  bit. Only bit 16 is used, but steer clear by using the top 8 bits.
o Don't gratuitously move fatal_signal
o add has_trapno function for those signals that have si_trapno.
o Move to using synchronous signals or signals artificially crated by
  qemu. Since only one of these can ever happen at the time, we
  can simplify the code in a manner similar to linux-user.
o Fix a number of "see this routine" pointers to match modern FreeBSD
  and/or remove obsolete architectures from the generic pointers.
o Fixed the division of labor between host_to_target_siginfo_noswap
  and tswap_siginfo. We now record a 'si_type' field that can be
  used to determine which parts of the siginfo are valid. _noswap
  will record its guess and if that guess is present, tswap_siginfo
  will use it.
o Fix arm get_mcontext to match what FreeBSD does by removing saving
  of vfp there and zeroing the vfp pointers.
o Exclude SIGPROF when CONFIG_GPROF active.
o A few formatting issues that I'd ignored for version 1.
o consistently used env as the name for CPUArchState (noted in one
  patch, but present in more and in a couple places in upstream so
  I fixed those too).

Not adressed:
o Signal mask issues around sigaction and sigreturn. These will be
  addressed while people comment on the rest of these changes. I've
  noted the exact details in a couple of commit messages.

Warner Losh (40):
  bsd-user: Complete FreeBSD siginfo
  bsd-user: Create setup_sigframe_arch to setup sigframe context
  bsd-user/arm/signal.c: Implement setup_sigframe_arch for arm
  bsd-user/arm/signal.c: get_mcontext should zero vfp data
  bsd-user: Remove vestiges of signal queueing code
  bsd-user: Bring in docs from linux-user for signal_pending
  bsd-user/arm/target_arch_cpu.h: Move EXCP_ATOMIC to match linux-user
  bsd-user/signal.c: implement force_sig_fault
  bsd-user/signal-common.h: Move signal functions prototypes to here
  bsd-user/signal.c: Implement cpu_loop_exit_sigsegv
  bsd-user/signal.c: implement cpu_loop_exit_sigbus
  bsd-user/arm/arget_arch_cpu.h: Move EXCP_DEBUG and EXCP_BKPT together
  bsd-user/arm/target_arch_cpu.h: Correct code pointer
  bsd-user/arm/target_arch_cpu.h: Use force_sig_fault for EXCP_UDEF
  bsd-user/arm/target_arch_cpu.h: Implement data faults
  bsd-user/signal.c: implement abstract target / host signal translation
  bsd-user/signal.c: Implement signal_init()
  bsd-user/signal.c: Add si_type argument to queue_signal
  bsd-user/host/arm/host-signal.h: Implement host_signal_*
  bsd-user/host/i386/host-signal.h: Implement host_signal_*
  bsd-user/host/x86_64/host-signal.h: Implement host_signal_*
  bsd-user: Add host signals to the build
  bsd-user: Add trace events for bsd-user
  bsd-user/signal.c: host_to_target_siginfo_noswap
  bsd-user/signal.c: Implement rewind_if_in_safe_syscall
  bsd-user/signal.c: Implement host_signal_handler
  bsd-user/strace.c: print_taken_signal
  bsd-user/signal.c: Implement dump_core_and_abort
  bsd-user/signal.c: Fill in queue_signal
  bsd-user/signal.c: sigset manipulation routines.
  bsd-user/signal.c: setup_frame
  bsd-user/signal.c: handle_pending_signal
  bsd-user/signal.c: tswap_siginfo
  bsd-user/signal.c: process_pending_signals
  bsd-user/signal.c: implement do_sigreturn
  bsd-user/signal.c: implement do_sigaction
  bsd-user/signal.c: do_sigaltstack
  MAINTAINERS: Add tests/vm/*bsd to the list to get reviews on
  bsd-user: Rename arg name for target_cpu_reset to env
  bsd-user/freebsd/target_os_ucontext.h: Prefer env as arg name for
    CPUArchState args

 MAINTAINERS                           |    1 +
 bsd-user/arm/signal.c                 |   58 +-
 bsd-user/arm/target_arch_cpu.h        |  101 +--
 bsd-user/freebsd/target_os_siginfo.h  |   15 +-
 bsd-user/freebsd/target_os_signal.h   |    3 +
 bsd-user/freebsd/target_os_ucontext.h |    6 +-
 bsd-user/host/arm/host-signal.h       |   35 +
 bsd-user/host/i386/host-signal.h      |   37 +
 bsd-user/host/x86_64/host-signal.h    |   37 +
 bsd-user/i386/signal.c                |   13 +
 bsd-user/i386/target_arch_cpu.h       |    4 +-
 bsd-user/main.c                       |   14 +-
 bsd-user/meson.build                  |    1 +
 bsd-user/qemu.h                       |   62 +-
 bsd-user/signal-common.h              |   70 ++
 bsd-user/signal.c                     | 1001 ++++++++++++++++++++++++-
 bsd-user/strace.c                     |   97 +++
 bsd-user/syscall_defs.h               |    1 +
 bsd-user/trace-events                 |   11 +
 bsd-user/trace.h                      |    1 +
 bsd-user/x86_64/signal.c              |   13 +
 bsd-user/x86_64/target_arch_cpu.h     |    4 +-
 meson.build                           |    6 +-
 23 files changed, 1477 insertions(+), 114 deletions(-)
 create mode 100644 bsd-user/host/arm/host-signal.h
 create mode 100644 bsd-user/host/i386/host-signal.h
 create mode 100644 bsd-user/host/x86_64/host-signal.h
 create mode 100644 bsd-user/signal-common.h
 create mode 100644 bsd-user/trace-events
 create mode 100644 bsd-user/trace.h

-- 
2.33.1