* [Qemu-devel] [PATCH 01/11] alpha-linux-user: Fix umount syscall numbers
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
@ 2013-09-27 12:09 ` riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 02/11] mips-linux-user: Adjust names in mips_syscall_args riku.voipio
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:09 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson
From: Richard Henderson <rth@twiddle.net>
It has been pointed out on LKML that the alpha umount syscall numbers
are named wrong, and a patch to rectify that has been posted for 3.11.
Glibc works around this by treating NR_umount as NR_umount2 if
NR_oldumount exists. That's more complicated than we need in QEMU,
given that we control linux-user/*/syscall_nr.h.
This is the last instance of TARGET_NR_oldumount, so delete that from
the strace.list.
Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/alpha/syscall_nr.h | 4 ++--
linux-user/strace.list | 3 ---
linux-user/syscall.c | 2 +-
3 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/linux-user/alpha/syscall_nr.h b/linux-user/alpha/syscall_nr.h
index ac2b6e2..d52d76e 100644
--- a/linux-user/alpha/syscall_nr.h
+++ b/linux-user/alpha/syscall_nr.h
@@ -20,7 +20,7 @@
#define TARGET_NR_lseek 19
#define TARGET_NR_getxpid 20
#define TARGET_NR_osf_mount 21
-#define TARGET_NR_umount 22
+#define TARGET_NR_umount2 22
#define TARGET_NR_setuid 23
#define TARGET_NR_getxuid 24
#define TARGET_NR_exec_with_loader 25 /* not implemented */
@@ -255,7 +255,7 @@
#define TARGET_NR_sysinfo 318
#define TARGET_NR__sysctl 319
/* 320 was sys_idle. */
-#define TARGET_NR_oldumount 321
+#define TARGET_NR_umount 321
#define TARGET_NR_swapon 322
#define TARGET_NR_times 323
#define TARGET_NR_personality 324
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 08f115d..4f9c364 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -612,9 +612,6 @@
#ifdef TARGET_NR_oldstat
{ TARGET_NR_oldstat, "oldstat" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_oldumount
-{ TARGET_NR_oldumount, "oldumount" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_olduname
{ TARGET_NR_olduname, "olduname" , NULL, NULL, NULL },
#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c62d875..5c33e44 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5697,7 +5697,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
unlock_user(p, arg1, 0);
}
break;
-#ifdef TARGET_NR_umount2 /* not on alpha */
+#ifdef TARGET_NR_umount2
case TARGET_NR_umount2:
if (!(p = lock_user_string(arg1)))
goto efault;
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 02/11] mips-linux-user: Adjust names in mips_syscall_args
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 01/11] alpha-linux-user: Fix umount syscall numbers riku.voipio
@ 2013-09-27 12:09 ` riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 03/11] linux-user: convert /proc/net/route when endianess differs riku.voipio
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:09 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson
From: Richard Henderson <rth@twiddle.net>
The name field of MIPS_SYS isn't actually used; it's just documentation.
But adjust the umount entries to match mips/syscall_nr.h anyway.
Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index 01e3cd4..3eed252 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1861,7 +1861,7 @@ static const uint8_t mips_syscall_args[] = {
MIPS_SYS(sys_lseek , 3)
MIPS_SYS(sys_getpid , 0) /* 4020 */
MIPS_SYS(sys_mount , 5)
- MIPS_SYS(sys_oldumount , 1)
+ MIPS_SYS(sys_umount , 1)
MIPS_SYS(sys_setuid , 1)
MIPS_SYS(sys_getuid , 0)
MIPS_SYS(sys_stime , 1) /* 4025 */
@@ -1891,7 +1891,7 @@ static const uint8_t mips_syscall_args[] = {
MIPS_SYS(sys_geteuid , 0)
MIPS_SYS(sys_getegid , 0) /* 4050 */
MIPS_SYS(sys_acct , 0)
- MIPS_SYS(sys_umount , 2)
+ MIPS_SYS(sys_umount2 , 2)
MIPS_SYS(sys_ni_syscall , 0)
MIPS_SYS(sys_ioctl , 3)
MIPS_SYS(sys_fcntl , 3) /* 4055 */
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 03/11] linux-user: convert /proc/net/route when endianess differs
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 01/11] alpha-linux-user: Fix umount syscall numbers riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 02/11] mips-linux-user: Adjust names in mips_syscall_args riku.voipio
@ 2013-09-27 12:09 ` riku.voipio
2013-09-27 12:09 ` [Qemu-devel] [PATCH 04/11] linux-user: Add setsockopt(SO_ATTACH_FILTER) riku.voipio
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:09 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
From: Laurent Vivier <laurent@vivier.eu>
This patch allows to have IP addresses in correct order
in the case of "netstat -nr" when the endianess of the
guest differs from one of the host.
For instance, an m68k guest on an x86_64 host:
WITHOUT this patch:
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 1.3.0.10 0.0.0.0 UG 0 0 0 eth0
0.3.0.10 0.0.0.0 0.255.255.255 U 0 0 0 eth0
$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
eth0 00000000 0103000A 0003 0 0 0 000000000 0 0
eth0 0003000A 00000000 0001 0 0 0 00FFFFFF0 0 0
WITH this patch:
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.3.1 0.0.0.0 UG 0 0 0 eth0
10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
eth0 00000000 0a000301 0003 0 0 0 000000000 0 0
eth0 0a000300 00000000 0001 0 0 0 ffffff000 0 0
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 53 insertions(+), 5 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5c33e44..251c116 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5071,22 +5071,70 @@ static int is_proc_myself(const char *filename, const char *entry)
return 0;
}
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+static int is_proc(const char *filename, const char *entry)
+{
+ return strcmp(filename, entry) == 0;
+}
+
+static int open_net_route(void *cpu_env, int fd)
+{
+ FILE *fp;
+ char *line = NULL;
+ size_t len = 0;
+ ssize_t read;
+
+ fp = fopen("/proc/net/route", "r");
+ if (fp == NULL) {
+ return -EACCES;
+ }
+
+ /* read header */
+
+ read = getline(&line, &len, fp);
+ dprintf(fd, "%s", line);
+
+ /* read routes */
+
+ while ((read = getline(&line, &len, fp)) != -1) {
+ char iface[16];
+ uint32_t dest, gw, mask;
+ unsigned int flags, refcnt, use, metric, mtu, window, irtt;
+ sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+ iface, &dest, &gw, &flags, &refcnt, &use, &metric,
+ &mask, &mtu, &window, &irtt);
+ dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+ iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
+ metric, tswap32(mask), mtu, window, irtt);
+ }
+
+ free(line);
+ fclose(fp);
+
+ return 0;
+}
+#endif
+
static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
{
struct fake_open {
const char *filename;
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 },
- { "stat", open_self_stat },
- { "auxv", open_self_auxv },
- { NULL, NULL }
+ { "maps", open_self_maps, is_proc_myself },
+ { "stat", open_self_stat, is_proc_myself },
+ { "auxv", open_self_auxv, is_proc_myself },
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+ { "/proc/net/route", open_net_route, is_proc },
+#endif
+ { NULL, NULL, NULL }
};
for (fake_open = fakes; fake_open->filename; fake_open++) {
- if (is_proc_myself(pathname, fake_open->filename)) {
+ if (fake_open->cmp(pathname, fake_open->filename)) {
break;
}
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 04/11] linux-user: Add setsockopt(SO_ATTACH_FILTER)
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (2 preceding siblings ...)
2013-09-27 12:09 ` [Qemu-devel] [PATCH 03/11] linux-user: convert /proc/net/route when endianess differs riku.voipio
@ 2013-09-27 12:09 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 05/11] linux-user: allow use of TIOCGSID riku.voipio
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:09 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
From: Laurent Vivier <laurent@vivier.eu>
This is needed to be able to run dhclient.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
linux-user/syscall_defs.h | 12 ++++++++++++
2 files changed, 56 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 251c116..505031b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -106,6 +106,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
#include <linux/dm-ioctl.h>
#include <linux/reboot.h>
#include <linux/route.h>
+#include <linux/filter.h>
#include "linux_loop.h"
#include "cpu-uname.h"
@@ -1357,6 +1358,49 @@ set_timeout:
case TARGET_SO_SNDTIMEO:
optname = SO_SNDTIMEO;
goto set_timeout;
+ case TARGET_SO_ATTACH_FILTER:
+ {
+ struct target_sock_fprog *tfprog;
+ struct target_sock_filter *tfilter;
+ struct sock_fprog fprog;
+ struct sock_filter *filter;
+ int i;
+
+ if (optlen != sizeof(*tfprog)) {
+ return -TARGET_EINVAL;
+ }
+ if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)) {
+ return -TARGET_EFAULT;
+ }
+ if (!lock_user_struct(VERIFY_READ, tfilter,
+ tswapal(tfprog->filter), 0)) {
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return -TARGET_EFAULT;
+ }
+
+ fprog.len = tswap16(tfprog->len);
+ filter = malloc(fprog.len * sizeof(*filter));
+ if (filter == NULL) {
+ unlock_user_struct(tfilter, tfprog->filter, 1);
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return -TARGET_ENOMEM;
+ }
+ for (i = 0; i < fprog.len; i++) {
+ filter[i].code = tswap16(tfilter[i].code);
+ filter[i].jt = tfilter[i].jt;
+ filter[i].jf = tfilter[i].jf;
+ filter[i].k = tswap32(tfilter[i].k);
+ }
+ fprog.filter = filter;
+
+ ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+ SO_ATTACH_FILTER, &fprog, sizeof(fprog)));
+ free(filter);
+
+ unlock_user_struct(tfilter, tfprog->filter, 1);
+ unlock_user_struct(tfprog, optval_addr, 1);
+ return ret;
+ }
/* Options with 'int' argument. */
case TARGET_SO_DEBUG:
optname = SO_DEBUG;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 2ebe356..5f53a28 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -119,6 +119,18 @@ struct target_sockaddr {
uint8_t sa_data[14];
};
+struct target_sock_filter {
+ abi_ushort code;
+ uint8_t jt;
+ uint8_t jf;
+ abi_uint k;
+};
+
+struct target_sock_fprog {
+ abi_ushort len;
+ abi_ulong filter;
+};
+
struct target_in_addr {
uint32_t s_addr; /* big endian */
};
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 05/11] linux-user: allow use of TIOCGSID
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (3 preceding siblings ...)
2013-09-27 12:09 ` [Qemu-devel] [PATCH 04/11] linux-user: Add setsockopt(SO_ATTACH_FILTER) riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 06/11] linux-user: add some IPV6 commands in setsockop() riku.voipio
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
From: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/ioctls.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 439c2a9..7381012 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -20,6 +20,7 @@
IOCTL(TIOCSCTTY, 0, TYPE_INT)
IOCTL(TIOCGPGRP, IOC_R, MK_PTR(TYPE_INT))
IOCTL(TIOCSPGRP, IOC_W, MK_PTR(TYPE_INT))
+ IOCTL(TIOCGSID, IOC_W, MK_PTR(TYPE_INT))
IOCTL(TIOCOUTQ, IOC_R, MK_PTR(TYPE_INT))
IOCTL(TIOCSTI, IOC_W, MK_PTR(TYPE_INT))
IOCTL(TIOCMGET, IOC_R, MK_PTR(TYPE_INT))
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 06/11] linux-user: add some IPV6 commands in setsockop()
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (4 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 05/11] linux-user: allow use of TIOCGSID riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 07/11] linux-user: add support of binfmt_misc 'O' flag riku.voipio
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
From: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 505031b..7a093ba 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1315,6 +1315,26 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
goto unimplemented;
}
break;
+ case SOL_IPV6:
+ switch (optname) {
+ case IPV6_MTU_DISCOVER:
+ case IPV6_MTU:
+ case IPV6_V6ONLY:
+ case IPV6_RECVPKTINFO:
+ val = 0;
+ if (optlen < sizeof(uint32_t)) {
+ return -TARGET_EINVAL;
+ }
+ if (get_user_u32(val, optval_addr)) {
+ return -TARGET_EFAULT;
+ }
+ ret = get_errno(setsockopt(sockfd, level, optname,
+ &val, sizeof(val)));
+ break;
+ default:
+ goto unimplemented;
+ }
+ break;
case SOL_RAW:
switch (optname) {
case ICMP_FILTER:
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 07/11] linux-user: add support of binfmt_misc 'O' flag
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (5 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 06/11] linux-user: add some IPV6 commands in setsockop() riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 08/11] linux-user: correct how SOL_SOCKET is converted from target to host and back riku.voipio
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
From: Laurent Vivier <laurent@vivier.eu>
The binfmt_misc module can calculate the credentials and security
token according to the binary instead of to the interpreter if the
'C' flag is enabled.
To be able to execute non-readable binaries, this flag implies 'O'
flag. When 'O' flag is enabled, bintfmt_misc opens the file for
reading and pass the file descriptor to the interpreter.
References:
linux/Documentation/binfmt_misc.txt ['O' and 'C' description]
linux/fs/binfmt_misc.c linux/fs/binfmt_elf.c [ AT_EXECFD usage ]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/linuxload.c | 8 ++------
linux-user/main.c | 32 +++++++++++++++++++++++++++++++-
linux-user/qemu.h | 2 +-
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 5cd6d91..a1fe5ed 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -131,7 +131,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
return sp;
}
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
struct target_pt_regs * regs, struct image_info *infop,
struct linux_binprm *bprm)
{
@@ -140,11 +140,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
memset(bprm->page, 0, sizeof(bprm->page));
- retval = open(filename, O_RDONLY);
- if (retval < 0) {
- return -errno;
- }
- bprm->fd = retval;
+ bprm->fd = fdexec;
bprm->filename = (char *)filename;
bprm->argc = count(argv);
bprm->argv = argv;
diff --git a/linux-user/main.c b/linux-user/main.c
index 3eed252..016e2e1 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3618,6 +3618,26 @@ static int parse_args(int argc, char **argv)
return optind;
}
+static int get_execfd(char **envp)
+{
+ typedef struct {
+ long a_type;
+ long a_val;
+ } auxv_t;
+ auxv_t *auxv;
+
+ while (*envp++ != NULL) {
+ ;
+ }
+
+ for (auxv = (auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
+ if (auxv->a_type == AT_EXECFD) {
+ return auxv->a_val;
+ }
+ }
+ return -1;
+}
+
int main(int argc, char **argv, char **envp)
{
struct target_pt_regs regs1, *regs = ®s1;
@@ -3632,6 +3652,7 @@ int main(int argc, char **argv, char **envp)
int target_argc;
int i;
int ret;
+ int execfd;
module_call_init(MODULE_INIT_QOM);
@@ -3809,7 +3830,16 @@ int main(int argc, char **argv, char **envp)
env->opaque = ts;
task_settid(ts);
- ret = loader_exec(filename, target_argv, target_environ, regs,
+ execfd = get_execfd(envp);
+ if (execfd < 0) {
+ execfd = open(filename, O_RDONLY);
+ }
+ if (execfd < 0) {
+ printf("Error while loading %s: %s\n", filename, strerror(-execfd));
+ _exit(1);
+ }
+
+ ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
info, &bprm);
if (ret != 0) {
printf("Error while loading %s: %s\n", filename, strerror(-ret));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 617cac1..da64e87 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -174,7 +174,7 @@ struct linux_binprm {
void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
struct target_pt_regs * regs, struct image_info *infop,
struct linux_binprm *);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 08/11] linux-user: correct how SOL_SOCKET is converted from target to host and back
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (6 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 07/11] linux-user: add support of binfmt_misc 'O' flag riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 09/11] linux-user: Check type of microMIPS break instruction riku.voipio
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Petar Jovanovic
From: Petar Jovanovic <petar.jovanovic@imgtec.com>
Previous implementation does not take into account that SOL_SOCKET constant
can be arch specific. This change fixes some issues with sendmsg/recvmsg.
Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7a093ba..aebe36d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1150,11 +1150,15 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
break;
}
- cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
+ if (tswap32(target_cmsg->cmsg_level) == TARGET_SOL_SOCKET) {
+ cmsg->cmsg_level = SOL_SOCKET;
+ } else {
+ cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
+ }
cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
cmsg->cmsg_len = CMSG_LEN(len);
- if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+ if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
memcpy(data, target_data, len);
} else {
@@ -1205,11 +1209,15 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
break;
}
- target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
+ if (cmsg->cmsg_level == SOL_SOCKET) {
+ target_cmsg->cmsg_level = tswap32(TARGET_SOL_SOCKET);
+ } else {
+ target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
+ }
target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
- if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+ if ((cmsg->cmsg_level == SOL_SOCKET) &&
(cmsg->cmsg_type == SCM_RIGHTS)) {
int *fd = (int *)data;
int *target_fd = (int *)target_data;
@@ -1217,7 +1225,7 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
for (i = 0; i < numfds; i++)
target_fd[i] = tswap32(fd[i]);
- } else if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+ } else if ((cmsg->cmsg_level == SOL_SOCKET) &&
(cmsg->cmsg_type == SO_TIMESTAMP) &&
(len == sizeof(struct timeval))) {
/* copy struct timeval to target */
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 09/11] linux-user: Check type of microMIPS break instruction
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (7 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 08/11] linux-user: correct how SOL_SOCKET is converted from target to host and back riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 10/11] [v2] linux-user: implement m68k atomic syscalls riku.voipio
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Kwok Cheung Yeung
From: Kwok Cheung Yeung <kcy@codesourcery.com>
microMIPS instructions that cause breakpoint exceptions come in
16-bit and 32-bit variants. When handling exceptions caused by
such instructions, the instruction type needs to be taken into
account when extracting the break code.
The code has also been restructured for better clarity.
Signed-off-by: Kwok Cheung Yeung <kcy@codesourcery.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/main.c | 56 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index 016e2e1..1561950 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2400,12 +2400,31 @@ done_syscall:
if (env->hflags & MIPS_HFLAG_M16) {
if (env->insn_flags & ASE_MICROMIPS) {
/* microMIPS mode */
- abi_ulong instr[2];
-
- ret = get_user_u16(instr[0], env->active_tc.PC) ||
- get_user_u16(instr[1], env->active_tc.PC + 2);
+ ret = get_user_u16(trap_instr, env->active_tc.PC);
+ if (ret != 0) {
+ goto error;
+ }
- trap_instr = (instr[0] << 16) | instr[1];
+ if ((trap_instr >> 10) == 0x11) {
+ /* 16-bit instruction */
+ code = trap_instr & 0xf;
+ } else {
+ /* 32-bit instruction */
+ abi_ulong instr_lo;
+
+ ret = get_user_u16(instr_lo,
+ env->active_tc.PC + 2);
+ if (ret != 0) {
+ goto error;
+ }
+ trap_instr = (trap_instr << 16) | instr_lo;
+ code = ((trap_instr >> 6) & ((1 << 20) - 1));
+ /* Unfortunately, microMIPS also suffers from
+ the old assembler bug... */
+ if (code >= (1 << 10)) {
+ code >>= 10;
+ }
+ }
} else {
/* MIPS16e mode */
ret = get_user_u16(trap_instr, env->active_tc.PC);
@@ -2413,26 +2432,21 @@ done_syscall:
goto error;
}
code = (trap_instr >> 6) & 0x3f;
- if (do_break(env, &info, code) != 0) {
- goto error;
- }
- break;
}
} else {
ret = get_user_ual(trap_instr, env->active_tc.PC);
- }
-
- if (ret != 0) {
- goto error;
- }
+ if (ret != 0) {
+ goto error;
+ }
- /* As described in the original Linux kernel code, the
- * below checks on 'code' are to work around an old
- * assembly bug.
- */
- code = ((trap_instr >> 6) & ((1 << 20) - 1));
- if (code >= (1 << 10)) {
- code >>= 10;
+ /* As described in the original Linux kernel code, the
+ * below checks on 'code' are to work around an old
+ * assembly bug.
+ */
+ code = ((trap_instr >> 6) & ((1 << 20) - 1));
+ if (code >= (1 << 10)) {
+ code >>= 10;
+ }
}
if (do_break(env, &info, code) != 0) {
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 10/11] [v2] linux-user: implement m68k atomic syscalls
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (8 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 09/11] linux-user: Check type of microMIPS break instruction riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 12:10 ` [Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host riku.voipio
2013-09-27 15:20 ` [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates Edgar E. Iglesias
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Riku Voipio, Laurent Vivier
From: Riku Voipio <riku.voipio@linaro.org>
With nptl enabled, atomic_cmpxchg_32 and atomic_barrier
system calls are needed. This patch enabled really dummy
versions of the system calls, modeled after the m68k
kernel code.
With this patch I am able to execute m68k binaries
with qemu linux-user (busybox compiled for coldfire).
[v2] que an segfault instead of returning a EFAULT
to keep in line with kernel code.
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/strace.list | 6 ++++++
linux-user/syscall.c | 28 ++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 4f9c364..cf5841a 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1521,3 +1521,9 @@
#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
+#ifdef TARGET_NR_atomic_barrier
+{ TARGET_NR_atomic_barrier, "atomic_barrier", NULL, NULL, NULL },
+#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index aebe36d..b3822b3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9133,6 +9133,34 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
break;
}
#endif
+#ifdef TARGET_NR_atomic_cmpxchg_32
+ case TARGET_NR_atomic_cmpxchg_32:
+ {
+ /* should use start_exclusive from main.c */
+ abi_ulong mem_value;
+ if (get_user_u32(mem_value, arg6)) {
+ target_siginfo_t info;
+ info.si_signo = SIGSEGV;
+ info.si_errno = 0;
+ info.si_code = TARGET_SEGV_MAPERR;
+ info._sifields._sigfault._addr = arg6;
+ queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
+ ret = 0xdeadbeef;
+
+ }
+ if (mem_value == arg2)
+ put_user_u32(arg1, arg6);
+ ret = mem_value;
+ break;
+ }
+#endif
+#ifdef TARGET_NR_atomic_barrier
+ case TARGET_NR_atomic_barrier:
+ {
+ /* Like the kernel implementation and the qemu arm barrier, no-op this? */
+ break;
+ }
+#endif
default:
unimplemented:
gemu_log("qemu: Unsupported syscall: %d\n", num);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (9 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 10/11] [v2] linux-user: implement m68k atomic syscalls riku.voipio
@ 2013-09-27 12:10 ` riku.voipio
2013-09-27 15:20 ` [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates Edgar E. Iglesias
11 siblings, 0 replies; 13+ messages in thread
From: riku.voipio @ 2013-09-27 12:10 UTC (permalink / raw)
To: qemu-devel; +Cc: Edgar E. Iglesias
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
If the host lacks SOCK_CLOEXEC, bail out with -EINVAL.
If the host lacks SOCK_ONONBLOCK, try to emulate it with fcntl()
and O_NONBLOCK.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b3822b3..4a14a43 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1773,7 +1773,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
free(vec);
}
-static inline void target_to_host_sock_type(int *type)
+static inline int target_to_host_sock_type(int *type)
{
int host_type = 0;
int target_type = *type;
@@ -1790,22 +1790,56 @@ static inline void target_to_host_sock_type(int *type)
break;
}
if (target_type & TARGET_SOCK_CLOEXEC) {
+#if defined(SOCK_CLOEXEC)
host_type |= SOCK_CLOEXEC;
+#else
+ return -TARGET_EINVAL;
+#endif
}
if (target_type & TARGET_SOCK_NONBLOCK) {
+#if defined(SOCK_NONBLOCK)
host_type |= SOCK_NONBLOCK;
+#elif !defined(O_NONBLOCK)
+ return -TARGET_EINVAL;
+#endif
}
*type = host_type;
+ return 0;
+}
+
+/* Try to emulate socket type flags after socket creation. */
+static int sock_flags_fixup(int fd, int target_type)
+{
+#if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK)
+ if (target_type & TARGET_SOCK_NONBLOCK) {
+ int flags = fcntl(fd, F_GETFL);
+ if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) {
+ close(fd);
+ return -TARGET_EINVAL;
+ }
+ }
+#endif
+ return fd;
}
/* do_socket() Must return target values and target errnos. */
static abi_long do_socket(int domain, int type, int protocol)
{
- target_to_host_sock_type(&type);
+ int target_type = type;
+ int ret;
+
+ ret = target_to_host_sock_type(&type);
+ if (ret) {
+ return ret;
+ }
if (domain == PF_NETLINK)
return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
- return get_errno(socket(domain, type, protocol));
+ ret = get_errno(socket(domain, type, protocol));
+ if (ret >= 0) {
+ ret = sock_flags_fixup(ret, target_type);
+ }
+ return ret;
}
/* do_bind() Must return target values and target errnos. */
--
1.8.1.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates
2013-09-27 12:09 [Qemu-devel] [PULL] [PATCH 00/11] Linux-user updates riku.voipio
` (10 preceding siblings ...)
2013-09-27 12:10 ` [Qemu-devel] [PATCH 11/11] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host riku.voipio
@ 2013-09-27 15:20 ` Edgar E. Iglesias
11 siblings, 0 replies; 13+ messages in thread
From: Edgar E. Iglesias @ 2013-09-27 15:20 UTC (permalink / raw)
To: riku.voipio; +Cc: qemu-devel
On Fri, Sep 27, 2013 at 03:09:55PM +0300, riku.voipio@linaro.org wrote:
> From: Riku Voipio <riku.voipio@linaro.org>
>
> The following changes since commit f828a4c8faa118e0ebab3e353ac6840f3b2a0318:
>
> Merge remote-tracking branch 'stefanha/tracing' into staging (2013-09-23 11:53:22 -0500)
>
> are available in the git repository at:
>
> git://git.linaro.org/people/rikuvoipio/qemu.git linux-user-for-upstream
>
> for you to fetch changes up to 53d09b761f032f50c4424e8649396a9041070bae:
>
> linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host (2013-09-24 10:47:07 +0300)
Pulled, thanks Riku.
Cheers,
Edgar
>
> ----------------------------------------------------------------
>
> Edgar E. Iglesias (1):
> linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on host
>
> Kwok Cheung Yeung (1):
> linux-user: Check type of microMIPS break instruction
>
> Laurent Vivier (5):
> linux-user: convert /proc/net/route when endianess differs
> linux-user: Add setsockopt(SO_ATTACH_FILTER)
> linux-user: allow use of TIOCGSID
> linux-user: add some IPV6 commands in setsockop()
> linux-user: add support of binfmt_misc 'O' flag
>
> Petar Jovanovic (1):
> linux-user: correct how SOL_SOCKET is converted from target to host
> and back
>
> Richard Henderson (2):
> alpha-linux-user: Fix umount syscall numbers
> mips-linux-user: Adjust names in mips_syscall_args
>
> Riku Voipio (1):
> [v2] linux-user: implement m68k atomic syscalls
>
> linux-user/alpha/syscall_nr.h | 4 +-
> linux-user/ioctls.h | 1 +
> linux-user/linuxload.c | 8 +-
> linux-user/main.c | 92 +++++++++++++-----
> linux-user/qemu.h | 2 +-
> linux-user/strace.list | 9 +-
> linux-user/syscall.c | 210 +++++++++++++++++++++++++++++++++++++++---
> linux-user/syscall_defs.h | 12 +++
> 8 files changed, 288 insertions(+), 50 deletions(-)
>
> --
> 1.8.1.2
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread