Merge branch 'master' of /home/nchip/public_html/qemu into garage-push
[qemu] / linux-user / syscall.c
index 3095e20..2087226 100644 (file)
@@ -203,7 +203,7 @@ _syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count)
 _syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count);
 #endif
 _syscall2(int, sys_getpriority, int, which, int, who);
-#if !defined (__x86_64__)
+#if defined(TARGET_NR__llseek) && !defined (__x86_64__)
 _syscall5(int, _llseek,  uint,  fd, ulong, hi, ulong, lo,
           loff_t *, res, uint, wh);
 #endif
@@ -948,21 +948,22 @@ static abi_long do_select(int n,
 
     return ret;
 }
-static abi_long pipe_set_flag(int fd, int readcmd, int writecmd, long newflag)
+
+static abi_long do_pipe2(int host_pipe[], int flags)
 {
-    int flags = fcntl(fd, readcmd);
-    if (flags<0)
-        return get_errno(flags);
-    flags |= newflag;
-    flags = fcntl(fd, writecmd, flags);
-    return get_errno(flags);
+#ifdef CONFIG_PIPE2
+    return pipe2(host_pipe, flags);
+#else
+    return -ENOSYS;
+#endif
 }
 
 static abi_long do_pipe(void *cpu_env, int pipedes, int flags)
 {
     int host_pipe[2];
     abi_long ret;
-    ret = pipe(host_pipe);
+    ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
+
     if (is_error(ret))
         return get_errno(ret);
 #if defined(TARGET_MIPS)
@@ -976,22 +977,6 @@ static abi_long do_pipe(void *cpu_env, int pipedes, int flags)
         || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0])))
         return -TARGET_EFAULT;
 #endif
-    if (flags & O_NONBLOCK) {
-        ret = pipe_set_flag(host_pipe[0], F_GETFL, F_SETFL, O_NONBLOCK);
-        if (is_error(ret))
-            return get_errno(ret);
-        ret = pipe_set_flag(host_pipe[1], F_GETFL, F_SETFL, O_NONBLOCK);
-        if (is_error(ret))
-            return get_errno(ret);
-    }
-    if (flags & O_CLOEXEC) {
-        ret = pipe_set_flag(host_pipe[0], F_GETFD, F_SETFD, FD_CLOEXEC);
-        if (is_error(ret))
-            return get_errno(ret);
-        ret = pipe_set_flag(host_pipe[1], F_GETFD, F_SETFD, FD_CLOEXEC);
-        if (is_error(ret))
-            return get_errno(ret);
-    }
     return get_errno(ret);
 }
 
@@ -2841,7 +2826,7 @@ static abi_long do_ipc(unsigned int call, int first,
 /* kernel structure types definitions */
 #define IFNAMSIZ        16
 
-#define STRUCT(name, list...) STRUCT_ ## name,
+#define STRUCT(name, ...) STRUCT_ ## name,
 #define STRUCT_SPECIAL(name) STRUCT_ ## name,
 enum {
 #include "syscall_types.h"
@@ -2849,7 +2834,7 @@ enum {
 #undef STRUCT
 #undef STRUCT_SPECIAL
 
-#define STRUCT(name, list...) static const argtype struct_ ## name ## _def[] = { list, TYPE_NULL };
+#define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = {  __VA_ARGS__, TYPE_NULL };
 #define STRUCT_SPECIAL(name)
 #include "syscall_types.h"
 #undef STRUCT
@@ -2870,8 +2855,8 @@ typedef struct IOCTLEntry {
 #define MAX_STRUCT_SIZE 4096
 
 static IOCTLEntry ioctl_entries[] = {
-#define IOCTL(cmd, access, types...) \
-    { TARGET_ ## cmd, cmd, #cmd, access, { types } },
+#define IOCTL(cmd, access, ...) \
+    { TARGET_ ## cmd, cmd, #cmd, access, {  __VA_ARGS__ } },
 #include "ioctls.h"
     { 0, 0, },
 };
@@ -3484,8 +3469,9 @@ static void *clone_func(void *arg)
     env = info->env;
     thread_env = env;
     ts = (TaskState *)thread_env->opaque;
-    info->tid = gettid();
     task_settid(ts);
+    info->tid = gettid();
+    env->host_tid = info->tid;
     if (info->child_tidptr)
         put_user_u32(info->tid, info->child_tidptr);
     if (info->parent_tidptr)
@@ -3784,7 +3770,7 @@ void syscall_init(void)
     int size;
     int i;
 
-#define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
+#define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
 #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
 #include "syscall_types.h"
 #undef STRUCT
@@ -3996,6 +3982,8 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
                          pts, NULL, 0));
     case FUTEX_WAKE:
         return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+    case FUTEX_WAKE_OP:
+        return get_errno(sys_futex(g2h(uaddr), op, val, NULL, g2h(uaddr2), val3 ));
     case FUTEX_FD:
         return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_REQUEUE:
@@ -4083,6 +4071,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
       /* FIXME: This probably breaks if a signal arrives.  We should probably
          be disabling signals.  */
       if (first_cpu->next_cpu) {
+          TaskState *ts;
           CPUState **lastp;
           CPUState *p;
 
@@ -4100,7 +4089,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
           /* Remove the CPU from the list.  */
           *lastp = p->next_cpu;
           cpu_list_unlock();
-          TaskState *ts = ((CPUState *)cpu_env)->opaque;
+          ts = ((CPUState *)cpu_env)->opaque;
           if (ts->child_tidptr) {
               put_user_u32(0, ts->child_tidptr);
               sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
@@ -5133,7 +5122,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_mmap
     case TARGET_NR_mmap:
-#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS)
+#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE)
         {
             abi_ulong *v;
             abi_ulong v1, v2, v3, v4, v5, v6;