]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DARWIN sync: sys_open wrapper.
authorNicholas Nethercote <njn@valgrind.org>
Sun, 24 May 2009 22:32:33 +0000 (22:32 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sun, 24 May 2009 22:32:33 +0000 (22:32 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10131

coregrind/m_syswrap/syswrap-generic.c

index 0057339dd075e9b286135d169a3668b961102c09..b716bf00f477fd949fede54595057959b18a5355 100644 (file)
@@ -3393,9 +3393,6 @@ POST(sys_nanosleep)
 
 PRE(sys_open)
 {
-   HChar  name[30];
-   SysRes sres;
-
    if (ARG2 & VKI_O_CREAT) {
       // 3-arg version
       PRINT("sys_open ( %#lx(%s), %ld, %ld )",ARG1,(char*)ARG1,ARG2,ARG3);
@@ -3413,19 +3410,25 @@ PRE(sys_open)
       /proc/<pid>/cmdline, and just give it a copy of the fd for the
       fake file we cooked up at startup (in m_main).  Also, seek the
       cloned fd back to the start. */
+   {
+      HChar  name[30];
+      Char*  arg1s = (Char*) ARG1;
+      SysRes sres;
 
-   VG_(sprintf)(name, "/proc/%d/cmdline", VG_(getpid)());
-   if (ML_(safe_to_deref)( (void*)ARG1, 1 )
-       && (VG_(strcmp)((Char *)ARG1, name) == 0 
-           || VG_(strcmp)((Char *)ARG1, "/proc/self/cmdline") == 0)) {
-      sres = VG_(dup)( VG_(cl_cmdline_fd) );
-      SET_STATUS_from_SysRes( sres );
-      if (!sr_isError(sres)) {
-         OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET );
-         if (off < 0)
-            SET_STATUS_Failure( VKI_EMFILE );
+      VG_(sprintf)(name, "/proc/%d/cmdline", VG_(getpid)());
+      if (ML_(safe_to_deref)( arg1s, 1 ) &&
+          (VG_STREQ(arg1s, name) || VG_STREQ(arg1s, "/proc/self/cmdline"))
+         )
+      {
+         sres = VG_(dup)( VG_(cl_cmdline_fd) );
+         SET_STATUS_from_SysRes( sres );
+         if (!sr_isError(sres)) {
+            OffT off = VG_(lseek)( sr_Res(sres), 0, VKI_SEEK_SET );
+            if (off < 0)
+               SET_STATUS_Failure( VKI_EMFILE );
+         }
+         return;
       }
-      return;
    }
 
    /* Otherwise handle normally */