Hi,

qemu-user implements calling signal-race-safe syscalls for the guest
in assembly directly to the kernel instead of going through the host's libc.

The proposed patch adds a switch to go through libc, which allows interposition
of libc's syscall(), even when the guest program is statically linked.

The motivation behind the change is intercepting statically linked binaries [1]
with firebuild [2], a build accelerator implemented in userspace.

Since v1 I found out that faketime can also benefit greatly from -libc-syscalls,
since some time related calls are wrapped in safe_syscall, such as
clock_nanosleep. Faketime did not cover the syscall, but I patched it [3],
and it is getting closer to fully faking time for static binaries, too,
if qemu's support is there.

I have tested the Linux changes, but not not BSD ones.
I think they are trivial enough to work and I'd like to port firebuild
to BSD, too, in the future.

I understand from the previous review that signal handling should be as
perfect as it can be in qemu, but I hope that now that the changes don't
affect qemu's behaviour unless they are specifically enabled at build time,
they may be acceptable.

Changes in v2:
- Moved signal handling closer to the syscall call, addressing one
  review point.  
- Minimized the changes
- Introduced CONFIG_LIBC_SYSCALLS to isolate the changes to take effect
  only if qemu-user is configured to enable using libc-backed safe-syscalls.
- Introduced --{enable|disable}-libc-syscalls configuration option

Cheers,
Balint

[1] https://github.com/firebuild/firebuild/pull/1334
[2] https://github.com/firebuild/firebuild
[3] https://github.com/wolfcw/libfaketime/pull/522

Balint Reczey (1):
  user: add runtime switch to call safe_syscall via libc

 bsd-user/main.c               | 20 +++++++++++
 common-user/meson.build       |  4 +++
 common-user/safe-syscall.c    | 66 +++++++++++++++++++++++++++++++++++
 docs/user/main.rst            | 30 ++++++++++++++--
 include/user/safe-syscall.h   | 19 +++++++++-
 linux-user/main.c             | 15 ++++++++
 meson.build                   |  1 +
 meson_options.txt             |  4 +++
 scripts/meson-buildoptions.sh |  4 +++
 9 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 common-user/safe-syscall.c

-- 
2.43.0


Reply via email to