diff mbox series

[16/33] linux-user: Split out link, linkat

Message ID 20180601073050.8054-17-richard.henderson@linaro.org
State New
Headers show
Series linux-user: Begin splitting do_syscall | expand

Commit Message

Richard Henderson June 1, 2018, 7:30 a.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/syscall.c | 77 +++++++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 34 deletions(-)

-- 
2.17.0
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e208f8647a..b5736436f8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8078,6 +8078,43 @@  IMPL(fork)
 }
 #endif
 
+#ifdef TARGET_NR_link
+IMPL(link)
+{
+    char *p1 = lock_user_string(arg1);
+    char *p2 = lock_user_string(arg2);
+    abi_long ret = -TARGET_EFAULT;
+
+    if (p1 && p2) {
+        ret = get_errno(link(p1, p2));
+    }
+    unlock_user(p1, arg1, 0);
+    unlock_user(p2, arg2, 0);
+    return ret;
+}
+#endif
+
+#if defined(TARGET_NR_linkat)
+IMPL(linkat)
+{
+    char *p1, *p2;
+    abi_long ret;
+
+    if (is_hostfd(arg1)) {
+        return -TARGET_EBADF;
+    }
+    p1 = lock_user_string(arg2);
+    p2 = lock_user_string(arg4);
+    ret = -TARGET_EFAULT;
+    if (p1 && p2) {
+        ret = get_errno(linkat(arg1, p1, arg3, p2, arg5));
+    }
+    unlock_user(p1, arg2, 0);
+    unlock_user(p2, arg4, 0);
+    return ret;
+}
+#endif
+
 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
 IMPL(name_to_handle_at)
 {
@@ -8315,40 +8352,6 @@  IMPL(everything_else)
     char *fn;
 
     switch(num) {
-#ifdef TARGET_NR_link
-    case TARGET_NR_link:
-        {
-            void * p2;
-            p = lock_user_string(arg1);
-            p2 = lock_user_string(arg2);
-            if (!p || !p2)
-                ret = -TARGET_EFAULT;
-            else
-                ret = get_errno(link(p, p2));
-            unlock_user(p2, arg2, 0);
-            unlock_user(p, arg1, 0);
-        }
-        return ret;
-#endif
-#if defined(TARGET_NR_linkat)
-    case TARGET_NR_linkat:
-        if (is_hostfd(arg1)) {
-            return -TARGET_EBADF;
-        } else {
-            void * p2 = NULL;
-            if (!arg2 || !arg4)
-                return -TARGET_EFAULT;
-            p  = lock_user_string(arg2);
-            p2 = lock_user_string(arg4);
-            if (!p || !p2)
-                ret = -TARGET_EFAULT;
-            else
-                ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
-            unlock_user(p, arg2, 0);
-            unlock_user(p2, arg4, 0);
-        }
-        return ret;
-#endif
 #ifdef TARGET_NR_unlink
     case TARGET_NR_unlink:
         if (!(p = lock_user_string(arg1)))
@@ -12958,6 +12961,12 @@  static impl_fn * const syscall_table[] = {
 #ifdef TARGET_NR_fork
     [TARGET_NR_fork] = impl_fork,
 #endif
+#ifdef TARGET_NR_link
+    [TARGET_NR_link] = impl_link,
+#endif
+#if defined(TARGET_NR_linkat)
+    [TARGET_NR_linkat] = impl_linkat,
+#endif
 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
     [TARGET_NR_name_to_handle_at] = impl_name_to_handle_at,
 #endif