From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v7 05/74] linux-user: Split out readlink, readlinkat
Date: Sun, 19 May 2019 13:36:17 -0700 [thread overview]
Message-ID: <20190519203726.20729-6-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org>
Split out a shared implementation for both of these;
unify the best parts of /proc/self/exe checking.
Remove the temporary forward declaration for is_proc_self.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/syscall-defs.h | 6 ++++
linux-user/strace.c | 29 ------------------
linux-user/syscall-file.inc.c | 45 ++++++++++++++++++++++++++++
linux-user/syscall.c | 55 -----------------------------------
linux-user/strace.list | 6 ----
5 files changed, 51 insertions(+), 90 deletions(-)
diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 1f3a9c47ab..d1a6c6fa3c 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -20,3 +20,9 @@
SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
#endif
SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+#ifdef TARGET_NR_readlink
+SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
+#ifdef TARGET_NR_readlinkat
+SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 24ef14b5e6..2f1c7e537f 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -2256,35 +2256,6 @@ print_fstatat64(const struct syscallname *name,
#define print_newfstatat print_fstatat64
#endif
-#ifdef TARGET_NR_readlink
-static void
-print_readlink(const struct syscallname *name,
- abi_long arg0, abi_long arg1, abi_long arg2,
- abi_long arg3, abi_long arg4, abi_long arg5)
-{
- print_syscall_prologue(name);
- print_string(arg0, 0);
- print_pointer(arg1, 0);
- print_raw_param("%u", arg2, 1);
- print_syscall_epilogue(name);
-}
-#endif
-
-#ifdef TARGET_NR_readlinkat
-static void
-print_readlinkat(const struct syscallname *name,
- abi_long arg0, abi_long arg1, abi_long arg2,
- abi_long arg3, abi_long arg4, abi_long arg5)
-{
- print_syscall_prologue(name);
- print_at_dirfd(arg0, 0);
- print_string(arg1, 0);
- print_pointer(arg2, 0);
- print_raw_param("%u", arg3, 1);
- print_syscall_epilogue(name);
-}
-#endif
-
#ifdef TARGET_NR_rename
static void
print_rename(const struct syscallname *name,
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 30f8e35cdd..4ef0be2c6f 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -314,3 +314,48 @@ SYSCALL_IMPL(openat)
{
return do_openat(cpu_env, arg1, arg2, arg3, arg4);
}
+
+static abi_long do_readlinkat(int dirfd, abi_ulong target_path,
+ abi_ulong target_buf, abi_ulong bufsiz)
+{
+ char *p = lock_user_string(target_path);
+ void *buf = lock_user(VERIFY_WRITE, target_buf, bufsiz, 0);
+ abi_long ret;
+
+ if (!p || !buf) {
+ ret = -TARGET_EFAULT;
+ } else if (!bufsiz) {
+ /* Short circuit this for the magic exe check. */
+ ret = -TARGET_EINVAL;
+ } else if (is_proc_myself((const char *)p, "exe")) {
+ char real[PATH_MAX];
+ char *temp = realpath(exec_path, real);
+
+ if (temp == NULL) {
+ ret = -host_to_target_errno(errno);
+ } else {
+ ret = MIN(strlen(real), bufsiz);
+ /* We cannot NUL terminate the string. */
+ memcpy(buf, real, ret);
+ }
+ } else {
+ ret = get_errno(readlinkat(dirfd, path(p), buf, bufsiz));
+ }
+ unlock_user(buf, target_buf, ret);
+ unlock_user(p, target_path, 0);
+ return ret;
+}
+
+#ifdef TARGET_NR_readlink
+SYSCALL_IMPL(readlink)
+{
+ return do_readlinkat(AT_FDCWD, arg1, arg2, arg3);
+}
+#endif
+
+#ifdef TARGET_NR_readlinkat
+SYSCALL_IMPL(readlinkat)
+{
+ return do_readlinkat(arg1, arg2, arg3, arg4);
+}
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fe52ac15c2..53fb211f16 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6633,8 +6633,6 @@ int host_to_target_waitstatus(int status)
return status;
}
-static int is_proc_myself(const char *filename, const char *entry);
-
#define TIMER_MAGIC 0x0caf0000
#define TIMER_MAGIC_MASK 0xffff0000
@@ -8108,59 +8106,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
}
return ret;
#endif
-#ifdef TARGET_NR_readlink
- case TARGET_NR_readlink:
- {
- void *p2;
- p = lock_user_string(arg1);
- p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
- if (!p || !p2) {
- ret = -TARGET_EFAULT;
- } else if (!arg3) {
- /* Short circuit this for the magic exe check. */
- ret = -TARGET_EINVAL;
- } else if (is_proc_myself((const char *)p, "exe")) {
- char real[PATH_MAX], *temp;
- temp = realpath(exec_path, real);
- /* Return value is # of bytes that we wrote to the buffer. */
- if (temp == NULL) {
- ret = get_errno(-1);
- } else {
- /* Don't worry about sign mismatch as earlier mapping
- * logic would have thrown a bad address error. */
- ret = MIN(strlen(real), arg3);
- /* We cannot NUL terminate the string. */
- memcpy(p2, real, ret);
- }
- } else {
- ret = get_errno(readlink(path(p), p2, arg3));
- }
- unlock_user(p2, arg2, ret);
- unlock_user(p, arg1, 0);
- }
- return ret;
-#endif
-#if defined(TARGET_NR_readlinkat)
- case TARGET_NR_readlinkat:
- {
- void *p2;
- p = lock_user_string(arg2);
- p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
- if (!p || !p2) {
- ret = -TARGET_EFAULT;
- } else if (is_proc_myself((const char *)p, "exe")) {
- char real[PATH_MAX], *temp;
- temp = realpath(exec_path, real);
- ret = temp == NULL ? get_errno(-1) : strlen(real) ;
- snprintf((char *)p2, arg4, "%s", real);
- } else {
- ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
- }
- unlock_user(p2, arg3, ret);
- unlock_user(p, arg2, 0);
- }
- return ret;
-#endif
#ifdef TARGET_NR_swapon
case TARGET_NR_swapon:
if (!(p = lock_user_string(arg1)))
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 2c7a595e19..53cee3db92 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1079,12 +1079,6 @@
#ifdef TARGET_NR_readdir
{ TARGET_NR_readdir, "readdir" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_readlink
-{ TARGET_NR_readlink, "readlink" , NULL, print_readlink, NULL },
-#endif
-#ifdef TARGET_NR_readlinkat
-{ TARGET_NR_readlinkat, "readlinkat" , NULL, print_readlinkat, NULL },
-#endif
#ifdef TARGET_NR_readv
{ TARGET_NR_readv, "readv" , NULL, NULL, NULL },
#endif
--
2.17.1
next prev parent reply other threads:[~2019-05-19 20:45 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-19 20:36 [Qemu-devel] [PATCH v7 00/74] linux-user: Split do_syscall Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 01/74] linux-user: Setup split syscall infrastructure Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 02/74] linux-user: Split out open, open_at Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 03/74] linux-user: Share more code for open and openat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes Richard Henderson
2019-05-19 20:36 ` Richard Henderson [this message]
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 06/74] linux-user: Split out close Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 07/74] linux-user: Split out read, write Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 08/74] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 09/74] linux-user: Split out readv, writev Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 10/74] linux-user: Split out pread64, pwrite64 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 11/74] linux-user: Split out preadv, pwritev Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 12/74] linux-user: Split out name_to_handle_at, open_by_handle_at Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 13/74] linux-user: Split out ipc syscalls Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 14/74] linux-user: Split out memory syscalls Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 15/74] linux-user: Split out exit Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 16/74] linux-user: Split out brk Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 17/74] linux-user: Split out clone, fork, vfork Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 18/74] linux-user: Split out wait4, waitid, waitpid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 19/74] linux-user: Implement rusage argument to waitid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 20/74] linux-user: Split out creat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 21/74] linux-user: Split out link, linkat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 22/74] linux-user: Split out unlink, unlinkat, rmdir Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 23/74] linux-user: Split out execve Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 24/74] linux-user: Implement execveat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 25/74] linux-user: Split out chdir Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 26/74] linux-user: Split out time Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 27/74] linux-user: Split out mknod, mknodat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 28/74] linux-user: Split out chmod, fchmod, fchmodat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 29/74] linux-user: Split out lseek, llseek Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 30/74] linux-user: Split out getpid, getppid, getxpid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 31/74] linux-user: Split out mount Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 32/74] linux-user: Split out umount, umount2 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 33/74] linux-user: Split out stime Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 34/74] linux-user: Split out alarm, pause Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 35/74] linux-user: Split out utime, utimes, futimesat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 36/74] linux-user: Split out access, faccessat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 37/74] linux-user: Split out nice Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 38/74] linux-user: Split out sync, syncfs Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 39/74] linux-user: Split out kill Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 40/74] linux-user: Split out rename, renameat, renameat2 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 41/74] linux-user: Split out mkdir, mkdirat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 42/74] linux-user: Split out dup, dup2, dup3 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 43/74] linux-user: Split out pipe, pipe2 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 44/74] linux-user: Split out times Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 45/74] linux-user: Split out acct Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 46/74] linux-user: Move syscall_init to the end Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 47/74] linux-user: Split out ioctl Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 48/74] linux-user: Fix types in ioctl logging Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 49/74] linux-user: Remove sentinel from ioctl_entries Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 50/74] linux-user: Split out fcntl, fcntl64 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 51/74] linux-user: Split out setpgid Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 52/74] linux-user: Split out umask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 53/74] linux-user: Split out chroot Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 54/74] linux-user: Split out getpgid, getpgrp Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 55/74] linux-user: Split out getsid, setsid Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 56/74] linux-user: Split out sigaction, rt_sigaction Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 57/74] linux-user: Split out sgetmask, ssetmask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 58/74] linux-user: Split out sigprocmask, rt_sigprocmask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 59/74] linux-user: Split out sigpending, rt_sigpending Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 60/74] linux-user: Split out sigsuspend, rt_sigsuspend Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 61/74] linux-user: Split out rt_sigtimedwait Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 62/74] linux-user: Split out rt_sigqueueinfo, rt_tgsigqueueinfo Richard Henderson
2019-05-20 6:04 ` Aleksandar Markovic
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 63/74] linux-user: Split out sigreturn, rt_sigreturn Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 64/74] linux-user: Split out gethostname, sethostname Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 65/74] linux-user: Split out getrlimit, setrlimit Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 66/74] linux-user: Split out getrusage Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 67/74] linux-user: Split out gettimeofday, settimeofday Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 68/74] linux-user: Split out select, _newselect Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 69/74] linux-user: Split out pselect6 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 70/74] linux-user: Split out symlink, symlinkat Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 71/74] linux-user: Split out swapon, swapoff Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 72/74] linux-user: Split out reboot Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 73/74] linux-user: Split out truncate, truncate64, ftruncate, ftruncate64 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 74/74] linux-user: Split out getpriority, setpriority Richard Henderson
2019-05-20 6:21 ` [Qemu-devel] [PATCH v7 00/74] linux-user: Split do_syscall Laurent Vivier
2019-05-20 9:42 ` Peter Maydell
2019-05-20 10:13 ` Aleksandar Markovic
2019-05-22 6:11 ` Aleksandar Markovic
[not found] ` <CAL1e-=i_=EQ02A1DGmVgqNi1ik=h39FZTOsxkGWfMa4ZoM6rjg@mail.gmail.com>
2019-05-22 11:29 ` 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=20190519203726.20729-6-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).