linux-user: Split do_syscall
v6 cover linux-user: Split do_syscall
Since v5, I've split the patches into smaller pieces, and done a few more syscalls. But I've also been approaching them in a more "systematic" way -- taking from the top of the switch.
I've been trying to fix up checkpatch failures as I've moved code, but I've surely missed some. I've also been trying to share code between the "*at" syscalls and their original.
I've tested x86_64->armhf and aarch64->i386 vs LTP.
FYI, as measured by the line count of do_syscall1, this is about 25% of the total job to be done.
r~
PS: Patch 2/49 is a debugging patch I forgot to remove. Rather than regenerate the series, I just omitted it here.
Richard Henderson (49):
linux-user: Setup split syscall infrastructure
linux-user: Split out open, open_at
linux-user: Share more code for open and openat
linux-user: Tidy do_openat loop over fakes
linux-user: Split out readlink, readlinkat
linux-user: Split out close
linux-user: Split out read, write
linux-user: Reduce regpairs_aligned & target_offset64 ifdefs
linux-user: Split out readv, writev
linux-user: Split out pread64, pwrite64
linux-user: Split out preadv, pwritev
linux-user: Split out name_to_handle_at, open_by_handle_at
linux-user: Split out ipc syscalls
linux-user: Split out memory syscalls
linux-user: Split out exit
linux-user: Split out brk
linux-user: Split out clone, fork, vfork
linux-user: Split out wait4, waitid, waitpid
linux-user: Implement rusage argument to waitid
linux-user: Split out creat
linux-user: Split out link, linkat
linux-user: Split out unlink, unlinkat, rmdir
linux-user: Split out execve
linux-user: Implement execveat
linux-user: Split out chdir
linux-user: Split out time
linux-user: Split out mknod, mknodat
linux-user: Split out chmod, fchmod, fchmodat
linux-user: Split out lseek, llseek
linux-user: Split out getpid, getppid, getxpid
linux-user: Split out mount
linux-user: Split out umount, umount2
linux-user: Split out stime
linux-user: Split out alarm, pause
linux-user: Split out utime, utimes, futimesat
linux-user: Split out access, faccessat
linux-user: Split out nice
linux-user: Split out sync, syncfs
linux-user: Split out kill
linux-user: Split out rename, renameat, renameat2
linux-user: Split out mkdir, mkdirat
linux-user: Split out dup, dup2, dup3
linux-user: Split out pipe, pipe2
linux-user: Split out times
linux-user: Split out acct
linux-user: Move syscall_init to the end
linux-user: Split out ioctl
linux-user: Split out fcntl, fcntl64
linux-user/syscall-defs.h | 240 ++ linux-user/syscall.h | 102 + linux-user/strace.c | 1258 +++------- linux-user/syscall-fcntl.inc.c | 322 +++ linux-user/syscall-file.inc.c | 1229 ++++++++++ linux-user/syscall-ioctl.inc.c | 873 +++++++ linux-user/syscall-ipc.inc.c | 1086 +++++++++ linux-user/syscall-mem.inc.c | 244 ++ linux-user/syscall-proc.inc.c | 593 +++++ linux-user/syscall-sig.inc.c | 41 + linux-user/syscall-time.inc.c | 44 + linux-user/syscall.c | 4128 ++------------------------------ configure | 20 - linux-user/strace.list | 285 --- 14 files changed, 5376 insertions(+), 5089 deletions(-) create mode 100644 linux-user/syscall-defs.h create mode 100644 linux-user/syscall.h create mode 100644 linux-user/syscall-fcntl.inc.c create mode 100644 linux-user/syscall-file.inc.c create mode 100644 linux-user/syscall-ioctl.inc.c create mode 100644 linux-user/syscall-ipc.inc.c create mode 100644 linux-user/syscall-mem.inc.c create mode 100644 linux-user/syscall-proc.inc.c create mode 100644 linux-user/syscall-sig.inc.c create mode 100644 linux-user/syscall-time.inc.c
Signature · 1 line
2.17.2
PATCH v6 1/49 linux-user: Setup split syscall infrastructure
Defines a unified structure for implementation and strace.
--- linux-user/syscall-defs.h | 17 ++ linux-user/syscall.h | 89 +++++++++ linux-user/strace.c | 388 +++++++++++++++++++++++++++----------- linux-user/syscall.c | 103 +++++++++- 4 files changed, 484 insertions(+), 113 deletions(-) create mode 100644 linux-user/syscall-defs.h create mode 100644 linux-user/syscall.h
linux-user/syscall-defs.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Linux syscall definitions +* Copyright (c) 2003 Fabrice Bellard +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/
linux-user/syscall.h new file +89 -0
89 lines not on this page · raw message
linux-user/strace.c +283 -105
484 lines not on this page · raw message
linux-user/syscall.c +95 -8
129 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v6 3/49 linux-user: Split out open, open_at
In reply to Richard HendersonFor the moment, leave a forward declaration for is_proc_myself until the readlink syscalls are also moved to syscall-file.inc.c.
--- linux-user/syscall-defs.h | 5 + linux-user/strace.c | 35 ---- linux-user/syscall-file.inc.c | 319 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 282 +----------------------------- linux-user/strace.list | 6 - 5 files changed, 326 insertions(+), 321 deletions(-) create mode 100644 linux-user/syscall-file.inc.c
linux-user/syscall-defs.h +5 -0
@@ -15,3 +15,8 @@* You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ + +#ifdef TARGET_NR_open +SYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG ); +#endif +SYSCALL_DEF (openat,ARG_ATDIRFD ,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );
linux-user/strace.c +0 -35
@@ -2216,41 +2216,6 @@ print_mq_open(const struct syscallname *name, }#endif -#ifdef TARGET_NR_open -static void -print_open (const struct syscallname *name, -abi_long arg0,abi_long arg1,abi_long arg2, -abi_long arg3,abi_long arg4,abi_long arg5) -{ -int is_creat = (arg1 &TARGET_O_CREAT ); - -print_syscall_prologue (name); -print_string (arg0,0 ); -print_open_flags (arg1, (is_creat ==0 )); -if (is_creat) -print_file_mode (arg2,1 ); -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_openat -static void -print_openat (const struct syscallname *name, -abi_long arg0,abi_long arg1,abi_long arg2, -abi_long arg3,abi_long arg4,abi_long arg5) -{ -int is_creat = (arg2 &TARGET_O_CREAT ); - -print_syscall_prologue (name); -print_at_dirfd (arg0,0 ); -print_string (arg1,0 ); -print_open_flags (arg2, (is_creat ==0 )); -if (is_creat) -print_file_mode (arg3,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_mq_unlink static void print_mq_unlink(const struct syscallname *name,
linux-user/syscall-file.inc.c new file +319 -0
319 lines not on this page · raw message
linux-user/syscall.c +2 -280
300 lines not on this page · raw message
linux-user/strace.list +0 -6
@@ -677,12 +677,6 @@ #ifdef TARGET_NR_olduname { TARGET_NR_olduname, "olduname" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_open -{ TARGET_NR_open, "open" , NULL, print_open, NULL }, -#endif -#ifdef TARGET_NR_openat -{ TARGET_NR_openat, "openat" , NULL, print_openat, NULL }, -#endif #ifdef TARGET_NR_osf_adjtime { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 4/49 linux-user: Share more code for open and openat
In reply to Richard HendersonThe do_openat helper can have all of the code that is not directly related to the argument ordering of these two syscalls.
--- linux-user/syscall-file.inc.c | 69 ++++++++++++++++------------------- 1 file changed, 31 insertions(+), 38 deletions(-)
linux-user/syscall-file.inc.c +31 -38
@@ -221,8 +221,8 @@ static int open_net_route(void *cpu_env, int fd) }#endif -static int do_openat (void *cpu_env,int dirfd,const char *pathname, -int flags,mode_t mode) +static abi_long do_openat (void *cpu_env,int dirfd,abi_ulong target_path, +int target_flags,mode_t mode) {struct fake_open {const char *filename;
@@ -241,9 +241,20 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, { NULL, NULL, NULL } }; +char *pathname =lock_user_string (target_path); +int flags =target_to_host_bitmask (target_flags, fcntl_flags_tbl); +abi_long ret; + +if (!pathname) { +return -TARGET_EFAULT ; + } +if (is_proc_myself (pathname,"exe" )) { -int execfd =qemu_getauxval (AT_EXECFD ); -return execfd ? execfd :safe_openat (dirfd, exec_path, flags, mode); + ret =qemu_getauxval (AT_EXECFD ); +if (ret ==0 ) { + ret =get_errno (safe_openat (dirfd, exec_path, flags, mode)); + } + goto done; }for (fake_open = fakes; fake_open->filename; fake_open++) {
@@ -255,7 +266,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname,if (fake_open->filename) {const char *tmpdir;char filename[PATH_MAX ]; -int fd, r; +int fd;/* create temporary file to map stat to */ tmpdir =getenv ("TMPDIR" );
@@ -265,55 +276,37 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname,snprintf (filename,sizeof (filename),"%s/qemu-open.XXXXXX" , tmpdir); fd =mkstemp (filename);if (fd <0 ) { -return fd; + ret = -TARGET_ENOENT ; + goto done; }unlink (filename); - r = fake_open->fill (cpu_env, fd); -if (r) { -int e = errno; + ret = fake_open->fill (cpu_env, fd); +if (ret) { + ret =get_errno (ret);close (fd); - errno = e; -return r; + goto done; }lseek (fd,0 ,SEEK_SET ); - -return fd; + ret = fd; + goto done; } -return safe_openat (dirfd,path (pathname), flags, mode); + ret =get_errno (safe_openat (dirfd,path (pathname), flags, mode)); + done: +fd_trans_unregister (ret); +unlock_user (pathname, target_path,0 ); +return ret; }#ifdef TARGET_NR_openSYSCALL_IMPL (open) { -char *p =lock_user_string (arg1); -abi_long ret; - -if (!p) { -return -TARGET_EFAULT ; - } - ret =get_errno (do_openat (cpu_env,AT_FDCWD , p, -target_to_host_bitmask (arg2, fcntl_flags_tbl), - arg3)); -fd_trans_unregister (ret); -unlock_user (p, arg1,0 ); -return ret; +return do_openat (cpu_env,AT_FDCWD , arg1, arg2, arg3); }#endif SYSCALL_IMPL (openat) { -char *p =lock_user_string (arg2); -abi_long ret; - -if (!p) { -return -TARGET_EFAULT ; - } - ret =get_errno (do_openat (cpu_env, arg1, p, -target_to_host_bitmask (arg3, fcntl_flags_tbl), - arg4)); -fd_trans_unregister (ret); -unlock_user (p, arg2,0 ); -return ret; +return do_openat (cpu_env, arg1, arg2, arg3, arg4); }
Signature · 1 line
2.17.2
PATCH v6 5/49 linux-user: Tidy do_openat loop over fakes
In reply to Richard HendersonCleaner to use ARRAY_SIZE to loop over elements instead of using a sentinel within the data structure.
--- linux-user/syscall-file.inc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
linux-user/syscall-file.inc.c +7 -9
@@ -229,7 +229,6 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path,int (*fill)(void *cpu_env,int fd);int (*cmp)(const char *s1,const char *s2); }; -const struct fake_open *fake_open;static const struct fake_open fakes[] = { {"maps" , open_self_maps, is_proc_myself }, {"stat" , open_self_stat, is_proc_myself },
@@ -238,12 +237,12 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path, #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) { "/proc/net/route", open_net_route, is_proc }, #endif - { NULL, NULL, NULL } }; char *pathname = lock_user_string(target_path); int flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl); abi_long ret; + size_t i; if (!pathname) { return -TARGET_EFAULT;
@@ -257,17 +256,16 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path, goto done; } -for (fake_open = fakes; fake_open->filename; fake_open++) { -if (fake_open->cmp (pathname, fake_open->filename)) { -break ; - } - } - -if (fake_open->filename) { +for (i =0 ; i <ARRAY_SIZE (fakes); ++i) { +const struct fake_open *fake_open = &fakes[i];const char *tmpdir;char filename[PATH_MAX ];int fd; +if (!fake_open->cmp (pathname, fake_open->filename)) { +continue ; + } +/* create temporary file to map stat to */ tmpdir =getenv ("TMPDIR" );if (!tmpdir) {
Signature · 1 line
2.17.2
PATCH v6 6/49 linux-user: Split out readlink, readlinkat
In reply to Richard HendersonSplit 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.
--- 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(-)
linux-user/syscall-defs.h +6 -0
@@ -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
linux-user/strace.c +0 -29
@@ -2244,35 +2244,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,
linux-user/syscall-file.inc.c +45 -0
48 lines not on this page · raw message
linux-user/syscall.c +0 -55
67 lines not on this page · raw message
linux-user/strace.list +0 -6
@@ -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
Signature · 1 line
2.17.2
PATCH v6 7/49 linux-user: Split out close
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall-file.inc.c | 8 ++++++++ linux-user/syscall.c | 4 ---- linux-user/strace.list | 3 --- 4 files changed, 9 insertions(+), 7 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -16,6 +16,7 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +SYSCALL_DEF (close,ARG_DEC );#ifdef TARGET_NR_openSYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );#endif
linux-user/syscall-file.inc.c +8 -0
@@ -16,6 +16,14 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +SYSCALL_IMPL (close) +{ +int fd = arg1; + +fd_trans_unregister (fd); +return get_errno (close (fd)); +} +/* * Helpers for do_openat, manipulating /proc/self/foo. */
linux-user/syscall.c +0 -4
@@ -6771,10 +6771,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,fd_trans_unregister (ret);return ret;#endif -case TARGET_NR_close: -fd_trans_unregister (arg1); -return get_errno (close (arg1)); -case TARGET_NR_brk:return do_brk (arg1);#ifdef TARGET_NR_fork
linux-user/strace.list +0 -3
@@ -97,9 +97,6 @@ #ifdef TARGET_NR_clone { TARGET_NR_clone, "clone" , NULL, print_clone, NULL }, #endif -#ifdef TARGET_NR_close -{ TARGET_NR_close, "close" , "%s(%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_connect { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 8/49 linux-user: Split out read, write
In reply to Richard Henderson--- linux-user/syscall-defs.h | 2 ++ linux-user/syscall-file.inc.c | 58 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 34 -------------------- linux-user/strace.list | 6 ---- 4 files changed, 60 insertions(+), 40 deletions(-)
linux-user/syscall-defs.h +2 -0
@@ -21,9 +21,11 @@ SYSCALL_DEF(close, ARG_DEC);SYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );#endif SYSCALL_DEF (openat,ARG_ATDIRFD ,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG ); +SYSCALL_DEF (read,ARG_DEC ,ARG_PTR ,ARG_DEC );#ifdef TARGET_NR_readlinkSYSCALL_DEF (readlink,ARG_STR ,ARG_PTR ,ARG_DEC );#endif #ifdef TARGET_NR_readlinkatSYSCALL_DEF (readlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_DEC );#endif +SYSCALL_DEF (write,ARG_DEC ,ARG_PTR ,ARG_DEC );
linux-user/syscall-file.inc.c +58 -0
67 lines not on this page · raw message
linux-user/syscall.c +0 -34
@@ -6726,40 +6726,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,preexit_cleanup (cpu_env, arg1);_exit (arg1);return 0 ;/* avoid warning */ -case TARGET_NR_read: -if (arg3 ==0 ) { -return 0 ; - }else { -if (!(p =lock_user (VERIFY_WRITE , arg2, arg3,0 ))) -return -TARGET_EFAULT ; - ret =get_errno (safe_read (arg1, p, arg3)); -if (ret >=0 && -fd_trans_host_to_target_data (arg1)) { - ret =fd_trans_host_to_target_data (arg1)(p, ret); - } -unlock_user (p, arg2, ret); - } -return ret; -case TARGET_NR_write: -if (arg2 ==0 && arg3 ==0 ) { -return get_errno (safe_write (arg1,0 ,0 )); - } -if (!(p =lock_user (VERIFY_READ , arg2, arg3,1 ))) -return -TARGET_EFAULT ; -if (fd_trans_target_to_host_data (arg1)) { -void *copy =g_malloc (arg3); -memcpy (copy, p, arg3); - ret =fd_trans_target_to_host_data (arg1)(copy, arg3); -if (ret >=0 ) { - ret =get_errno (safe_write (arg1, copy, ret)); - } -g_free (copy); - }else { - ret =get_errno (safe_write (arg1, p, arg3)); - } -unlock_user (p, arg2,0 ); -return ret; -#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE )case TARGET_NR_name_to_handle_at: ret =do_name_to_handle_at (arg1, arg2, arg3, arg4, arg5);
linux-user/strace.list +0 -6
@@ -1067,9 +1067,6 @@ #ifdef TARGET_NR_quotactl { TARGET_NR_quotactl, "quotactl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_read -{ TARGET_NR_read, "read" , "%s(%d,%#x,%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_readahead { TARGET_NR_readahead, "readahead" , NULL, NULL, NULL }, #endif
@@ -1611,9 +1608,6 @@ #ifdef TARGET_NR_waitpid { TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, #endif -#ifdef TARGET_NR_write -{ TARGET_NR_write, "write" , "%s(%d,%#x,%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_writev { TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 9/49 linux-user: Reduce regpairs_aligned & target_offset64 ifdefs
In reply to Richard Henderson--- linux-user/syscall.c | 54 ++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 29 deletions(-)
linux-user/syscall.c +25 -29
@@ -474,37 +474,38 @@ static inline int next_free_host_timer(void) }#endif -/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ +/* +* Returns true if syscall NUM expects 64bit types aligned even +* on pairs of registers. +*/ +static inline bool regpairs_aligned (void *cpu_env,int num) +{#ifdef TARGET_ARM -static inline int regpairs_aligned (void *cpu_env,int num) -{ -return ((((CPUARMState *)cpu_env)->eabi) ==1 ) ; -} -#elif defined(TARGET_MIPS ) && (TARGET_ABI_BITS ==32 ) -static inline int regpairs_aligned (void *cpu_env,int num) {return 1 ; } +return ((CPUARMState *)cpu_env)->eabi; +#elif defined(TARGET_MIPS ) &&TARGET_ABI_BITS ==32 +return true;#elif defined(TARGET_PPC ) && !defined(TARGET_PPC64 ) -/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs -* of registers which translates to the same as ARM/MIPS, because we start with -* r3 as arg1 */ -static inline int regpairs_aligned (void *cpu_env,int num) {return 1 ; } +/* +* SysV AVI for PPC32 expects 64bit parameters to be passed on +* odd/even pairs of registers which translates to the same as +* we start with r3 as arg1. +*/ +return true;#elif defined(TARGET_SH4 ) -/* SH4 doesn't align register pairs, except for p{read,write}64 */ -static inline int regpairs_aligned (void *cpu_env,int num) -{ +/* SH4 doesn't align register pairs, except for p{read,write}64. */ switch (num) {case TARGET_NR_pread64:case TARGET_NR_pwrite64: -return 1 ; - +return true;default : -return 0 ; +return false; } -}#elif defined(TARGET_XTENSA ) -static inline int regpairs_aligned (void *cpu_env,int num) {return 1 ; } +return true;#else -static inline int regpairs_aligned (void *cpu_env,int num) {return 0 ; } +return false;#endif +}#define ERRNO_TABLE_SIZE 1200
@@ -6105,21 +6106,16 @@ void syscall_init(void) } } -#if TARGET_ABI_BITS ==32 -static inline uint64_t target_offset64 (uint32_t word0,uint32_t word1) +static inline uint64_t target_offset64 (abi_ulong word0,abi_ulong word1) { -#ifdef TARGET_WORDS_BIGENDIAN +#if TARGET_ABI_BITS ==64 +return word0; +#elif defined(TARGET_WORDS_BIGENDIAN )return ((uint64_t )word0 <<32 ) | word1;#else return ((uint64_t )word1 <<32 ) | word0;#endif } -#else /* TARGET_ABI_BITS == 32 */ -static inline uint64_t target_offset64 (uint64_t word0,uint64_t word1) -{ -return word0; -} -#endif /* TARGET_ABI_BITS != 32 */ #ifdef TARGET_NR_truncate64 static inline abi_long target_truncate64(void *cpu_env, const char *arg1,
Signature · 1 line
2.17.2
PATCH v6 10/49 linux-user: Split out readv, writev
In reply to Richard Henderson--- linux-user/syscall-defs.h | 2 ++ linux-user/syscall-file.inc.c | 34 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 22 ---------------------- linux-user/strace.list | 6 ------ 4 files changed, 36 insertions(+), 28 deletions(-)
linux-user/syscall-defs.h +2 -0
@@ -28,4 +28,6 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);#ifdef TARGET_NR_readlinkatSYSCALL_DEF (readlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_DEC );#endif +SYSCALL_DEF (readv,ARG_DEC ,ARG_PTR ,ARG_DEC );SYSCALL_DEF (write,ARG_DEC ,ARG_PTR ,ARG_DEC ); +SYSCALL_DEF (writev,ARG_DEC ,ARG_PTR ,ARG_DEC );
linux-user/syscall-file.inc.c +34 -0
@@ -343,6 +343,23 @@ SYSCALL_IMPL(read)return ret; } +SYSCALL_IMPL (readv) +{ +int fd = arg1; +abi_ulong target_vec = arg2; +int count = arg3; +struct iovec *vec =lock_iovec (VERIFY_WRITE , target_vec, count,0 ); +abi_long ret; + +if (vec !=NULL ) { + ret =get_errno (safe_readv (fd, vec, count)); +unlock_iovec (vec, target_vec, count,1 ); + }else { + ret = -host_to_target_errno (errno); + } +return ret; +} +static abi_long do_readlinkat (int dirfd,abi_ulong target_path,abi_ulong target_buf,abi_ulong bufsiz) {
@@ -419,3 +436,20 @@ SYSCALL_IMPL(write)unlock_user (p, target_p,0 );return ret; } + +SYSCALL_IMPL (writev) +{ +int fd = arg1; +abi_ulong target_vec = arg2; +int count = arg3; +struct iovec *vec =lock_iovec (VERIFY_READ , target_vec, count,1 ); +abi_long ret; + +if (vec !=NULL ) { + ret =get_errno (safe_writev (fd, vec, count)); +unlock_iovec (vec, target_vec, count,0 ); + }else { + ret = -host_to_target_errno (errno); + } +return ret; +}
linux-user/syscall.c +0 -22
@@ -8949,28 +8949,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,/* NOTE: the flock constant seems to be the same for every Linux platform */ return get_errno (safe_flock (arg1, arg2)); -case TARGET_NR_readv: - { -struct iovec *vec =lock_iovec (VERIFY_WRITE , arg2, arg3,0 ); -if (vec !=NULL ) { - ret =get_errno (safe_readv (arg1, vec, arg3)); -unlock_iovec (vec, arg2, arg3,1 ); - }else { - ret = -host_to_target_errno (errno); - } - } -return ret; -case TARGET_NR_writev: - { -struct iovec *vec =lock_iovec (VERIFY_READ , arg2, arg3,1 ); -if (vec !=NULL ) { - ret =get_errno (safe_writev (arg1, vec, arg3)); -unlock_iovec (vec, arg2, arg3,0 ); - }else { - ret = -host_to_target_errno (errno); - } - } -return ret;#if defined(TARGET_NR_preadv)case TARGET_NR_preadv: {
linux-user/strace.list +0 -6
@@ -1073,9 +1073,6 @@ #ifdef TARGET_NR_readdir { TARGET_NR_readdir, "readdir" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_readv -{ TARGET_NR_readv, "readv" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_reboot { TARGET_NR_reboot, "reboot" , NULL, NULL, NULL }, #endif
@@ -1608,9 +1605,6 @@ #ifdef TARGET_NR_waitpid { TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, #endif -#ifdef TARGET_NR_writev -{ TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL }, -#endif #ifdef TARGET_NR_utimensat { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 11/49 linux-user: Split out pread64, pwrite64
In reply to Richard Henderson--- linux-user/syscall-defs.h | 6 ++++ linux-user/syscall-file.inc.c | 62 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 36 -------------------- linux-user/strace.list | 6 ---- 4 files changed, 68 insertions(+), 42 deletions(-)
linux-user/syscall-defs.h +6 -0
@@ -21,6 +21,12 @@ SYSCALL_DEF(close, ARG_DEC);SYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );#endif SYSCALL_DEF (openat,ARG_ATDIRFD ,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG ); +SYSCALL_DEF_FULL(pread64, .impl = impl_pread64, + .args = args_pread64_pwrite64, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); +SYSCALL_DEF_FULL(pwrite64, .impl = impl_pwrite64, + .args = args_pread64_pwrite64, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });SYSCALL_DEF (read,ARG_DEC ,ARG_PTR ,ARG_DEC );#ifdef TARGET_NR_readlinkSYSCALL_DEF (readlink,ARG_STR ,ARG_PTR ,ARG_DEC );
linux-user/syscall-file.inc.c +62 -0
68 lines not on this page · raw message
linux-user/syscall.c +0 -36
@@ -9312,42 +9312,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#else #error unreachable#endif -#endif -#ifdef TARGET_NR_pread64 -case TARGET_NR_pread64: -if (regpairs_aligned (cpu_env, num)) { - arg4 = arg5; - arg5 = arg6; - } -if (arg2 ==0 && arg3 ==0 ) { -/* Special-case NULL buffer and zero length, which should succeed */ - p =0 ; - }else { - p =lock_user (VERIFY_WRITE , arg2, arg3,0 ); -if (!p) { -return -TARGET_EFAULT ; - } - } - ret =get_errno (pread64 (arg1, p, arg3,target_offset64 (arg4, arg5))); -unlock_user (p, arg2, ret); -return ret; -case TARGET_NR_pwrite64: -if (regpairs_aligned (cpu_env, num)) { - arg4 = arg5; - arg5 = arg6; - } -if (arg2 ==0 && arg3 ==0 ) { -/* Special-case NULL buffer and zero length, which should succeed */ - p =0 ; - }else { - p =lock_user (VERIFY_READ , arg2, arg3,1 ); -if (!p) { -return -TARGET_EFAULT ; - } - } - ret =get_errno (pwrite64 (arg1, p, arg3,target_offset64 (arg4, arg5))); -unlock_user (p, arg2,0 ); -return ret;#endif case TARGET_NR_getcwd:if (!(p =lock_user (VERIFY_WRITE , arg1, arg2,0 )))
linux-user/strace.list +0 -6
@@ -1025,9 +1025,6 @@ #ifdef TARGET_NR_prctl { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pread64 -{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_preadv { TARGET_NR_preadv, "preadv" , NULL, NULL, NULL }, #endif
@@ -1055,9 +1052,6 @@ #ifdef TARGET_NR_putpmsg { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pwrite64 -{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_pwritev { TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 12/49 linux-user: Split out preadv, pwritev
In reply to Richard Henderson--- linux-user/syscall-defs.h | 6 ++++ linux-user/syscall-file.inc.c | 64 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 49 --------------------------- linux-user/strace.list | 6 ---- 4 files changed, 70 insertions(+), 55 deletions(-)
linux-user/syscall-defs.h +6 -0
@@ -27,6 +27,12 @@ SYSCALL_DEF_FULL(pread64, .impl = impl_pread64, SYSCALL_DEF_FULL(pwrite64, .impl = impl_pwrite64, .args = args_pread64_pwrite64, .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); +SYSCALL_DEF_FULL(preadv, .impl = impl_preadv, + .args = args_preadv_pwritev, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 }); +SYSCALL_DEF_FULL(pwritev, .impl = impl_pwritev, + .args = args_preadv_pwritev, + .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });SYSCALL_DEF (read,ARG_DEC ,ARG_PTR ,ARG_DEC );#ifdef TARGET_NR_readlinkSYSCALL_DEF (readlink,ARG_STR ,ARG_PTR ,ARG_DEC );
linux-user/syscall-file.inc.c +64 -0
70 lines not on this page · raw message
linux-user/syscall.c +0 -49
61 lines not on this page · raw message
linux-user/strace.list +0 -6
@@ -1025,9 +1025,6 @@ #ifdef TARGET_NR_prctl { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_preadv -{ TARGET_NR_preadv, "preadv" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_prlimit64 { TARGET_NR_prlimit64, "prlimit64" , NULL, NULL, NULL }, #endif
@@ -1052,9 +1049,6 @@ #ifdef TARGET_NR_putpmsg { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pwritev -{ TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_query_module { TARGET_NR_query_module, "query_module" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 13/49 linux-user: Split out name_to_handle_at, open_by_handle_at
In reply to Richard HendersonAll targets have these syscalls, so they need not be ifdefed. If we provide safe syscalls for the host, we can remove the configure test for this too.
--- linux-user/syscall-defs.h | 3 + linux-user/syscall.h | 1 + linux-user/strace.c | 5 +- linux-user/syscall-file.inc.c | 81 +++++++++++++++++++++++++++ linux-user/syscall.c | 102 ++-------------------------------- configure | 20 ------- linux-user/strace.list | 3 - 7 files changed, 93 insertions(+), 122 deletions(-)
linux-user/syscall-defs.h +3 -0
@@ -17,10 +17,13 @@*/ SYSCALL_DEF (close,ARG_DEC ); +SYSCALL_DEF (name_to_handle_at, +ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );#ifdef TARGET_NR_openSYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );#endif SYSCALL_DEF (openat,ARG_ATDIRFD ,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG ); +SYSCALL_DEF (open_by_handle_at,ARG_DEC ,ARG_PTR ,ARG_OPENFLAG ); SYSCALL_DEF_FULL(pread64, .impl = impl_pread64, .args = args_pread64_pwrite64, .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
linux-user/syscall.h +1 -0
@@ -57,6 +57,7 @@ typedef enum {/* These print as sets of flags. */ ARG_ATDIRFD , +ARG_ATFLAG ,ARG_MODEFLAG , ARG_OPENFLAG,
linux-user/strace.c +4 -1
@@ -780,7 +780,7 @@ UNUSED static struct flags access_flags[] = { FLAG_END, }; -UNUSED static struct flags at_file_flags[] = { +static struct flags const at_file_flags[] = { #ifdef AT_EACCESSFLAG_GENERIC (AT_EACCESS ), #endif
@@ -2681,6 +2681,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_ATDIRFD : len =add_atdirfd (b, rest, arg);break ; +case ARG_ATFLAG : + len =add_flags (b, rest, at_file_flags, arg, false); +break ;case ARG_MODEFLAG : len =add_flags (b, rest, mode_flags, arg, true);break ;
linux-user/syscall-file.inc.c +81 -0
87 lines not on this page · raw message
linux-user/syscall.c +4 -98
120 lines not on this page · raw message
configure +0 -20
@@ -5028,22 +5028,6 @@ if test "$debug_stack_usage" = "yes"; then fi -########################################## -# check if we have open_by_handle_at - -open_by_handle_at=no -cat > $TMPC << EOF -#include <fcntl.h> -#if !defined(AT_EMPTY_PATH) -# error missing definition -#else -int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); } -#endif -EOF -if compile_prog "" "" ; then - open_by_handle_at=yes -fi - ######################################## # check if we have linux/magic.h
@@ -6701,10 +6685,6 @@ if test "$crypto_afalg" = "yes" ; then echo "CONFIG_AF_ALG=y" >> $config_host_mak fi -if test "$open_by_handle_at" = "yes" ; then - echo "CONFIG_OPEN_BY_HANDLE=y" >> $config_host_mak -fi - if test "$linux_magic_h" = "yes" ; then echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak fi
linux-user/strace.list +0 -3
@@ -635,9 +635,6 @@ #ifdef TARGET_NR_munmap { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL }, #endif -#ifdef TARGET_NR_name_to_handle_at -{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_nanosleep { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 14/49 linux-user: Split out ipc syscalls
In reply to Richard HendersonBecause of the ipc multiplex syscall, these must be done all at once.
--- linux-user/syscall-defs.h | 38 ++ linux-user/strace.c | 83 --- linux-user/syscall-ipc.inc.c | 1086 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 972 +----------------------------- linux-user/strace.list | 42 -- 5 files changed, 1127 insertions(+), 1094 deletions(-) create mode 100644 linux-user/syscall-ipc.inc.c
linux-user/syscall-defs.h +38 -0
@@ -17,6 +17,21 @@*/ SYSCALL_DEF (close,ARG_DEC ); +#ifdef TARGET_NR_ipc +SYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgctl) +SYSCALL_DEF (msgctl,ARG_DEC ,ARG_DEC ,ARG_PTR ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgget) +SYSCALL_DEF (msgget,ARG_DEC ,ARG_DEC ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgrcv) +SYSCALL_DEF (msgrcv,ARG_DEC ,ARG_PTR ,ARG_DEC ,ARG_DEC ,ARG_HEX ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgsnd) +SYSCALL_DEF (msgsnd,ARG_DEC ,ARG_PTR ,ARG_DEC ,ARG_HEX ); +#endif SYSCALL_DEF (name_to_handle_at,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );#ifdef TARGET_NR_open
@@ -44,5 +59,28 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);SYSCALL_DEF (readlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_DEC );#endif SYSCALL_DEF (readv,ARG_DEC ,ARG_PTR ,ARG_DEC ); +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_semctl) +SYSCALL_DEF (semctl,ARG_DEC ,ARG_DEC ,ARG_DEC ,ARG_HEX ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_semget) +SYSCALL_DEF (semget,ARG_DEC ,ARG_DEC ,ARG_HEX ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_semop) +SYSCALL_DEF (semop,ARG_DEC ,ARG_PTR ,ARG_DEC ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmat) +SYSCALL_DEF_FULL(shmat, .impl = impl_shmat, + .print_ret = print_syscall_ptr_ret, + .arg_type = { ARG_DEC, ARG_PTR, ARG_HEX }); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmctl) +SYSCALL_DEF (shmctl,ARG_DEC ,ARG_DEC ,ARG_PTR ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmdt) +SYSCALL_DEF (shmdt,ARG_PTR ); +#endif +#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmget) +SYSCALL_DEF (shmget,ARG_DEC ,ARG_DEC ,ARG_HEX ); +#endif SYSCALL_DEF (write,ARG_DEC ,ARG_PTR ,ARG_DEC );SYSCALL_DEF (writev,ARG_DEC ,ARG_PTR ,ARG_DEC );
linux-user/strace.c +0 -83
105 lines not on this page · raw message
linux-user/syscall-ipc.inc.c new file +1086 -0
1,086 lines not on this page · raw message
linux-user/syscall.c +3 -969
1,008 lines not on this page · raw message
linux-user/strace.list +0 -42
72 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v6 15/49 linux-user: Split out memory syscalls
In reply to Richard HendersonThis includes mmap, mmap2, munmap, mlock, mlockall, munlock, munlockall, mprotect, mremap, msync.
--- linux-user/syscall-defs.h | 24 ++++++ linux-user/syscall.h | 2 + linux-user/strace.c | 55 ++----------- linux-user/syscall-mem.inc.c | 154 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 119 +-------------------------- linux-user/strace.list | 33 -------- 6 files changed, 189 insertions(+), 198 deletions(-) create mode 100644 linux-user/syscall-mem.inc.c
linux-user/syscall-defs.h +24 -0
@@ -20,6 +20,26 @@ SYSCALL_DEF(close, ARG_DEC);#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif +SYSCALL_DEF (mlock,ARG_PTR ,ARG_DEC ); +SYSCALL_DEF (mlockall,ARG_HEX ); +#ifdef TARGET_NR_mmap +SYSCALL_DEF_FULL(mmap, .impl = impl_mmap, + .args = args_mmap, + .print_ret = print_syscall_ptr_ret, + .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT, + ARG_MMAPFLAG, ARG_DEC, ARG_DEC }); +#endif +#ifdef TARGET_NR_mmap2 +SYSCALL_DEF_FULL(mmap2, .impl = impl_mmap, + .args = args_mmap2, + .print_ret = print_syscall_ptr_ret, + .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT, + ARG_MMAPFLAG, ARG_DEC, ARG_DEC64 }); +#endif +SYSCALL_DEF (mprotect,ARG_PTR ,ARG_DEC ,ARG_MMAPPROT ); +SYSCALL_DEF_FULL(mremap, .impl = impl_mremap, + .print_ret = print_syscall_ptr_ret, + .arg_type = { ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR });#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgctl)SYSCALL_DEF (msgctl,ARG_DEC ,ARG_DEC ,ARG_PTR );#endif
@@ -32,6 +52,10 @@ SYSCALL_DEF(msgrcv, ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX);#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_msgsnd)SYSCALL_DEF (msgsnd,ARG_DEC ,ARG_PTR ,ARG_DEC ,ARG_HEX );#endif +SYSCALL_DEF (msync,ARG_PTR ,ARG_DEC ,ARG_HEX ); +SYSCALL_DEF (munlock,ARG_PTR ,ARG_DEC ); +SYSCALL_DEF (munlockall); +SYSCALL_DEF (munmap,ARG_PTR ,ARG_DEC );SYSCALL_DEF (name_to_handle_at,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );#ifdef TARGET_NR_open
linux-user/syscall.h +2 -0
@@ -58,6 +58,8 @@ typedef enum {/* These print as sets of flags. */ ARG_ATDIRFD ,ARG_ATFLAG , +ARG_MMAPFLAG , +ARG_MMAPPROT ,ARG_MODEFLAG , ARG_OPENFLAG,
linux-user/strace.c +8 -47
79 lines not on this page · raw message
linux-user/syscall-mem.inc.c new file +154 -0
154 lines not on this page · raw message
linux-user/syscall.c +1 -118
143 lines not on this page · raw message
linux-user/strace.list +0 -33
@@ -554,21 +554,6 @@ #ifdef TARGET_NR_mknodat { TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL }, #endif -#ifdef TARGET_NR_mlock -{ TARGET_NR_mlock, "mlock" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_mlock2 -{ TARGET_NR_mlock2, "mlock2" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_mlockall -{ TARGET_NR_mlockall, "mlockall" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_mmap -{ TARGET_NR_mmap, "mmap" , NULL, print_mmap, print_syscall_ret_addr }, -#endif -#ifdef TARGET_NR_mmap2 -{ TARGET_NR_mmap2, "mmap2" , NULL, print_mmap2, print_syscall_ret_addr }, -#endif #ifdef TARGET_NR_modify_ldt { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL }, #endif
@@ -578,9 +563,6 @@ #ifdef TARGET_NR_move_pages { TARGET_NR_move_pages, "move_pages" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_mprotect -{ TARGET_NR_mprotect, "mprotect" , NULL, print_mprotect, NULL }, -#endif #ifdef TARGET_NR_mpx { TARGET_NR_mpx, "mpx" , NULL, NULL, NULL }, #endif
@@ -602,24 +584,9 @@ #ifdef TARGET_NR_mq_unlink { TARGET_NR_mq_unlink, "mq_unlink" , NULL, print_mq_unlink, NULL }, #endif -#ifdef TARGET_NR_mremap -{ TARGET_NR_mremap, "mremap" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_msync -{ TARGET_NR_msync, "msync" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_multiplexer { TARGET_NR_multiplexer, "multiplexer" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_munlock -{ TARGET_NR_munlock, "munlock" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_munlockall -{ TARGET_NR_munlockall, "munlockall" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_munmap -{ TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL }, -#endif #ifdef TARGET_NR_nanosleep { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 16/49 linux-user: Split out exit
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall-proc.inc.c | 61 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 38 +--------------------- 3 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 linux-user/syscall-proc.inc.c
linux-user/syscall-defs.h +1 -0
@@ -17,6 +17,7 @@*/ SYSCALL_DEF (close,ARG_DEC ); +SYSCALL_DEF (exit,ARG_DEC );#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif
linux-user/syscall-proc.inc.c new file +61 -0
61 lines not on this page · raw message
linux-user/syscall.c +1 -37
@@ -5626,43 +5626,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_exit: -/* In old applications this may be used to implement _exit(2). -However in threaded applictions it is used for thread termination, -and _exit_group is used for application termination. -Do thread termination if we have more then one thread. */ - -if (block_signals ()) { -return -TARGET_ERESTARTSYS ; - } - -cpu_list_lock (); - -if (CPU_NEXT (first_cpu)) { -TaskState *ts; - -/* Remove the CPU from the list. */ -QTAILQ_REMOVE_RCU (&cpus, cpu, node); - -cpu_list_unlock (); - - ts = cpu->opaque; -if (ts->child_tidptr) { -put_user_u32 (0 , ts->child_tidptr); -sys_futex (g2h (ts->child_tidptr),FUTEX_WAKE ,INT_MAX , -NULL ,NULL ,0 ); - } - thread_cpu =NULL ; -object_unref (OBJECT (cpu)); -g_free (ts); -rcu_unregister_thread (); -pthread_exit (NULL ); - } - -cpu_list_unlock (); -preexit_cleanup (cpu_env, arg1); -_exit (arg1); -return 0 ;/* avoid warning */ case TARGET_NR_brk:return do_brk (arg1);#ifdef TARGET_NR_fork
@@ -9884,6 +9847,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#include "syscall-file.inc.c" #include "syscall-ipc.inc.c" #include "syscall-mem.inc.c" +#include "syscall-proc.inc.c" #undef SYSCALL_IMPL#undef SYSCALL_ARGS
Signature · 1 line
2.17.2
PATCH v6 17/49 linux-user: Split out brk
In reply to Richard Henderson--- linux-user/syscall-defs.h | 3 ++ linux-user/strace.c | 35 -------------- linux-user/syscall-mem.inc.c | 90 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 93 ------------------------------------ linux-user/strace.list | 3 -- 5 files changed, 93 insertions(+), 131 deletions(-)
linux-user/syscall-defs.h +3 -0
@@ -16,6 +16,9 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +SYSCALL_DEF_FULL(brk, .impl = impl_brk, + .print_ret = print_syscall_ptr_ret, + .arg_type = { ARG_PTR });SYSCALL_DEF (close,ARG_DEC );SYSCALL_DEF (exit,ARG_DEC );#ifdef TARGET_NR_ipc
linux-user/strace.c +0 -35
@@ -604,29 +604,6 @@ print_execve(const struct syscallname *name,* Variants for the return value output function */ -static void -print_syscall_ret_addr (const struct syscallname *name,abi_long ret) -{ -const char *errstr =NULL ; - -if (ret <0 ) { - errstr =target_strerror (-ret); - } -if (errstr) { -gemu_log (" = -1 errno=%d (%s)\n" , (int )-ret, errstr); - }else { -gemu_log (" = 0x" TARGET_ABI_FMT_lx"\n" , ret); - } -} - -#if 0 /* currently unused */ -static void -print_syscall_ret_raw (struct syscallname *name,abi_long ret) -{ -gemu_log (" = 0x" TARGET_ABI_FMT_lx"\n" , ret); -} -#endif -#ifdef TARGET_NR__newselectstatic void print_syscall_ret_newselect (const struct syscallname *name,abi_long ret)
@@ -1168,18 +1145,6 @@ print_access(const struct syscallname *name, }#endif -#ifdef TARGET_NR_brk -static void -print_brk (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_pointer (arg0,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_chdir static void print_chdir(const struct syscallname *name,
linux-user/syscall-mem.inc.c +90 -0
96 lines not on this page · raw message
linux-user/syscall.c +0 -93
105 lines not on this page · raw message
linux-user/strace.list +0 -3
@@ -49,9 +49,6 @@ #ifdef TARGET_NR_break { TARGET_NR_break, "break" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_brk -{ TARGET_NR_brk, "brk" , NULL, print_brk, print_syscall_ret_addr }, -#endif #ifdef TARGET_NR_cachectl { TARGET_NR_cachectl, "cachectl" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 18/49 linux-user: Split out clone, fork, vfork
In reply to Richard HendersonRename do_fork to do_clone, since that is what it does.
--- linux-user/syscall-defs.h | 8 ++ linux-user/syscall.h | 1 + linux-user/strace.c | 36 +---- linux-user/syscall-proc.inc.c | 259 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 218 ---------------------------- linux-user/strace.list | 9 -- 6 files changed, 272 insertions(+), 259 deletions(-)
linux-user/syscall-defs.h +8 -0
@@ -19,8 +19,12 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk, .print_ret = print_syscall_ptr_ret, .arg_type = { ARG_PTR }); +SYSCALL_DEF_ARGS (clone,ARG_CLONEFLAG ,ARG_PTR ,ARG_PTR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (close,ARG_DEC );SYSCALL_DEF (exit,ARG_DEC ); +#ifdef TARGET_NR_fork +SYSCALL_DEF (fork); +#endif #ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif
@@ -110,5 +114,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmget)SYSCALL_DEF (shmget,ARG_DEC ,ARG_DEC ,ARG_HEX );#endif +#ifdef TARGET_NR_vfork +/* Emulate vfork() with fork(). */ +SYSCALL_DEF_FULL(vfork, .impl = impl_fork); +#endif SYSCALL_DEF (write,ARG_DEC ,ARG_PTR ,ARG_DEC );SYSCALL_DEF (writev,ARG_DEC ,ARG_PTR ,ARG_DEC );
linux-user/syscall.h +1 -0
@@ -58,6 +58,7 @@ typedef enum {/* These print as sets of flags. */ ARG_ATDIRFD ,ARG_ATFLAG , +ARG_CLONEFLAG ,ARG_MMAPFLAG ,ARG_MMAPPROT , ARG_MODEFLAG,
linux-user/strace.c +4 -32
@@ -813,7 +813,7 @@ static struct flags const mmap_flags[] = { FLAG_END, }; -UNUSED static struct flags clone_flags[] = { +static struct flags const clone_flags[] = {FLAG_GENERIC (CLONE_VM ),FLAG_GENERIC (CLONE_FS ),FLAG_GENERIC (CLONE_FILES ),
@@ -1183,37 +1183,6 @@ print_clock_adjtime(const struct syscallname *name, }#endif -#ifdef TARGET_NR_clone -static void do_print_clone (unsigned int flags,abi_ulong newsp, -abi_ulong parent_tidptr,target_ulong newtls, -abi_ulong child_tidptr) -{ -print_flags (clone_flags, flags,0 ); -print_raw_param ("child_stack=0x" TARGET_ABI_FMT_lx, newsp,0 ); -print_raw_param ("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr,0 ); -print_raw_param ("tls=0x" TARGET_ABI_FMT_lx, newtls,0 ); -print_raw_param ("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr,1 ); -} - -static void -print_clone (const struct syscallname *name, -abi_long arg1,abi_long arg2,abi_long arg3, -abi_long arg4,abi_long arg5,abi_long arg6) -{ -print_syscall_prologue (name); -#if defined(TARGET_MICROBLAZE ) -do_print_clone (arg1, arg2, arg4, arg6, arg5); -#elif defined(TARGET_CLONE_BACKWARDS ) -do_print_clone (arg1, arg2, arg3, arg4, arg5); -#elif defined(TARGET_CLONE_BACKWARDS2 ) -do_print_clone (arg2, arg1, arg3, arg5, arg4); -#else -do_print_clone (arg1, arg2, arg3, arg5, arg4); -#endif -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_creat static void print_creat(const struct syscallname *name,
@@ -2521,6 +2490,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_ATFLAG : len =add_flags (b, rest, at_file_flags, arg, false);break ; +case ARG_CLONEFLAG : + len =add_flags (b, rest, clone_flags, arg, false); +break ;case ARG_MMAPFLAG : len =add_flags (b, rest, mmap_flags, arg, false);break ;
linux-user/syscall-proc.inc.c +259 -0
268 lines not on this page · raw message
linux-user/syscall.c +0 -218
248 lines not on this page · raw message
linux-user/strace.list +0 -9
@@ -91,9 +91,6 @@ #ifdef TARGET_NR_clock_settime { TARGET_NR_clock_settime, "clock_settime" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_clone -{ TARGET_NR_clone, "clone" , NULL, print_clone, NULL }, -#endif #ifdef TARGET_NR_connect { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL }, #endif
@@ -220,9 +217,6 @@ #ifdef TARGET_NR_flock { TARGET_NR_flock, "flock" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_fork -{ TARGET_NR_fork, "fork" , "%s()", NULL, NULL }, -#endif #ifdef TARGET_NR_fremovexattr { TARGET_NR_fremovexattr, "fremovexattr" , NULL, NULL, NULL }, #endif
@@ -1485,9 +1479,6 @@ #ifdef TARGET_NR_utrap_install { TARGET_NR_utrap_install, "utrap_install" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_vfork -{ TARGET_NR_vfork, "vfork" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_vhangup { TARGET_NR_vhangup, "vhangup" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 19/49 linux-user: Split out wait4, waitid, waitpid
In reply to Richard HendersonNote that waitid is universally provided and need not be conditional.
--- linux-user/syscall-defs.h | 5 ++ linux-user/syscall-proc.inc.c | 88 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 67 -------------------------- linux-user/strace.list | 9 ---- 4 files changed, 93 insertions(+), 76 deletions(-)
linux-user/syscall-defs.h +5 -0
@@ -118,5 +118,10 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);/* Emulate vfork() with fork(). */ SYSCALL_DEF_FULL(vfork, .impl = impl_fork);#endif +SYSCALL_DEF (wait4,ARG_DEC ,ARG_PTR ,ARG_HEX ,ARG_PTR ); +SYSCALL_DEF (waitid,ARG_HEX ,ARG_DEC ,ARG_PTR ,ARG_HEX ); +#ifdef TARGET_NR_waitpid +SYSCALL_DEF (waitpid,ARG_DEC ,ARG_PTR ,ARG_HEX ); +#endif SYSCALL_DEF (write,ARG_DEC ,ARG_PTR ,ARG_DEC );SYSCALL_DEF (writev,ARG_DEC ,ARG_PTR ,ARG_DEC );
linux-user/syscall-proc.inc.c +88 -0
91 lines not on this page · raw message
linux-user/syscall.c +0 -67
85 lines not on this page · raw message
linux-user/strace.list +0 -9
@@ -1494,15 +1494,6 @@ #ifdef TARGET_NR_vserver { TARGET_NR_vserver, "vserver" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_wait4 -{ TARGET_NR_wait4, "wait4" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_waitid -{ TARGET_NR_waitid, "waitid" , "%s(%#x,%d,%p,%#x)", NULL, NULL }, -#endif -#ifdef TARGET_NR_waitpid -{ TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, -#endif #ifdef TARGET_NR_utimensat { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 20/49 linux-user: Implement rusage argument to waitid
In reply to Richard HendersonThe kernel interface, which we are supposed to be implementing, takes a fifth argument: an rusage pointer akin to wait4.
--- linux-user/syscall-defs.h | 2 +- linux-user/syscall-proc.inc.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-)
linux-user/syscall-defs.h +1 -1
@@ -119,7 +119,7 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX); SYSCALL_DEF_FULL(vfork, .impl = impl_fork);#endif SYSCALL_DEF (wait4,ARG_DEC ,ARG_PTR ,ARG_HEX ,ARG_PTR ); -SYSCALL_DEF (waitid,ARG_HEX ,ARG_DEC ,ARG_PTR ,ARG_HEX ); +SYSCALL_DEF (waitid,ARG_HEX ,ARG_DEC ,ARG_PTR ,ARG_HEX ,ARG_PTR );#ifdef TARGET_NR_waitpidSYSCALL_DEF (waitpid,ARG_DEC ,ARG_PTR ,ARG_HEX );#endif
linux-user/syscall-proc.inc.c +19 -8
@@ -370,19 +370,30 @@ SYSCALL_IMPL(waitid)id_t id = arg2;abi_ulong target_info = arg3;int options = arg4; +abi_ulong target_rusage = arg5;siginfo_t info, *info_ptr = target_info ? &info :NULL ; +struct rusage rusage; +struct rusage *rusage_ptr = target_rusage ? &rusage :NULL ;abi_long ret; info.si_pid =0 ; - ret =get_errno (safe_waitid (idtype, id, info_ptr, options,NULL )); -if (!is_error (ret) && target_info && info.si_pid !=0 ) { -target_siginfo_t *p =lock_user (VERIFY_WRITE , target_info, -sizeof (target_siginfo_t),0 ); -if (!p) { -return -TARGET_EFAULT ; + ret =get_errno (safe_waitid (idtype, id, info_ptr, options, rusage_ptr)); +if (!is_error (ret)) { +if (target_info && info.si_pid !=0 ) { +target_siginfo_t *p =lock_user (VERIFY_WRITE , target_info, +sizeof (target_siginfo_t),0 ); +if (!p) { +return -TARGET_EFAULT ; + } +host_to_target_siginfo (p, &info); +unlock_user (p, target_info,sizeof (target_siginfo_t)); + } +if (target_rusage) { +abi_long err =host_to_target_rusage (target_rusage, &rusage); +if (err) { + ret = err; + } } -host_to_target_siginfo (p, &info); -unlock_user (p, target_info,sizeof (target_siginfo_t)); }return ret; }
Signature · 1 line
2.17.2
PATCH v6 21/49 linux-user: Split out creat
In reply to Richard Henderson--- linux-user/syscall-defs.h | 3 +++ linux-user/strace.c | 13 ------------- linux-user/syscall-file.inc.c | 16 ++++++++++++++++ linux-user/syscall.c | 9 --------- linux-user/strace.list | 3 --- 5 files changed, 19 insertions(+), 25 deletions(-)
linux-user/syscall-defs.h +3 -0
@@ -21,6 +21,9 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk, .arg_type = { ARG_PTR });SYSCALL_DEF_ARGS (clone,ARG_CLONEFLAG ,ARG_PTR ,ARG_PTR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (close,ARG_DEC ); +#ifdef TARGET_NR_creat +SYSCALL_DEF (creat,ARG_STR ,ARG_MODEFLAG ); +#endif SYSCALL_DEF (exit,ARG_DEC );#ifdef TARGET_NR_forkSYSCALL_DEF (fork);
linux-user/strace.c +0 -13
@@ -1183,19 +1183,6 @@ print_clock_adjtime(const struct syscallname *name, }#endif -#ifdef TARGET_NR_creat -static void -print_creat (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_file_mode (arg1,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_execv static void print_execv(const struct syscallname *name,
linux-user/syscall-file.inc.c +16 -0
@@ -24,6 +24,22 @@ SYSCALL_IMPL(close)return get_errno (close (fd)); } +#ifdef TARGET_NR_creat +SYSCALL_IMPL (creat) +{ +char *p =lock_user_string (arg1); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (creat (p, arg2)); +fd_trans_unregister (ret); +unlock_user (p, arg1,0 ); +return ret; +} +#endif +/* * Helpers for do_openat, manipulating /proc/self/foo. */
linux-user/syscall.c +0 -9
@@ -5330,15 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_creat/* not on alpha */ -case TARGET_NR_creat: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (creat (p, arg2)); -fd_trans_unregister (ret); -unlock_user (p, arg1,0 ); -return ret; -#endif #ifdef TARGET_NR_linkcase TARGET_NR_link: {
linux-user/strace.list +0 -3
@@ -94,9 +94,6 @@ #ifdef TARGET_NR_connect { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL }, #endif -#ifdef TARGET_NR_creat -{ TARGET_NR_creat, "creat" , NULL, print_creat, NULL }, -#endif #ifdef TARGET_NR_create_module { TARGET_NR_create_module, "create_module" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 22/49 linux-user: Split out link, linkat
In reply to Richard HendersonNote that linkat is universally provided.
--- linux-user/syscall-defs.h | 4 ++++ linux-user/strace.c | 29 ----------------------------- linux-user/syscall-file.inc.c | 28 ++++++++++++++++++++++++++++ linux-user/syscall.c | 32 -------------------------------- linux-user/strace.list | 6 ------ 5 files changed, 32 insertions(+), 67 deletions(-)
linux-user/syscall-defs.h +4 -0
@@ -31,6 +31,10 @@ SYSCALL_DEF(fork);#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif +#ifdef TARGET_NR_link +SYSCALL_DEF (link,ARG_STR ,ARG_STR ); +#endif +SYSCALL_DEF (linkat,ARG_ATDIRFD ,ARG_STR ,ARG_ATDIRFD ,ARG_STR ,ARG_ATFLAG );SYSCALL_DEF (mlock,ARG_PTR ,ARG_DEC );SYSCALL_DEF (mlockall,ARG_HEX );#ifdef TARGET_NR_mmap
linux-user/strace.c +0 -29
@@ -1357,35 +1357,6 @@ print_futimesat(const struct syscallname *name, }#endif -#ifdef TARGET_NR_link -static void -print_link (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_string (arg1,1 ); -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_linkat -static void -print_linkat (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_at_dirfd (arg2,0 ); -print_string (arg3,0 ); -print_flags (at_file_flags, arg4,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR__llseek static void print__llseek(const struct syscallname *name,
linux-user/syscall-file.inc.c +28 -0
@@ -40,6 +40,34 @@ SYSCALL_IMPL(creat) }#endif +static abi_long do_linkat (int olddirfd,abi_ulong target_oldpath, +int newdirfd,abi_ulong target_newpath, +int flags) +{ +char *oldpath =lock_user_string (target_oldpath); +char *newpath =lock_user_string (target_newpath); +abi_long ret = -TARGET_EFAULT ; + +if (oldpath && newpath) { + ret =get_errno (linkat (olddirfd, oldpath, newdirfd, newpath, flags)); + } +unlock_user (oldpath, target_oldpath,0 ); +unlock_user (newpath, target_newpath,0 ); +return ret; +} + +#ifdef TARGET_NR_link +SYSCALL_IMPL (link) +{ +return do_linkat (AT_FDCWD , arg1,AT_FDCWD , arg2,0 ); +} +#endif + +SYSCALL_IMPL (linkat) +{ +return do_linkat (arg1, arg2, arg3, arg4, arg5); +} +/* * Helpers for do_openat, manipulating /proc/self/foo. */
linux-user/syscall.c +0 -32
@@ -5330,38 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_link -case TARGET_NR_link: - { -void * p2; - p =lock_user_string (arg1); - p2 =lock_user_string (arg2); -if (!p || !p2) - ret = -TARGET_EFAULT ; -else - ret =get_errno (link (p, p2)); -unlock_user (p2, arg2,0 ); -unlock_user (p, arg1,0 ); - } -return ret; -#endif -#if defined(TARGET_NR_linkat) -case TARGET_NR_linkat: - { -void * p2 =NULL ; -if (!arg2 || !arg4) -return -TARGET_EFAULT ; - p =lock_user_string (arg2); - p2 =lock_user_string (arg4); -if (!p || !p2) - ret = -TARGET_EFAULT ; -else - ret =get_errno (linkat (arg1, p, arg3, p2, arg5)); -unlock_user (p, arg2,0 ); -unlock_user (p2, arg4,0 ); - } -return ret; -#endif #ifdef TARGET_NR_unlinkcase TARGET_NR_unlink:if (!(p =lock_user_string (arg1)))
linux-user/strace.list +0 -6
@@ -461,12 +461,6 @@ #ifdef TARGET_NR_lgetxattr { TARGET_NR_lgetxattr, "lgetxattr" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_link -{ TARGET_NR_link, "link" , NULL, print_link, NULL }, -#endif -#ifdef TARGET_NR_linkat -{ TARGET_NR_linkat, "linkat" , NULL, print_linkat, NULL }, -#endif #ifdef TARGET_NR_Linux { TARGET_NR_Linux, "Linux" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 23/49 linux-user: Split out unlink, unlinkat, rmdir
In reply to Richard HendersonNote that unlinkat is universally provided.
Implement rmdir in terms of unlinkat.
--- linux-user/syscall-defs.h | 7 ++++++ linux-user/syscall.h | 1 + linux-user/strace.c | 43 ++++------------------------------- linux-user/syscall-file.inc.c | 32 ++++++++++++++++++++++++++ linux-user/syscall.c | 24 ------------------- linux-user/strace.list | 9 -------- 6 files changed, 44 insertions(+), 72 deletions(-)
linux-user/syscall-defs.h +7 -0
@@ -98,6 +98,9 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);SYSCALL_DEF (readlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_DEC );#endif SYSCALL_DEF (readv,ARG_DEC ,ARG_PTR ,ARG_DEC ); +#ifdef TARGET_NR_rmdir +SYSCALL_DEF (rmdir,ARG_STR ); +#endif #if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_semctl)SYSCALL_DEF (semctl,ARG_DEC ,ARG_DEC ,ARG_DEC ,ARG_HEX );#endif
@@ -121,6 +124,10 @@ SYSCALL_DEF(shmdt, ARG_PTR);#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmget)SYSCALL_DEF (shmget,ARG_DEC ,ARG_DEC ,ARG_HEX );#endif +#ifdef TARGET_NR_unlink +SYSCALL_DEF (unlink,ARG_STR ); +#endif +SYSCALL_DEF (unlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_UNLINKATFLAG );#ifdef TARGET_NR_vfork/* Emulate vfork() with fork(). */ SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
linux-user/syscall.h +1 -0
@@ -63,6 +63,7 @@ typedef enum {ARG_MMAPPROT ,ARG_MODEFLAG ,ARG_OPENFLAG , +ARG_UNLINKATFLAG ,/* These are interpreted as pointers. */ ARG_PTR,
linux-user/strace.c +4 -39
67 lines not on this page · raw message
linux-user/syscall-file.inc.c +32 -0
@@ -656,6 +656,38 @@ SYSCALL_IMPL(readlinkat) }#endif +static abi_long do_unlinkat (int dirfd,abi_ulong target_path,int flags) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (unlinkat (dirfd, p, flags)); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_unlink +SYSCALL_IMPL (unlink) +{ +return do_unlinkat (AT_FDCWD , arg1,0 ); +} +#endif + +#ifdef TARGET_NR_rmdir +SYSCALL_IMPL (rmdir) +{ +return do_unlinkat (AT_FDCWD , arg1,AT_REMOVEDIR ); +} +#endif + +SYSCALL_IMPL (unlinkat) +{ +return do_unlinkat (arg1, arg2, arg3); +} +SYSCALL_IMPL (write) {int fd = arg1;
linux-user/syscall.c +0 -24
@@ -5330,22 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_unlink -case TARGET_NR_unlink: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (unlink (p)); -unlock_user (p, arg1,0 ); -return ret; -#endif -#if defined(TARGET_NR_unlinkat) -case TARGET_NR_unlinkat: -if (!(p =lock_user_string (arg2))) -return -TARGET_EFAULT ; - ret =get_errno (unlinkat (arg1, p, arg3)); -unlock_user (p, arg2,0 ); -return ret; -#endif case TARGET_NR_execve: {char **argp, **envp;
@@ -5737,14 +5721,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, ret =get_errno (mkdirat (arg1, p, arg3));unlock_user (p, arg2,0 );return ret; -#endif -#ifdef TARGET_NR_rmdir -case TARGET_NR_rmdir: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (rmdir (p)); -unlock_user (p, arg1,0 ); -return ret;#endif case TARGET_NR_dup: ret =get_errno (dup (arg1));
linux-user/strace.list +0 -9
@@ -527,9 +527,6 @@ #ifdef TARGET_NR_mkdirat { TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL }, #endif -#ifdef TARGET_NR_rmdir -{ TARGET_NR_rmdir, "rmdir" , NULL, print_rmdir, NULL }, -#endif #ifdef TARGET_NR_mknod { TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL }, #endif
@@ -1425,12 +1422,6 @@ #ifdef TARGET_NR_uname { TARGET_NR_uname, "uname" , "%s(%p)", NULL, NULL }, #endif -#ifdef TARGET_NR_unlink -{ TARGET_NR_unlink, "unlink" , NULL, print_unlink, NULL }, -#endif -#ifdef TARGET_NR_unlinkat -{ TARGET_NR_unlinkat, "unlinkat" , NULL, print_unlinkat, NULL }, -#endif #ifdef TARGET_NR_unshare { TARGET_NR_unshare, "unshare" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 24/49 linux-user: Split out execve
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/strace.c | 32 ---------- linux-user/syscall-proc.inc.c | 110 ++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 97 ------------------------------ linux-user/strace.list | 3 - 5 files changed, 111 insertions(+), 132 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -25,6 +25,7 @@ SYSCALL_DEF(close, ARG_DEC);SYSCALL_DEF (creat,ARG_STR ,ARG_MODEFLAG );#endif SYSCALL_DEF (exit,ARG_DEC ); +SYSCALL_DEF (execve,ARG_STR ,ARG_PTR ,ARG_PTR );#ifdef TARGET_NR_forkSYSCALL_DEF (fork);#endif
linux-user/strace.c +0 -32
@@ -568,38 +568,6 @@ print_newselect(const struct syscallname *name, }#endif -static void -print_execve (const struct syscallname *name, -abi_long arg1,abi_long arg2,abi_long arg3, -abi_long arg4,abi_long arg5,abi_long arg6) -{ -abi_ulong arg_ptr_addr; -char *s; - -if (!(s =lock_user_string (arg1))) -return ; -gemu_log ("%s(\"%s\",{" , name->name, s); -unlock_user (s, arg1,0 ); - -for (arg_ptr_addr = arg2; ; arg_ptr_addr +=sizeof (abi_ulong)) { -abi_ulong *arg_ptr, arg_addr; - - arg_ptr =lock_user (VERIFY_READ , arg_ptr_addr,sizeof (abi_ulong),1 ); -if (!arg_ptr) -return ; - arg_addr =tswapal (*arg_ptr); -unlock_user (arg_ptr, arg_ptr_addr,0 ); -if (!arg_addr) -break ; -if ((s =lock_user_string (arg_addr))) { -gemu_log ("\"%s\"," , s); -unlock_user (s, arg_addr,0 ); - } - } - -gemu_log ("NULL})" ); -} -/* * Variants for the return value output function */
linux-user/syscall-proc.inc.c +110 -0
116 lines not on this page · raw message
linux-user/syscall.c +0 -97
103 lines not on this page · raw message
linux-user/strace.list +0 -3
@@ -139,9 +139,6 @@ #ifdef TARGET_NR_execv { TARGET_NR_execv, "execv" , NULL, print_execv, NULL }, #endif -#ifdef TARGET_NR_execve -{ TARGET_NR_execve, "execve" , NULL, print_execve, NULL }, -#endif #ifdef TARGET_NR_execveat { TARGET_NR_execveat, "execveat" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 25/49 linux-user: Implement execveat
In reply to Richard HendersonA trivial extension to our current execve implementation to support the new(ish) syscall.
--- linux-user/syscall-defs.h | 1 + linux-user/syscall-proc.inc.c | 19 ++++++++++++++----- linux-user/syscall.c | 3 ++- linux-user/strace.list | 3 --- 4 files changed, 17 insertions(+), 9 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -26,6 +26,7 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);#endif SYSCALL_DEF (exit,ARG_DEC );SYSCALL_DEF (execve,ARG_STR ,ARG_PTR ,ARG_PTR ); +SYSCALL_DEF (execveat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );#ifdef TARGET_NR_forkSYSCALL_DEF (fork);#endif
linux-user/syscall-proc.inc.c +14 -5
@@ -269,14 +269,13 @@ SYSCALL_IMPL(clone)return do_clone (cpu_env, arg1, arg2, arg3, arg4, arg5); } -SYSCALL_IMPL (execve) +static abi_long do_execveat (int dirfd,abi_ulong guest_path, +abi_ulong guest_argp,abi_ulong guest_envp, +int flags) {char **argp, **envp;int argc, envc;abi_ulong gp; -abi_ulong guest_path = arg1; -abi_ulong guest_argp = arg2; -abi_ulong guest_envp = arg3;abi_ulong addr;char **q, *p;int total_size =0 ;
@@ -356,7 +355,7 @@ SYSCALL_IMPL(execve)* before the execve completes and makes it the other * program's problem. */ - ret =get_errno (safe_execve (p, argp, envp)); + ret =get_errno (safe_execveat (dirfd, p, argp, envp, flags));unlock_user (p, guest_path,0 ); execve_free:
@@ -379,6 +378,16 @@ SYSCALL_IMPL(execve)return ret; } +SYSCALL_IMPL (execve) +{ +return do_execveat (AT_FDCWD , arg1, arg2, arg3,0 ); +} + +SYSCALL_IMPL (execveat) +{ +return do_execveat (arg1, arg2, arg3, arg4, arg5); +} +SYSCALL_IMPL (exit) {CPUState *cpu =ENV_GET_CPU (cpu_env);
linux-user/syscall.c +2 -1
@@ -682,7 +682,8 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ struct rusage *, rusage) safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ int, options, struct rusage *, rusage) -safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) +safe_syscall5(int, execveat, int, dirfd, const char *, filename, + char **, argv, char **, envp, int, flags) safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ fd_set *, exceptfds, struct timespec *, timeout, void *, sig) safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds,
linux-user/strace.list +0 -3
@@ -139,9 +139,6 @@ #ifdef TARGET_NR_execv { TARGET_NR_execv, "execv" , NULL, print_execv, NULL }, #endif -#ifdef TARGET_NR_execveat -{ TARGET_NR_execveat, "execveat" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_exec_with_loader { TARGET_NR_exec_with_loader, "exec_with_loader" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 26/49 linux-user: Split out chdir
In reply to Richard HendersonNote that chdir is universally provided.
--- linux-user/syscall-defs.h | 1 + linux-user/strace.c | 12 ------------ linux-user/syscall-file.inc.c | 14 ++++++++++++++ linux-user/syscall.c | 6 ------ linux-user/strace.list | 3 --- 5 files changed, 15 insertions(+), 21 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -19,6 +19,7 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk, .print_ret = print_syscall_ptr_ret, .arg_type = { ARG_PTR }); +SYSCALL_DEF (chdir,ARG_STR );SYSCALL_DEF_ARGS (clone,ARG_CLONEFLAG ,ARG_PTR ,ARG_PTR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (close,ARG_DEC );#ifdef TARGET_NR_creat
linux-user/strace.c +0 -12
@@ -1113,18 +1113,6 @@ print_access(const struct syscallname *name, }#endif -#ifdef TARGET_NR_chdir -static void -print_chdir (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,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_chmod static void print_chmod(const struct syscallname *name,
linux-user/syscall-file.inc.c +14 -0
@@ -16,6 +16,20 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +SYSCALL_IMPL (chdir) +{ +abi_ulong target_path = arg1; +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (chdir (p)); +unlock_user (p, target_path,0 ); +return ret; +} +SYSCALL_IMPL (close) {int fd = arg1;
linux-user/syscall.c +0 -6
@@ -5331,12 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_chdir: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (chdir (p)); -unlock_user (p, arg1,0 ); -return ret;#ifdef TARGET_NR_timecase TARGET_NR_time: {
linux-user/strace.list +0 -3
@@ -61,9 +61,6 @@ #ifdef TARGET_NR_capset { TARGET_NR_capset, "capset" , "%s(%p,%p)", NULL, NULL }, #endif -#ifdef TARGET_NR_chdir -{ TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL }, -#endif #ifdef TARGET_NR_chmod { TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 27/49 linux-user: Split out time
In reply to Richard Henderson--- linux-user/syscall-defs.h | 3 +++ linux-user/syscall-time.inc.c | 32 ++++++++++++++++++++++++++++++++ linux-user/syscall.c | 13 +------------ linux-user/strace.list | 3 --- 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 linux-user/syscall-time.inc.c
linux-user/syscall-defs.h +3 -0
@@ -127,6 +127,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmget)SYSCALL_DEF (shmget,ARG_DEC ,ARG_DEC ,ARG_HEX );#endif +#ifdef TARGET_NR_time +SYSCALL_DEF (time,ARG_PTR ); +#endif #ifdef TARGET_NR_unlinkSYSCALL_DEF (unlink,ARG_STR );#endif
linux-user/syscall-time.inc.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Linux time related syscalls +* Copyright (c) 2003 Fabrice Bellard +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifdef TARGET_NR_time +SYSCALL_IMPL (time) +{ +time_t host_time; +abi_long ret =get_errno (time (&host_time)); + +if (!is_error (ret) + && arg1 + &&put_user_sal (host_time, arg1)) { +return -TARGET_EFAULT ; + } +return ret; +} +#endif
linux-user/syscall.c +1 -12
@@ -5331,18 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_time -case TARGET_NR_time: - { -time_t host_time; - ret =get_errno (time (&host_time)); -if (!is_error (ret) - && arg1 - &&put_user_sal (host_time, arg1)) -return -TARGET_EFAULT ; - } -return ret; -#endif #ifdef TARGET_NR_mknodcase TARGET_NR_mknod:if (!(p =lock_user_string (arg1)))
@@ -9303,6 +9291,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#include "syscall-ipc.inc.c" #include "syscall-mem.inc.c" #include "syscall-proc.inc.c" +#include "syscall-time.inc.c" #undef SYSCALL_IMPL#undef SYSCALL_ARGS
linux-user/strace.list +0 -3
@@ -1350,9 +1350,6 @@ #ifdef TARGET_NR_tgkill { TARGET_NR_tgkill, "tgkill" , NULL, print_tgkill, NULL }, #endif -#ifdef TARGET_NR_time -{ TARGET_NR_time, "time" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_timer_create { TARGET_NR_timer_create, "timer_create" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 28/49 linux-user: Split out mknod, mknodat
In reply to Richard HendersonNote that mknodat is universally provided.
--- linux-user/syscall-defs.h | 4 ++++ linux-user/strace.c | 39 ----------------------------------- linux-user/syscall-file.inc.c | 26 +++++++++++++++++++++++ linux-user/syscall.c | 16 -------------- linux-user/strace.list | 6 ------ 5 files changed, 30 insertions(+), 61 deletions(-)
linux-user/syscall-defs.h +4 -0
@@ -38,6 +38,10 @@ 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_mknod +SYSCALL_DEF (mknod,ARG_STR ,ARG_MODEFLAG ,ARG_HEX ); +#endif +SYSCALL_DEF (mknodat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG ,ARG_HEX );SYSCALL_DEF (mlock,ARG_PTR ,ARG_DEC );SYSCALL_DEF (mlockall,ARG_HEX );#ifdef TARGET_NR_mmap
linux-user/strace.c +0 -39
@@ -1911,45 +1911,6 @@ print_syslog(const struct syscallname *name, }#endif -#ifdef TARGET_NR_mknod -static void -print_mknod (const struct syscallname *name, -abi_long arg0,abi_long arg1,abi_long arg2, -abi_long arg3,abi_long arg4,abi_long arg5) -{ -int hasdev = (arg1 & (S_IFCHR |S_IFBLK )); - -print_syscall_prologue (name); -print_string (arg0,0 ); -print_file_mode (arg1, (hasdev ==0 )); -if (hasdev) { -print_raw_param ("makedev(%d" ,major (arg2),0 ); -print_raw_param ("%d)" ,minor (arg2),1 ); - } -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_mknodat -static void -print_mknodat (const struct syscallname *name, -abi_long arg0,abi_long arg1,abi_long arg2, -abi_long arg3,abi_long arg4,abi_long arg5) -{ -int hasdev = (arg2 & (S_IFCHR |S_IFBLK )); - -print_syscall_prologue (name); -print_at_dirfd (arg0,0 ); -print_string (arg1,0 ); -print_file_mode (arg2, (hasdev ==0 )); -if (hasdev) { -print_raw_param ("makedev(%d" ,major (arg3),0 ); -print_raw_param ("%d)" ,minor (arg3),1 ); - } -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_mq_open static void print_mq_open(const struct syscallname *name,
linux-user/syscall-file.inc.c +26 -0
@@ -82,6 +82,32 @@ SYSCALL_IMPL(linkat)return do_linkat (arg1, arg2, arg3, arg4, arg5); } +static abi_long do_mknodat (int dirfd,abi_ulong target_path, +mode_t mode,dev_t dev) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (mknodat (dirfd, p, mode, dev)); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_mknod +SYSCALL_IMPL (mknod) +{ +return do_mknodat (AT_FDCWD , arg1, arg2, arg3); +} +#endif + +SYSCALL_IMPL (mknodat) +{ +return do_mknodat (arg1, arg2, arg3, arg4); +} +/* * Helpers for do_openat, manipulating /proc/self/foo. */
linux-user/syscall.c +0 -16
@@ -5331,22 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_mknod -case TARGET_NR_mknod: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (mknod (p, arg2, arg3)); -unlock_user (p, arg1,0 ); -return ret; -#endif -#if defined(TARGET_NR_mknodat) -case TARGET_NR_mknodat: -if (!(p =lock_user_string (arg2))) -return -TARGET_EFAULT ; - ret =get_errno (mknodat (arg1, p, arg3, arg4)); -unlock_user (p, arg2,0 ); -return ret; -#endif #ifdef TARGET_NR_chmodcase TARGET_NR_chmod:if (!(p =lock_user_string (arg1)))
linux-user/strace.list +0 -6
@@ -518,12 +518,6 @@ #ifdef TARGET_NR_mkdirat { TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL }, #endif -#ifdef TARGET_NR_mknod -{ TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL }, -#endif -#ifdef TARGET_NR_mknodat -{ TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL }, -#endif #ifdef TARGET_NR_modify_ldt { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 29/49 linux-user: Split out chmod, fchmod, fchmodat
In reply to Richard HendersonNote that fchmodat is universally provided.
--- linux-user/syscall-defs.h | 5 +++++ linux-user/strace.c | 28 ---------------------------- linux-user/syscall-file.inc.c | 30 ++++++++++++++++++++++++++++++ linux-user/syscall.c | 18 ------------------ linux-user/strace.list | 9 --------- 5 files changed, 35 insertions(+), 55 deletions(-)
linux-user/syscall-defs.h +5 -0
@@ -20,6 +20,9 @@ SYSCALL_DEF_FULL(brk, .impl = impl_brk, .print_ret = print_syscall_ptr_ret, .arg_type = { ARG_PTR });SYSCALL_DEF (chdir,ARG_STR ); +#ifdef TARGET_NR_chmod +SYSCALL_DEF (chmod,ARG_STR ,ARG_MODEFLAG ); +#endif SYSCALL_DEF_ARGS (clone,ARG_CLONEFLAG ,ARG_PTR ,ARG_PTR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (close,ARG_DEC );#ifdef TARGET_NR_creat
@@ -28,6 +31,8 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);SYSCALL_DEF (exit,ARG_DEC );SYSCALL_DEF (execve,ARG_STR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (execveat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG ); +SYSCALL_DEF (fchmod,ARG_DEC ,ARG_MODEFLAG ); +SYSCALL_DEF (fchmodat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG );#ifdef TARGET_NR_forkSYSCALL_DEF (fork);#endif
linux-user/strace.c +0 -28
@@ -1113,19 +1113,6 @@ print_access(const struct syscallname *name, }#endif -#ifdef TARGET_NR_chmod -static void -print_chmod (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_file_mode (arg1,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_clock_adjtime static void print_clock_adjtime(const struct syscallname *name,
@@ -1167,21 +1154,6 @@ print_faccessat(const struct syscallname *name, }#endif -#ifdef TARGET_NR_fchmodat -static void -print_fchmodat (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_file_mode (arg2,0 ); -print_flags (at_file_flags, arg3,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_fchownat static void print_fchownat(const struct syscallname *name,
linux-user/syscall-file.inc.c +30 -0
@@ -30,6 +30,26 @@ SYSCALL_IMPL(chdir)return ret; } +static abi_long do_fchmodat (int dirfd,abi_ulong target_path,mode_t mode) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (fchmodat (dirfd, p, mode,0 )); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_chmod +SYSCALL_IMPL (chmod) +{ +return do_fchmodat (AT_FDCWD , arg1, arg2); +} +#endif +SYSCALL_IMPL (close) {int fd = arg1;
@@ -54,6 +74,16 @@ SYSCALL_IMPL(creat) }#endif +SYSCALL_IMPL (fchmod) +{ +return get_errno (fchmod (arg1, arg2)); +} + +SYSCALL_IMPL (fchmodat) +{ +return do_fchmodat (arg1, arg2, arg3); +} +static abi_long do_linkat (int olddirfd,abi_ulong target_oldpath,int newdirfd,abi_ulong target_newpath,int flags)
linux-user/syscall.c +0 -18
@@ -5331,14 +5331,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_chmod -case TARGET_NR_chmod: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (chmod (p, arg2)); -unlock_user (p, arg1,0 ); -return ret; -#endif #ifdef TARGET_NR_lseekcase TARGET_NR_lseek:return get_errno (lseek (arg1, arg2, arg3));
@@ -6410,16 +6402,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_ftruncatecase TARGET_NR_ftruncate:return get_errno (ftruncate (arg1, arg2)); -#endif -case TARGET_NR_fchmod: -return get_errno (fchmod (arg1, arg2)); -#if defined(TARGET_NR_fchmodat) -case TARGET_NR_fchmodat: -if (!(p =lock_user_string (arg2))) -return -TARGET_EFAULT ; - ret =get_errno (fchmodat (arg1, p, arg3,0 )); -unlock_user (p, arg2,0 ); -return ret;#endif case TARGET_NR_getpriority:/* Note that negative values are valid for getpriority, so we must
linux-user/strace.list +0 -9
@@ -61,9 +61,6 @@ #ifdef TARGET_NR_capset { TARGET_NR_capset, "capset" , "%s(%p,%p)", NULL, NULL }, #endif -#ifdef TARGET_NR_chmod -{ TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL }, -#endif #ifdef TARGET_NR_chown { TARGET_NR_chown, "chown" , NULL, NULL, NULL }, #endif
@@ -169,12 +166,6 @@ #ifdef TARGET_NR_fchdir { TARGET_NR_fchdir, "fchdir" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_fchmod -{ TARGET_NR_fchmod, "fchmod" , "%s(%d,%#o)", NULL, NULL }, -#endif -#ifdef TARGET_NR_fchmodat -{ TARGET_NR_fchmodat, "fchmodat" , NULL, print_fchmodat, NULL }, -#endif #ifdef TARGET_NR_fchown { TARGET_NR_fchown, "fchown" , "%s(%d,%d,%d)", NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 30/49 linux-user: Split out lseek, llseek
In reply to Richard HendersonCanonicalise 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).
--- 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(-)
linux-user/syscall-defs.h +6 -0
@@ -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_mknodSYSCALL_DEF (mknod,ARG_STR ,ARG_MODEFLAG ,ARG_HEX );#endif
linux-user/syscall.h +1 -0
@@ -64,6 +64,7 @@ typedef enum {ARG_MODEFLAG ,ARG_OPENFLAG ,ARG_UNLINKATFLAG , +ARG_LSEEKWHENCE ,/* These are interpreted as pointers. */ ARG_PTR,
linux-user/strace.c +17 -22
@@ -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) {
@@ -1285,28 +1299,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,
@@ -2317,6 +2309,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 ;
linux-user/syscall-file.inc.c +36 -0
@@ -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) {
linux-user/syscall.c +2 -30
@@ -195,8 +195,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 #ifdef __NR_gettid
@@ -227,10 +227,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)
@@ -5331,10 +5327,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:
@@ -6833,26 +6825,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_getdentscase TARGET_NR_getdents:#ifdef EMULATE_GETDENTS_WITH_GETDENTS
linux-user/strace.list +0 -6
@@ -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
Signature · 1 line
2.17.2
PATCH v6 31/49 linux-user: Split out getpid, getppid, getxpid
In reply to Richard Henderson--- linux-user/syscall-defs.h | 9 +++++++++ linux-user/syscall-proc.inc.c | 23 +++++++++++++++++++++++ linux-user/syscall.c | 14 -------------- linux-user/strace.list | 9 --------- 4 files changed, 32 insertions(+), 23 deletions(-)
linux-user/syscall-defs.h +9 -0
@@ -36,6 +36,15 @@ SYSCALL_DEF(fchmodat, ARG_ATDIRFD, ARG_STR, ARG_MODEFLAG);#ifdef TARGET_NR_forkSYSCALL_DEF (fork);#endif +#ifdef TARGET_NR_getpid +SYSCALL_DEF (getpid); +#endif +#ifdef TARGET_NR_getppid +SYSCALL_DEF (getppid); +#endif +#ifdef TARGET_NR_getxpid +SYSCALL_DEF (getxpid); +#endif #ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif
linux-user/syscall-proc.inc.c +23 -0
@@ -438,6 +438,29 @@ SYSCALL_IMPL(fork) }#endif +#ifdef TARGET_NR_getpid +SYSCALL_IMPL (getpid) +{ +return getpid (); +} +#endif + +#ifdef TARGET_NR_getppid +SYSCALL_IMPL (getppid) +{ +return getppid (); +} +#endif + +#ifdef TARGET_NR_getxpid +SYSCALL_IMPL (getxpid) +{ +/* Alpha specific */ + cpu_env->ir[IR_A4 ] =getppid (); +return getpid (); +} +#endif +/* * Map host to target signal numbers for the wait family of syscalls. * Assume all other status bits are the same.
linux-user/syscall.c +0 -14
@@ -5327,16 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA ) -/* Alpha specific */ -case TARGET_NR_getxpid: - ((CPUAlphaState *)cpu_env)->ir[IR_A4 ] =getppid (); -return get_errno (getpid ()); -#endif -#ifdef TARGET_NR_getpid -case TARGET_NR_getpid: -return get_errno (getpid ()); -#endif case TARGET_NR_mount: {/* need to look at the data field */
@@ -5668,10 +5658,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; }#endif -#ifdef TARGET_NR_getppid/* not on alpha */ -case TARGET_NR_getppid: -return get_errno (getppid ()); -#endif #ifdef TARGET_NR_getpgrpcase TARGET_NR_getpgrp:return get_errno (getpgrp ());
linux-user/strace.list +0 -9
@@ -298,15 +298,9 @@ #ifdef TARGET_NR_getpgrp { TARGET_NR_getpgrp, "getpgrp" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_getpid -{ TARGET_NR_getpid, "getpid" , "%s()", NULL, NULL }, -#endif #ifdef TARGET_NR_getpmsg { TARGET_NR_getpmsg, "getpmsg" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_getppid -{ TARGET_NR_getppid, "getppid" , "%s()", NULL, NULL }, -#endif #ifdef TARGET_NR_getpriority { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL }, #endif
@@ -365,9 +359,6 @@ #ifdef TARGET_NR_getxgid { TARGET_NR_getxgid, "getxgid" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_getxpid -{ TARGET_NR_getxpid, "getxpid" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_getxuid { TARGET_NR_getxuid, "getxuid" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 32/49 linux-user: Split out mount
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall.h | 1 + linux-user/strace.c | 21 +++---------- linux-user/syscall-file.inc.c | 48 ++++++++++++++++++++++++++++++ linux-user/syscall.c | 55 ----------------------------------- linux-user/strace.list | 3 -- 6 files changed, 54 insertions(+), 75 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -78,6 +78,7 @@ SYSCALL_DEF_FULL(mmap2, .impl = impl_mmap, .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT, ARG_MMAPFLAG, ARG_DEC, ARG_DEC64 }); #endif +SYSCALL_DEF(mount, ARG_STR, ARG_STR, ARG_STR, ARG_MOUNTFLAG, ARG_PTR); SYSCALL_DEF(mprotect, ARG_PTR, ARG_DEC, ARG_MMAPPROT); SYSCALL_DEF_FULL(mremap, .impl = impl_mremap, .print_ret = print_syscall_ptr_ret,
linux-user/syscall.h +1 -0
@@ -62,6 +62,7 @@ typedef enum {ARG_MMAPFLAG ,ARG_MMAPPROT ,ARG_MODEFLAG , +ARG_MOUNTFLAG ,ARG_OPENFLAG ,ARG_UNLINKATFLAG , ARG_LSEEKWHENCE,
linux-user/strace.c +4 -17
@@ -708,7 +708,7 @@ static struct flags const open_flags[] = { FLAG_END, }; -UNUSED static struct flags mount_flags[] = { +static struct flags const mount_flags[] = { #ifdef MS_BINDFLAG_GENERIC (MS_BIND ), #endif
@@ -2003,22 +2003,6 @@ print_symlinkat(const struct syscallname *name, }#endif -#ifdef TARGET_NR_mount -static void -print_mount (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_string (arg1,0 ); -print_string (arg2,0 ); -print_flags (mount_flags, arg3,0 ); -print_pointer (arg4,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_umount static void print_umount(const struct syscallname *name,
@@ -2303,6 +2287,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_MODEFLAG : len =add_flags (b, rest, mode_flags, arg, true);break ; +case ARG_MOUNTFLAG : + len =add_flags (b, rest, mount_flags, arg, true); +break ;case ARG_OPENFLAG : len =add_open_flags (b, rest, arg);break ;
linux-user/syscall-file.inc.c +48 -0
54 lines not on this page · raw message
linux-user/syscall.c +0 -55
61 lines not on this page · raw message
linux-user/strace.list +0 -3
@@ -497,9 +497,6 @@ #ifdef TARGET_NR_modify_ldt { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_mount -{ TARGET_NR_mount, "mount" , NULL, print_mount, NULL }, -#endif #ifdef TARGET_NR_move_pages { TARGET_NR_move_pages, "move_pages" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 33/49 linux-user: Split out umount, umount2
In reply to Richard HendersonNote that umount2 is unconditionally available.
--- linux-user/syscall-defs.h | 4 ++++ linux-user/syscall.h | 1 + linux-user/strace.c | 30 ++++-------------------------- linux-user/syscall-file.inc.c | 25 +++++++++++++++++++++++++ linux-user/syscall.c | 16 ---------------- linux-user/strace.list | 6 ------ 6 files changed, 34 insertions(+), 48 deletions(-)
linux-user/syscall-defs.h +4 -0
@@ -155,6 +155,10 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);#ifdef TARGET_NR_timeSYSCALL_DEF (time,ARG_PTR );#endif +#ifdef TARGET_NR_umount +SYSCALL_DEF (umount,ARG_STR ); +#endif +SYSCALL_DEF (umount2,ARG_STR ,ARG_UMOUNTFLAG );#ifdef TARGET_NR_unlinkSYSCALL_DEF (unlink,ARG_STR );#endif
linux-user/syscall.h +1 -0
@@ -64,6 +64,7 @@ typedef enum {ARG_MODEFLAG ,ARG_MOUNTFLAG ,ARG_OPENFLAG , +ARG_UMOUNTFLAG ,ARG_UNLINKATFLAG , ARG_LSEEKWHENCE,
linux-user/strace.c +4 -26
@@ -733,7 +733,7 @@ static struct flags const mount_flags[] = { FLAG_END, }; -UNUSED static struct flags umount2_flags[] = { +static struct flags const umount2_flags[] = { #ifdef MNT_FORCEFLAG_GENERIC (MNT_FORCE ), #endif
@@ -2003,31 +2003,6 @@ print_symlinkat(const struct syscallname *name, }#endif -#ifdef TARGET_NR_umount -static void -print_umount (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,1 ); -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_umount2 -static void -print_umount2 (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_flags (umount2_flags, arg1,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_utime static void print_utime(const struct syscallname *name,
@@ -2293,6 +2268,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_OPENFLAG : len =add_open_flags (b, rest, arg);break ; +case ARG_UMOUNTFLAG : + len =add_flags (b, rest, umount2_flags, arg, false); +break ;case ARG_UNLINKATFLAG : len =add_flags (b, rest, unlinkat_flags, arg, true);break ;
linux-user/syscall-file.inc.c +25 -0
@@ -810,6 +810,31 @@ SYSCALL_IMPL(readlinkat) }#endif +static abi_long do_umount2 (abi_ulong target_path,int flags) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (umount2 (p, flags)); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_umount +SYSCALL_IMPL (umount) +{ +return do_umount2 (arg1,0 ); +} +#endif + +SYSCALL_IMPL (umount2) +{ +return do_umount2 (arg1, arg2); +} +static abi_long do_unlinkat (int dirfd,abi_ulong target_path,int flags) {char *p =lock_user_string (target_path);
linux-user/syscall.c +0 -16
@@ -5327,14 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_umount -case TARGET_NR_umount: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (umount (p)); -unlock_user (p, arg1,0 ); -return ret; -#endif #ifdef TARGET_NR_stime/* not on alpha */ case TARGET_NR_stime: {
@@ -5555,14 +5547,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,unlock_user (p, arg1,0 ); }return ret; -#ifdef TARGET_NR_umount2 -case TARGET_NR_umount2: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (umount2 (p, arg2)); -unlock_user (p, arg1,0 ); -return ret; -#endif case TARGET_NR_ioctl:return do_ioctl (arg1, arg2, arg3);#ifdef TARGET_NR_fcntl
linux-user/strace.list +0 -6
@@ -1368,12 +1368,6 @@ #ifdef TARGET_NR_umask { TARGET_NR_umask, "umask" , "%s(%#o)", NULL, NULL }, #endif -#ifdef TARGET_NR_umount -{ TARGET_NR_umount, "umount" , NULL, print_umount, NULL }, -#endif -#ifdef TARGET_NR_umount2 -{ TARGET_NR_umount2, "umount2" , NULL, print_umount2, NULL }, -#endif #ifdef TARGET_NR_uname { TARGET_NR_uname, "uname" , "%s(%p)", NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 34/49 linux-user: Split out stime
In reply to Richard Henderson--- linux-user/syscall-defs.h | 3 +++ linux-user/syscall-time.inc.c | 12 ++++++++++++ linux-user/syscall.c | 9 --------- linux-user/strace.list | 3 --- 4 files changed, 15 insertions(+), 12 deletions(-)
linux-user/syscall-defs.h +3 -0
@@ -152,6 +152,9 @@ SYSCALL_DEF(shmdt, ARG_PTR);#if !defined(SYSCALL_TABLE ) || defined(TARGET_NR_shmget)SYSCALL_DEF (shmget,ARG_DEC ,ARG_DEC ,ARG_HEX );#endif +#ifdef TARGET_NR_stime +SYSCALL_DEF (stime,ARG_PTR ); +#endif #ifdef TARGET_NR_timeSYSCALL_DEF (time,ARG_PTR );#endif
linux-user/syscall-time.inc.c +12 -0
@@ -16,6 +16,18 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#ifdef TARGET_NR_stime +SYSCALL_IMPL (stime) +{ +time_t host_time; + +if (get_user_sal (host_time, arg1)) { +return -TARGET_EFAULT ; + } +return get_errno (stime (&host_time)); +} +#endif +#ifdef TARGET_NR_timeSYSCALL_IMPL (time) {
linux-user/syscall.c +0 -9
@@ -5327,15 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_stime/* not on alpha */ -case TARGET_NR_stime: - { -time_t host_time; -if (get_user_sal (host_time, arg1)) -return -TARGET_EFAULT ; -return get_errno (stime (&host_time)); - } -#endif #ifdef TARGET_NR_alarm/* not on alpha */ case TARGET_NR_alarm:return alarm (arg1);
linux-user/strace.list +0 -3
@@ -1254,9 +1254,6 @@ #ifdef TARGET_NR_statfs64 { TARGET_NR_statfs64, "statfs64" , NULL, print_statfs64, NULL }, #endif -#ifdef TARGET_NR_stime -{ TARGET_NR_stime, "stime" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_streams1 { TARGET_NR_streams1, "streams1" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 35/49 linux-user: Split out alarm, pause
In reply to Richard Henderson--- linux-user/syscall-defs.h | 6 ++++++ linux-user/syscall-sig.inc.c | 36 ++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 12 +----------- linux-user/strace.list | 6 ------ 4 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 linux-user/syscall-sig.inc.c
linux-user/syscall-defs.h +6 -0
@@ -16,6 +16,9 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#ifdef TARGET_NR_alarm +SYSCALL_DEF (alarm,ARG_DEC ); +#endif SYSCALL_DEF_FULL(brk, .impl = impl_brk, .print_ret = print_syscall_ptr_ret, .arg_type = { ARG_PTR });
@@ -106,6 +109,9 @@ SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);#endif SYSCALL_DEF (openat,ARG_ATDIRFD ,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );SYSCALL_DEF (open_by_handle_at,ARG_DEC ,ARG_PTR ,ARG_OPENFLAG ); +#ifdef TARGET_NR_pause +SYSCALL_DEF (pause); +#endif SYSCALL_DEF_FULL(pread64, .impl = impl_pread64, .args = args_pread64_pwrite64, .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
linux-user/syscall-sig.inc.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Linux signal related syscalls +* Copyright (c) 2003 Fabrice Bellard +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifdef TARGET_NR_alarm +SYSCALL_IMPL (alarm) +{ +return alarm (arg1); +} +#endif + +#ifdef TARGET_NR_pause +SYSCALL_IMPL (pause) +{ +if (!block_signals ()) { +CPUState *cpu =ENV_GET_CPU (cpu_env); +TaskState *ts = cpu->opaque; +sigsuspend (&ts->signal_mask); + } +return -TARGET_EINTR ; +} +#endif
linux-user/syscall.c +1 -11
@@ -5327,17 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_alarm/* not on alpha */ -case TARGET_NR_alarm: -return alarm (arg1); -#endif -#ifdef TARGET_NR_pause/* not on alpha */ -case TARGET_NR_pause: -if (!block_signals ()) { -sigsuspend (&((TaskState *)cpu->opaque)->signal_mask); - } -return -TARGET_EINTR ; -#endif #ifdef TARGET_NR_utimecase TARGET_NR_utime: {
@@ -9135,6 +9124,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#include "syscall-ipc.inc.c" #include "syscall-mem.inc.c" #include "syscall-proc.inc.c" +#include "syscall-sig.inc.c" #include "syscall-time.inc.c" #undef SYSCALL_IMPL
linux-user/strace.list +0 -6
@@ -25,9 +25,6 @@ #ifdef TARGET_NR_afs_syscall { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_alarm -{ TARGET_NR_alarm, "alarm" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_aplib { TARGET_NR_aplib, "aplib" , NULL, NULL, NULL }, #endif
@@ -872,9 +869,6 @@ #ifdef TARGET_NR_osf_waitid { TARGET_NR_osf_waitid, "osf_waitid" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pause -{ TARGET_NR_pause, "pause" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_pciconfig_iobase { TARGET_NR_pciconfig_iobase, "pciconfig_iobase" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 36/49 linux-user: Split out utime, utimes, futimesat
In reply to Richard Henderson--- linux-user/syscall-defs.h | 9 ++++ linux-user/strace.c | 41 --------------- linux-user/syscall-file.inc.c | 95 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 63 ----------------------- linux-user/strace.list | 9 ---- 5 files changed, 104 insertions(+), 113 deletions(-)
linux-user/syscall-defs.h +9 -0
@@ -36,6 +36,9 @@ SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);SYSCALL_DEF (execveat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );SYSCALL_DEF (fchmod,ARG_DEC ,ARG_MODEFLAG );SYSCALL_DEF (fchmodat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG ); +#ifdef TARGET_NR_futimesat +SYSCALL_DEF (futimesat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ); +#endif #ifdef TARGET_NR_forkSYSCALL_DEF (fork);#endif
@@ -172,6 +175,12 @@ SYSCALL_DEF(umount2, ARG_STR, ARG_UMOUNTFLAG);SYSCALL_DEF (unlink,ARG_STR );#endif SYSCALL_DEF (unlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_UNLINKATFLAG ); +#ifdef TARGET_NR_utime +SYSCALL_DEF (utime,ARG_STR ,ARG_PTR ); +#endif +#ifdef TARGET_NR_utimes +SYSCALL_DEF (utimes,ARG_STR ,ARG_PTR ); +#endif #ifdef TARGET_NR_vfork/* Emulate vfork() with fork(). */ SYSCALL_DEF_FULL(vfork, .impl = impl_fork);
linux-user/strace.c +0 -41
53 lines not on this page · raw message
linux-user/syscall-file.inc.c +95 -0
107 lines not on this page · raw message
linux-user/syscall.c +0 -63
69 lines not on this page · raw message
linux-user/strace.list +0 -9
@@ -226,9 +226,6 @@ #ifdef TARGET_NR_futex { TARGET_NR_futex, "futex" , NULL, print_futex, NULL }, #endif -#ifdef TARGET_NR_futimesat -{ TARGET_NR_futimesat, "futimesat" , NULL, print_futimesat, NULL }, -#endif #ifdef TARGET_NR_getcpu { TARGET_NR_getcpu, "getcpu" , "%s(%p,%d)", NULL, NULL }, #endif
@@ -1392,12 +1389,6 @@ #ifdef TARGET_NR_ustat { TARGET_NR_ustat, "ustat" , "%s(%#x,%p)", NULL, NULL }, #endif -#ifdef TARGET_NR_utime -{ TARGET_NR_utime, "utime" , NULL, print_utime, NULL }, -#endif -#ifdef TARGET_NR_utimes -{ TARGET_NR_utimes, "utimes" , NULL, print_utimes, NULL }, -#endif #ifdef TARGET_NR_utrap_install { TARGET_NR_utrap_install, "utrap_install" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 37/49 linux-user: Split out access, faccessat
In reply to Richard HendersonNote that faccessat is unconditionally available.
--- linux-user/syscall-defs.h | 4 ++++ linux-user/syscall.h | 1 + linux-user/strace.c | 33 ++++----------------------------- linux-user/syscall-file.inc.c | 25 +++++++++++++++++++++++++ linux-user/syscall.c | 18 ------------------ linux-user/strace.list | 6 ------ 6 files changed, 34 insertions(+), 53 deletions(-)
linux-user/syscall-defs.h +4 -0
@@ -16,6 +16,9 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#ifdef TARGET_NR_access +SYSCALL_DEF (access,ARG_STR ,ARG_ACCESSFLAG ); +#endif #ifdef TARGET_NR_alarmSYSCALL_DEF (alarm,ARG_DEC );#endif
@@ -34,6 +37,7 @@ SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);SYSCALL_DEF (exit,ARG_DEC );SYSCALL_DEF (execve,ARG_STR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (execveat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG ); +SYSCALL_DEF (faccessat,ARG_ATDIRFD ,ARG_STR ,ARG_ACCESSFLAG );SYSCALL_DEF (fchmod,ARG_DEC ,ARG_MODEFLAG );SYSCALL_DEF (fchmodat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG );#ifdef TARGET_NR_futimesat
linux-user/syscall.h +1 -0
@@ -57,6 +57,7 @@ typedef enum {/* These print as sets of flags. */ ARG_ATDIRFD , +ARG_ACCESSFLAG ,ARG_ATFLAG ,ARG_CLONEFLAG , ARG_MMAPFLAG,
linux-user/strace.c +4 -29
@@ -634,7 +634,7 @@ print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)gemu_log ("\n" ); } -UNUSED static struct flags access_flags[] = { +static struct flags const access_flags[] = {FLAG_GENERIC (F_OK ),FLAG_GENERIC (R_OK ),FLAG_GENERIC (W_OK ),
@@ -1114,19 +1114,6 @@ print_accept(const struct syscallname *name, }#endif -#ifdef TARGET_NR_access -static void -print_access (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_flags (access_flags, arg1,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_clock_adjtime static void print_clock_adjtime(const struct syscallname *name,
@@ -1153,21 +1140,6 @@ print_execv(const struct syscallname *name, }#endif -#ifdef TARGET_NR_faccessat -static void -print_faccessat (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_flags (access_flags, arg2,0 ); -print_flags (at_file_flags, arg3,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_fchownat static void print_fchownat(const struct syscallname *name,
@@ -2206,6 +2178,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_ATDIRFD : len =add_atdirfd (b, rest, arg);break ; +case ARG_ACCESSFLAG : + len =add_flags (b, rest, access_flags, arg, false); +break ;case ARG_ATFLAG : len =add_flags (b, rest, at_file_flags, arg, false);break ;
linux-user/syscall-file.inc.c +25 -0
@@ -16,6 +16,26 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +static abi_long do_faccessat (int dirfd,abi_ulong target_path,int mode) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (faccessat (dirfd, p, mode,0 )); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_access +SYSCALL_IMPL (access) +{ +return do_faccessat (AT_FDCWD , arg1, arg2); +} +#endif +SYSCALL_IMPL (chdir) {abi_ulong target_path = arg1;
@@ -74,6 +94,11 @@ SYSCALL_IMPL(creat) }#endif +SYSCALL_IMPL (faccessat) +{ +return do_faccessat (arg1, arg2, arg3); +} +SYSCALL_IMPL (fchmod) {return get_errno (fchmod (arg1, arg2));
linux-user/syscall.c +0 -18
@@ -5327,24 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_access -case TARGET_NR_access: -if (!(p =lock_user_string (arg1))) { -return -TARGET_EFAULT ; - } - ret =get_errno (access (path (p), arg2)); -unlock_user (p, arg1,0 ); -return ret; -#endif -#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) -case TARGET_NR_faccessat: -if (!(p =lock_user_string (arg2))) { -return -TARGET_EFAULT ; - } - ret =get_errno (faccessat (arg1, p, arg3,0 )); -unlock_user (p, arg2,0 ); -return ret; -#endif #ifdef TARGET_NR_nice/* not on alpha */ case TARGET_NR_nice:return get_errno (nice (arg1));
linux-user/strace.list +0 -6
@@ -9,9 +9,6 @@ #ifdef TARGET_NR_accept4 { TARGET_NR_accept4, "accept4" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_access -{ TARGET_NR_access, "access" , NULL, print_access, NULL }, -#endif #ifdef TARGET_NR_acct { TARGET_NR_acct, "acct" , NULL, NULL, NULL }, #endif
@@ -142,9 +139,6 @@ #ifdef TARGET_NR_exit_group { TARGET_NR_exit_group, "exit_group" , "%s(%d)\n", NULL, NULL }, #endif -#ifdef TARGET_NR_faccessat -{ TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL }, -#endif #ifdef TARGET_NR_fadvise64 { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 38/49 linux-user: Split out nice
In reply to Richard Henderson--- linux-user/syscall-defs.h | 3 +++ linux-user/syscall-proc.inc.c | 7 +++++++ linux-user/syscall.c | 4 ---- linux-user/strace.list | 3 --- 4 files changed, 10 insertions(+), 7 deletions(-)
linux-user/syscall-defs.h +3 -0
@@ -111,6 +111,9 @@ SYSCALL_DEF(munlockall);SYSCALL_DEF (munmap,ARG_PTR ,ARG_DEC );SYSCALL_DEF (name_to_handle_at,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG ); +#ifdef TARGET_NR_nice +SYSCALL_DEF (nice,ARG_DEC ); +#endif #ifdef TARGET_NR_openSYSCALL_DEF (open,ARG_STR ,ARG_OPENFLAG ,ARG_MODEFLAG );#endif
linux-user/syscall-proc.inc.c +7 -0
@@ -461,6 +461,13 @@ SYSCALL_IMPL(getxpid) }#endif +#ifdef TARGET_NR_nice +SYSCALL_IMPL (nice) +{ +return get_errno (nice (arg1)); +} +#endif +/* * Map host to target signal numbers for the wait family of syscalls. * Assume all other status bits are the same.
linux-user/syscall.c +0 -4
@@ -5327,10 +5327,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_nice/* not on alpha */ -case TARGET_NR_nice: -return get_errno (nice (arg1)); -#endif case TARGET_NR_sync:sync ();return 0 ;
linux-user/strace.list +0 -3
@@ -527,9 +527,6 @@ #ifdef TARGET_NR_nfsservctl { TARGET_NR_nfsservctl, "nfsservctl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_nice -{ TARGET_NR_nice, "nice" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_old_adjtimex { TARGET_NR_old_adjtimex, "old_adjtimex" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 39/49 linux-user: Split out sync, syncfs
In reply to Richard HendersonNote that syncfs is universally available.
If !CONFIG_SYNCFS, provide our own syscall replacement.
--- linux-user/syscall-defs.h | 2 ++ linux-user/syscall-file.inc.c | 11 +++++++++++ linux-user/syscall.c | 20 ++++++++++++-------- linux-user/strace.list | 6 ------ 4 files changed, 25 insertions(+), 14 deletions(-)
linux-user/syscall-defs.h +2 -0
@@ -171,6 +171,8 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);#ifdef TARGET_NR_stimeSYSCALL_DEF (stime,ARG_PTR );#endif +SYSCALL_DEF (sync); +SYSCALL_DEF (syncfs,ARG_DEC );#ifdef TARGET_NR_timeSYSCALL_DEF (time,ARG_PTR );#endif
linux-user/syscall-file.inc.c +11 -0
@@ -867,6 +867,17 @@ SYSCALL_IMPL(readlinkat) }#endif +SYSCALL_IMPL (sync) +{ +sync (); +return 0 ; +} + +SYSCALL_IMPL (syncfs) +{ +return get_errno (syncfs (arg1)); +} +static abi_long do_umount2 (abi_ulong target_path,int flags) {char *p =lock_user_string (target_path);
linux-user/syscall.c +12 -8
@@ -199,6 +199,15 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \#define TARGET_NR_llseek TARGET_NR__llseek#endif +/* +* These definitions produce an ENOSYS from the host kernel. +* Performing a bogus sysacll is lazier than boilerplating +* the replacement functions here in C. +*/ +#ifndef __NR_syncfs +#define __NR_syncfs -1 +#endif +#ifdef __NR_gettid_syscall0 (int, gettid) #else
@@ -264,11 +273,13 @@ _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)#if defined(TARGET_NR_getrandom) && defined(__NR_getrandom) _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)#endif -#if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)_syscall5 (int, kcmp, pid_t, pid1, pid_t, pid2, int, type, unsigned long, idx1, unsigned long, idx2)#endif +#ifndef CONFIG_SYNCFS +_syscall1(int, syncfs, int, fd) +#endif static bitmask_transtbl fcntl_flags_tbl[] = { {TARGET_O_ACCMODE ,TARGET_O_WRONLY ,O_ACCMODE ,O_WRONLY , },
@@ -5327,13 +5338,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_sync: -sync (); -return 0 ; -#if defined(TARGET_NR_syncfs) && defined(CONFIG_SYNCFS ) -case TARGET_NR_syncfs: -return get_errno (syncfs (arg1)); -#endif case TARGET_NR_kill:return get_errno (safe_kill (arg1,target_to_host_signal (arg2)));#ifdef TARGET_NR_rename
linux-user/strace.list +0 -6
@@ -1260,12 +1260,6 @@ #ifdef TARGET_NR_symlinkat { TARGET_NR_symlinkat, "symlinkat", NULL, print_symlinkat, NULL }, #endif -#ifdef TARGET_NR_sync -{ TARGET_NR_sync, "sync" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_syncfs -{ TARGET_NR_syncfs, "syncfs" , "%s(%d)", NULL, NULL }, -#endif #ifdef TARGET_NR_syscall { TARGET_NR_syscall, "syscall" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 40/49 linux-user: Split out kill
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall.h | 7 +++- linux-user/strace.c | 76 ++++++++++++++++++------------------ linux-user/syscall-sig.inc.c | 5 +++ linux-user/syscall.c | 2 - linux-user/strace.list | 3 -- 6 files changed, 48 insertions(+), 46 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -58,6 +58,7 @@ SYSCALL_DEF(getxpid);#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif +SYSCALL_DEF (kill,ARG_DEC ,ARG_SIGNAL );#ifdef TARGET_NR_linkSYSCALL_DEF (link,ARG_STR ,ARG_STR );#endif
linux-user/syscall.h +5 -2
@@ -55,8 +55,12 @@ typedef enum {ARG_HEX ,ARG_OCT , -/* These print as sets of flags. */ +/* These numbers are interpreted. */ ARG_ATDIRFD , +ARG_SIGNAL , +ARG_LSEEKWHENCE , + +/* These print as sets of flags. */ ARG_ACCESSFLAG ,ARG_ATFLAG , ARG_CLONEFLAG,
@@ -67,7 +71,6 @@ typedef enum {ARG_OPENFLAG ,ARG_UMOUNTFLAG ,ARG_UNLINKATFLAG , -ARG_LSEEKWHENCE ,/* These are interpreted as pointers. */ ARG_PTR,
linux-user/strace.c +37 -39
97 lines not on this page · raw message
linux-user/syscall-sig.inc.c +5 -0
@@ -23,6 +23,11 @@ SYSCALL_IMPL(alarm) }#endif +SYSCALL_IMPL (kill) +{ +return get_errno (safe_kill (arg1,target_to_host_signal (arg2))); +} +#ifdef TARGET_NR_pauseSYSCALL_IMPL (pause) {
linux-user/syscall.c +0 -2
@@ -5338,8 +5338,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_kill: -return get_errno (safe_kill (arg1,target_to_host_signal (arg2)));#ifdef TARGET_NR_renamecase TARGET_NR_rename: {
linux-user/strace.list +0 -3
@@ -410,9 +410,6 @@ #ifdef TARGET_NR_keyctl { TARGET_NR_keyctl, "keyctl" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_kill -{ TARGET_NR_kill, "kill", NULL, print_kill, NULL }, -#endif #ifdef TARGET_NR_lchown { TARGET_NR_lchown, "lchown" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 41/49 linux-user: Split out rename, renameat, renameat2
In reply to Richard HendersonNote that renameat2 is universally available for guests. Merge sys_renameat2 into the new do_renameat2 helper.
--- linux-user/syscall-defs.h | 8 +++++ linux-user/syscall.h | 1 + linux-user/strace.c | 39 ++++++--------------- linux-user/syscall-file.inc.c | 45 ++++++++++++++++++++++++ linux-user/syscall.c | 64 ----------------------------------- linux-user/strace.list | 9 ----- 6 files changed, 65 insertions(+), 101 deletions(-)
linux-user/syscall-defs.h +8 -0
@@ -142,6 +142,14 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);#ifdef TARGET_NR_readlinkatSYSCALL_DEF (readlinkat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_DEC );#endif +#ifdef TARGET_NR_rename +SYSCALL_DEF (rename,ARG_STR ,ARG_STR ); +#endif +#ifdef TARGET_NR_renameat +SYSCALL_DEF (renameat,ARG_ATDIRFD ,ARG_STR ,ARG_ATDIRFD ,ARG_STR ); +#endif +SYSCALL_DEF (renameat2,ARG_ATDIRFD ,ARG_STR , +ARG_ATDIRFD ,ARG_STR ,ARG_RENAMEFLAG );SYSCALL_DEF (readv,ARG_DEC ,ARG_PTR ,ARG_DEC );#ifdef TARGET_NR_rmdirSYSCALL_DEF (rmdir,ARG_STR );
linux-user/syscall.h +1 -0
@@ -69,6 +69,7 @@ typedef enum {ARG_MODEFLAG ,ARG_MOUNTFLAG ,ARG_OPENFLAG , +ARG_RENAMEFLAG ,ARG_UMOUNTFLAG , ARG_UNLINKATFLAG,
linux-user/strace.c +11 -28
@@ -4,6 +4,7 @@#include <arpa/inet.h> #include <netinet/tcp.h> #include <linux/if_packet.h> +#include <linux/fs.h> #include <sched.h> #include "qemu.h" #include "syscall.h"
@@ -741,6 +742,13 @@ static struct flags const mount_flags[] = { FLAG_END, }; +static struct flags const renameat2_flags[] = { +FLAG_GENERIC (RENAME_EXCHANGE ), +FLAG_GENERIC (RENAME_NOREPLACE ), +FLAG_GENERIC (RENAME_WHITEOUT ), +FLAG_END , +}; +static struct flags const umount2_flags[] = { #ifdef MNT_FORCE FLAG_GENERIC(MNT_FORCE),
@@ -1887,34 +1895,6 @@ print_fstatat64(const struct syscallname *name,#define print_newfstatat print_fstatat64#endif -#ifdef TARGET_NR_rename -static void -print_rename (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_string (arg1,1 ); -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_renameat -static void -print_renameat (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_at_dirfd (arg2,0 ); -print_string (arg3,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_statfs static void print_statfs(const struct syscallname *name,
@@ -2200,6 +2180,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])case ARG_OPENFLAG : len =add_open_flags (b, rest, arg);break ; +case ARG_RENAMEFLAG : + len =add_flags (b, rest, renameat2_flags, arg, false); +break ;case ARG_UMOUNTFLAG : len =add_flags (b, rest, umount2_flags, arg, false);break ;
linux-user/syscall-file.inc.c +45 -0
51 lines not on this page · raw message
linux-user/syscall.c +0 -64
76 lines not on this page · raw message
linux-user/strace.list +0 -9
@@ -944,15 +944,6 @@ #ifdef TARGET_NR_removexattr { TARGET_NR_removexattr, "removexattr" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_rename -{ TARGET_NR_rename, "rename" , NULL, print_rename, NULL }, -#endif -#ifdef TARGET_NR_renameat -{ TARGET_NR_renameat, "renameat" , NULL, print_renameat, NULL }, -#endif -#ifdef TARGET_NR_renameat2 -{ TARGET_NR_renameat2, "renameat2" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_request_key { TARGET_NR_request_key, "request_key" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 42/49 linux-user: Split out mkdir, mkdirat
In reply to Richard HendersonNote that mkdirat is universally available.
--- linux-user/syscall-defs.h | 4 ++++ linux-user/strace.c | 27 --------------------------- linux-user/syscall-file.inc.c | 25 +++++++++++++++++++++++++ linux-user/syscall.c | 16 ---------------- linux-user/strace.list | 6 ------ 5 files changed, 29 insertions(+), 49 deletions(-)
linux-user/syscall-defs.h +4 -0
@@ -69,6 +69,10 @@ SYSCALL_DEF(lseek, ARG_DEC, ARG_DEC, ARG_LSEEKWHENCE);#ifdef TARGET_NR_llseekSYSCALL_DEF_ARGS (llseek,ARG_DEC ,ARG_DEC ,ARG_PTR ,ARG_LSEEKWHENCE );#endif +#ifdef TARGET_NR_mkdir +SYSCALL_DEF (mkdir,ARG_STR ,ARG_MODEFLAG ); +#endif +SYSCALL_DEF (mkdirat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG );#ifdef TARGET_NR_mknodSYSCALL_DEF (mknod,ARG_STR ,ARG_MODEFLAG ,ARG_HEX );#endif
linux-user/strace.c +0 -27
@@ -1664,33 +1664,6 @@ print_fstat(const struct syscallname *name,#define print_fstat64 print_fstat#endif -#ifdef TARGET_NR_mkdir -static void -print_mkdir (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_file_mode (arg1,1 ); -print_syscall_epilogue (name); -} -#endif - -#ifdef TARGET_NR_mkdirat -static void -print_mkdirat (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_file_mode (arg2,1 ); -print_syscall_epilogue (name); -} -#endif -#ifdef TARGET_NR_rt_sigaction static void print_rt_sigaction(const struct syscallname *name,
linux-user/syscall-file.inc.c +25 -0
@@ -205,6 +205,31 @@ SYSCALL_IMPL(llseek) }#endif +static abi_long do_mkdirat (int dirfd,abi_ulong target_path,mode_t mode) +{ +char *p =lock_user_string (target_path); +abi_long ret; + +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (mkdirat (dirfd, p, mode)); +unlock_user (p, target_path,0 ); +return ret; +} + +#ifdef TARGET_NR_mkdir +SYSCALL_IMPL (mkdir) +{ +return do_mkdirat (AT_FDCWD , arg1, arg2); +} +#endif + +SYSCALL_IMPL (mkdirat) +{ +return do_mkdirat (arg1, arg2, arg3); +} +static abi_long do_mknodat (int dirfd,abi_ulong target_path,mode_t mode,dev_t dev) {
linux-user/syscall.c +0 -16
@@ -5320,22 +5320,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -#ifdef TARGET_NR_mkdir -case TARGET_NR_mkdir: -if (!(p =lock_user_string (arg1))) -return -TARGET_EFAULT ; - ret =get_errno (mkdir (p, arg2)); -unlock_user (p, arg1,0 ); -return ret; -#endif -#if defined(TARGET_NR_mkdirat) -case TARGET_NR_mkdirat: -if (!(p =lock_user_string (arg2))) -return -TARGET_EFAULT ; - ret =get_errno (mkdirat (arg1, p, arg3)); -unlock_user (p, arg2,0 ); -return ret; -#endif case TARGET_NR_dup: ret =get_errno (dup (arg1));if (ret >=0 ) {
linux-user/strace.list +0 -6
@@ -473,12 +473,6 @@ #ifdef TARGET_NR_mincore { TARGET_NR_mincore, "mincore" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_mkdir -{ TARGET_NR_mkdir, "mkdir" , NULL, print_mkdir, NULL }, -#endif -#ifdef TARGET_NR_mkdirat -{ TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL }, -#endif #ifdef TARGET_NR_modify_ldt { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 43/49 linux-user: Split out dup, dup2, dup3
In reply to Richard HendersonNote that dup3 is universally available for guests. Implement host support with syscall when !CONFIG_DUP3.
--- linux-user/syscall-defs.h | 5 +++++ linux-user/syscall-file.inc.c | 42 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 33 +++------------------------ linux-user/strace.list | 6 ----- 4 files changed, 50 insertions(+), 36 deletions(-)
linux-user/syscall-defs.h +5 -0
@@ -34,6 +34,11 @@ SYSCALL_DEF(close, ARG_DEC);#ifdef TARGET_NR_creatSYSCALL_DEF (creat,ARG_STR ,ARG_MODEFLAG );#endif +SYSCALL_DEF (dup,ARG_DEC ); +#ifdef TARGET_NR_dup2 +SYSCALL_DEF (dup2,ARG_DEC ,ARG_DEC ); +#endif +SYSCALL_DEF (dup3,ARG_DEC ,ARG_DEC ,ARG_OPENFLAG );SYSCALL_DEF (exit,ARG_DEC );SYSCALL_DEF (execve,ARG_STR ,ARG_PTR ,ARG_PTR );SYSCALL_DEF (execveat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR ,ARG_PTR ,ARG_ATFLAG );
linux-user/syscall-file.inc.c +42 -0
48 lines not on this page · raw message
linux-user/syscall.c +3 -30
@@ -204,6 +204,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \* Performing a bogus sysacll is lazier than boilerplating * the replacement functions here in C. */ +#ifndef __NR_dup3 +#define __NR_dup3 -1 +#endif #ifndef __NR_syncfs#define __NR_syncfs -1#endif
@@ -5320,12 +5323,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_dup: - ret =get_errno (dup (arg1)); -if (ret >=0 ) { -fd_trans_dup (arg1, ret); - } -return ret;#ifdef TARGET_NR_pipecase TARGET_NR_pipe:return do_pipe (cpu_env, arg1,0 ,0 );
@@ -5380,30 +5377,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, ret =get_errno (chroot (p));unlock_user (p, arg1,0 );return ret; -#ifdef TARGET_NR_dup2 -case TARGET_NR_dup2: - ret =get_errno (dup2 (arg1, arg2)); -if (ret >=0 ) { -fd_trans_dup (arg1, arg2); - } -return ret; -#endif -#if defined(CONFIG_DUP3 ) && defined(TARGET_NR_dup3) -case TARGET_NR_dup3: - { -int host_flags; - -if ((arg3 & ~TARGET_O_CLOEXEC ) !=0 ) { -return -EINVAL ; - } - host_flags =target_to_host_bitmask (arg3, fcntl_flags_tbl); - ret =get_errno (dup3 (arg1, arg2, host_flags)); -if (ret >=0 ) { -fd_trans_dup (arg1, arg2); - } -return ret; - } -#endif #ifdef TARGET_NR_getpgrpcase TARGET_NR_getpgrp:return get_errno (getpgrp ());
linux-user/strace.list +0 -6
@@ -91,12 +91,6 @@ #ifdef TARGET_NR_dipc { TARGET_NR_dipc, "dipc" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_dup -{ TARGET_NR_dup, "dup" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_dup2 -{ TARGET_NR_dup2, "dup2" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_epoll_create { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 44/49 linux-user: Split out pipe, pipe2
In reply to Richard HendersonNote that pipe2 is universally available for guests. Implement host support with syscall when !CONFIG_PIPE2.
--- linux-user/syscall-defs.h | 10 ++++++ linux-user/syscall-file.inc.c | 51 +++++++++++++++++++++++++++ linux-user/syscall.c | 65 +++++++---------------------------- linux-user/strace.list | 6 ---- 4 files changed, 74 insertions(+), 58 deletions(-)
linux-user/syscall-defs.h +10 -0
@@ -132,6 +132,16 @@ SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG);#ifdef TARGET_NR_pauseSYSCALL_DEF (pause);#endif +#ifdef TARGET_NR_pipe +# if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || \ + defined(TARGET_SH4 ) || defined(TARGET_SPARC ) +/* ??? We have no way for strace to display the second returned fd. */ +SYSCALL_DEF (pipe); +# else +SYSCALL_DEF (pipe,ARG_PTR ); +# endif +#endif +SYSCALL_DEF (pipe2,ARG_PTR ,ARG_OPENFLAG ); SYSCALL_DEF_FULL(pread64, .impl = impl_pread64, .args = args_pread64_pwrite64, .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
linux-user/syscall-file.inc.c +51 -0
57 lines not on this page · raw message
linux-user/syscall.c +13 -52
89 lines not on this page · raw message
linux-user/strace.list +0 -6
@@ -860,9 +860,6 @@ #ifdef TARGET_NR_personality { TARGET_NR_personality, "personality" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pipe -{ TARGET_NR_pipe, "pipe" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_pivot_root { TARGET_NR_pivot_root, "pivot_root" , NULL, NULL, NULL }, #endif
@@ -1377,9 +1374,6 @@ #ifdef TARGET_NR_sync_file_range2 { TARGET_NR_sync_file_range2, "sync_file_range2", NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_pipe2 -{ TARGET_NR_pipe2, "pipe2", NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_atomic_cmpxchg_32 { TARGET_NR_atomic_cmpxchg_32, "atomic_cmpxchg_32", NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 45/49 linux-user: Split out times
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall-proc.inc.c | 25 +++++++++++++++++++++++++ linux-user/syscall.c | 18 ------------------ linux-user/strace.list | 3 --- 4 files changed, 26 insertions(+), 21 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -204,6 +204,7 @@ SYSCALL_DEF(syncfs, ARG_DEC);#ifdef TARGET_NR_timeSYSCALL_DEF (time,ARG_PTR );#endif +SYSCALL_DEF (times,ARG_PTR );#ifdef TARGET_NR_umountSYSCALL_DEF (umount,ARG_STR );#endif
linux-user/syscall-proc.inc.c +25 -0
@@ -468,6 +468,31 @@ SYSCALL_IMPL(nice) }#endif +SYSCALL_IMPL (times) +{ +abi_ulong target_buf = arg1; +struct tms tms; +abi_long ret; + + ret =get_errno (times (&tms)); +if (target_buf) { +struct target_tms *tmsp =lock_user (VERIFY_WRITE , target_buf, +sizeof (struct target_tms ),0 ); +if (!tmsp) { +return -TARGET_EFAULT ; + } + tmsp->tms_utime =tswapal (host_to_target_clock_t (tms.tms_utime)); + tmsp->tms_stime =tswapal (host_to_target_clock_t (tms.tms_stime)); + tmsp->tms_cutime =tswapal (host_to_target_clock_t (tms.tms_cutime)); + tmsp->tms_cstime =tswapal (host_to_target_clock_t (tms.tms_cstime)); +unlock_user (tmsp, target_buf,sizeof (struct target_tms )); + } +if (!is_error (ret)) { + ret =host_to_target_clock_t (ret); + } +return ret; +} +/* * Map host to target signal numbers for the wait family of syscalls. * Assume all other status bits are the same.
linux-user/syscall.c +0 -18
@@ -5293,24 +5293,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_times: - { -struct target_tms *tmsp; -struct tms tms; - ret =get_errno (times (&tms)); -if (arg1) { - tmsp =lock_user (VERIFY_WRITE , arg1,sizeof (struct target_tms ),0 ); -if (!tmsp) -return -TARGET_EFAULT ; - tmsp->tms_utime =tswapal (host_to_target_clock_t (tms.tms_utime)); - tmsp->tms_stime =tswapal (host_to_target_clock_t (tms.tms_stime)); - tmsp->tms_cutime =tswapal (host_to_target_clock_t (tms.tms_cutime)); - tmsp->tms_cstime =tswapal (host_to_target_clock_t (tms.tms_cstime)); - } -if (!is_error (ret)) - ret =host_to_target_clock_t (ret); - } -return ret;case TARGET_NR_acct:if (arg1 ==0 ) { ret =get_errno (acct (NULL ));
linux-user/strace.list +0 -3
@@ -1290,9 +1290,6 @@ #ifdef TARGET_NR_timerfd_settime { TARGET_NR_timerfd_settime, "timerfd_settime" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_times -{ TARGET_NR_times, "times" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_tkill { TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 46/49 linux-user: Split out acct
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall-file.inc.c | 18 ++++++++++++++++++ linux-user/syscall.c | 11 ----------- linux-user/strace.list | 3 --- 4 files changed, 19 insertions(+), 14 deletions(-)
linux-user/syscall-defs.h +1 -0
@@ -19,6 +19,7 @@#ifdef TARGET_NR_accessSYSCALL_DEF (access,ARG_STR ,ARG_ACCESSFLAG );#endif +SYSCALL_DEF (acct,ARG_STR );#ifdef TARGET_NR_alarmSYSCALL_DEF (alarm,ARG_DEC );#endif
linux-user/syscall-file.inc.c +18 -0
@@ -36,6 +36,24 @@ SYSCALL_IMPL(access) }#endif +SYSCALL_IMPL (acct) +{ +abi_ulong target_path = arg1; +abi_long ret; + +if (target_path ==0 ) { + ret =get_errno (acct (NULL )); + }else { +char *p =lock_user_string (target_path); +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (acct (path (p))); +unlock_user (p, target_path,0 ); + } +return ret; +} +SYSCALL_IMPL (chdir) {abi_ulong target_path = arg1;
linux-user/syscall.c +0 -11
@@ -5293,17 +5293,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_acct: -if (arg1 ==0 ) { - ret =get_errno (acct (NULL )); - }else { -if (!(p =lock_user_string (arg1))) { -return -TARGET_EFAULT ; - } - ret =get_errno (acct (path (p))); -unlock_user (p, arg1,0 ); - } -return ret;case TARGET_NR_ioctl:return do_ioctl (arg1, arg2, arg3);#ifdef TARGET_NR_fcntl
linux-user/strace.list +0 -3
@@ -9,9 +9,6 @@ #ifdef TARGET_NR_accept4 { TARGET_NR_accept4, "accept4" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_acct -{ TARGET_NR_acct, "acct" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_add_key { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
PATCH v6 47/49 linux-user: Move syscall_init to the end
In reply to Richard HendersonNo functional change. This will aid moving everything related to ioctls to a separate file.
--- linux-user/syscall.c | 113 +++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 52 deletions(-)
linux-user/syscall.c +61 -52
@@ -4778,58 +4778,6 @@ _syscall1(int, sys_setgid, gid_t, gid) _syscall3(int, sys_setresuid, uid_t, ruid, uid_t, euid, uid_t, suid) _syscall3(int, sys_setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid) -void syscall_init (void ) -{ -IOCTLEntry *ie; -const argtype *arg_type; -int size; -int i; - -thunk_init (STRUCT_MAX ); - -#define STRUCT (name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); -#define STRUCT_SPECIAL (name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); -#include "syscall_types.h" -#undef STRUCT -#undef STRUCT_SPECIAL - -/* Build target_to_host_errno_table[] table from -* host_to_target_errno_table[]. */ -for (i =0 ; i <ERRNO_TABLE_SIZE ; i++) { - target_to_host_errno_table[host_to_target_errno_table[i]] = i; - } - -/* we patch the ioctl size if necessary. We rely on the fact that -no ioctl has all the bits at '1' in the size field */ - ie = ioctl_entries; -while (ie->target_cmd !=0 ) { -if (((ie->target_cmd >>TARGET_IOC_SIZESHIFT ) &TARGET_IOC_SIZEMASK ) == -TARGET_IOC_SIZEMASK ) { - arg_type = ie->arg_type; -if (arg_type[0 ] !=TYPE_PTR ) { -fprintf (stderr,"cannot patch size for ioctl 0x%x\n" , - ie->target_cmd); -exit (1 ); - } - arg_type++; - size =thunk_type_size (arg_type,0 ); - ie->target_cmd = (ie->target_cmd & - ~(TARGET_IOC_SIZEMASK <<TARGET_IOC_SIZESHIFT )) | - (size <<TARGET_IOC_SIZESHIFT ); - } - -/* automatic consistency check if same arch */ -#if (defined(__i386__) && defined(TARGET_I386 ) && defined(TARGET_ABI32 )) || \ - (defined(__x86_64__) && defined(TARGET_X86_64 )) -if (unlikely (ie->target_cmd != ie->host_cmd)) { -fprintf (stderr,"ERROR: ioctl(%s): target=0x%x host=0x%x\n" , - ie->name, ie->target_cmd, ie->host_cmd); - } -#endif - ie++; - } -} -static inline uint64_t target_offset64 (abi_ulong word0,abi_ulong word1) {#if TARGET_ABI_BITS ==64
@@ -8983,3 +8931,64 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,trace_guest_user_syscall_ret (cpu, num, ret);return ret; } + +void syscall_init (void ) +{ +IOCTLEntry *ie; +const argtype *arg_type; +int size; +int i; + +thunk_init (STRUCT_MAX ); + +#define STRUCT (name, ...) \ + thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); +#define STRUCT_SPECIAL (name) \ + thunk_register_struct_direct(STRUCT_ ## name, #name, \ + &struct_ ## name ## _def); + +#include "syscall_types.h" + +#undef STRUCT +#undef STRUCT_SPECIAL + +/* +* Build target_to_host_errno_table[] table from +* host_to_target_errno_table[]. +*/ +for (i =0 ; i <ERRNO_TABLE_SIZE ; i++) { + target_to_host_errno_table[host_to_target_errno_table[i]] = i; + } + +/* +* We patch the ioctl size if necessary. We rely on the fact that +* no ioctl has all the bits at '1' in the size field. +*/ + ie = ioctl_entries; +while (ie->target_cmd !=0 ) { +if (((ie->target_cmd >>TARGET_IOC_SIZESHIFT ) &TARGET_IOC_SIZEMASK ) == +TARGET_IOC_SIZEMASK ) { + arg_type = ie->arg_type; +if (arg_type[0 ] !=TYPE_PTR ) { +fprintf (stderr,"cannot patch size for ioctl 0x%x\n" , + ie->target_cmd); +exit (1 ); + } + arg_type++; + size =thunk_type_size (arg_type,0 ); + ie->target_cmd = (ie->target_cmd & + ~(TARGET_IOC_SIZEMASK <<TARGET_IOC_SIZESHIFT )) | + (size <<TARGET_IOC_SIZESHIFT ); + } + +/* automatic consistency check if same arch */ +#if (defined(__i386__) && defined(TARGET_I386 ) && defined(TARGET_ABI32 )) || \ + (defined(__x86_64__) && defined(TARGET_X86_64 )) +if (unlikely (ie->target_cmd != ie->host_cmd)) { +fprintf (stderr,"ERROR: ioctl(%s): target=0x%x host=0x%x\n" , + ie->name, ie->target_cmd, ie->host_cmd); + } +#endif + ie++; + } +}
Signature · 1 line
2.17.2
PATCH v6 48/49 linux-user: Split out ioctl
In reply to Richard Henderson--- linux-user/syscall-defs.h | 1 + linux-user/syscall-ioctl.inc.c | 873 +++++++++++++++++++++++++++++++++ linux-user/syscall.c | 843 +------------------------------ linux-user/strace.list | 3 - 4 files changed, 875 insertions(+), 845 deletions(-) create mode 100644 linux-user/syscall-ioctl.inc.c
linux-user/syscall-defs.h +1 -0
@@ -61,6 +61,7 @@ SYSCALL_DEF(getppid);#ifdef TARGET_NR_getxpidSYSCALL_DEF (getxpid);#endif +SYSCALL_DEF (ioctl,ARG_DEC ,ARG_HEX );#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif
linux-user/syscall-ioctl.inc.c new file +873 -0
873 lines not on this page · raw message
linux-user/syscall.c +1 -842
861 lines not on this page · raw message
linux-user/strace.list +0 -3
@@ -365,9 +365,6 @@ #ifdef TARGET_NR_io_cancel { TARGET_NR_io_cancel, "io_cancel" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_ioctl -{ TARGET_NR_ioctl, "ioctl" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_io_destroy { TARGET_NR_io_destroy, "io_destroy" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Hi,
this one is really a cut'n'paste but it introduces a problem with qemu-alpha, I don't know how/why:
$ sudo unshare --ipc --uts --pid --fork --kill-child --mount chroot chroot/alpha/sid/ Unsupported ioctl: cmd=0x80047476
And then it hangs.
I'll try to debug.
Thanks,
Laurent
Quoted 1,783 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- linux-user/syscall-defs.h | 1 + linux-user/syscall-ioctl.inc.c | 873 +++++++++++++++++++++++++++++++++ linux-user/syscall.c | 843 +------------------------------ linux-user/strace.list | 3 - 4 files changed, 875 insertions(+), 845 deletions(-) create mode 100644 linux-user/syscall-ioctl.inc.clinux-user/syscall-defs.h +1
-0@@ -61,6 +61,7 @@ SYSCALL_DEF(getppid);#ifdef TARGET_NR_getxpidSYSCALL_DEF (getxpid);#endif +SYSCALL_DEF (ioctl,ARG_DEC ,ARG_HEX );#ifdef TARGET_NR_ipcSYSCALL_DEF_ARGS (ipc,ARG_HEX ,ARG_DEC ,ARG_DEC ,ARG_HEX ,ARG_PTR ,ARG_HEX );#endif linux-user/syscall-ioctl.inc.c new file +873
-0@@ -0,0 +1,873 @@ +/* +* Linux ioctl syscall implementation +* Copyright (c) 2003 Fabrice Bellard +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +typedef struct IOCTLEntry IOCTLEntry ; + +typedef abi_long do_ioctl_fn (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg); + +struct IOCTLEntry { +int target_cmd; +unsigned int host_cmd; +const char *name; +int access; +do_ioctl_fn *do_ioctl; +const argtype arg_type[5 ]; +}; + +#define IOC_R 0x0001 +#define IOC_W 0x0002 +#define IOC_RW (IOC_R | IOC_W) + +#define MAX_STRUCT_SIZE 4096 + +#ifdef CONFIG_FIEMAP +/* +* So fiemap access checks don't overflow on 32 bit systems. +* This is very slightly smaller than the limit imposed by +* the underlying kernel. +*/ +#define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \ + / sizeof(struct fiemap_extent)) + +static abi_long do_ioctl_fs_ioc_fiemap (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +/* +* The parameter for this ioctl is a struct fiemap followed +* by an array of struct fiemap_extent whose size is set +* in fiemap->fm_extent_count. The array is filled in by the +* ioctl. +*/ +int target_size_in, target_size_out; +struct fiemap *fm; +const argtype *arg_type = ie->arg_type; +const argtype extent_arg_type[] = {MK_STRUCT (STRUCT_fiemap_extent) }; +void *argptr, *p; +abi_long ret; +int i, extent_size =thunk_type_size (extent_arg_type,0 ); +uint32_t outbufsz; +int free_fm =0 ; + +assert (arg_type[0 ] ==TYPE_PTR ); +assert (ie->access ==IOC_RW ); + arg_type++; + target_size_in =thunk_type_size (arg_type,0 ); + argptr =lock_user (VERIFY_READ , arg, target_size_in,1 ); +if (!argptr) { +return -TARGET_EFAULT ; + } +thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + fm = (struct fiemap *)buf_temp; +if (fm->fm_extent_count >FIEMAP_MAX_EXTENTS ) { +return -TARGET_EINVAL ; + } + + outbufsz =sizeof (*fm) +sizeof (struct fiemap_extent ) * fm->fm_extent_count; + +if (outbufsz >MAX_STRUCT_SIZE ) { +/* +* We can't fit all the extents into the fixed size buffer. +* Allocate one that is large enough and use it instead. +*/ + fm =g_try_malloc (outbufsz); +if (!fm) { +return -TARGET_ENOMEM ; + } +memcpy (fm, buf_temp,sizeof (struct fiemap )); + free_fm =1 ; + } + ret =get_errno (safe_ioctl (fd, ie->host_cmd, fm)); +if (!is_error (ret)) { + target_size_out = target_size_in; +/* +* An extent_count of 0 means we were only counting the extents +* so there are no structs to copy +*/ +if (fm->fm_extent_count !=0 ) { + target_size_out += fm->fm_mapped_extents * extent_size; + } + argptr =lock_user (VERIFY_WRITE , arg, target_size_out,0 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + }else { +/* Convert the struct fiemap */ +thunk_convert (argptr, fm, arg_type,THUNK_TARGET ); +if (fm->fm_extent_count !=0 ) { + p = argptr + target_size_in; +/* ...and then all the struct fiemap_extents */ +for (i =0 ; i < fm->fm_mapped_extents; i++) { +thunk_convert (p, &fm->fm_extents[i], extent_arg_type, +THUNK_TARGET ); + p += extent_size; + } + } +unlock_user (argptr, arg, target_size_out); + } + } +if (free_fm) { +g_free (fm); + } +return ret; +} +#endif + +static abi_long do_ioctl_ifconf (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +const argtype *arg_type = ie->arg_type; +int target_size; +void *argptr; +int ret; +struct ifconf *host_ifconf; +uint32_t outbufsz; +const argtype ifreq_arg_type[] = {MK_STRUCT (STRUCT_sockaddr_ifreq) }; +int target_ifreq_size; +int nb_ifreq; +int free_buf =0 ; +int i; +int target_ifc_len; +abi_long target_ifc_buf; +int host_ifc_len; +char *host_ifc_buf; + +assert (arg_type[0 ] ==TYPE_PTR ); +assert (ie->access ==IOC_RW ); + + arg_type++; + target_size =thunk_type_size (arg_type,0 ); + + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { +return -TARGET_EFAULT ; + } +thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + + host_ifconf = (struct ifconf *)(unsigned long )buf_temp; + target_ifc_len = host_ifconf->ifc_len; + target_ifc_buf = (abi_long )(unsigned long )host_ifconf->ifc_buf; + + target_ifreq_size =thunk_type_size (ifreq_arg_type,0 ); + nb_ifreq = target_ifc_len / target_ifreq_size; + host_ifc_len = nb_ifreq *sizeof (struct ifreq ); + + outbufsz =sizeof (*host_ifconf) + host_ifc_len; +if (outbufsz >MAX_STRUCT_SIZE ) { +/* +* We can't fit all the extents into the fixed size buffer. +* Allocate one that is large enough and use it instead. +*/ + host_ifconf =malloc (outbufsz); +if (!host_ifconf) { +return -TARGET_ENOMEM ; + } +memcpy (host_ifconf, buf_temp,sizeof (*host_ifconf)); + free_buf =1 ; + } + host_ifc_buf = (char *)host_ifconf +sizeof (*host_ifconf); + + host_ifconf->ifc_len = host_ifc_len; + host_ifconf->ifc_buf = host_ifc_buf; + + ret =get_errno (safe_ioctl (fd, ie->host_cmd, host_ifconf)); +if (!is_error (ret)) { +/* convert host ifc_len to target ifc_len */ + + nb_ifreq = host_ifconf->ifc_len /sizeof (struct ifreq ); + target_ifc_len = nb_ifreq * target_ifreq_size; + host_ifconf->ifc_len = target_ifc_len; + +/* restore target ifc_buf */ + + host_ifconf->ifc_buf = (char *)(unsigned long )target_ifc_buf; + +/* copy struct ifconf to target user */ + + argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); +if (!argptr) { +return -TARGET_EFAULT ; + } +thunk_convert (argptr, host_ifconf, arg_type,THUNK_TARGET ); +unlock_user (argptr, arg, target_size); + +/* copy ifreq[] to target user */ + + argptr =lock_user (VERIFY_WRITE , target_ifc_buf, target_ifc_len,0 ); +for (i =0 ; i < nb_ifreq ; i++) { +thunk_convert (argptr + i * target_ifreq_size, + host_ifc_buf + i *sizeof (struct ifreq ), + ifreq_arg_type,THUNK_TARGET ); + } +unlock_user (argptr, target_ifc_buf, target_ifc_len); + } + +if (free_buf) { +free (host_ifconf); + } + +return ret; +} + +#if defined(CONFIG_USBFS ) +#if HOST_LONG_BITS >64 +#error USBDEVFS thunks do not support >64 bit hosts yet. +#endif +struct live_urb { +uint64_t target_urb_adr; +uint64_t target_buf_adr; +char *target_buf_ptr; +struct usbdevfs_urb host_urb; +}; + +static GHashTable *usbdevfs_urb_hashtable (void ) +{ +static GHashTable *urb_hashtable; + +if (!urb_hashtable) { + urb_hashtable =g_hash_table_new (g_int64_hash, g_int64_equal); + } +return urb_hashtable; +} + +static void urb_hashtable_insert (struct live_urb *urb) +{ +GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); +g_hash_table_insert (urb_hashtable, urb, urb); +} + +static struct live_urb *urb_hashtable_lookup (uint64_t target_urb_adr) +{ +GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); +return g_hash_table_lookup (urb_hashtable, &target_urb_adr); +} + +static void urb_hashtable_remove (struct live_urb *urb) +{ +GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); +g_hash_table_remove (urb_hashtable, urb); +} + +static abi_long +do_ioctl_usbdevfs_reapurb (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +const argtype usbfsurb_arg_type[] = {MK_STRUCT (STRUCT_usbdevfs_urb) }; +const argtype ptrvoid_arg_type[] = {TYPE_PTRVOID ,0 ,0 }; +struct live_urb *lurb; +void *argptr; +uint64_t hurb; +int target_size; +uintptr_t target_urb_adr; +abi_long ret; + + target_size =thunk_type_size (usbfsurb_arg_type,THUNK_TARGET ); + +memset (buf_temp,0 ,sizeof (uint64_t )); + ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); +if (is_error (ret)) { +return ret; + } + +memcpy (&hurb, buf_temp,sizeof (uint64_t )); + lurb = (void *)((uintptr_t )hurb - offsetof(struct live_urb , host_urb)); +if (!lurb->target_urb_adr) { +return -TARGET_EFAULT ; + } +urb_hashtable_remove (lurb); +unlock_user (lurb->target_buf_ptr, lurb->target_buf_adr, + lurb->host_urb.buffer_length); + lurb->target_buf_ptr =NULL ; + +/* restore the guest buffer pointer */ + lurb->host_urb.buffer = (void *)(uintptr_t )lurb->target_buf_adr; + +/* update the guest urb struct */ + argptr =lock_user (VERIFY_WRITE , lurb->target_urb_adr, target_size,0 ); +if (!argptr) { +g_free (lurb); +return -TARGET_EFAULT ; + } +thunk_convert (argptr, &lurb->host_urb, usbfsurb_arg_type,THUNK_TARGET ); +unlock_user (argptr, lurb->target_urb_adr, target_size); + + target_size =thunk_type_size (ptrvoid_arg_type,THUNK_TARGET ); +/* write back the urb handle */ + argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); +if (!argptr) { +g_free (lurb); +return -TARGET_EFAULT ; + } + +/* GHashTable uses 64-bit keys but thunk_convert expects uintptr_t */ + target_urb_adr = lurb->target_urb_adr; +thunk_convert (argptr, &target_urb_adr, ptrvoid_arg_type,THUNK_TARGET ); +unlock_user (argptr, arg, target_size); + +g_free (lurb); +return ret; +} + +static abi_long +do_ioctl_usbdevfs_discardurb (const IOCTLEntry *ie, +uint8_t *buf_temp __attribute__((unused)), +int fd,int cmd,abi_long arg) +{ +struct live_urb *lurb; + +/* map target address back to host URB with metadata. */ + lurb =urb_hashtable_lookup (arg); +if (!lurb) { +return -TARGET_EFAULT ; + } +return get_errno (safe_ioctl (fd, ie->host_cmd, &lurb->host_urb)); +} + +static abi_long +do_ioctl_usbdevfs_submiturb (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +const argtype *arg_type = ie->arg_type; +int target_size; +abi_long ret; +void *argptr; +int rw_dir; +struct live_urb *lurb; + +/* +* each submitted URB needs to map to a unique ID for the +* kernel, and that unique ID needs to be a pointer to +* host memory. hence, we need to malloc for each URB. +* isochronous transfers have a variable length struct. +*/ + arg_type++; + target_size =thunk_type_size (arg_type,THUNK_TARGET ); + +/* construct host copy of urb and metadata */ + lurb =g_try_malloc0 (sizeof (struct live_urb )); +if (!lurb) { +return -TARGET_ENOMEM ; + } + + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { +g_free (lurb); +return -TARGET_EFAULT ; + } +thunk_convert (&lurb->host_urb, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + + lurb->target_urb_adr = arg; + lurb->target_buf_adr = (uintptr_t )lurb->host_urb.buffer; + +/* buffer space used depends on endpoint type so lock the entire buffer */ +/* control type urbs should check the buffer contents for true direction */ + rw_dir = lurb->host_urb.endpoint &USB_DIR_IN ?VERIFY_WRITE :VERIFY_READ ; + lurb->target_buf_ptr =lock_user (rw_dir, lurb->target_buf_adr, + lurb->host_urb.buffer_length,1 ); +if (lurb->target_buf_ptr ==NULL ) { +g_free (lurb); +return -TARGET_EFAULT ; + } + +/* update buffer pointer in host copy */ + lurb->host_urb.buffer = lurb->target_buf_ptr; + + ret =get_errno (safe_ioctl (fd, ie->host_cmd, &lurb->host_urb)); +if (is_error (ret)) { +unlock_user (lurb->target_buf_ptr, lurb->target_buf_adr,0 ); +g_free (lurb); + }else { +urb_hashtable_insert (lurb); + } + +return ret; +} +#endif /* CONFIG_USBFS */ + +static abi_long do_ioctl_dm (const IOCTLEntry *ie,uint8_t *buf_temp,int fd, +int cmd,abi_long arg) +{ +void *argptr; +struct dm_ioctl *host_dm; +abi_long guest_data; +uint32_t guest_data_size; +int target_size; +const argtype *arg_type = ie->arg_type; +abi_long ret; +void *big_buf =NULL ; +char *host_data; + + arg_type++; + target_size =thunk_type_size (arg_type,0 ); + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + goto out; + } +thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + +/* buf_temp is too small, so fetch things into a bigger buffer */ + big_buf =g_malloc0 (((struct dm_ioctl *)buf_temp)->data_size *2 ); +memcpy (big_buf, buf_temp, target_size); + buf_temp = big_buf; + host_dm = big_buf; + + guest_data = arg + host_dm->data_start; +if ((guest_data - arg) <0 ) { + ret = -TARGET_EINVAL ; + goto out; + } + guest_data_size = host_dm->data_size - host_dm->data_start; + host_data = (char *)host_dm + host_dm->data_start; + + argptr =lock_user (VERIFY_READ , guest_data, guest_data_size,1 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + goto out; + } + +switch (ie->host_cmd) { +case DM_REMOVE_ALL : +case DM_LIST_DEVICES : +case DM_DEV_CREATE : +case DM_DEV_REMOVE : +case DM_DEV_SUSPEND : +case DM_DEV_STATUS : +case DM_DEV_WAIT : +case DM_TABLE_STATUS : +case DM_TABLE_CLEAR : +case DM_TABLE_DEPS : +case DM_LIST_VERSIONS : +/* no input data */ +break ; +case DM_DEV_RENAME : +case DM_DEV_SET_GEOMETRY : +/* data contains only strings */ +memcpy (host_data, argptr, guest_data_size); +break ; +case DM_TARGET_MSG : +memcpy (host_data, argptr, guest_data_size); + *(uint64_t *)host_data =tswap64 (*(uint64_t *)argptr); +break ; +case DM_TABLE_LOAD : + { +void *gspec = argptr; +void *cur_data = host_data; +const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_target_spec) }; +int spec_size =thunk_type_size (arg_type,0 ); +int i; + +for (i =0 ; i < host_dm->target_count; i++) { +struct dm_target_spec *spec = cur_data; +uint32_t next; +int slen; + +thunk_convert (spec, gspec, arg_type,THUNK_HOST ); + slen =strlen ((char *)gspec + spec_size) +1 ; + next = spec->next; + spec->next =sizeof (*spec) + slen; +strcpy ((char *)&spec[1 ], gspec + spec_size); + gspec += next; + cur_data += spec->next; + } +break ; + } +default : + ret = -TARGET_EINVAL ; +unlock_user (argptr, guest_data,0 ); + goto out; + } +unlock_user (argptr, guest_data,0 ); + + ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); +if (!is_error (ret)) { + guest_data = arg + host_dm->data_start; + guest_data_size = host_dm->data_size - host_dm->data_start; + argptr =lock_user (VERIFY_WRITE , guest_data, guest_data_size,0 ); +switch (ie->host_cmd) { +case DM_REMOVE_ALL : +case DM_DEV_CREATE : +case DM_DEV_REMOVE : +case DM_DEV_RENAME : +case DM_DEV_SUSPEND : +case DM_DEV_STATUS : +case DM_TABLE_LOAD : +case DM_TABLE_CLEAR : +case DM_TARGET_MSG : +case DM_DEV_SET_GEOMETRY : +/* no return data */ +break ; +case DM_LIST_DEVICES : + { +struct dm_name_list *nl = (void *)host_dm + host_dm->data_start; +uint32_t remaining_data = guest_data_size; +void *cur_data = argptr; +const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_name_list) }; +int nl_size =12 ;/* can't use thunk_size due to alignment */ + +while (1 ) { +uint32_t next = nl->next; +if (next) { + nl->next = nl_size + (strlen (nl->name) +1 ); + } +if (remaining_data < nl->next) { + host_dm->flags |=DM_BUFFER_FULL_FLAG ; +break ; + } +thunk_convert (cur_data, nl, arg_type,THUNK_TARGET ); +strcpy (cur_data + nl_size, nl->name); + cur_data += nl->next; + remaining_data -= nl->next; +if (!next) { +break ; + } + nl = (void *)nl + next; + } +break ; + } +case DM_DEV_WAIT : +case DM_TABLE_STATUS : + { +struct dm_target_spec *spec + = (void *)host_dm + host_dm->data_start; +void *cur_data = argptr; +const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_target_spec) }; +int spec_size =thunk_type_size (arg_type,0 ); +int i; + +for (i =0 ; i < host_dm->target_count; i++) { +uint32_t next = spec->next; +int slen =strlen ((char *)&spec[1 ]) +1 ; + spec->next = (cur_data - argptr) + spec_size + slen; +if (guest_data_size < spec->next) { + host_dm->flags |=DM_BUFFER_FULL_FLAG ; +break ; + } +thunk_convert (cur_data, spec, arg_type,THUNK_TARGET ); +strcpy (cur_data + spec_size, (char *)&spec[1 ]); + cur_data = argptr + spec->next; + spec = (void *)host_dm + host_dm->data_start + next; + } +break ; + } +case DM_TABLE_DEPS : + { +void *hdata = (void *)host_dm + host_dm->data_start; +int count = *(uint32_t *)hdata; +uint64_t *hdev = hdata +8 ; +uint64_t *gdev = argptr +8 ; +int i; + + *(uint32_t *)argptr =tswap32 (count); +for (i =0 ; i < count; i++) { + *gdev =tswap64 (*hdev); + gdev++; + hdev++; + } +break ; + } +case DM_LIST_VERSIONS : + { +struct dm_target_versions *vers + = (void *)host_dm + host_dm->data_start; +uint32_t remaining_data = guest_data_size; +void *cur_data = argptr; +const argtype arg_type[] + = {MK_STRUCT (STRUCT_dm_target_versions) }; +int vers_size =thunk_type_size (arg_type,0 ); + +while (1 ) { +uint32_t next = vers->next; +if (next) { + vers->next = vers_size +strlen (vers->name) +1 ; + } +if (remaining_data < vers->next) { + host_dm->flags |=DM_BUFFER_FULL_FLAG ; +break ; + } +thunk_convert (cur_data, vers, arg_type,THUNK_TARGET ); +strcpy (cur_data + vers_size, vers->name); + cur_data += vers->next; + remaining_data -= vers->next; +if (!next) { +break ; + } + vers = (void *)vers + next; + } +break ; + } +default : +unlock_user (argptr, guest_data,0 ); + ret = -TARGET_EINVAL ; + goto out; + } +unlock_user (argptr, guest_data, guest_data_size); + + argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + goto out; + } +thunk_convert (argptr, buf_temp, arg_type,THUNK_TARGET ); +unlock_user (argptr, arg, target_size); + } +out: +g_free (big_buf); +return ret; +} + +static abi_long do_ioctl_blkpg (const IOCTLEntry *ie,uint8_t *buf_temp,int fd, +int cmd,abi_long arg) +{ +void *argptr; +int target_size; +const argtype *arg_type = ie->arg_type; +const argtype part_arg_type[] = {MK_STRUCT (STRUCT_blkpg_partition) }; +abi_long ret; +struct blkpg_ioctl_arg *host_blkpg = (void *)buf_temp; +struct blkpg_partition host_part; + +/* Read and convert blkpg */ + arg_type++; + target_size =thunk_type_size (arg_type,0 ); + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + goto out; + } +thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + +switch (host_blkpg->op) { +case BLKPG_ADD_PARTITION : +case BLKPG_DEL_PARTITION : +/* payload is struct blkpg_partition */ +break ; +default : +/* Unknown opcode */ + ret = -TARGET_EINVAL ; + goto out; + } + +/* Read and convert blkpg->data */ + arg = (abi_long )(uintptr_t )host_blkpg->data; + target_size =thunk_type_size (part_arg_type,0 ); + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { + ret = -TARGET_EFAULT ; + goto out; + } +thunk_convert (&host_part, argptr, part_arg_type,THUNK_HOST ); +unlock_user (argptr, arg,0 ); + +/* Swizzle the data pointer to our local copy and call! */ + host_blkpg->data = &host_part; + ret =get_errno (safe_ioctl (fd, ie->host_cmd, host_blkpg)); + +out: +return ret; +} + +static abi_long do_ioctl_rt (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +const argtype *arg_type = ie->arg_type; +const StructEntry *se; +const argtype *field_types; +const int *dst_offsets, *src_offsets; +int target_size; +void *argptr; +abi_ulong *target_rt_dev_ptr; +unsigned long *host_rt_dev_ptr; +abi_long ret; +int i; + +assert (ie->access ==IOC_W ); +assert (*arg_type ==TYPE_PTR ); + arg_type++; +assert (*arg_type ==TYPE_STRUCT ); + target_size =thunk_type_size (arg_type,0 ); + argptr =lock_user (VERIFY_READ , arg, target_size,1 ); +if (!argptr) { +return -TARGET_EFAULT ; + } + arg_type++; +assert (*arg_type == (int )STRUCT_rtentry); + se = struct_entries + *arg_type++; +assert (se->convert[0 ] ==NULL ); +/* convert struct here to be able to catch rt_dev string */ + field_types = se->field_types; + dst_offsets = se->field_offsets[THUNK_HOST ]; + src_offsets = se->field_offsets[THUNK_TARGET ]; +for (i =0 ; i < se->nb_fields; i++) { +if (dst_offsets[i] == offsetof(struct rtentry , rt_dev)) { +assert (*field_types ==TYPE_PTRVOID ); + target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]); + host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]); +if (*target_rt_dev_ptr !=0 ) { + *host_rt_dev_ptr = (unsigned long )lock_user_string ( +tswapal (*target_rt_dev_ptr)); +if (!*host_rt_dev_ptr) { +unlock_user (argptr, arg,0 ); +return -TARGET_EFAULT ; + } + }else { + *host_rt_dev_ptr =0 ; + } + field_types++; +continue ; + } + field_types =thunk_convert (buf_temp + dst_offsets[i], + argptr + src_offsets[i], + field_types,THUNK_HOST ); + } +unlock_user (argptr, arg,0 ); + + ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); +if (*host_rt_dev_ptr !=0 ) { +unlock_user ((void *)*host_rt_dev_ptr, + *target_rt_dev_ptr,0 ); + } +return ret; +} + +static abi_long do_ioctl_kdsigaccept (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +int sig =target_to_host_signal (arg); +return get_errno (safe_ioctl (fd, ie->host_cmd, sig)); +} + +#ifdef TIOCGPTPEER +static abi_long do_ioctl_tiocgptpeer (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +int flags =target_to_host_bitmask (arg, fcntl_flags_tbl); +return get_errno (safe_ioctl (fd, ie->host_cmd, flags)); +} +#endif + +static IOCTLEntry ioctl_entries[] = { +#define IOCTL(cmd, access, ...) \ + { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, +#define IOCTL_SPECIAL(cmd, access, dofn, ...) \ + { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } }, +#define IOCTL_IGNORE(cmd) \ + { TARGET_ ## cmd, 0, #cmd }, +#include "ioctls.h" + { 0, 0, }, +}; + +/* ??? Implement proper locking for ioctls. */ +SYSCALL_IMPL(ioctl) +{ + int fd = arg1; + abi_ulong cmd = arg2; + abi_ulong arg = arg3; + const IOCTLEntry *ie; + const argtype *arg_type; + abi_long ret; + uint8_t buf_temp[MAX_STRUCT_SIZE]; + int target_size; + void *argptr; + + for (ie = ioctl_entries; ; ie++) { + if (ie->target_cmd == 0) { + gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); + return -TARGET_ENOSYS; + } + if (ie->target_cmd == cmd) { + break; + } + } + + arg_type = ie->arg_type; + if (ie->do_ioctl) { + return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); + } else if (!ie->host_cmd) { + /* + * Some architectures define BSD ioctls in their headers + * that are not implemented in Linux. + */ + return -TARGET_ENOSYS; + } + + switch (arg_type[0]) { + case TYPE_NULL: + /* no argument */ + ret = get_errno(safe_ioctl(fd, ie->host_cmd)); + break; + case TYPE_PTRVOID: + case TYPE_INT: + ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg)); + break; + case TYPE_PTR: + arg_type++; + target_size = thunk_type_size(arg_type, 0); + switch (ie->access) { + case IOC_R: + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + if (!is_error(ret)) { + argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); + unlock_user(argptr, arg, target_size); + } + break; + case IOC_W: + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + break; + default: + case IOC_RW: + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + if (!is_error(ret)) { + argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); + unlock_user(argptr, arg, target_size); + } + break; + } + break; + default: + gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", + (long)cmd, arg_type[0]); + ret = -TARGET_ENOSYS; + break; + } + return ret; +}linux-user/syscall.c +1
-842@@ -2935,846 +2935,6 @@ STRUCT_MAX#undef STRUCT#undef STRUCT_SPECIAL -typedef struct IOCTLEntry IOCTLEntry ; - -typedef abi_long do_ioctl_fn (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg); - -struct IOCTLEntry { -int target_cmd; -unsigned int host_cmd; -const char *name; -int access; -do_ioctl_fn *do_ioctl; -const argtype arg_type[5 ]; -}; - -#define IOC_R 0x0001 -#define IOC_W 0x0002 -#define IOC_RW (IOC_R | IOC_W) - -#define MAX_STRUCT_SIZE 4096 - -#ifdef CONFIG_FIEMAP -/* So fiemap access checks don't overflow on 32 bit systems. -* This is very slightly smaller than the limit imposed by -* the underlying kernel. -*/ -#define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \ - / sizeof(struct fiemap_extent)) - -static abi_long do_ioctl_fs_ioc_fiemap (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -/* The parameter for this ioctl is a struct fiemap followed -* by an array of struct fiemap_extent whose size is set -* in fiemap->fm_extent_count. The array is filled in by the -* ioctl. -*/ -int target_size_in, target_size_out; -struct fiemap *fm; -const argtype *arg_type = ie->arg_type; -const argtype extent_arg_type[] = {MK_STRUCT (STRUCT_fiemap_extent) }; -void *argptr, *p; -abi_long ret; -int i, extent_size =thunk_type_size (extent_arg_type,0 ); -uint32_t outbufsz; -int free_fm =0 ; - -assert (arg_type[0 ] ==TYPE_PTR ); -assert (ie->access ==IOC_RW ); - arg_type++; - target_size_in =thunk_type_size (arg_type,0 ); - argptr =lock_user (VERIFY_READ , arg, target_size_in,1 ); -if (!argptr) { -return -TARGET_EFAULT ; - } -thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - fm = (struct fiemap *)buf_temp; -if (fm->fm_extent_count >FIEMAP_MAX_EXTENTS ) { -return -TARGET_EINVAL ; - } - - outbufsz =sizeof (*fm) + - (sizeof (struct fiemap_extent ) * fm->fm_extent_count); - -if (outbufsz >MAX_STRUCT_SIZE ) { -/* We can't fit all the extents into the fixed size buffer. -* Allocate one that is large enough and use it instead. -*/ - fm =g_try_malloc (outbufsz); -if (!fm) { -return -TARGET_ENOMEM ; - } -memcpy (fm, buf_temp,sizeof (struct fiemap )); - free_fm =1 ; - } - ret =get_errno (safe_ioctl (fd, ie->host_cmd, fm)); -if (!is_error (ret)) { - target_size_out = target_size_in; -/* An extent_count of 0 means we were only counting the extents -* so there are no structs to copy -*/ -if (fm->fm_extent_count !=0 ) { - target_size_out += fm->fm_mapped_extents * extent_size; - } - argptr =lock_user (VERIFY_WRITE , arg, target_size_out,0 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - }else { -/* Convert the struct fiemap */ -thunk_convert (argptr, fm, arg_type,THUNK_TARGET ); -if (fm->fm_extent_count !=0 ) { - p = argptr + target_size_in; -/* ...and then all the struct fiemap_extents */ -for (i =0 ; i < fm->fm_mapped_extents; i++) { -thunk_convert (p, &fm->fm_extents[i], extent_arg_type, -THUNK_TARGET ); - p += extent_size; - } - } -unlock_user (argptr, arg, target_size_out); - } - } -if (free_fm) { -g_free (fm); - } -return ret; -} -#endif - -static abi_long do_ioctl_ifconf (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -const argtype *arg_type = ie->arg_type; -int target_size; -void *argptr; -int ret; -struct ifconf *host_ifconf; -uint32_t outbufsz; -const argtype ifreq_arg_type[] = {MK_STRUCT (STRUCT_sockaddr_ifreq) }; -int target_ifreq_size; -int nb_ifreq; -int free_buf =0 ; -int i; -int target_ifc_len; -abi_long target_ifc_buf; -int host_ifc_len; -char *host_ifc_buf; - -assert (arg_type[0 ] ==TYPE_PTR ); -assert (ie->access ==IOC_RW ); - - arg_type++; - target_size =thunk_type_size (arg_type,0 ); - - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) -return -TARGET_EFAULT ; -thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - - host_ifconf = (struct ifconf *)(unsigned long )buf_temp; - target_ifc_len = host_ifconf->ifc_len; - target_ifc_buf = (abi_long )(unsigned long )host_ifconf->ifc_buf; - - target_ifreq_size =thunk_type_size (ifreq_arg_type,0 ); - nb_ifreq = target_ifc_len / target_ifreq_size; - host_ifc_len = nb_ifreq *sizeof (struct ifreq ); - - outbufsz =sizeof (*host_ifconf) + host_ifc_len; -if (outbufsz >MAX_STRUCT_SIZE ) { -/* We can't fit all the extents into the fixed size buffer. -* Allocate one that is large enough and use it instead. -*/ - host_ifconf =malloc (outbufsz); -if (!host_ifconf) { -return -TARGET_ENOMEM ; - } -memcpy (host_ifconf, buf_temp,sizeof (*host_ifconf)); - free_buf =1 ; - } - host_ifc_buf = (char *)host_ifconf +sizeof (*host_ifconf); - - host_ifconf->ifc_len = host_ifc_len; - host_ifconf->ifc_buf = host_ifc_buf; - - ret =get_errno (safe_ioctl (fd, ie->host_cmd, host_ifconf)); -if (!is_error (ret)) { -/* convert host ifc_len to target ifc_len */ - - nb_ifreq = host_ifconf->ifc_len /sizeof (struct ifreq ); - target_ifc_len = nb_ifreq * target_ifreq_size; - host_ifconf->ifc_len = target_ifc_len; - -/* restore target ifc_buf */ - - host_ifconf->ifc_buf = (char *)(unsigned long )target_ifc_buf; - -/* copy struct ifconf to target user */ - - argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); -if (!argptr) -return -TARGET_EFAULT ; -thunk_convert (argptr, host_ifconf, arg_type,THUNK_TARGET ); -unlock_user (argptr, arg, target_size); - -/* copy ifreq[] to target user */ - - argptr =lock_user (VERIFY_WRITE , target_ifc_buf, target_ifc_len,0 ); -for (i =0 ; i < nb_ifreq ; i++) { -thunk_convert (argptr + i * target_ifreq_size, - host_ifc_buf + i *sizeof (struct ifreq ), - ifreq_arg_type,THUNK_TARGET ); - } -unlock_user (argptr, target_ifc_buf, target_ifc_len); - } - -if (free_buf) { -free (host_ifconf); - } - -return ret; -} - -#if defined(CONFIG_USBFS ) -#if HOST_LONG_BITS >64 -#error USBDEVFS thunks do not support >64 bit hosts yet. -#endif -struct live_urb { -uint64_t target_urb_adr; -uint64_t target_buf_adr; -char *target_buf_ptr; -struct usbdevfs_urb host_urb; -}; - -static GHashTable *usbdevfs_urb_hashtable (void ) -{ -static GHashTable *urb_hashtable; - -if (!urb_hashtable) { - urb_hashtable =g_hash_table_new (g_int64_hash, g_int64_equal); - } -return urb_hashtable; -} - -static void urb_hashtable_insert (struct live_urb *urb) -{ -GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); -g_hash_table_insert (urb_hashtable, urb, urb); -} - -static struct live_urb *urb_hashtable_lookup (uint64_t target_urb_adr) -{ -GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); -return g_hash_table_lookup (urb_hashtable, &target_urb_adr); -} - -static void urb_hashtable_remove (struct live_urb *urb) -{ -GHashTable *urb_hashtable =usbdevfs_urb_hashtable (); -g_hash_table_remove (urb_hashtable, urb); -} - -static abi_long -do_ioctl_usbdevfs_reapurb (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -const argtype usbfsurb_arg_type[] = {MK_STRUCT (STRUCT_usbdevfs_urb) }; -const argtype ptrvoid_arg_type[] = {TYPE_PTRVOID ,0 ,0 }; -struct live_urb *lurb; -void *argptr; -uint64_t hurb; -int target_size; -uintptr_t target_urb_adr; -abi_long ret; - - target_size =thunk_type_size (usbfsurb_arg_type,THUNK_TARGET ); - -memset (buf_temp,0 ,sizeof (uint64_t )); - ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); -if (is_error (ret)) { -return ret; - } - -memcpy (&hurb, buf_temp,sizeof (uint64_t )); - lurb = (void *)((uintptr_t )hurb - offsetof(struct live_urb , host_urb)); -if (!lurb->target_urb_adr) { -return -TARGET_EFAULT ; - } -urb_hashtable_remove (lurb); -unlock_user (lurb->target_buf_ptr, lurb->target_buf_adr, - lurb->host_urb.buffer_length); - lurb->target_buf_ptr =NULL ; - -/* restore the guest buffer pointer */ - lurb->host_urb.buffer = (void *)(uintptr_t )lurb->target_buf_adr; - -/* update the guest urb struct */ - argptr =lock_user (VERIFY_WRITE , lurb->target_urb_adr, target_size,0 ); -if (!argptr) { -g_free (lurb); -return -TARGET_EFAULT ; - } -thunk_convert (argptr, &lurb->host_urb, usbfsurb_arg_type,THUNK_TARGET ); -unlock_user (argptr, lurb->target_urb_adr, target_size); - - target_size =thunk_type_size (ptrvoid_arg_type,THUNK_TARGET ); -/* write back the urb handle */ - argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); -if (!argptr) { -g_free (lurb); -return -TARGET_EFAULT ; - } - -/* GHashTable uses 64-bit keys but thunk_convert expects uintptr_t */ - target_urb_adr = lurb->target_urb_adr; -thunk_convert (argptr, &target_urb_adr, ptrvoid_arg_type,THUNK_TARGET ); -unlock_user (argptr, arg, target_size); - -g_free (lurb); -return ret; -} - -static abi_long -do_ioctl_usbdevfs_discardurb (const IOCTLEntry *ie, -uint8_t *buf_temp __attribute__((unused)), -int fd,int cmd,abi_long arg) -{ -struct live_urb *lurb; - -/* map target address back to host URB with metadata. */ - lurb =urb_hashtable_lookup (arg); -if (!lurb) { -return -TARGET_EFAULT ; - } -return get_errno (safe_ioctl (fd, ie->host_cmd, &lurb->host_urb)); -} - -static abi_long -do_ioctl_usbdevfs_submiturb (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -const argtype *arg_type = ie->arg_type; -int target_size; -abi_long ret; -void *argptr; -int rw_dir; -struct live_urb *lurb; - -/* -* each submitted URB needs to map to a unique ID for the -* kernel, and that unique ID needs to be a pointer to -* host memory. hence, we need to malloc for each URB. -* isochronous transfers have a variable length struct. -*/ - arg_type++; - target_size =thunk_type_size (arg_type,THUNK_TARGET ); - -/* construct host copy of urb and metadata */ - lurb =g_try_malloc0 (sizeof (struct live_urb )); -if (!lurb) { -return -TARGET_ENOMEM ; - } - - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) { -g_free (lurb); -return -TARGET_EFAULT ; - } -thunk_convert (&lurb->host_urb, argptr, arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - - lurb->target_urb_adr = arg; - lurb->target_buf_adr = (uintptr_t )lurb->host_urb.buffer; - -/* buffer space used depends on endpoint type so lock the entire buffer */ -/* control type urbs should check the buffer contents for true direction */ - rw_dir = lurb->host_urb.endpoint &USB_DIR_IN ?VERIFY_WRITE :VERIFY_READ ; - lurb->target_buf_ptr =lock_user (rw_dir, lurb->target_buf_adr, - lurb->host_urb.buffer_length,1 ); -if (lurb->target_buf_ptr ==NULL ) { -g_free (lurb); -return -TARGET_EFAULT ; - } - -/* update buffer pointer in host copy */ - lurb->host_urb.buffer = lurb->target_buf_ptr; - - ret =get_errno (safe_ioctl (fd, ie->host_cmd, &lurb->host_urb)); -if (is_error (ret)) { -unlock_user (lurb->target_buf_ptr, lurb->target_buf_adr,0 ); -g_free (lurb); - }else { -urb_hashtable_insert (lurb); - } - -return ret; -} -#endif /* CONFIG_USBFS */ - -static abi_long do_ioctl_dm (const IOCTLEntry *ie,uint8_t *buf_temp,int fd, -int cmd,abi_long arg) -{ -void *argptr; -struct dm_ioctl *host_dm; -abi_long guest_data; -uint32_t guest_data_size; -int target_size; -const argtype *arg_type = ie->arg_type; -abi_long ret; -void *big_buf =NULL ; -char *host_data; - - arg_type++; - target_size =thunk_type_size (arg_type,0 ); - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - goto out; - } -thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - -/* buf_temp is too small, so fetch things into a bigger buffer */ - big_buf =g_malloc0 (((struct dm_ioctl *)buf_temp)->data_size *2 ); -memcpy (big_buf, buf_temp, target_size); - buf_temp = big_buf; - host_dm = big_buf; - - guest_data = arg + host_dm->data_start; -if ((guest_data - arg) <0 ) { - ret = -TARGET_EINVAL ; - goto out; - } - guest_data_size = host_dm->data_size - host_dm->data_start; - host_data = (char *)host_dm + host_dm->data_start; - - argptr =lock_user (VERIFY_READ , guest_data, guest_data_size,1 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - goto out; - } - -switch (ie->host_cmd) { -case DM_REMOVE_ALL : -case DM_LIST_DEVICES : -case DM_DEV_CREATE : -case DM_DEV_REMOVE : -case DM_DEV_SUSPEND : -case DM_DEV_STATUS : -case DM_DEV_WAIT : -case DM_TABLE_STATUS : -case DM_TABLE_CLEAR : -case DM_TABLE_DEPS : -case DM_LIST_VERSIONS : -/* no input data */ -break ; -case DM_DEV_RENAME : -case DM_DEV_SET_GEOMETRY : -/* data contains only strings */ -memcpy (host_data, argptr, guest_data_size); -break ; -case DM_TARGET_MSG : -memcpy (host_data, argptr, guest_data_size); - *(uint64_t *)host_data =tswap64 (*(uint64_t *)argptr); -break ; -case DM_TABLE_LOAD : - { -void *gspec = argptr; -void *cur_data = host_data; -const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_target_spec) }; -int spec_size =thunk_type_size (arg_type,0 ); -int i; - -for (i =0 ; i < host_dm->target_count; i++) { -struct dm_target_spec *spec = cur_data; -uint32_t next; -int slen; - -thunk_convert (spec, gspec, arg_type,THUNK_HOST ); - slen =strlen ((char *)gspec + spec_size) +1 ; - next = spec->next; - spec->next =sizeof (*spec) + slen; -strcpy ((char *)&spec[1 ], gspec + spec_size); - gspec += next; - cur_data += spec->next; - } -break ; - } -default : - ret = -TARGET_EINVAL ; -unlock_user (argptr, guest_data,0 ); - goto out; - } -unlock_user (argptr, guest_data,0 ); - - ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); -if (!is_error (ret)) { - guest_data = arg + host_dm->data_start; - guest_data_size = host_dm->data_size - host_dm->data_start; - argptr =lock_user (VERIFY_WRITE , guest_data, guest_data_size,0 ); -switch (ie->host_cmd) { -case DM_REMOVE_ALL : -case DM_DEV_CREATE : -case DM_DEV_REMOVE : -case DM_DEV_RENAME : -case DM_DEV_SUSPEND : -case DM_DEV_STATUS : -case DM_TABLE_LOAD : -case DM_TABLE_CLEAR : -case DM_TARGET_MSG : -case DM_DEV_SET_GEOMETRY : -/* no return data */ -break ; -case DM_LIST_DEVICES : - { -struct dm_name_list *nl = (void *)host_dm + host_dm->data_start; -uint32_t remaining_data = guest_data_size; -void *cur_data = argptr; -const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_name_list) }; -int nl_size =12 ;/* can't use thunk_size due to alignment */ - -while (1 ) { -uint32_t next = nl->next; -if (next) { - nl->next = nl_size + (strlen (nl->name) +1 ); - } -if (remaining_data < nl->next) { - host_dm->flags |=DM_BUFFER_FULL_FLAG ; -break ; - } -thunk_convert (cur_data, nl, arg_type,THUNK_TARGET ); -strcpy (cur_data + nl_size, nl->name); - cur_data += nl->next; - remaining_data -= nl->next; -if (!next) { -break ; - } - nl = (void *)nl + next; - } -break ; - } -case DM_DEV_WAIT : -case DM_TABLE_STATUS : - { -struct dm_target_spec *spec = (void *)host_dm + host_dm->data_start; -void *cur_data = argptr; -const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_target_spec) }; -int spec_size =thunk_type_size (arg_type,0 ); -int i; - -for (i =0 ; i < host_dm->target_count; i++) { -uint32_t next = spec->next; -int slen =strlen ((char *)&spec[1 ]) +1 ; - spec->next = (cur_data - argptr) + spec_size + slen; -if (guest_data_size < spec->next) { - host_dm->flags |=DM_BUFFER_FULL_FLAG ; -break ; - } -thunk_convert (cur_data, spec, arg_type,THUNK_TARGET ); -strcpy (cur_data + spec_size, (char *)&spec[1 ]); - cur_data = argptr + spec->next; - spec = (void *)host_dm + host_dm->data_start + next; - } -break ; - } -case DM_TABLE_DEPS : - { -void *hdata = (void *)host_dm + host_dm->data_start; -int count = *(uint32_t *)hdata; -uint64_t *hdev = hdata +8 ; -uint64_t *gdev = argptr +8 ; -int i; - - *(uint32_t *)argptr =tswap32 (count); -for (i =0 ; i < count; i++) { - *gdev =tswap64 (*hdev); - gdev++; - hdev++; - } -break ; - } -case DM_LIST_VERSIONS : - { -struct dm_target_versions *vers = (void *)host_dm + host_dm->data_start; -uint32_t remaining_data = guest_data_size; -void *cur_data = argptr; -const argtype arg_type[] = {MK_STRUCT (STRUCT_dm_target_versions) }; -int vers_size =thunk_type_size (arg_type,0 ); - -while (1 ) { -uint32_t next = vers->next; -if (next) { - vers->next = vers_size + (strlen (vers->name) +1 ); - } -if (remaining_data < vers->next) { - host_dm->flags |=DM_BUFFER_FULL_FLAG ; -break ; - } -thunk_convert (cur_data, vers, arg_type,THUNK_TARGET ); -strcpy (cur_data + vers_size, vers->name); - cur_data += vers->next; - remaining_data -= vers->next; -if (!next) { -break ; - } - vers = (void *)vers + next; - } -break ; - } -default : -unlock_user (argptr, guest_data,0 ); - ret = -TARGET_EINVAL ; - goto out; - } -unlock_user (argptr, guest_data, guest_data_size); - - argptr =lock_user (VERIFY_WRITE , arg, target_size,0 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - goto out; - } -thunk_convert (argptr, buf_temp, arg_type,THUNK_TARGET ); -unlock_user (argptr, arg, target_size); - } -out: -g_free (big_buf); -return ret; -} - -static abi_long do_ioctl_blkpg (const IOCTLEntry *ie,uint8_t *buf_temp,int fd, -int cmd,abi_long arg) -{ -void *argptr; -int target_size; -const argtype *arg_type = ie->arg_type; -const argtype part_arg_type[] = {MK_STRUCT (STRUCT_blkpg_partition) }; -abi_long ret; - -struct blkpg_ioctl_arg *host_blkpg = (void *)buf_temp; -struct blkpg_partition host_part; - -/* Read and convert blkpg */ - arg_type++; - target_size =thunk_type_size (arg_type,0 ); - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - goto out; - } -thunk_convert (buf_temp, argptr, arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - -switch (host_blkpg->op) { -case BLKPG_ADD_PARTITION : -case BLKPG_DEL_PARTITION : -/* payload is struct blkpg_partition */ -break ; -default : -/* Unknown opcode */ - ret = -TARGET_EINVAL ; - goto out; - } - -/* Read and convert blkpg->data */ - arg = (abi_long )(uintptr_t )host_blkpg->data; - target_size =thunk_type_size (part_arg_type,0 ); - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) { - ret = -TARGET_EFAULT ; - goto out; - } -thunk_convert (&host_part, argptr, part_arg_type,THUNK_HOST ); -unlock_user (argptr, arg,0 ); - -/* Swizzle the data pointer to our local copy and call! */ - host_blkpg->data = &host_part; - ret =get_errno (safe_ioctl (fd, ie->host_cmd, host_blkpg)); - -out: -return ret; -} - -static abi_long do_ioctl_rt (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -const argtype *arg_type = ie->arg_type; -const StructEntry *se; -const argtype *field_types; -const int *dst_offsets, *src_offsets; -int target_size; -void *argptr; -abi_ulong *target_rt_dev_ptr; -unsigned long *host_rt_dev_ptr; -abi_long ret; -int i; - -assert (ie->access ==IOC_W ); -assert (*arg_type ==TYPE_PTR ); - arg_type++; -assert (*arg_type ==TYPE_STRUCT ); - target_size =thunk_type_size (arg_type,0 ); - argptr =lock_user (VERIFY_READ , arg, target_size,1 ); -if (!argptr) { -return -TARGET_EFAULT ; - } - arg_type++; -assert (*arg_type == (int )STRUCT_rtentry); - se = struct_entries + *arg_type++; -assert (se->convert[0 ] ==NULL ); -/* convert struct here to be able to catch rt_dev string */ - field_types = se->field_types; - dst_offsets = se->field_offsets[THUNK_HOST ]; - src_offsets = se->field_offsets[THUNK_TARGET ]; -for (i =0 ; i < se->nb_fields; i++) { -if (dst_offsets[i] == offsetof(struct rtentry , rt_dev)) { -assert (*field_types ==TYPE_PTRVOID ); - target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]); - host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]); -if (*target_rt_dev_ptr !=0 ) { - *host_rt_dev_ptr = (unsigned long )lock_user_string ( -tswapal (*target_rt_dev_ptr)); -if (!*host_rt_dev_ptr) { -unlock_user (argptr, arg,0 ); -return -TARGET_EFAULT ; - } - }else { - *host_rt_dev_ptr =0 ; - } - field_types++; -continue ; - } - field_types =thunk_convert (buf_temp + dst_offsets[i], - argptr + src_offsets[i], - field_types,THUNK_HOST ); - } -unlock_user (argptr, arg,0 ); - - ret =get_errno (safe_ioctl (fd, ie->host_cmd, buf_temp)); -if (*host_rt_dev_ptr !=0 ) { -unlock_user ((void *)*host_rt_dev_ptr, - *target_rt_dev_ptr,0 ); - } -return ret; -} - -static abi_long do_ioctl_kdsigaccept (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -int sig =target_to_host_signal (arg); -return get_errno (safe_ioctl (fd, ie->host_cmd, sig)); -} - -#ifdef TIOCGPTPEER -static abi_long do_ioctl_tiocgptpeer (const IOCTLEntry *ie,uint8_t *buf_temp, -int fd,int cmd,abi_long arg) -{ -int flags =target_to_host_bitmask (arg, fcntl_flags_tbl); -return get_errno (safe_ioctl (fd, ie->host_cmd, flags)); -} -#endif - -static IOCTLEntry ioctl_entries[] = { -#define IOCTL(cmd, access, ...) \ - { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, -#define IOCTL_SPECIAL(cmd, access, dofn, ...) \ - { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } }, -#define IOCTL_IGNORE(cmd) \ - { TARGET_ ## cmd, 0, #cmd }, -#include "ioctls.h" - { 0, 0, }, -}; - -/* ??? Implement proper locking for ioctls. */ -/* do_ioctl() Must return target values and target errnos. */ -static abi_long do_ioctl(int fd, int cmd, abi_long arg) -{ - const IOCTLEntry *ie; - const argtype *arg_type; - abi_long ret; - uint8_t buf_temp[MAX_STRUCT_SIZE]; - int target_size; - void *argptr; - - ie = ioctl_entries; - for(;;) { - if (ie->target_cmd == 0) { - gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); - return -TARGET_ENOSYS; - } - if (ie->target_cmd == cmd) - break; - ie++; - } - arg_type = ie->arg_type; - if (ie->do_ioctl) { - return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); - } else if (!ie->host_cmd) { - /* Some architectures define BSD ioctls in their headers - that are not implemented in Linux. */ - return -TARGET_ENOSYS; - } - - switch(arg_type[0]) { - case TYPE_NULL: - /* no argument */ - ret = get_errno(safe_ioctl(fd, ie->host_cmd)); - break; - case TYPE_PTRVOID: - case TYPE_INT: - ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg)); - break; - case TYPE_PTR: - arg_type++; - target_size = thunk_type_size(arg_type, 0); - switch(ie->access) { - case IOC_R: - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - if (!is_error(ret)) { - argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); - unlock_user(argptr, arg, target_size); - } - break; - case IOC_W: - argptr = lock_user(VERIFY_READ, arg, target_size, 1); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); - unlock_user(argptr, arg, 0); - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - break; - default: - case IOC_RW: - argptr = lock_user(VERIFY_READ, arg, target_size, 1); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); - unlock_user(argptr, arg, 0); - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - if (!is_error(ret)) { - argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); - unlock_user(argptr, arg, target_size); - } - break; - } - break; - default: - gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", - (long)cmd, arg_type[0]); - ret = -TARGET_ENOSYS; - break; - } - return ret; -} -static const bitmask_transtbl iflag_tbl[] = { {TARGET_IGNBRK ,TARGET_IGNBRK ,IGNBRK ,IGNBRK }, {TARGET_BRKINT ,TARGET_BRKINT ,BRKINT ,BRKINT },@@ -5241,8 +4401,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,void *p;switch (num) { -case TARGET_NR_ioctl: -return do_ioctl (arg1, arg2, arg3);#ifdef TARGET_NR_fcntlcase TARGET_NR_fcntl:return do_fcntl (arg1, arg2, arg3);@@ -8811,6 +7969,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, int64_t arg5, int64_t arg6)#include "syscall-file.inc.c" +#include "syscall-ioctl.inc.c" #include "syscall-ipc.inc.c" #include "syscall-mem.inc.c" #include "syscall-proc.inc.c" linux-user/strace.list +0
-3@@ -365,9 +365,6 @@ #ifdef TARGET_NR_io_cancel { TARGET_NR_io_cancel, "io_cancel" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_ioctl -{ TARGET_NR_ioctl, "ioctl" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_io_destroy { TARGET_NR_io_destroy, "io_destroy" , NULL, NULL, NULL }, #endif
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 11 lines · Laurent Vivier
Hi,
this one is really a cut'n'paste but it introduces a problem with qemu-alpha, I don't know how/why:
$ sudo unshare --ipc --uts --pid --fork --kill-child --mount chroot chroot/alpha/sid/ Unsupported ioctl: cmd=0x80047476And then it hangs.
I'll try to debug.
In fact it happens with sid, with ppc64 too, but not with m68k and sh4.
And only with "unshare --pid --fork".
Without "unshare", the result is:
Unsupported ioctl: cmd=0x80047476
bash: cannot set terminal process group (11507): Function not implemented
bash: no job control in this shell
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x802c7415
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 17 lines · Laurent Vivier
Quoted 11 lines · Laurent Vivier
Hi,
this one is really a cut'n'paste but it introduces a problem with qemu-alpha, I don't know how/why:
$ sudo unshare --ipc --uts --pid --fork --kill-child --mount chroot chroot/alpha/sid/ Unsupported ioctl: cmd=0x80047476And then it hangs.
I'll try to debug.
In fact it happens with sid, with ppc64 too, but not with m68k and sh4.
And only with "unshare --pid --fork".
Quoted 8 lines
Without "unshare", the result is:
Unsupported ioctl: cmd=0x80047476
bash: cannot set terminal process group (11507): Function not implemented
bash: no job control in this shell
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x802c7415
I'm just now getting back to this, and cannot replicate the issue, at least rebased onto master. With or without unshare, I see your "without unshare" results.
The rebase onto master is at
https://github.com/rth7680/qemu.git lu-split-6
r~
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Laurent Vivier
In fact it happens with sid, with ppc64 too, but not with m68k and sh4.
And only with "unshare --pid --fork".
Without "unshare", the result is:
Quoted 8 lines
Quoted 6 lines
Unsupported ioctl: cmd=0x80047476
bash: cannot set terminal process group (11507): Function not implemented
bash: no job control in this shell
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x802c7415I'm just now getting back to this, and cannot replicate the issue
... Oh nevermind. I should be expecting no "unsupported" at all, since that's what we get with master.
r~
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 15 lines · Richard Henderson
Quoted 14 lines · Richard Henderson
Quoted 12 lines · Laurent Vivier
In fact it happens with sid, with ppc64 too, but not with m68k and sh4.
And only with "unshare --pid --fork".
Without "unshare", the result is:
Unsupported ioctl: cmd=0x80047476
bash: cannot set terminal process group (11507): Function not implemented
bash: no job control in this shell
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x80087467
Unsupported ioctl: cmd=0x802c7415
Quoted 4 lines
Quoted 1 line
I'm just now getting back to this, and cannot replicate the issue
... Oh nevermind. I should be expecting no "unsupported" at all, since that's what we get with master.
The cause is that "cmd" accidentally changed from "int" in the do_ioctl parameter list to "abi_ulong" as a local variable in impl_ioctl. This caused a table lookup failure on any ioctl with bit 31 set, for 64-bit guests.
r~
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 16 lines · Richard Henderson
Quoted 15 lines · Richard Henderson
Quoted 14 lines · Richard Henderson
Quoted 12 lines · Laurent Vivier
In fact it happens with sid, with ppc64 too, but not with m68k and sh4.
And only with "unshare --pid --fork".
Without "unshare", the result is:
Unsupported ioctl: cmd=0x80047476 bash: cannot set terminal process group (11507): Function not implemented bash: no job control in this shell Unsupported ioctl: cmd=0x80087467 Unsupported ioctl: cmd=0x80087467 Unsupported ioctl: cmd=0x802c7415
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I'm just now getting back to this, and cannot replicate the issue
... Oh nevermind. I should be expecting no "unsupported" at all, since that's what we get with master.
The cause is that "cmd" accidentally changed from "int" in the
do_ioctlparameter list to "abi_ulong" as a local variable inimpl_ioctl. This caused a table lookup failure on any ioctl with bit 31 set, for 64-bit guests.
Do you plan to send a new version of this series?
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl
Quoted 1 line · Laurent Vivier
Do you plan to send a new version of this series?
Yes. Soon(tm).
r~
PATCH v6 49/49 linux-user: Split out fcntl, fcntl64
In reply to Richard HendersonPreserving strace functionality is tricky with this one. Rearrange to lookup structures that contain the data for both execution and strace for each command.
Do not allow lookup of 64-bit fcntl commands from 32-bit fcntl.
--- linux-user/syscall-defs.h | 6 + linux-user/strace.c | 100 ---------- linux-user/syscall-fcntl.inc.c | 322 +++++++++++++++++++++++++++++++++ linux-user/syscall.c | 256 +------------------------- linux-user/strace.list | 6 - 5 files changed, 329 insertions(+), 361 deletions(-) create mode 100644 linux-user/syscall-fcntl.inc.c
linux-user/syscall-defs.h +6 -0
@@ -46,6 +46,12 @@ SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);SYSCALL_DEF (faccessat,ARG_ATDIRFD ,ARG_STR ,ARG_ACCESSFLAG );SYSCALL_DEF (fchmod,ARG_DEC ,ARG_MODEFLAG );SYSCALL_DEF (fchmodat,ARG_ATDIRFD ,ARG_STR ,ARG_MODEFLAG ); +#ifdef TARGET_NR_fcntl +SYSCALL_DEF_FULL(fcntl, .impl = impl_fcntl, .print = print_fcntl); +#endif +#if TARGET_ABI_BITS ==32 +SYSCALL_DEF_FULL(fcntl64, .impl = impl_fcntl64, .print = print_fcntl64); +#endif #ifdef TARGET_NR_futimesatSYSCALL_DEF (futimesat,ARG_ATDIRFD ,ARG_STR ,ARG_PTR );#endif
linux-user/strace.c +0 -100
106 lines not on this page · raw message
linux-user/syscall-fcntl.inc.c new file +322 -0
322 lines not on this page · raw message
linux-user/syscall.c +1 -255
286 lines not on this page · raw message
linux-user/strace.list +0 -6
@@ -157,12 +157,6 @@ #ifdef TARGET_NR_fchownat { TARGET_NR_fchownat, "fchownat" , NULL, print_fchownat, NULL }, #endif -#ifdef TARGET_NR_fcntl -{ TARGET_NR_fcntl, "fcntl" , NULL, print_fcntl, NULL }, -#endif -#ifdef TARGET_NR_fcntl64 -{ TARGET_NR_fcntl64, "fcntl64" , NULL, print_fcntl64, NULL }, -#endif #ifdef TARGET_NR_fdatasync { TARGET_NR_fdatasync, "fdatasync" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.17.2