This is a back-port of D29185 to 12-STABLE that doesn't modify a field
that is in the middle of struct thread based on kib's suggestion. I
believe the same approach should work for 13-STABLE.
Note that this doesn't bother copying the original_syscall value on
fork. I believe this is fine because the value is only ever accessed
on the return path from failed system calls: if a fork has succeeded,
then the value won't be read until it's been written by the next system
call entry, so it's fine to leave it undefined. Counter examples
welcome in code review!
The syscall number is stored in the same register as the syscall return
on amd64 (and possibly other architectures) and so it is impossible to
recover in the signal handler after the call has returned. This small
tweak delivers it in the si_value field of the signal, which is
sufficient to catch capability violations and emulate them with a call
to a more-privileged process in the signal handler.