diff mbox series

[v2,015/108] linux-user: Split out creat, fork, waitid, waitpid

Message ID 20180610030220.3777-16-richard.henderson@linaro.org
State New
Headers show
Series linux-user: Split do_syscall | expand

Commit Message

Richard Henderson June 10, 2018, 3 a.m. UTC
All targets define waitid; remove the ifdef.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/syscall.c | 104 +++++++++++++++++++++++++++----------------
 1 file changed, 65 insertions(+), 39 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f51cc7e937..a146b696fd 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7882,6 +7882,22 @@  IMPL(close)
     return get_errno(close(arg1));
 }
 
+#ifdef TARGET_NR_creat
+IMPL(creat)
+{
+    char *p = lock_user_string(arg1);
+    abi_long ret;
+
+    if (!p) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(creat(p, arg2));
+    fd_trans_unregister(ret);
+    unlock_user(p, arg1, 0);
+    return ret;
+}
+#endif
+
 IMPL(execve)
 {
     abi_ulong *guest_ptrs;
@@ -8029,6 +8045,13 @@  IMPL(exit)
     g_assert_not_reached();
 }
 
+#ifdef TARGET_NR_fork
+IMPL(fork)
+{
+    return get_errno(do_fork(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0));
+}
+#endif
+
 #ifdef CONFIG_OPEN_BY_HANDLE
 IMPL(name_to_handle_at)
 {
@@ -8174,6 +8197,38 @@  IMPL(read)
     return ret;
 }
 
+IMPL(waitid)
+{
+    siginfo_t info;
+    abi_long ret;
+
+    info.si_pid = 0;
+    ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));
+    if (!is_error(ret) && arg3 && info.si_pid != 0) {
+        target_siginfo_t *p
+            = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0);
+        if (!p) {
+            return -TARGET_EFAULT;
+        }
+        host_to_target_siginfo(p, &info);
+        unlock_user(p, arg3, sizeof(target_siginfo_t));
+    }
+    return ret;
+}
+
+#ifdef TARGET_NR_waitpid
+IMPL(waitpid)
+{
+    int status;
+    abi_long ret = get_errno(safe_wait4(arg1, &status, arg3, 0));
+    if (!is_error(ret) && arg2 && ret &&
+        put_user_s32(host_to_target_waitstatus(status), arg2)) {
+        return -TARGET_EFAULT;
+    }
+    return ret;
+}
+#endif
+
 IMPL(write)
 {
     abi_long ret;
@@ -8215,45 +8270,6 @@  static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1,
     void *p;
 
     switch(num) {
-#ifdef TARGET_NR_fork
-    case TARGET_NR_fork:
-        return get_errno(do_fork(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0));
-#endif
-#ifdef TARGET_NR_waitpid
-    case TARGET_NR_waitpid:
-        {
-            int status;
-            ret = get_errno(safe_wait4(arg1, &status, arg3, 0));
-            if (!is_error(ret) && arg2 && ret
-                && put_user_s32(host_to_target_waitstatus(status), arg2))
-                return -TARGET_EFAULT;
-        }
-        return ret;
-#endif
-#ifdef TARGET_NR_waitid
-    case TARGET_NR_waitid:
-        {
-            siginfo_t info;
-            info.si_pid = 0;
-            ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL));
-            if (!is_error(ret) && arg3 && info.si_pid != 0) {
-                if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0)))
-                    return -TARGET_EFAULT;
-                host_to_target_siginfo(p, &info);
-                unlock_user(p, arg3, sizeof(target_siginfo_t));
-            }
-        }
-        return ret;
-#endif
-#ifdef TARGET_NR_creat /* not on alpha */
-    case TARGET_NR_creat:
-        if (!(p = lock_user_string(arg1)))
-            return -TARGET_EFAULT;
-        ret = get_errno(creat(p, arg2));
-        fd_trans_unregister(ret);
-        unlock_user(p, arg1, 0);
-        return ret;
-#endif
 #ifdef TARGET_NR_link
     case TARGET_NR_link:
         {
@@ -12482,8 +12498,14 @@  static impl_fn *syscall_table(unsigned num)
          */
         SYSCALL(brk);
         SYSCALL(close);
+#ifdef TARGET_NR_creat
+        SYSCALL(creat);
+#endif
         SYSCALL(execve);
         SYSCALL(exit);
+#ifdef TARGET_NR_fork
+        SYSCALL(fork);
+#endif
 #ifdef CONFIG_OPEN_BY_HANDLE
         SYSCALL(name_to_handle_at);
 #endif
@@ -12495,6 +12517,10 @@  static impl_fn *syscall_table(unsigned num)
         SYSCALL(open_by_handle_at);
 #endif
         SYSCALL(read);
+        SYSCALL(waitid);
+#ifdef TARGET_NR_waitpid
+        SYSCALL(waitpid);
+#endif
         SYSCALL(write);
     }