diff mbox series

[v2,075/108] linux-user: Split out chown, getresgid, getresuid

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

Commit Message

Richard Henderson June 10, 2018, 3:01 a.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/syscall.c | 94 +++++++++++++++++++++++++++-----------------
 1 file changed, 57 insertions(+), 37 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 75b869fb33..c55c414239 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7787,6 +7787,21 @@  IMPL(chmod)
 }
 #endif
 
+#ifdef TARGET_NR_chown
+IMPL(chown)
+{
+    char *p = lock_user_string(arg1);
+    abi_long ret;
+
+    if (!p) {
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
+    unlock_user(p, arg1, 0);
+    return ret;
+}
+#endif
+
 IMPL(chroot)
 {
     char *p = lock_user_string(arg1);
@@ -8588,6 +8603,38 @@  IMPL(getrandom)
     return ret;
 }
 
+#ifdef TARGET_NR_getresgid
+IMPL(getresgid)
+{
+    gid_t rgid, egid, sgid;
+    abi_long ret = get_errno(getresgid(&rgid, &egid, &sgid));
+
+    if (!is_error(ret) &&
+        (put_user_id(high2lowgid(rgid), arg1) ||
+         put_user_id(high2lowgid(egid), arg2) ||
+         put_user_id(high2lowgid(sgid), arg3))) {
+        return -TARGET_EFAULT;
+    }
+    return ret;
+}
+#endif
+
+#ifdef TARGET_NR_getresuid
+IMPL(getresuid)
+{
+    uid_t ruid, euid, suid;
+    abi_long ret = get_errno(getresuid(&ruid, &euid, &suid));
+
+    if (!is_error(ret) &&
+        (put_user_id(high2lowuid(ruid), arg1) ||
+         put_user_id(high2lowuid(euid), arg2) ||
+         put_user_id(high2lowuid(suid), arg3))) {
+        return -TARGET_EFAULT;
+    }
+    return ret;
+}
+#endif
+
 IMPL(getrlimit)
 {
     int resource = target_to_host_resource(arg1);
@@ -11547,42 +11594,6 @@  static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1,
     void *p;
 
     switch(num) {
-#ifdef TARGET_NR_getresuid
-    case TARGET_NR_getresuid:
-        {
-            uid_t ruid, euid, suid;
-            ret = get_errno(getresuid(&ruid, &euid, &suid));
-            if (!is_error(ret)) {
-                if (put_user_id(high2lowuid(ruid), arg1)
-                    || put_user_id(high2lowuid(euid), arg2)
-                    || put_user_id(high2lowuid(suid), arg3))
-                    return -TARGET_EFAULT;
-            }
-        }
-        return ret;
-#endif
-#ifdef TARGET_NR_getresgid
-    case TARGET_NR_getresgid:
-        {
-            gid_t rgid, egid, sgid;
-            ret = get_errno(getresgid(&rgid, &egid, &sgid));
-            if (!is_error(ret)) {
-                if (put_user_id(high2lowgid(rgid), arg1)
-                    || put_user_id(high2lowgid(egid), arg2)
-                    || put_user_id(high2lowgid(sgid), arg3))
-                    return -TARGET_EFAULT;
-            }
-        }
-        return ret;
-#endif
-#ifdef TARGET_NR_chown
-    case TARGET_NR_chown:
-        if (!(p = lock_user_string(arg1)))
-            return -TARGET_EFAULT;
-        ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3)));
-        unlock_user(p, arg1, 0);
-        return ret;
-#endif
     case TARGET_NR_setuid:
         return get_errno(sys_setuid(low2highuid(arg1)));
     case TARGET_NR_setgid:
@@ -13080,10 +13091,13 @@  static impl_fn *syscall_table(unsigned num)
         SYSCALL(clone);
         SYSCALL(close);
         SYSCALL(chdir);
-        SYSCALL(chroot);
 #ifdef TARGET_NR_chmod
         SYSCALL(chmod);
 #endif
+#ifdef TARGET_NR_chown
+        SYSCALL(chown);
+#endif
+        SYSCALL(chroot);
 #ifdef TARGET_NR_connect
         SYSCALL(connect);
 #endif
@@ -13169,6 +13183,12 @@  static impl_fn *syscall_table(unsigned num)
 #endif
         SYSCALL(getpriority);
         SYSCALL(getrandom);
+#ifdef TARGET_NR_getresgid
+        SYSCALL(getresgid);
+#endif
+#ifdef TARGET_NR_getresuid
+        SYSCALL(getresuid);
+#endif
         SYSCALL(getrlimit);
         SYSCALL(getrusage);
         SYSCALL(getsid);