diff mbox

[16/34] linux-user: Use safe_syscall for open and openat system calls

Message ID 1441497448-32489-17-git-send-email-T.E.Baldwin99@members.leeds.ac.uk
State New
Headers show

Commit Message

Timothy Baldwin Sept. 5, 2015, 11:57 p.m. UTC
Restart open() and openat() if signals occur before,
or during with SA_RESTART.

Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk>
---
 linux-user/syscall.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Comments

Peter Maydell Sept. 10, 2015, 6:54 p.m. UTC | #1
On 6 September 2015 at 00:57, Timothy E Baldwin
<T.E.Baldwin99@members.leeds.ac.uk> wrote:
> Restart open() and openat() if signals occur before,
> or during with SA_RESTART.
>
> Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

When we get to the cases where not all the host architectures provide
a particular syscall (ie where we're currently relying on glibc to
implement a function with whatever the host arch's syscall ABI demands)
this is going to get trickier, but for the functions so far I think
they're present with the same ABI on all archs.

thanks
-- PMM
diff mbox

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index df9b2ca..e68eddb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -303,18 +303,6 @@  static int sys_getcwd1(char *buf, size_t size)
   return strlen(buf)+1;
 }
 
-static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode)
-{
-  /*
-   * open(2) has extra parameter 'mode' when called with
-   * flag O_CREAT.
-   */
-  if ((flags & O_CREAT) != 0) {
-      return (openat(dirfd, pathname, flags, mode));
-  }
-  return (openat(dirfd, pathname, flags));
-}
-
 #ifdef TARGET_NR_utimensat
 #ifdef CONFIG_UTIMENSAT
 static int sys_utimensat(int dirfd, const char *pathname,
@@ -708,6 +696,8 @@  static type safe_##name (type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
 
 safe_syscall3(ssize_t, read, int, fd, void *, buff, size_t, count)
 safe_syscall3(ssize_t, write, int, fd, const void *, buff, size_t, count)
+safe_syscall4(int, openat, int, dirfd, const char *, pathname, \
+    int, flags, mode_t, mode)
 
 
 static inline int host_to_target_sock_type(int host_type)
@@ -5624,7 +5614,7 @@  static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
 
     if (is_proc_myself(pathname, "exe")) {
         int execfd = qemu_getauxval(AT_EXECFD);
-        return execfd ? execfd : get_errno(sys_openat(dirfd, exec_path, flags, mode));
+        return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode);
     }
 
     for (fake_open = fakes; fake_open->filename; fake_open++) {
@@ -5658,7 +5648,7 @@  static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
         return fd;
     }
 
-    return get_errno(sys_openat(dirfd, path(pathname), flags, mode));
+    return safe_openat(dirfd, path(pathname), flags, mode);
 }
 
 #define TIMER_MAGIC 0x0caf0000