linux-user: Add syscall dispatch support
PATCH 1/1 linux-user: Add syscall dispatch support
This commit adds support for the prctl(PR_SET_SYSCALL_DISPATCH) function in the Linux userspace emulator.
It is implemented as a fully host-independent function, by forcing a SIGSYS early during syscall handling, if the PC is outside the allowed range.
Tested on [uglendix][1], will probably also apply to recent versions of Wine that use syscall dispatch.
[1]: https://sr.ht/~arusekk/uglendix
--- linux-user/main.c | 2 ++ linux-user/qemu.h | 5 +++ linux-user/syscall.c | 64 ++++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 6 ++++ 4 files changed, 76 insertions(+), 1 deletion(-)
linux-user/main.c +2 -0
@@ -230,6 +230,8 @@ void init_task_state(TaskState *ts) ts->start_boottime += bt.tv_nsec * (uint64_t ) ticks_per_sec /NANOSECONDS_PER_SECOND ; } + + ts->sys_dispatch_len = (abi_ulong )~0ULL ; }CPUArchState *cpu_copy (CPUArchState *env)
linux-user/qemu.h +5 -0
@@ -161,6 +161,11 @@ struct TaskState {/* This thread's sigaltstack, if it has one */ struct target_sigaltstack sigaltstack_used; +/* This thread's SYSCALL_USER_DISPATCH state, len=~0 means disabled */ +abi_ulong sys_dispatch; +abi_ulong sys_dispatch_len; +abi_ulong sys_dispatch_selector; +/* Start time of task after system boot in clock ticks */ uint64_t start_boottime; };
linux-user/syscall.c +63 -1
100 lines not on this page · raw message
linux-user/syscall_defs.h +6 -0
@@ -693,6 +693,12 @@ typedef struct target_siginfo {#define TARGET_TRAP_HWBKPT (4)/* hardware breakpoint/watchpoint */ #define TARGET_TRAP_UNK (5)/* undiagnosed trap */ +/* +* SIGSYS si_codes +*/ +#define TARGET_SYS_SECCOMP (1)/* seccomp triggered */ +#define TARGET_SYS_USER_DISPATCH (2)/* syscall user dispatch triggered */ +/* * SIGEMT si_codes */
Signature · 1 line
2.47.1
Quoted 2 lines · Arusekk via
This commit adds support for the
prctl(PR_SET_SYSCALL_DISPATCH)function in the Linux userspace emulator.
Typo: this should be PR_SET_SYSCALL_USER_DISPATCH.
Quoted 19 lines
It is implemented as a fully host-independent function, by forcing a SIGSYS early during syscall handling, if the PC is outside the allowed
range.Tested on [uglendix][1], will probably also apply to recent versions of
Wine that use syscall dispatch.[1]: https://sr.ht/~arusekk/uglendix
Signed-off-by Arusekk <[email protected]>---
linux-user/main.c | 2 ++
linux-user/qemu.h | 5 +++
linux-user/syscall.c | 64
++++++++++++++++++++++++++++++++++++++-
linux-user/syscall_defs.h | 6 ++++4 files changed, 76 insertions(+), 1 deletion(-)
[...]
linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 13890
Quoted 7 lines
linux-user/syscall.c +0
-0@@ -13852,12 +13886,34 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return ret; }linux-user/syscall.c +2
-0+static bool sys_dispatch (abi_ulong pc,TaskState *ts) +{
What about this line from the kernel implementation?
if (unlikely(arch_syscall_is_vdso_sigreturn(regs)))
return false;I think qemu's vdso implements sigreturn, e.g., in linux-user/arm/vdso.S.
[...]