[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 29/74] linux-user: Split out lseek, llseek
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PATCH v7 29/74] linux-user: Split out lseek, llseek |
Date: |
Sun, 19 May 2019 13:36:41 -0700 |
Canonicalise the target syscall name on llseek (new kernels)
instead of _llseek (old kernels). Always use host lseek(3)
rather than attempting to use the host llseek(2).
Signed-off-by: Richard Henderson <address@hidden>
---
linux-user/syscall-defs.h | 6 ++++++
linux-user/syscall.h | 1 +
linux-user/strace.c | 39 +++++++++++++++--------------------
linux-user/syscall-file.inc.c | 36 ++++++++++++++++++++++++++++++++
linux-user/syscall.c | 32 ++--------------------------
linux-user/strace.list | 6 ------
6 files changed, 62 insertions(+), 58 deletions(-)
diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 3ddf8aa0e3..3453e7afdf 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -43,6 +43,12 @@ SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX,
ARG_PTR, ARG_HEX);
SYSCALL_DEF(link, ARG_STR, ARG_STR);
#endif
SYSCALL_DEF(linkat, ARG_ATDIRFD, ARG_STR, ARG_ATDIRFD, ARG_STR, ARG_ATFLAG);
+#ifdef TARGET_NR_lseek
+SYSCALL_DEF(lseek, ARG_DEC, ARG_DEC, ARG_LSEEKWHENCE);
+#endif
+#ifdef TARGET_NR_llseek
+SYSCALL_DEF_ARGS(llseek, ARG_DEC, ARG_DEC, ARG_PTR, ARG_LSEEKWHENCE);
+#endif
#ifdef TARGET_NR_mknod
SYSCALL_DEF(mknod, ARG_STR, ARG_MODEFLAG, ARG_HEX);
#endif
diff --git a/linux-user/syscall.h b/linux-user/syscall.h
index bdc4d653c4..c16c0a3f1e 100644
--- a/linux-user/syscall.h
+++ b/linux-user/syscall.h
@@ -64,6 +64,7 @@ typedef enum {
ARG_MODEFLAG,
ARG_OPENFLAG,
ARG_UNLINKATFLAG,
+ ARG_LSEEKWHENCE,
/* These are interpreted as pointers. */
ARG_PTR,
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 4771badeb5..a4d7b397b4 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -934,6 +934,20 @@ print_open_flags(abi_long flags, int last)
gemu_log("%s%s", buf, get_comma(last));
}
+static int add_lseek_whence(char *buf, int size, int whence)
+{
+ switch (whence) {
+ case SEEK_SET:
+ return snprintf(buf, size, "SEEK_SET");
+ case SEEK_CUR:
+ return snprintf(buf, size, "SEEK_CUR");
+ case SEEK_END:
+ return snprintf(buf, size, "SEEK_END");
+ default:
+ return snprintf(buf, size, "%#x", whence);
+ }
+}
+
static void
print_syscall_prologue(const struct syscallname *sc)
{
@@ -1297,28 +1311,6 @@ print_futimesat(const struct syscallname *name,
}
#endif
-#ifdef TARGET_NR__llseek
-static void
-print__llseek(const struct syscallname *name,
- abi_long arg0, abi_long arg1, abi_long arg2,
- abi_long arg3, abi_long arg4, abi_long arg5)
-{
- const char *whence = "UNKNOWN";
- print_syscall_prologue(name);
- print_raw_param("%d", arg0, 0);
- print_raw_param("%ld", arg1, 0);
- print_raw_param("%ld", arg2, 0);
- print_pointer(arg3, 0);
- switch(arg4) {
- case SEEK_SET: whence = "SEEK_SET"; break;
- case SEEK_CUR: whence = "SEEK_CUR"; break;
- case SEEK_END: whence = "SEEK_END"; break;
- }
- gemu_log("%s",whence);
- print_syscall_epilogue(name);
-}
-#endif
-
#if defined(TARGET_NR_socket)
static void
print_socket(const struct syscallname *name,
@@ -2329,6 +2321,9 @@ static void print_syscall_def1(const SyscallDef *def,
int64_t args[6])
case ARG_UNLINKATFLAG:
len = add_flags(b, rest, unlinkat_flags, arg, true);
break;
+ case ARG_LSEEKWHENCE:
+ len = add_lseek_whence(b, rest, arg);
+ break;
case ARG_PTR:
len = add_pointer(b, rest, arg);
break;
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index fb64d5bd1d..e267adec1e 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -112,6 +112,42 @@ SYSCALL_IMPL(linkat)
return do_linkat(arg1, arg2, arg3, arg4, arg5);
}
+#ifdef TARGET_NR_lseek
+SYSCALL_IMPL(lseek)
+{
+ return get_errno(lseek(arg1, arg2, arg3));
+}
+#endif
+
+#ifdef TARGET_NR_llseek
+SYSCALL_ARGS(llseek)
+{
+ /* The parts for offset are *always* in big-endian order. */
+ abi_ulong lo = in[2], hi = in[1];
+ out[1] = (((uint64_t)hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+ out[2] = in[3];
+ out[3] = in[4];
+ return def;
+}
+
+SYSCALL_IMPL(llseek)
+{
+ int fd = arg1;
+ int64_t offset = arg2;
+ abi_ulong target_res = arg3;
+ int whence = arg4;
+
+ off_t res = lseek(fd, offset, whence);
+
+ if (res == -1) {
+ return get_errno(-1);
+ } else if (put_user_s64(res, target_res)) {
+ return -TARGET_EFAULT;
+ }
+ return 0;
+}
+#endif
+
static abi_long do_mknodat(int dirfd, abi_ulong target_path,
mode_t mode, dev_t dev)
{
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3c0de73aa4..9eff91d67e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -192,8 +192,8 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4
arg4,type5 arg5, \
#endif
/* Newer kernel ports have llseek() instead of _llseek() */
-#if defined(TARGET_NR_llseek) && !defined(TARGET_NR__llseek)
-#define TARGET_NR__llseek TARGET_NR_llseek
+#if !defined(TARGET_NR_llseek) && defined(TARGET_NR__llseek)
+#define TARGET_NR_llseek TARGET_NR__llseek
#endif
#define __NR_sys_gettid __NR_gettid
@@ -217,10 +217,6 @@ _syscall3(int, sys_getdents, uint, fd, struct linux_dirent
*, dirp, uint, count)
(defined(TARGET_NR_getdents64) && defined(__NR_getdents64))
_syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint,
count);
#endif
-#if defined(TARGET_NR__llseek) && defined(__NR_llseek)
-_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
- loff_t *, res, uint, wh);
-#endif
_syscall3(int, sys_rt_sigqueueinfo, pid_t, pid, int, sig, siginfo_t *, uinfo)
_syscall4(int, sys_rt_tgsigqueueinfo, pid_t, pid, pid_t, tid, int, sig,
siginfo_t *, uinfo)
@@ -5384,10 +5380,6 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
void *p;
switch(num) {
-#ifdef TARGET_NR_lseek
- case TARGET_NR_lseek:
- return get_errno(lseek(arg1, arg2, arg3));
-#endif
#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
/* Alpha specific */
case TARGET_NR_getxpid:
@@ -6886,26 +6878,6 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
return get_errno(fchdir(arg1));
case TARGET_NR_personality:
return get_errno(personality(arg1));
-#ifdef TARGET_NR__llseek /* Not on alpha */
- case TARGET_NR__llseek:
- {
- int64_t res;
-#if !defined(__NR_llseek)
- res = lseek(arg1, ((uint64_t)arg2 << 32) | (abi_ulong)arg3, arg5);
- if (res == -1) {
- ret = get_errno(res);
- } else {
- ret = 0;
- }
-#else
- ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5));
-#endif
- if ((ret == 0) && put_user_s64(res, arg4)) {
- return -TARGET_EFAULT;
- }
- }
- return ret;
-#endif
#ifdef TARGET_NR_getdents
case TARGET_NR_getdents:
#ifdef EMULATE_GETDENTS_WITH_GETDENTS
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 0906aba812..fb37c72a1f 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -455,9 +455,6 @@
#ifdef TARGET_NR_llistxattr
{ TARGET_NR_llistxattr, "llistxattr" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR__llseek
-{ TARGET_NR__llseek, "_llseek" , NULL, print__llseek, NULL },
-#endif
#ifdef TARGET_NR_lock
{ TARGET_NR_lock, "lock" , NULL, NULL, NULL },
#endif
@@ -467,9 +464,6 @@
#ifdef TARGET_NR_lremovexattr
{ TARGET_NR_lremovexattr, "lremovexattr" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_lseek
-{ TARGET_NR_lseek, "lseek" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_lsetxattr
{ TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },
#endif
--
2.17.1
- [Qemu-devel] [PATCH v7 23/74] linux-user: Split out execve, (continued)
- [Qemu-devel] [PATCH v7 23/74] linux-user: Split out execve, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 20/74] linux-user: Split out creat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 24/74] linux-user: Implement execveat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 26/74] linux-user: Split out time, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 27/74] linux-user: Split out mknod, mknodat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 30/74] linux-user: Split out getpid, getppid, getxpid, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 28/74] linux-user: Split out chmod, fchmod, fchmodat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 25/74] linux-user: Split out chdir, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 33/74] linux-user: Split out stime, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 32/74] linux-user: Split out umount, umount2, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 29/74] linux-user: Split out lseek, llseek,
Richard Henderson <=
- [Qemu-devel] [PATCH v7 31/74] linux-user: Split out mount, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 34/74] linux-user: Split out alarm, pause, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 35/74] linux-user: Split out utime, utimes, futimesat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 36/74] linux-user: Split out access, faccessat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 37/74] linux-user: Split out nice, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 38/74] linux-user: Split out sync, syncfs, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 42/74] linux-user: Split out dup, dup2, dup3, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 40/74] linux-user: Split out rename, renameat, renameat2, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 41/74] linux-user: Split out mkdir, mkdirat, Richard Henderson, 2019/05/19
- [Qemu-devel] [PATCH v7 45/74] linux-user: Split out acct, Richard Henderson, 2019/05/19