linux-user update
PATCH 1/10 linux-user: /proc/self/maps content
In reply to [email protected]From: Mikhail Ilyin <[email protected]>
Build /proc/self/maps doing a match against guest memory translation table. Output only that map records which are valid for guest memory layout.
--- include/exec/cpu-all.h | 2 ++ linux-user/syscall.c | 25 ++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-)
include/exec/cpu-all.h +2 -0
@@ -198,6 +198,8 @@ extern unsigned long reserved_va;#define RESERVED_VA 0ul#endif +#define GUEST_ADDR_MAX (RESERVED_VA ? RESERVED_VA : \ + (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)#endif /* page related stuff */
linux-user/syscall.c +10 -15
@@ -5092,10 +5092,8 @@ static int open_self_cmdline(void *cpu_env, int fd)static int open_self_maps (void *cpu_env,int fd) { -#if defined(TARGET_ARM ) || defined(TARGET_M68K ) || defined(TARGET_UNICORE32 )CPUState *cpu =ENV_GET_CPU ((CPUArchState *)cpu_env);TaskState *ts = cpu->opaque; -#endif FILE *fp;char *line =NULL ;size_t len =0 ;
@@ -5118,13 +5116,18 @@ static int open_self_maps(void *cpu_env, int fd)if ((fields <10 ) || (fields >11 )) {continue ; } -if (!strncmp (path,"[stack]" ,7 )) { -continue ; - } -if (h2g_valid (min) &&h2g_valid (max)) { +if (h2g_valid (min)) { +int flags =page_get_flags (h2g (min)); + max =h2g_valid (max -1 ) ? max : (uintptr_t )g2h (GUEST_ADDR_MAX ); +if (page_check_range (h2g (min), max - min, flags) ==-1 ) { +continue ; + } +if (h2g (min) == ts->info->stack_limit) { +pstrcpy (path,sizeof (path)," [stack]" ); + }dprintf (fd, TARGET_ABI_FMT_lx"-" TARGET_ABI_FMT_lx" %c%c%c%c %08" PRIx64" %02x:%02x %d %s%s\n" , -h2g (min),h2g (max), flag_r, flag_w, +h2g (min),h2g (max -1 ) +1 , flag_r, flag_w, flag_x, flag_p, offset, dev_maj, dev_min, inode, path[0 ] ?" " :"" , path); }
@@ -5133,14 +5136,6 @@ static int open_self_maps(void *cpu_env, int fd)free (line);fclose (fp); -#if defined(TARGET_ARM ) || defined(TARGET_M68K ) || defined(TARGET_UNICORE32 ) -dprintf (fd,"%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n" , - (unsigned long long )ts->info->stack_limit, - (unsigned long long )(ts->info->start_stack + - (TARGET_PAGE_SIZE -1 )) &TARGET_PAGE_MASK , - (unsigned long long )0 ); -#endif -return 0 ; }
Signature · 1 line
2.0.1
PATCH 3/10 linux-user: make binfmt flag O require P
In reply to [email protected]From: Joakim Tjernlund <[email protected]>
QEMU can autodetect if it is started from Linux binfmt loader when binfmt flag O is on.
Use that and require binfmt flag P as well which will enable QEMU to pass in correct argv0 to the application.
--- linux-user/main.c | 19 +++++++++++++++---- scripts/qemu-binfmt-conf.sh | 36 ++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 22 deletions(-)
linux-user/main.c +15 -4
@@ -3751,7 +3751,7 @@ static void usage(void)exit (1 ); } -static int parse_args (int argc,char **argv) +static int parse_args (int argc,char **argv,int assume_P_flag) {const char *r;int optind;
@@ -3767,7 +3767,18 @@ static int parse_args(int argc, char **argv) arginfo->handle_opt (r); } } - +if (assume_P_flag) { +/* Assume started by binmisc and binfmt P flag is set */ +if (argc <3 ) { +fprintf (stderr,"%s: Please use me through binfmt with P flag\n" , + argv[0 ]); +exit (1 ); + } + filename = argv[1 ]; + exec_path = argv[1 ]; +/* Next argv must be argv0 for the app */ +return 2 ; + } optind =1 ;for (;;) {if (optind >= argc) {
@@ -3858,7 +3869,8 @@ int main(int argc, char **argv, char **envp)cpudef_setup ();/* parse cpu definitions in target config file (TBD) */ #endif - optind =parse_args (argc, argv); + execfd =qemu_getauxval (AT_EXECFD ); + optind =parse_args (argc, argv, execfd >0 );/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
@@ -4004,7 +4016,6 @@ int main(int argc, char **argv, char **envp) cpu->opaque = ts;task_settid (ts); - execfd =qemu_getauxval (AT_EXECFD );if (execfd ==0 ) { execfd =open (filename,O_RDONLY );if (execfd <0 ) {
scripts/qemu-binfmt-conf.sh +18 -18
@@ -31,42 +31,42 @@ esac # register the interpreter for each cpu except for the native one if [ $cpu != "i386" ] ; then - echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register - echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register + echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:PO' > /proc/sys/fs/binfmt_misc/register + echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "alpha" ] ; then - echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:' > /proc/sys/fs/binfmt_misc/register + echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "arm" ] ; then - echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register - echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:' > /proc/sys/fs/binfmt_misc/register + echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:PO' > /proc/sys/fs/binfmt_misc/register + echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "aarch64" ] ; then - echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-aarch64:' > /proc/sys/fs/binfmt_misc/register + echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-aarch64:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "sparc" ] ; then - echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:' > /proc/sys/fs/binfmt_misc/register + echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "ppc" ] ; then - echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:' > /proc/sys/fs/binfmt_misc/register + echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "m68k" ] ; then echo 'Please check cpu value and header information for m68k!' - echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:' > /proc/sys/fs/binfmt_misc/register + echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "mips" ] ; then # FIXME: We could use the other endianness on a MIPS host. - echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:' > /proc/sys/fs/binfmt_misc/register - echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:' > /proc/sys/fs/binfmt_misc/register - echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:' > /proc/sys/fs/binfmt_misc/register - echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:' > /proc/sys/fs/binfmt_misc/register + echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:PO' > /proc/sys/fs/binfmt_misc/register + echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:PO' > /proc/sys/fs/binfmt_misc/register + echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:PO' > /proc/sys/fs/binfmt_misc/register + echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:PO' > /proc/sys/fs/binfmt_misc/register + echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:PO' > /proc/sys/fs/binfmt_misc/register + echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "sh" ] ; then - echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:' > /proc/sys/fs/binfmt_misc/register - echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:' > /proc/sys/fs/binfmt_misc/register + echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:PO' > /proc/sys/fs/binfmt_misc/register + echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:PO' > /proc/sys/fs/binfmt_misc/register fi if [ $cpu != "s390x" ] ; then - echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:' > /proc/sys/fs/binfmt_misc/register + echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:PO' > /proc/sys/fs/binfmt_misc/register fi
Signature · 1 line
2.0.1
PATCH 6/10 linux-user: fix readlink handling with magic exe symlink
In reply to [email protected]From: Mike Frysinger <[email protected]>
The current code always returns the length of the path when it should be returning the number of bytes it wrote to the output string.
Further, readlink is not supposed to append a NUL byte, but the current snprintf logic will always do just that.
Even further, if you pass in a length of 0, you're suppoesd to get back an error (EINVAL), but the current logic just returns 0.
Further still, if there was an error reading the symlink, we should not go ahead and try to read the target buffer as it is garbage.
Simple test for the first two issues:
$ cat test.c
int main() {
char buf[50];
size_t len;
for (len = 0; len < 10; ++len) {
memset(buf, '!', sizeof(buf));
ssize_t ret = readlink("/proc/self/exe", buf, len);
buf[20] = '\0';
printf("readlink(/proc/self/exe, {%s}, %zu) = %zi\n", buf, len, ret);
}
return 0;
}Now compare the output of the native:
$ gcc test.c -o /tmp/x $ /tmp/x $ strace /tmp/x
With what qemu does:
$ armv7a-cros-linux-gnueabi-gcc test.c -o /tmp/x -static $ qemu-arm /tmp/x $ qemu-arm -strace /tmp/x
--- linux-user/syscall.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
linux-user/syscall.c +13 -2
@@ -6636,11 +6636,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, p2 =lock_user (VERIFY_WRITE , arg2, arg3,0 );if (!p || !p2) { ret = -TARGET_EFAULT ; + }else if (!arg3) { +/* Short circuit this for the magic exe check. */ + ret = -TARGET_EINVAL ; }else if (is_proc_myself ((const char *)p,"exe" )) {char real[PATH_MAX ], *temp; temp =realpath (exec_path, real); - ret = temp ==NULL ?get_errno (-1 ) :strlen (real) ; -snprintf ((char *)p2, arg3,"%s" , real); +/* Return value is # of bytes that we wrote to the buffer. */ +if (temp ==NULL ) { + ret =get_errno (-1 ); + }else { +/* Don't worry about sign mismatch as earlier mapping +* logic would have thrown a bad address error. */ + ret =MIN (strlen (real), arg3); +/* We cannot NUL terminate the string. */ +memcpy (p2, real, ret); + } }else { ret =get_errno (readlink (path (p), p2, arg3)); }
Signature · 1 line
2.0.1
PATCH 9/10 linux-user: support {name_to, open_by}_handle_at syscalls
In reply to [email protected]From: Riku Voipio <[email protected]>
Implement support for the name_to_handle_at and open_by_handle_at syscalls, allowing their use by the target program.
Modified by Riku - move syscalls to functions and put behind the already existing CONFIG_OPEN_BY_HANDLE to avoid build failure with old glibc's.
--- linux-user/strace.c | 30 ++++++++++++++++++++++ linux-user/strace.list | 6 +++++ linux-user/syscall.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+)
linux-user/strace.c +30 -0
@@ -1552,6 +1552,36 @@ print_kill(const struct syscallname *name, }#endif +#ifdef TARGET_NR_name_to_handle_at +static void +print_name_to_handle_at (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_pointer (arg3,0 ); +print_raw_param ("0x%x" , arg4,1 ); +print_syscall_epilogue (name); +} +#endif + +#ifdef TARGET_NR_open_by_handle_at +static void +print_open_by_handle_at (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_pointer (arg2,0 ); +print_open_flags (arg3,1 ); +print_syscall_epilogue (name); +} +#endif +/* * An array of all of the syscalls we know about */
linux-user/strace.list +6 -0
@@ -582,6 +582,9 @@ #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, print_name_to_handle_at, NULL }, +#endif #ifdef TARGET_NR_nanosleep { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL }, #endif
@@ -624,6 +627,9 @@ #ifdef TARGET_NR_openat { TARGET_NR_openat, "openat" , NULL, print_openat, NULL }, #endif +#ifdef TARGET_NR_open_by_handle_at +{ TARGET_NR_open_by_handle_at, "open_by_handle_at" , NULL, print_open_by_handle_at, NULL }, +#endif #ifdef TARGET_NR_osf_adjtime { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL }, #endif
linux-user/syscall.c +70 -0
82 lines not on this page · raw message
Signature · 1 line
2.0.1
PATCH 10/10 linux-user: add setns and unshare
In reply to [email protected]From: Riku Voipio <[email protected]>
Add support for the setns and unshare syscalls, trivially passed through to the host. Based on patches by Paul Burton, added configure check.
--- configure | 20 ++++++++++++++++++++ linux-user/strace.list | 3 +++ linux-user/syscall.c | 11 +++++++++++ 3 files changed, 34 insertions(+)
configure +20 -0
@@ -3434,6 +3434,23 @@ if compile_prog "" "" ; then timerfd=yes fi +# check for setns and unshare support +setns=no +cat > $TMPC << EOF +#include <sched.h> + +int main(void) +{ + int ret; + ret = setns(0, 0); + ret = unshare(0); + return ret; +} +EOF +if compile_prog "" "" ; then + setns=yes +fi + # Check if tools are available to build documentation. if test "$docs" != "no" ; then if has makeinfo && has pod2man; then
@@ -4503,6 +4520,9 @@ fi if test "$timerfd" = "yes" ; then echo "CONFIG_TIMERFD=y" >> $config_host_mak fi +if test "$setns" = "yes" ; then + echo "CONFIG_SETNS=y" >> $config_host_mak +fi if test "$inotify" = "yes" ; then echo "CONFIG_INOTIFY=y" >> $config_host_mak fi
linux-user/strace.list +3 -0
@@ -1191,6 +1191,9 @@ #ifdef TARGET_NR_set_mempolicy { TARGET_NR_set_mempolicy, "set_mempolicy" , NULL, NULL, NULL }, #endif +#ifdef TARGET_NR_setns +{ TARGET_NR_setns, "setns" , NULL, NULL, NULL }, +#endif #ifdef TARGET_NR_setpgid { TARGET_NR_setpgid, "setpgid" , NULL, NULL, NULL }, #endif
linux-user/syscall.c +11 -0
@@ -9680,6 +9680,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;#endif +#if defined(TARGET_NR_setns) && defined(CONFIG_SETNS ) +case TARGET_NR_setns: + ret =get_errno (setns (arg1, arg2)); +break ; +#endif +#if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS ) +case TARGET_NR_unshare: + ret =get_errno (unshare (arg1)); +break ; +#endif +default : unimplemented:gemu_log ("qemu: Unsupported syscall: %d\n" , num);
Signature · 1 line
2.0.1
PATCH 5/10 linux-user: Fix conversion of sigevent argument to timer_create
In reply to [email protected]From: Peter Maydell <[email protected]>
There were a number of bugs in the conversion of the sigevent argument to timer_create from target to host format:
* signal number not converted from target to host
* thread ID not copied across
* sigev_value not copied across
* we never unlocked the struct when we were done
Between them, these problems meant that SIGEV_THREAD_ID timers (and the glibc-implemented SIGEV_THREAD timers which depend on them) didn't work.
Fix these problems and clean up the code a little by pulling the struct conversion out into its own function, in line with how we convert various other structs. This allows the test program in bug LP:1042388 to run.
--- linux-user/syscall.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
linux-user/syscall.c +30 -8
@@ -4912,6 +4912,32 @@ static inline abi_long host_to_target_itimerspec(abi_ulong target_addr,return 0 ; } +static inline abi_long target_to_host_sigevent (struct sigevent *host_sevp, +abi_ulong target_addr) +{ +struct target_sigevent *target_sevp; + +if (!lock_user_struct (VERIFY_READ , target_sevp, target_addr,1 )) { +return -TARGET_EFAULT ; + } + +/* This union is awkward on 64 bit systems because it has a 32 bit +* integer and a pointer in it; we follow the conversion approach +* used for handling sigval types in signal.c so the guest should get +* the correct value back even if we did a 64 bit byteswap and it's +* using the 32 bit integer. +*/ + host_sevp->sigev_value.sival_ptr = + (void *)(uintptr_t )tswapal (target_sevp->sigev_value.sival_ptr); + host_sevp->sigev_signo = +target_to_host_signal (tswap32 (target_sevp->sigev_signo)); + host_sevp->sigev_notify =tswap32 (target_sevp->sigev_notify); + host_sevp->_sigev_un._tid =tswap32 (target_sevp->_sigev_un._tid); + +unlock_user_struct (target_sevp, target_addr,1 ); +return 0 ; +} +#if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat) static inline abi_long host_to_target_stat64(void *cpu_env, abi_ulong target_addr,
@@ -9403,7 +9429,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,/* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */ struct sigevent host_sevp = { {0 }, }, *phost_sevp =NULL ; -struct target_sigevent *ptarget_sevp;struct target_timer_t *ptarget_timer;int clkid = arg1;
@@ -9415,14 +9440,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,timer_t *phtimer = g_posix_timers + timer_index;if (arg2) { -if (!lock_user_struct (VERIFY_READ , ptarget_sevp, arg2,1 )) { - goto efault; - } - - host_sevp.sigev_signo =tswap32 (ptarget_sevp->sigev_signo); - host_sevp.sigev_notify =tswap32 (ptarget_sevp->sigev_notify); - phost_sevp = &host_sevp; + ret =target_to_host_sigevent (phost_sevp, arg2); +if (ret !=0 ) { +break ; + } } ret =get_errno (timer_create (clkid, phost_sevp, phtimer));
Signature · 1 line
2.0.1
PATCH 8/10 linux-user: support ioprio_{get, set} syscalls
In reply to [email protected]From: Paul Burton <[email protected]>
Add support for the ioprio_get & ioprio_set syscalls, allowing their use by target programs.
--- linux-user/syscall.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
linux-user/syscall.c +18 -0
@@ -252,6 +252,12 @@ _syscall2(int, capget, struct __user_cap_header_struct *, header, struct __user_cap_data_struct *, data); _syscall2(int, capset, struct __user_cap_header_struct *, header, struct __user_cap_data_struct *, data); +#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) +_syscall2(int, ioprio_get, int, which, int, who) +#endif +#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set) +_syscall3(int, ioprio_set, int, which, int, who, int, ioprio) +#endif static bitmask_transtbl fcntl_flags_tbl[] = { {TARGET_O_ACCMODE ,TARGET_O_WRONLY ,O_ACCMODE ,O_WRONLY , },
@@ -9592,6 +9598,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,break ;#endif +#if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) +case TARGET_NR_ioprio_get: + ret =get_errno (ioprio_get (arg1, arg2)); +break ; +#endif + +#if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set) +case TARGET_NR_ioprio_set: + ret =get_errno (ioprio_set (arg1, arg2, arg3)); +break ; +#endif +default : unimplemented:gemu_log ("qemu: Unsupported syscall: %d\n" , num);
Signature · 1 line
2.0.1
PATCH 4/10 linux-user: Fix syscall instruction usermode emulation on X86_64
In reply to [email protected]From: Jincheng Miao <[email protected]>
Currently syscall instruction is buggy on user mode X86_64, the EIP is updated after do_syscall(), that is too late for clone(). Because clone() will create a thread at the env->EIP (the address of syscall insn), and then child thread enters do_syscall() again, that is not expected. Sometimes it is tragic.
User mode syscall insn emulation is not used MSR, so the action should be same to INT 0x80. INT 0x80 will update EIP in do_interrupt(), ditto for syscall() for consistency.
--- linux-user/main.c | 1 - target-i386/seg_helper.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
linux-user/main.c +0 -1
@@ -309,7 +309,6 @@ void cpu_loop(CPUX86State *env) env->regs[8 ], env->regs[9 ], 0, 0); - env->eip = env->exception_next_eip;break ;#endif case EXCP0B_NOSEG :
target-i386/seg_helper.c +2 -2
@@ -1127,8 +1127,8 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,/* Since we emulate only user space, we cannot do more than exiting the emulation with the suitable exception and error -code */ -if (is_int) { +code. So update EIP for INT 0x80 and EXCP_SYSCALL. */ +if (is_int || intno ==EXCP_SYSCALL ) { env->eip = next_eip; } }
Signature · 1 line
2.0.1
PATCH 7/10 linux-user: support timerfd_{create, gettime, settime} syscalls
In reply to [email protected]From: Riku Voipio <[email protected]>
Adds support for the timerfd_create, timerfd_gettime & timerfd_settime syscalls, allowing use of timerfds by target programs.
v2: By Riku - added configure check for timerfd and ifdefs for benefit of old distributions like RHEL5.
--- configure | 17 +++++++++++++++++ linux-user/strace.list | 9 +++++++++ linux-user/syscall.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
configure +17 -0
@@ -3420,6 +3420,20 @@ if compile_prog "" "" ; then sendfile=yes fi +# check for timerfd support (glibc 2.8 and newer) +timerfd=no +cat > $TMPC << EOF +#include <sys/timerfd.h> + +int main(void) +{ + return(timerfd_create(CLOCK_REALTIME, 0)); +} +EOF +if compile_prog "" "" ; then + timerfd=yes +fi + # Check if tools are available to build documentation. if test "$docs" != "no" ; then if has makeinfo && has pod2man; then
@@ -4486,6 +4500,9 @@ fi if test "$sendfile" = "yes" ; then echo "CONFIG_SENDFILE=y" >> $config_host_mak fi +if test "$timerfd" = "yes" ; then + echo "CONFIG_TIMERFD=y" >> $config_host_mak +fi if test "$inotify" = "yes" ; then echo "CONFIG_INOTIFY=y" >> $config_host_mak fi
linux-user/strace.list +9 -0
@@ -1404,6 +1404,15 @@ #ifdef TARGET_NR_timer_settime { TARGET_NR_timer_settime, "timer_settime" , NULL, NULL, NULL }, #endif +#ifdef TARGET_NR_timerfd_create +{ TARGET_NR_timerfd_create, "timerfd_create" , NULL, NULL, NULL }, +#endif +#ifdef TARGET_NR_timerfd_gettime +{ TARGET_NR_timerfd_gettime, "timerfd_gettime" , NULL, NULL, NULL }, +#endif +#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
linux-user/syscall.c +45 -0
57 lines not on this page · raw message
Signature · 1 line
2.0.1
cover linux-user update
From: Riku Voipio <[email protected]>
The current contents of linux-user git tree at
git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream
For testing and review. I'm still need to test some (especially my) patches before sending them in pull request. Since this needs a update in my ltp test setup for newer syscalls, it might take a few days till I get time for it.
Jincheng Miao (1):
linux-user: Fix syscall instruction usermode emulation on X86_64
Joakim Tjernlund (1):
linux-user: make binfmt flag O require P
Mike Frysinger (1):
linux-user: fix readlink handling with magic exe symlink
Mikhail Ilyin (1):
linux-user: /proc/self/maps content
Paul Burton (1):
linux-user: support ioprio_{get, set} syscalls
Peter Maydell (1):
linux-user: Fix conversion of sigevent argument to timer_create
Riku Voipio (4):
linux-user: redirect openat calls
linux-user: support timerfd_{create, gettime, settime} syscalls
linux-user: support {name_to,open_by}_handle_at syscalls
linux-user: add setns and unshare
configure | 37 +++++++ include/exec/cpu-all.h | 2 + linux-user/main.c | 20 +++- linux-user/strace.c | 30 ++++++ linux-user/strace.list | 18 ++++ linux-user/syscall.c | 243 +++++++++++++++++++++++++++++++++++++------- scripts/qemu-binfmt-conf.sh | 36 +++---- target-i386/seg_helper.c | 4 +- 8 files changed, 327 insertions(+), 63 deletions(-)
Signature · 1 line
2.0.1
PATCH 2/10 linux-user: redirect openat calls
From: Riku Voipio <[email protected]>
While Mikhail fixed /proc/self/maps, it was noticed openat calls are not redirected currently. Some archs don't have open at all, so openat needs to be redirected.
Fix this by consolidating open/openat code to do_openat - open is implemented using openat(AT_FDCWD, ... ), which according to open(2) man page is identical.
Since all targets now have openat, remove the ifdef around sys_openat and openat: case in do_syscall.
--- linux-user/syscall.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
linux-user/syscall.c +9 -14
@@ -294,7 +294,6 @@ static int sys_getcwd1(char *buf, size_t size)return strlen (buf)+1 ; } -#ifdef TARGET_NR_openatstatic int sys_openat (int dirfd,const char *pathname,int flags,mode_t mode) {/*
@@ -306,7 +305,6 @@ static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) }return (openat (dirfd, pathname, flags)); } -#endif #ifdef TARGET_NR_utimensat#ifdef CONFIG_UTIMENSAT
@@ -5274,7 +5272,7 @@ static int open_net_route(void *cpu_env, int fd) }#endif -static int do_open (void *cpu_env,const char *pathname,int flags,mode_t mode) +static int do_openat (void *cpu_env,int dirfd,const char *pathname,int flags,mode_t mode) {struct fake_open {const char *filename;
@@ -5295,7 +5293,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)if (is_proc_myself (pathname,"exe" )) {int execfd =qemu_getauxval (AT_EXECFD ); -return execfd ? execfd :get_errno (open (exec_path, flags, mode)); +return execfd ? execfd :get_errno (sys_openat (dirfd, exec_path, flags, mode)); }for (fake_open = fakes; fake_open->filename; fake_open++) {
@@ -5329,7 +5327,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)return fd; } -return get_errno (open (path (pathname), flags, mode)); +return get_errno (sys_openat (dirfd,path (pathname), flags, mode)); }/* do_syscall() should always have a single exit point at the end so
@@ -5404,22 +5402,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_open:if (!(p =lock_user_string (arg1))) goto efault; - ret =get_errno (do_open (cpu_env, p, -target_to_host_bitmask (arg2, fcntl_flags_tbl), - arg3)); + ret =get_errno (do_openat (cpu_env,AT_FDCWD , p, +target_to_host_bitmask (arg2, fcntl_flags_tbl), + arg3));unlock_user (p, arg1,0 );break ; -#if defined(TARGET_NR_openat) && defined(__NR_openat)case TARGET_NR_openat:if (!(p =lock_user_string (arg2))) goto efault; - ret =get_errno (sys_openat (arg1, -path (p), -target_to_host_bitmask (arg3, fcntl_flags_tbl), - arg4)); + ret =get_errno (do_openat (cpu_env, arg1, p, +target_to_host_bitmask (arg3, fcntl_flags_tbl), + arg4));unlock_user (p, arg2,0 );break ; -#endif case TARGET_NR_close: ret =get_errno (close (arg1));break ;
Signature · 1 line
2.0.1