Misc linux-user updates
From: Riku Voipio <[email protected]>
The following changes since commit 9964e96dc9999cf7f7c936ee854a795415d19b60:
Merge remote-tracking branch 'jasowang/tags/net-pull-request' into staging (2017-05-23 15:01:31 +0100)
are available in the git repository at:
git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20170531
for you to fetch changes up to ba9fcea1cb6d80536f780760d870416fe5b85863:
linux-user: add strace support for uinfo structure of rt_sigqueueinfo() and rt_tgsigqueueinfo() (2017-05-29 14:56:09 +0300)
----------------------------------------------------------------
Misc linux-user updates
----------------------------------------------------------------
Andreas Schwab (1):
linux-user: remove all traces of qemu from /proc/self/cmdline
Laurent Vivier (4):
linux-user: call fd_trans_target_to_host_data() for write()
linux-user: fix eventfd
linux-user: fix fadvise64_64() on ppc
linux-user: fix inotify
Miloš Stojanović (9):
linux-user: add strace for getuid(), gettid(), getppid(), geteuid()
linux-user: add tkill(), tgkill() and rt_sigqueueinfo() strace
linux-user: fix ssetmask() system call
linux-user: fix mismatch of lock/unlock_user() invocations in
rt_sigqueinfo() syscall
linux-user: fix argument type declaration of rt_sigqueinfo() syscall
linux-user: add support for rt_tgsigqueueinfo() system call
linux-user: add rt_tgsigqueueinfo() strace
linux-user: fix inconsistent spaces in print_siginfo() output
linux-user: add strace support for uinfo structure of
rt_sigqueueinfo() and rt_tgsigqueueinfo()
Prasad J Pandit (1):
linux-user: allocate heap memory for execve arguments
linux-user/strace.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++-- linux-user/strace.list | 16 ++--- linux-user/syscall.c | 161 ++++++++++++++++++++++++++++---------------- 3 files changed, 284 insertions(+), 70 deletions(-)
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 01/15] linux-user: call fd_trans_target_to_host_data() for write()
From: Laurent Vivier <[email protected]>
As for sendmsg() or sendto(), we must call the target to host data translator if it is defined. This is needed for eventfd(): the write() syscall allows to add a value to the internal counter, and so, it must be byte-swapped to the host order.
--- linux-user/syscall.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
linux-user/syscall.c +11 -1
@@ -7767,7 +7767,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_write:if (!(p =lock_user (VERIFY_READ , arg2, arg3,1 ))) goto efault; - ret =get_errno (safe_write (arg1, p, arg3)); +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 );break ;#ifdef TARGET_NR_open
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 02/15] linux-user: fix eventfd
In reply to [email protected]From: Laurent Vivier <[email protected]>
When a fd is opened using eventfd(), a read provides a 64bit counter in the host byte order, and a write increase the internal counter by the provided 64bit value.
--- linux-user/syscall.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
linux-user/syscall.c +24 -2
@@ -7671,6 +7671,28 @@ static target_timer_t get_timer_id(abi_long arg)return timerid; } +static abi_long swap_data_eventfd (void *buf,size_t len) +{ +uint64_t *counter = buf; +int i; + +if (len <sizeof (uint64_t )) { +return -EINVAL ; + } + +for (i =0 ; i < len; i +=sizeof (uint64_t )) { + *counter =tswap64 (*counter); + counter++; + } + +return len; +} + +static TargetFdTrans target_eventfd_trans = { + .host_to_target_data = swap_data_eventfd, + .target_to_host_data = swap_data_eventfd, +}; +/* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -11876,7 +11898,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#if defined(TARGET_NR_eventfd)case TARGET_NR_eventfd: ret =get_errno (eventfd (arg1,0 )); -fd_trans_unregister (ret); +fd_trans_register (ret, &target_eventfd_trans);break ;#endif #if defined(TARGET_NR_eventfd2)
@@ -11890,7 +11912,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, host_flags |= O_CLOEXEC; } ret =get_errno (eventfd (arg1, host_flags)); -fd_trans_unregister (ret); +fd_trans_register (ret, &target_eventfd_trans);break ; }#endif
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 03/15] linux-user: fix fadvise64_64() on ppc
In reply to [email protected]From: Laurent Vivier <[email protected]>
On ppc, advice is arg2, not arg6:
long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
u32 len_high, u32 len_low)
--- linux-user/syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
linux-user/syscall.c +10 -0
@@ -11261,6 +11261,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_fadvise64_64 case TARGET_NR_fadvise64_64: +#if defined(TARGET_PPC) + /* 6 args: fd, advice, offset (high, low), len (high, low) */ + ret = arg2; + arg2 = arg3; + arg3 = arg4; + arg4 = arg5; + arg5 = arg6; + arg6 = ret; +#else /* 6 args: fd, offset (high, low), len (high, low), advice */ if (regpairs_aligned(cpu_env)) { /* offset is in (3,4), len in (5,6) and advice in 7 */
@@ -11270,6 +11279,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg5 = arg6; arg6 = arg7; } +#endif ret = -host_to_target_errno(posix_fadvise(arg1, target_offset64(arg2, arg3), target_offset64(arg4, arg5),
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 04/15] linux-user: fix inotify
In reply to [email protected]From: Laurent Vivier <[email protected]>
When a fd is opened using inotify_init(), a read provides one or more inotify_event structures:
struct inotify_event {
int wd;
uint32_t mask;
uint32_t cookie;
uint32_t len;
char name[];
};The integer fields must be byte-swapped to the target endianness.
--- linux-user/syscall.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
linux-user/syscall.c +29 -0
@@ -7693,6 +7693,33 @@ static TargetFdTrans target_eventfd_trans = { .target_to_host_data = swap_data_eventfd, }; +#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \ + (defined(CONFIG_INOTIFY1 ) && defined(TARGET_NR_inotify_init1) && \ + defined(__NR_inotify_init1)) +static abi_long host_to_target_data_inotify (void *buf,size_t len) +{ +struct inotify_event *ev; +int i; +uint32_t name_len; + +for (i =0 ; i < len; i +=sizeof (struct inotify_event ) + name_len) { + ev = (struct inotify_event *)((char *)buf + i); + name_len = ev->len; + + ev->wd =tswap32 (ev->wd); + ev->mask =tswap32 (ev->mask); + ev->cookie =tswap32 (ev->cookie); + ev->len =tswap32 (name_len); + } + +return len; +} + +static TargetFdTrans target_inotify_trans = { + .host_to_target_data = host_to_target_data_inotify, +}; +#endif +/* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -11736,6 +11763,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)case TARGET_NR_inotify_init: ret =get_errno (sys_inotify_init ()); +fd_trans_register (ret, &target_inotify_trans);break ;#endif #ifdef CONFIG_INOTIFY1
@@ -11743,6 +11771,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_inotify_init1: ret =get_errno (sys_inotify_init1 (target_to_host_bitmask (arg1, fcntl_flags_tbl))); +fd_trans_register (ret, &target_inotify_trans);break ;#endif #endif
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 06/15] linux-user: remove all traces of qemu from /proc/self/cmdline
In reply to [email protected]From: Andreas Schwab <[email protected]>
Instead of post-processing the real contents use the remembered target argv. That removes all traces of qemu, including command line options, and handles QEMU_ARGV0.
--- linux-user/syscall.c | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-)
linux-user/syscall.c +7 -40
@@ -7358,52 +7358,19 @@ int host_to_target_waitstatus(int status)static int open_self_cmdline (void *cpu_env,int fd) { -int fd_orig =-1 ; -bool word_skipped = false; - - fd_orig =open ("/proc/self/cmdline" ,O_RDONLY ); -if (fd_orig <0 ) { -return fd_orig; - } +CPUState *cpu =ENV_GET_CPU ((CPUArchState *)cpu_env); +struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm; +int i; -while (true) { -ssize_t nb_read; -char buf[128 ]; -char *cp_buf = buf; +for (i =0 ; i < bprm->argc; i++) { +size_t len =strlen (bprm->argv[i]) +1 ; - nb_read =read (fd_orig, buf,sizeof (buf)); -if (nb_read <0 ) { -int e = errno; - fd_orig =close (fd_orig); - errno = e; +if (write (fd, bprm->argv[i], len) != len) {return -1 ; - }else if (nb_read ==0 ) { -break ; - } - -if (!word_skipped) { -/* Skip the first string, which is the path to qemu-*-static -instead of the actual command. */ - cp_buf =memchr (buf,0 , nb_read); -if (cp_buf) { -/* Null byte found, skip one string */ - cp_buf++; - nb_read -= cp_buf - buf; - word_skipped = true; - } - } - -if (word_skipped) { -if (write (fd, cp_buf, nb_read) != nb_read) { -int e = errno; -close (fd_orig); - errno = e; -return -1 ; - } } } -return close (fd_orig); +return 0 ; }static int open_self_maps (void *cpu_env,int fd)
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 05/15] linux-user: allocate heap memory for execve arguments
In reply to [email protected]From: Prasad J Pandit <[email protected]>
Arguments passed to execve(2) call from user program could be large, allocating stack memory for them via alloca(3) call would lead to bad behaviour. Use 'g_new0' to allocate memory for such arguments.
--- linux-user/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
linux-user/syscall.c +5 -2
@@ -7985,8 +7985,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, envc++; } - argp =alloca ((argc +1 ) *sizeof (void *)); - envp =alloca ((envc +1 ) *sizeof (void *)); + argp = g_new0(char *, argc + 1); + envp = g_new0(char *, envc + 1);for (gp = guest_argp, q = argp; gp; gp +=sizeof (abi_ulong), q++) {
@@ -8047,6 +8047,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;unlock_user (*q, addr,0 ); } + +g_free (argp); +g_free (envp); }break ;case TARGET_NR_chdir:
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 08/15] linux-user: add tkill(), tgkill() and rt_sigqueueinfo() strace
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Improve strace support for syscall tkill(), tgkill() and rt_sigqueueinfo() by implementing print functions that match arguments types of the system calls and add them to the corresponding starce.list entry.
tkill:
Prior to this commit, typical strace output used to look like this:
4886 tkill(4886,50,0,4832615904,0,-9151031864016699136) = 0 After this commit, it looks like this:
4886 tkill(4886,50) = 0
tgkill:
Prior to this commit, typical strace output used to look like this:
4890 tgkill(4890,4890,50,8,4832630528,4832615904) = 0 After this commit, it looks like this:
4890 tgkill(4890,4890,50) = 0
rt_sigqueueinfo:
Prior to this commit, typical strace output used to look like this:
8307 rt_sigqueueinfo(8307,50,1996483164,0,0,50) = 0 After this commit, it looks like this:
8307 rt_sigqueueinfo(8307,50,0x00000040007ff6b0) = 0
--- linux-user/strace.c | 41 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 6 +++--- 2 files changed, 44 insertions(+), 3 deletions(-)
linux-user/strace.c +41 -0
@@ -1901,6 +1901,20 @@ print_rt_sigprocmask(const struct syscallname *name, }#endif +#ifdef TARGET_NR_rt_sigqueueinfo +static void +print_rt_sigqueueinfo (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_raw_param ("%d" , arg0,0 ); +print_signal (arg1,0 ); +print_pointer (arg2,1 ); +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_syslogstatic void print_syslog_action (abi_ulong arg,int last)
@@ -2415,6 +2429,33 @@ print_kill(const struct syscallname *name, }#endif +#ifdef TARGET_NR_tkill +static void +print_tkill (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_raw_param ("%d" , arg0,0 ); +print_signal (arg1,1 ); +print_syscall_epilogue (name); +} +#endif + +#ifdef TARGET_NR_tgkill +static void +print_tgkill (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_raw_param ("%d" , arg0,0 ); +print_raw_param ("%d" , arg1,0 ); +print_signal (arg2,1 ); +print_syscall_epilogue (name); +} +#endif +/* * An array of all of the syscalls we know about */
linux-user/strace.list +3 -3
@@ -1155,7 +1155,7 @@ { TARGET_NR_rt_sigprocmask, "rt_sigprocmask" , NULL, print_rt_sigprocmask, NULL }, #endif #ifdef TARGET_NR_rt_sigqueueinfo -{ TARGET_NR_rt_sigqueueinfo, "rt_sigqueueinfo" , NULL, NULL, NULL }, +{ TARGET_NR_rt_sigqueueinfo, "rt_sigqueueinfo" , NULL, print_rt_sigqueueinfo, NULL }, #endif #ifdef TARGET_NR_rt_sigreturn { TARGET_NR_rt_sigreturn, "rt_sigreturn" , NULL, NULL, NULL },
@@ -1498,7 +1498,7 @@ { TARGET_NR_tee, "tee" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_tgkill -{ TARGET_NR_tgkill, "tgkill" , NULL, NULL, NULL }, +{ TARGET_NR_tgkill, "tgkill" , NULL, print_tgkill, NULL }, #endif #ifdef TARGET_NR_time { TARGET_NR_time, "time" , NULL, NULL, NULL },
@@ -1534,7 +1534,7 @@ { TARGET_NR_times, "times" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_tkill -{ TARGET_NR_tkill, "tkill" , NULL, NULL, NULL }, +{ TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL }, #endif #ifdef TARGET_NR_truncate { TARGET_NR_truncate, "truncate" , NULL, NULL, NULL },
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 07/15] linux-user: add strace for getuid(), gettid(), getppid(), geteuid()
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Improve strace support for syscalls getuid(), gettid(), getppid() and geteuid(). Since these system calls don't have arguments, "%s()" is added in the corresponding strace.list entry so that no arguments are printed.
getuid:
Prior to this commit, typical strace output used to look like this:
4894 getuid(4894,0,0,274886293296,-3689348814741910323,4832615904) = 1000 After this commit, it looks like this:
4894 getuid() = 1000
gettid:
Prior to this commit, typical strace output used to look like this:
8307 gettid(0,0,64,0,4832630528,4832615840) = 8307
After this commit, it looks like this:
8307 gettid() = 8307
getppid:
Prior to this commit, typical strace output used to look like this:
20588 getppid(20588,64,0,4832630528,4832615888,0) = 20625 After this commit, it looks like this:
20588 getppid() = 20625
geteuid:
Prior to this commit, typical strace output used to look like this:
20588 geteuid(64,0,0,4832615888,0,-9151031864016699136) = 1000 After this commit, it looks like this:
20588 geteuid() = 1000
--- linux-user/strace.list | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
linux-user/strace.list +4 -4
@@ -290,7 +290,7 @@ { TARGET_NR_getegid32, "getegid32" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_geteuid -{ TARGET_NR_geteuid, "geteuid" , NULL, NULL, NULL }, +{ TARGET_NR_geteuid, "geteuid" , "%s()", NULL, NULL }, #endif #ifdef TARGET_NR_geteuid32 { TARGET_NR_geteuid32, "geteuid32" , NULL, NULL, NULL },
@@ -338,7 +338,7 @@ { TARGET_NR_getpmsg, "getpmsg" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_getppid -{ TARGET_NR_getppid, "getppid" , NULL, NULL, NULL }, +{ TARGET_NR_getppid, "getppid" , "%s()", NULL, NULL }, #endif #ifdef TARGET_NR_getpriority { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
@@ -381,13 +381,13 @@ NULL, NULL }, #endif #ifdef TARGET_NR_gettid -{ TARGET_NR_gettid, "gettid" , NULL, NULL, NULL }, +{ TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL }, #endif #ifdef TARGET_NR_gettimeofday { TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_getuid -{ TARGET_NR_getuid, "getuid" , NULL, NULL, NULL }, +{ TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL }, #endif #ifdef TARGET_NR_getuid32 { TARGET_NR_getuid32, "getuid32" , NULL, NULL, NULL },
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 09/15] linux-user: fix ssetmask() system call
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Fix the ssetmask() system call by removing the invocation of sigorset().
The ssetmask() system call should replace the old signal mask with the new and return the old mask. It shouldn't combine the old and the new mask with sigorset(). Fetching the old mask for sigorset() is also no longer needed.
The problem was detected after running LTP test group syscalls for the MIPS EL 32 R2 architecture where the test ssetmask01 failed with exit code 1. The test passes now that the ssetmask() system call is fixed.
--- linux-user/syscall.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
linux-user/syscall.c +1 -9
@@ -8621,17 +8621,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#ifdef TARGET_NR_ssetmask/* not on alpha */ case TARGET_NR_ssetmask: { -sigset_t set, oset, cur_set; +sigset_t set, oset;abi_ulong target_set = arg1; -/* We only have one word of the new mask so we must read -* the rest of it with do_sigprocmask() and OR in this word. -* We are guaranteed that a do_sigprocmask() that only queries -* the signal mask will not fail. -*/ - ret =do_sigprocmask (0 ,NULL , &cur_set); -assert (!ret);target_to_host_old_sigset (&set, &target_set); -sigorset (&set, &set, &cur_set); ret =do_sigprocmask (SIG_SETMASK , &set, &oset);if (!ret) {host_to_target_old_sigset (&target_set, &oset);
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 10/15] linux-user: fix mismatch of lock/unlock_user() invocations in rt_sigqueinfo() syscall
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Change the unlock_user() argument from arg1 to arg3 to match with lock_user(), since arg3 contains the pointer to the siginfo_t structure.
--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
@@ -8868,7 +8868,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, goto efault; }target_to_host_siginfo (&uinfo, p); -unlock_user (p, arg1,0 ); +unlock_user (p, arg3,0 ); ret =get_errno (sys_rt_sigqueueinfo (arg1, arg2, &uinfo)); }break ;
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 12/15] linux-user: add support for rt_tgsigqueueinfo() system call
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Add a new system call: rt_tgsigqueueinfo().
This system call is similar to rt_sigqueueinfo(), but instead of sending the signal and data to the whole thread group with the ID equal to the argument tgid, it sends it to a single thread within that thread group. The ID of the thread is specified by the tid argument.
The implementation is based on the rt_sigqueueinfo() in linux-user mode, where the tid is added as the second argument and the previous second and third argument become arguments three and four, respectively.
Conflicts:
linux-user/syscall.c
--- linux-user/syscall.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
linux-user/syscall.c +16 -0
@@ -238,6 +238,7 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \#define __NR_sys_getdents64 __NR_getdents64#define __NR_sys_getpriority __NR_getpriority#define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo +#define __NR_sys_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo#define __NR_sys_syslog __NR_syslog#define __NR_sys_futex __NR_futex#define __NR_sys_inotify_init __NR_inotify_init
@@ -275,6 +276,8 @@ _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) _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)#ifdef __NR_exit_group_syscall1 (int,exit_group,int,error_code)
@@ -8872,6 +8875,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =get_errno (sys_rt_sigqueueinfo (arg1, arg2, &uinfo)); }break ; +case TARGET_NR_rt_tgsigqueueinfo: + { +siginfo_t uinfo; + + p =lock_user (VERIFY_READ , arg4,sizeof (target_siginfo_t),1 ); +if (!p) { + goto efault; + } +target_to_host_siginfo (&uinfo, p); +unlock_user (p, arg4,0 ); + ret =get_errno (sys_rt_tgsigqueueinfo (arg1, arg2, arg3, &uinfo)); + } +break ;#ifdef TARGET_NR_sigreturncase TARGET_NR_sigreturn:if (block_signals ()) {
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 13/15] linux-user: add rt_tgsigqueueinfo() strace
In reply to [email protected]From: Miloš Stojanović <[email protected]>
This commit improves strace support for syscall rt_tgsigqueueinfo().
Prior to this commit, typical strace output used to look like this:
7775 rt_tgsigqueueinfo(7775,7775,50,1996483164,0,0) = 0
After this commit, it looks like this:
7775 rt_tgsigqueueinfo(7775,7775,50,0x76ffea5c) = 0
--- linux-user/strace.c | 15 +++++++++++++++ linux-user/strace.list | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-)
linux-user/strace.c +15 -0
@@ -1915,6 +1915,21 @@ print_rt_sigqueueinfo(const struct syscallname *name, }#endif +#ifdef TARGET_NR_rt_tgsigqueueinfo +static void +print_rt_tgsigqueueinfo (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_raw_param ("%d" , arg0,0 ); +print_raw_param ("%d" , arg1,0 ); +print_signal (arg2,0 ); +print_pointer (arg3,1 ); +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_syslogstatic void print_syslog_action (abi_ulong arg,int last)
linux-user/strace.list +1 -1
@@ -1167,7 +1167,7 @@ { TARGET_NR_rt_sigtimedwait, "rt_sigtimedwait" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_rt_tgsigqueueinfo -{ TARGET_NR_rt_tgsigqueueinfo, "rt_tgsigqueueinfo" , NULL, NULL, NULL }, +{ TARGET_NR_rt_tgsigqueueinfo, "rt_tgsigqueueinfo" , NULL, print_rt_tgsigqueueinfo, NULL }, #endif #ifdef TARGET_NR_sched_getaffinity { TARGET_NR_sched_getaffinity, "sched_getaffinity" , NULL, NULL, NULL },
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 14/15] linux-user: fix inconsistent spaces in print_siginfo() output
In reply to [email protected]From: Miloš Stojanović <[email protected]>
This patch improves the consistentcy of the output from print_siginfo() by removing spaces around the equal sign of si_pid, si_uid, si_timer1, si_timer2, si_band, si_fd, si_addr, si_status and si_sigval. This way they match si_signo and ci_code. Host strace was used as a reference for this chage.
Prior to this commit, typical strace output used to look like this:
--- linux-user/strace.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
linux-user/strace.c +6 -6
@@ -206,26 +206,26 @@ static void print_siginfo(const target_siginfo_t *tinfo)switch (si_type) {case QEMU_SI_KILL : -gemu_log (", si_pid = %u, si_uid = %u" , +gemu_log (", si_pid=%u, si_uid=%u" , (unsigned int )tinfo->_sifields._kill._pid, (unsigned int )tinfo->_sifields._kill._uid);break ;case QEMU_SI_TIMER : -gemu_log (", si_timer1 = %u, si_timer2 = %u" , +gemu_log (", si_timer1=%u, si_timer2=%u" , tinfo->_sifields._timer._timer1, tinfo->_sifields._timer._timer2);break ;case QEMU_SI_POLL : -gemu_log (", si_band = %d, si_fd = %d" , +gemu_log (", si_band=%d, si_fd=%d" , tinfo->_sifields._sigpoll._band, tinfo->_sifields._sigpoll._fd);break ;case QEMU_SI_FAULT : -gemu_log (", si_addr = " ); +gemu_log (", si_addr=" );print_pointer (tinfo->_sifields._sigfault._addr,1 );break ;case QEMU_SI_CHLD : - gemu_log(", si_pid = %u, si_uid = %u, si_status = %d" + gemu_log(", si_pid=%u, si_uid=%u, si_status=%d" ", si_utime=" TARGET_ABI_FMT_ld ", si_stime=" TARGET_ABI_FMT_ld, (unsigned int)(tinfo->_sifields._sigchld._pid),
@@ -235,7 +235,7 @@ static void print_siginfo(const target_siginfo_t *tinfo) tinfo->_sifields._sigchld._stime);break ;case QEMU_SI_RT : -gemu_log (", si_pid = %u, si_uid = %u, si_sigval = " TARGET_ABI_FMT_ld, +gemu_log (", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld, (unsigned int )tinfo->_sifields._rt._pid, (unsigned int )tinfo->_sifields._rt._uid, tinfo->_sifields._rt._sigval.sival_ptr);
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 11/15] linux-user: fix argument type declaration of rt_sigqueinfo() syscall
In reply to [email protected]From: Miloš Stojanović <[email protected]>
Change the type of the first argument of rt_sigqueinfo() from int to pid_t in the syscall declaration to match specifications of the system call.
Proper spacing is added to satisfy checkpatch.pl.
--- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/syscall.c +1 -1
@@ -274,7 +274,7 @@ _syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, co_syscall5 (int, _llseek, uint, fd, ulong, hi, ulong, lo, loff_t *, res, uint, wh);#endif -_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) +_syscall3(int, sys_rt_sigqueueinfo, pid_t, pid, int, sig, siginfo_t *, uinfo) _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)#ifdef __NR_exit_group_syscall1 (int,exit_group,int,error_code)
Signature · 1 line
2.11.0
[Qemu-devel] [PULL 15/15] linux-user: add strace support for uinfo structure of rt_sigqueueinfo() and rt_tgsigqueueinfo()
In reply to [email protected]From: Miloš Stojanović <[email protected]>
This commit adds support for printing the content of the target_siginfo_t structure in a similar way to how it is printed by the host strace. The pointer to this structure is sent as the last argument of the rt_sigqueueinfo() and rt_tgsigqueueinfo() system calls.
For this purpose, print_siginfo() is used and the get_target_siginfo() function is implemented in order to get the information obtained from the pointer into the form that print_siginfo() expects.
The get_target_siginfo() function is based on host_to_target_siginfo_noswap() in linux-user mode, but here both arguments are pointers to target_siginfo_t, so instead of converting the information to siginfo_t it just extracts and copies it to a target_siginfo_t structure.
Prior to this commit, typical strace output used to look like this:
8307 rt_sigqueueinfo(8307,50,0x00000040007ff6b0) = 0
After this commit, it looks like this:
8307 rt_sigqueueinfo(8307,50,{si_signo=50, si_code=SI_QUEUE, si_pid=8307, si_uid=1000, si_sigval=17716762128}) = 0
--- linux-user/strace.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-)
linux-user/strace.c +111 -2
@@ -188,6 +188,93 @@ static void print_si_code(int arg)gemu_log ("%s" , codename); } +static void get_target_siginfo (target_siginfo_t *tinfo, +const target_siginfo_t *info) +{ +abi_ulong sival_ptr; + +int sig; +int si_errno; +int si_code; +int si_type; + +__get_user (sig, &info->si_signo); +__get_user (si_errno, &tinfo->si_errno); +__get_user (si_code, &info->si_code); + + tinfo->si_signo = sig; + tinfo->si_errno = si_errno; + tinfo->si_code = si_code; + +/* Ensure we don't leak random junk to the guest later */ +memset (tinfo->_sifields._pad,0 ,sizeof (tinfo->_sifields._pad)); + +/* This is awkward, because we have to use a combination of +* the si_code and si_signo to figure out which of the union's +* members are valid. (Within the host kernel it is always possible +* to tell, but the kernel carefully avoids giving userspace the +* high 16 bits of si_code, so we don't have the information to +* do this the easy way...) We therefore make our best guess, +* bearing in mind that a guest can spoof most of the si_codes +* via rt_sigqueueinfo() if it likes. +* +* Once we have made our guess, we record it in the top 16 bits of +* the si_code, so that print_siginfo() later can use it. +* print_siginfo() will strip these top bits out before printing +* the si_code. +*/ + +switch (si_code) { +case SI_USER : +case SI_TKILL : +case SI_KERNEL : +/* Sent via kill(), tkill() or tgkill(), or direct from the kernel. +* These are the only unspoofable si_code values. +*/ +__get_user (tinfo->_sifields._kill._pid, &info->_sifields._kill._pid); +__get_user (tinfo->_sifields._kill._uid, &info->_sifields._kill._uid); + si_type =QEMU_SI_KILL ; +break ; +default : +/* Everything else is spoofable. Make best guess based on signal */ +switch (sig) { +case TARGET_SIGCHLD : +__get_user (tinfo->_sifields._sigchld._pid, + &info->_sifields._sigchld._pid); +__get_user (tinfo->_sifields._sigchld._uid, + &info->_sifields._sigchld._uid); +__get_user (tinfo->_sifields._sigchld._status, + &info->_sifields._sigchld._status); +__get_user (tinfo->_sifields._sigchld._utime, + &info->_sifields._sigchld._utime); +__get_user (tinfo->_sifields._sigchld._stime, + &info->_sifields._sigchld._stime); + si_type =QEMU_SI_CHLD ; +break ; +case TARGET_SIGIO : +__get_user (tinfo->_sifields._sigpoll._band, + &info->_sifields._sigpoll._band); +__get_user (tinfo->_sifields._sigpoll._fd, + &info->_sifields._sigpoll._fd); + si_type =QEMU_SI_POLL ; +break ; +default : +/* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */ +__get_user (tinfo->_sifields._rt._pid, &info->_sifields._rt._pid); +__get_user (tinfo->_sifields._rt._uid, &info->_sifields._rt._uid); +/* XXX: potential problem if 64 bit */ +__get_user (sival_ptr, &info->_sifields._rt._sigval.sival_ptr); + tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr; + + si_type =QEMU_SI_RT ; +break ; + } +break ; + } + + tinfo->si_code =deposit32 (si_code,16 ,16 , si_type); +} +static void print_siginfo (const target_siginfo_t *tinfo) {/* Print a target_siginfo_t in the format desired for printing
@@ -1907,10 +1994,21 @@ print_rt_sigqueueinfo(const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { + void *p; +target_siginfo_t uinfo; +print_syscall_prologue (name);print_raw_param ("%d" , arg0,0 );print_signal (arg1,0 ); -print_pointer (arg2,1 ); + p =lock_user (VERIFY_READ , arg2,sizeof (target_siginfo_t),1 ); +if (p) { +get_target_siginfo (&uinfo, p); +print_siginfo (&uinfo); + +unlock_user (p, arg2,0 ); + }else { +print_pointer (arg2,1 ); + }print_syscall_epilogue (name); }#endif
@@ -1921,11 +2019,22 @@ print_rt_tgsigqueueinfo(const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { + void *p; +target_siginfo_t uinfo; +print_syscall_prologue (name);print_raw_param ("%d" , arg0,0 );print_raw_param ("%d" , arg1,0 );print_signal (arg2,0 ); -print_pointer (arg3,1 ); + p =lock_user (VERIFY_READ , arg3,sizeof (target_siginfo_t),1 ); +if (p) { +get_target_siginfo (&uinfo, p); +print_siginfo (&uinfo); + +unlock_user (p, arg3,0 ); + }else { +print_pointer (arg3,1 ); + }print_syscall_epilogue (name); }#endif
Signature · 1 line
2.11.0
Peter Maydell
AppliedQuoted 8 lines · On 31 May 2017 at 14:08, <[email protected]> wrote:
From: Riku Voipio <[email protected]>
The following changes since commit
9964e96dc9999cf7f7c936ee854a795415d19b60:Merge remote-tracking branch 'jasowang/tags/net-pull-request' into staging (2017-05-23 15:01:31 +0100)
are available in the git repository at:
Quoted 9 lines
git://git.linaro.org/people/riku.voipio/qemu.gittags/pull-linux-user-20170531for you to fetch changes up to
ba9fcea1cb6d80536f780760d870416fe5b85863:linux-user: add strace support for uinfo structure of
rt_sigqueueinfo()andrt_tgsigqueueinfo()(2017-05-29 14:56:09 +0300)----------------------------------------------------------------
Misc linux-user updates
Applied, thanks.
-- PMM