From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls
Date: Sat, 9 Jun 2018 17:00:41 -1000 [thread overview]
Message-ID: <20180610030220.3777-10-richard.henderson@linaro.org> (raw)
In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org>
At the same time, split out set_robust_list and get_robust_list.
Put them together, along with their block comment, at the top
of syscall_table.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/syscall.c | 87 +++++++++++++++++++++++++++++++++-----------
1 file changed, 66 insertions(+), 21 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 46f123ee13..8678e749ee 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7947,6 +7947,17 @@ static int host_to_target_cpu_mask(const unsigned long *host_mask,
return 0;
}
+typedef abi_long impl_fn(void *cpu_env, unsigned num, abi_long arg1,
+ abi_long arg2, abi_long arg3, abi_long arg4,
+ abi_long arg5, abi_long arg6, abi_long arg7,
+ abi_long arg8);
+
+#define IMPL(NAME) \
+static abi_long impl_##NAME(void *cpu_env, unsigned num, abi_long arg1, \
+ abi_long arg2, abi_long arg3, abi_long arg4, \
+ abi_long arg5, abi_long arg6, abi_long arg7, \
+ abi_long arg8)
+
/* This is an internal helper for do_syscall so that it is easier
* to have a single return point, so that actions, such as logging
* of syscall results, can be performed.
@@ -11740,23 +11751,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1,
return get_errno(safe_tgkill((int)arg1, (int)arg2,
target_to_host_signal(arg3)));
-#ifdef TARGET_NR_set_robust_list
- case TARGET_NR_set_robust_list:
- case TARGET_NR_get_robust_list:
- /* The ABI for supporting robust futexes has userspace pass
- * the kernel a pointer to a linked list which is updated by
- * userspace after the syscall; the list is walked by the kernel
- * when the thread exits. Since the linked list in QEMU guest
- * memory isn't a valid linked list for the host and we have
- * no way to reliably intercept the thread-death event, we can't
- * support these. Silently return ENOSYS so that guest userspace
- * falls back to a non-robust futex implementation (which should
- * be OK except in the corner case of the guest crashing while
- * holding a mutex that is shared with another process via
- * shared memory).
- */
- return -TARGET_ENOSYS;
-#endif
#if defined(TARGET_NR_utimensat)
case TARGET_NR_utimensat:
@@ -12412,6 +12406,54 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1,
return ret;
}
+/* The default action for a syscall not listed in syscall_table is to
+ * log the missing syscall. If a syscall is intentionally emulated as
+ * not present, then list it with impl_enosys as the implementation,
+ * which will avoid the logging.
+ */
+IMPL(enosys)
+{
+ return -TARGET_ENOSYS;
+}
+
+/* For a given syscall number, return a function implementing it.
+ * Do this via switch statement instead of table because some targets
+ * do not begin at 0 and others have a large split in the middle of
+ * the numbers. The compiler should be able to produce a dense table.
+ */
+static impl_fn *syscall_table(unsigned num)
+{
+#define SYSCALL_WITH(X, Y) case TARGET_NR_##X: return impl_##Y
+#define SYSCALL(X) SYSCALL_WITH(X, X)
+
+ switch (num) {
+ /* The ABI for supporting robust futexes has userspace pass
+ * the kernel a pointer to a linked list which is updated by
+ * userspace after the syscall; the list is walked by the kernel
+ * when the thread exits. Since the linked list in QEMU guest
+ * memory isn't a valid linked list for the host and we have
+ * no way to reliably intercept the thread-death event, we can't
+ * support these. Silently return ENOSYS so that guest userspace
+ * falls back to a non-robust futex implementation (which should
+ * be OK except in the corner case of the guest crashing while
+ * holding a mutex that is shared with another process via
+ * shared memory).
+ */
+ SYSCALL_WITH(get_robust_list, enosys);
+ SYSCALL_WITH(set_robust_list, enosys);
+
+ /*
+ * Other syscalls listed in collation order, with '_' ignored.
+ */
+ }
+
+#undef SYSCALL
+#undef SYSCALL_WITH
+
+ /* After do_syscall1 is fully split, this will be impl_enosys. */
+ return do_syscall1;
+}
+
abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1,
abi_long arg2, abi_long arg3, abi_long arg4,
abi_long arg5, abi_long arg6, abi_long arg7,
@@ -12419,6 +12461,7 @@ abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1,
{
CPUState *cpu = ENV_GET_CPU(cpu_env);
abi_long ret;
+ impl_fn *fn;
#ifdef DEBUG_ERESTARTSYS
/* Debug-only code for exercising the syscall-restart code paths
@@ -12437,14 +12480,16 @@ abi_long do_syscall(void *cpu_env, unsigned num, abi_long arg1,
trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8);
+ fn = syscall_table(num);
+
if (unlikely(do_strace)) {
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
- ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
- arg5, arg6, arg7, arg8);
+ ret = fn(cpu_env, num, arg1, arg2, arg3, arg4,
+ arg5, arg6, arg7, arg8);
print_syscall_ret(num, ret);
} else {
- ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
- arg5, arg6, arg7, arg8);
+ ret = fn(cpu_env, num, arg1, arg2, arg3, arg4,
+ arg5, arg6, arg7, arg8);
}
trace_guest_user_syscall_ret(cpu, num, ret);
--
2.17.1
next prev parent reply other threads:[~2018-06-10 3:02 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-10 3:00 [Qemu-devel] [PATCH v2 000/108] linux-user: Split do_syscall Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 001/108] linux-user: Remove DEBUG Richard Henderson
2018-06-10 11:51 ` Laurent Vivier
2018-06-10 16:43 ` Philippe Mathieu-Daudé
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 002/108] linux-user: Split out do_syscall1 Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 003/108] linux-user: Relax single exit from "break" Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 004/108] linux-user: Propagate goto efault to return Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 005/108] linux-user: Propagate goto unimplemented_nowarn " Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 006/108] linux-user: Propagate goto unimplemented to default Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 007/108] linux-user: Propagate goto fail to return Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 008/108] linux-user: Make syscall number unsigned Richard Henderson
2018-06-10 3:00 ` Richard Henderson [this message]
2018-06-10 12:32 ` [Qemu-devel] [PATCH v2 009/108] linux-user: Set up infrastructure for table-izing syscalls Peter Maydell
2018-06-10 12:39 ` Peter Maydell
2018-06-10 19:03 ` Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 010/108] linux-user: Split out brk, close, exit, read, write Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 011/108] linux-user: Split out execve Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 012/108] linux-user: Split out open, openat Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 013/108] linux-user: Split out name_to_handle_at Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 014/108] linux-user: Split out open_to_handle_at Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 015/108] linux-user: Split out creat, fork, waitid, waitpid Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 016/108] linux-user: Split out link, linkat Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 017/108] linux-user: Split out unlink, unlinkat Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 018/108] linux-user: Split out chdir, mknod, mknodat, time, chmod Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 019/108] linux-user: Split out getpid, getxpid, lseek Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 020/108] linux-user: Split out mount, umount Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 021/108] linux-user: Split out alarm, pause, stime, utime, utimes Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 022/108] linux-user: Split out access, faccessat, futimesat, kill, nice, sync, syncfs Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 023/108] linux-user: Split out rename, renameat, renameat2 Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 024/108] linux-user: Split out dup, mkdir, mkdirat, rmdir Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 025/108] linux-user: Split out acct, pipe, pipe2, times, umount2 Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 026/108] linux-user: Split out ioctl Richard Henderson
2018-06-10 3:00 ` [Qemu-devel] [PATCH v2 027/108] linux-user: Split out chroot, dup2, dup3, fcntl, setpgid, umask Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 028/108] linux-user: Split out getpgrp, getppid, setsid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 029/108] linux-user: Split out rt_sigaction, sigaction Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 030/108] linux-user: Split out rt_sigprocmask, sgetmask, sigprocmask, ssetmask Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 031/108] linux-user: Split out rt_sigpending, rt_sigsuspend, sigpending, sigsuspend Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 032/108] linux-user: Split out rt_sigqueueinfo, rt_sigtimedwait, rt_tgsigqueueinfo Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 033/108] linux-user: Split out rt_sigreturn, sethostname, setrlimit, sigreturn Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 034/108] linux-user: Split out getrlimit, getrusage, gettimeofday, settimeofday Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 035/108] linux-user: Split out select, pselect6, newselect Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 036/108] linux-user: Split out symlink, symlinkat Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 037/108] linux-user: Split out readlink, readlinkat Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 038/108] linux-user: Split out mmap, mmap2, reboot, swapon Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 039/108] linux-user: Split out mprotect, mremap, msync, munmap Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 040/108] linux-user: Split out mlock, mlockall, munlock, munlockall Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 041/108] linux-user: Split out fchmod, fchmodat, ftruncate, truncate Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 042/108] linux-user: Split out fstatfs, fstatfs64, statfs, statfs64 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 043/108] linux-user: Split out getpriority, setpriority Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 044/108] linux-user: Split out socketcall Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 045/108] linux-user: Split out accept, accept4, bind, connect Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 046/108] linux-user: Split out 7 syscalls Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 047/108] linux-user: Split out recvmmsg, send, sendmmsg, sendmsg, sendto Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 048/108] linux-user: Split out getrandom, shutdown, setsockopt, socket, socketpair Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 049/108] linux-user: Fix stub gettid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 050/108] linux-user: Split out getitimer, setitimer, syslog Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 051/108] linux-user: Split out fstat, lstat, stat Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 052/108] linux-user: Unwrap TARGET_NR_syscall early Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 053/108] linux-user: Split out swapoff, sysinfo, vhangup, wait4 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 054/108] linux-user: Split out ipc Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 055/108] linux-user: Split out ipc syscalls Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 056/108] linux-user: Split out clone, exit_group, fsync Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 057/108] linux-user: Split out modify_ldt, setdomainname, uname Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 058/108] linux-user: Split out adjtimex, clock_adjtime, vm86 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 059/108] linux-user: Split out fchdir, getpgid, llseek, personality Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 060/108] linux-user: Split out getdents, getdents64 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 061/108] linux-user: Split out poll, ppoll Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 062/108] linux-user: Split out flock, preadv, pwritev, readv, writev Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 063/108] linux-user: Split out fdatasync, getsid, _sysctl Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 064/108] linux-user: Split out sched syscalls Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 065/108] linux-user: Split out getcpu, nanosleep, prctl Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 066/108] linux-user: Split out arch_prctl Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 067/108] linux-user: Split out getcwd, pread64, pwrite64, sigaltstack Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 068/108] linux-user: Split out capget, capset Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 069/108] linux-user: Split out sendfile, sendfile64 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 070/108] linux-user: Split out ftruncate64, truncate64, ugetrlimit, vfork Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 071/108] linux-user: Split out fstat64, fstatat64, newfstatat, lstat64, stat64 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 072/108] linux-user: Split out getegid, geteuid, getgid, getuid, lchown Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 073/108] linux-user: Split out getgroups, setgroups, setregid, setreuid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 074/108] linux-user: Split out fchown, fchownat, setresgid, setresuid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 075/108] linux-user: Split out chown, getresgid, getresuid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 076/108] linux-user: Split out setfsgid, setfsuid, setgid, setuid Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 077/108] linux-user: Split out getuid32, getxgid, getxuid, lchown32 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 078/108] linux-user: Split out osf_getsysinfo, osf_setsysinfo, osf_sigprocmask Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 079/108] linux-user: Split out getegid32, geteuid32, getgid32, setregid32, setreuid32 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 080/108] linux-user: Split out fchown32, getgroups32, setgroups32 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 081/108] linux-user: Split out getresgid32, getresuid32, setresgid32, setresuid32 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 082/108] linux-user: Split out chown32, setfsgid32, setfsuid32, setgid32, setuid32 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 083/108] linux-user: Split out mincore Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 084/108] linux-user: Split out fadvise64, fadvise64_64 Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 085/108] linux-user: Split out cacheflush, fcntl64, getpagesize, madvise Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 086/108] linux-user: Split out gettid, readahead Richard Henderson
2018-06-10 3:01 ` [Qemu-devel] [PATCH v2 087/108] linux-user: Split out xattr syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 088/108] linux-user: Split out getdomainname, get_thread_area, set_thread_area Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 089/108] linux-user: Split out clock syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 090/108] linux-user: Fix clock_nanosleep Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 091/108] linux-user: Split out set_tid_address, tgkill, tkill Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 092/108] linux-user: Split out futex, utimensat Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 093/108] linux-user: Remove sys_futex Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 094/108] linux-user: Split out inotify syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 095/108] linux-user: Split out mq syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 096/108] linux-user: Split out splice, tee, vmsplice Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 097/108] linux-user: Split out eventfd, eventfd2 Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 098/108] linux-user: Split out fallocate, sync_file_range/2 Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 099/108] linux-user: Split out signalfd, signalfd4 Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 100/108] linux-user: Split out epoll syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 101/108] linux-user: Split out prlimit64 Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 102/108] linux-user: Split out atomic_barrier, gethostname Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 103/108] linux-user: Split out atomic_cmpxchg_32 Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 104/108] linux-user: Split out timer syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 105/108] linux-user: Split out timerfd syscalls Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 106/108] linux-user: Split out ioprio_get, ioprio_set, kcmp Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 107/108] linux-user: Split out setns, unshare Richard Henderson
2018-06-10 3:02 ` [Qemu-devel] [PATCH v2 108/108] linux-user: Fold away do_syscall1 Richard Henderson
2018-06-10 4:30 ` [Qemu-devel] [PATCH v2 000/108] linux-user: Split do_syscall no-reply
2018-06-10 4:44 ` no-reply
2018-06-10 12:34 ` Peter Maydell
2018-06-10 18:51 ` Richard Henderson
2018-06-10 19:08 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180610030220.3777-10-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).