qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/5] linux-user: complete do_open function isolation


From: riku . voipio
Subject: [Qemu-devel] [PATCH 4/5] linux-user: complete do_open function isolation
Date: Fri, 12 Oct 2012 21:24:41 +0300

From: Riku Voipio <address@hidden>

In preparations for for refactoring the main switch/case out

Signed-off-by: Riku Voipio <address@hidden>
---
 linux-user/syscall.c |   32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a9bfe8c..eebf219 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5035,8 +5035,10 @@ static int open_self_auxv(void *cpu_env, int fd)
     return 0;
 }
 
-static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
+static int do_open(void *cpu_env, abi_long arg1, abi_long arg2, abi_long arg3)
 {
+    char *pathname;
+    int ret,flags;
     struct fake_open {
         const char *filename;
         int (*fill)(void *cpu_env, int fd);
@@ -5048,6 +5050,9 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
         { "/proc/self/auxv", open_self_auxv },
         { NULL, NULL }
     };
+    flags=target_to_host_bitmask(arg2, fcntl_flags_tbl);
+    if (!(pathname = lock_user_string(arg1)))
+        return -EFAULT;
 
     for (fake_open = fakes; fake_open->filename; fake_open++) {
         if (!strncmp(pathname, fake_open->filename,
@@ -5059,7 +5064,7 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
     if (fake_open->filename) {
         const char *tmpdir;
         char filename[PATH_MAX];
-        int fd, r;
+        int fd;
 
         /* create temporary file to map stat to */
         tmpdir = getenv("TMPDIR");
@@ -5068,20 +5073,24 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
         snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
         fd = mkstemp(filename);
         if (fd < 0) {
-            return fd;
+            ret = fd;
+            goto cleanup;
         }
         unlink(filename);
 
-        if ((r = fake_open->fill(cpu_env, fd))) {
+        if ((ret = fake_open->fill(cpu_env, fd))) {
             close(fd);
-            return r;
+            goto cleanup;
         }
         lseek(fd, 0, SEEK_SET);
-
-        return fd;
+        ret = fd;
+        goto cleanup;
     }
 
-    return get_errno(open(path(pathname), flags, mode));
+    ret = open(path(pathname), flags, arg3);
+cleanup:
+    unlock_user(pathname, arg1, 0);
+    return ret;
 }
 static void do_exit(void *, abi_long) __attribute__ ((noreturn));
 static void do_exit(void *cpu_env, abi_long arg1)
@@ -5186,12 +5195,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
         ret = get_errno(do_write(arg1, arg2, arg3));
         break;
     case TARGET_NR_open:
-        if (!(p = lock_user_string(arg1)))
-            goto efault;
-        ret = get_errno(do_open(cpu_env, p,
-                                target_to_host_bitmask(arg2, fcntl_flags_tbl),
-                                arg3));
-        unlock_user(p, arg1, 0);
+        ret = get_errno(do_open(cpu_env, arg1, arg2, arg3));
         break;
 #if defined(TARGET_NR_openat) && defined(__NR_openat)
     case TARGET_NR_openat:
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]