]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r9993, r9995 (comment changes about vg_stat) from the DARWIN branch,
authorNicholas Nethercote <njn@valgrind.org>
Wed, 20 May 2009 02:02:30 +0000 (02:02 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 20 May 2009 02:02:30 +0000 (02:02 +0000)
and rename all the vg_stat fields to avoid problems that the old names cause
on Darwin.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9996

coregrind/m_commandline.c
coregrind/m_debuginfo/debuginfo.c
coregrind/m_debuginfo/readelf.c
coregrind/m_libcfile.c
coregrind/m_ume/main.c
include/pub_tool_libcfile.h

index 60c4d3dcc14e93e2f189c7d1e96c4cf22be40ce1..e4ab751661f54d60ec03945a0230d6e8e92ba00d 100644 (file)
@@ -67,14 +67,14 @@ static HChar* read_dot_valgrindrc ( HChar* dir )
    if ( !sr_isError(fd) ) {
       Int res = VG_(fstat)( sr_Res(fd), &stat_buf );
       // Ignore if not owned by current user or world writeable (CVE-2008-4865)
-      if (!res && stat_buf.st_uid == VG_(geteuid)()
-          && (!(stat_buf.st_mode & VKI_S_IWOTH))) {
-         if ( stat_buf.st_size > 0 ) {
-            f_clo = VG_(malloc)("commandline.rdv.1", stat_buf.st_size+1);
+      if (!res && stat_buf.uid == VG_(geteuid)()
+          && (!(stat_buf.mode & VKI_S_IWOTH))) {
+         if ( stat_buf.size > 0 ) {
+            f_clo = VG_(malloc)("commandline.rdv.1", stat_buf.size+1);
             vg_assert(f_clo);
-            n = VG_(read)(sr_Res(fd), f_clo, stat_buf.st_size);
+            n = VG_(read)(sr_Res(fd), f_clo, stat_buf.size);
             if (n == -1) n = 0;
-            vg_assert(n >= 0 && n <= stat_buf.st_size+1);
+            vg_assert(n >= 0 && n <= stat_buf.size+1);
             f_clo[n] = '\0';
          }
       }
index 1aa6125e2638eaf904b5d307c6547bc3018eac03..d9d921777133dd5d5f949f262c65db416b5b9a7d 100644 (file)
@@ -645,7 +645,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV )
 
    /* stat dereferences symlinks, so we don't expect it to succeed and
       yet produce something that is a symlink. */
-   vg_assert(sr_isError(statres) || ! VKI_S_ISLNK(statbuf.st_mode));
+   vg_assert(sr_isError(statres) || ! VKI_S_ISLNK(statbuf.mode));
 
    /* Don't let the stat call fail silently.  Filter out some known
       sources of noise before complaining, though. */
@@ -662,7 +662,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV )
 
    /* Finally, the point of all this stattery: if it's not a regular file,
       don't try to read debug info from it. */
-   if (! VKI_S_ISREG(statbuf.st_mode))
+   if (! VKI_S_ISREG(statbuf.mode))
       return 0;
 
    /* no uses of statbuf below here. */
@@ -905,7 +905,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj,
    if (r == -1)
       goto out; /* stat failed ?! */
    vg_assert(r == 0);
-   obj_mtime = stat_buf.st_mtime;
+   obj_mtime = stat_buf.mtime;
 
    /* and get its name into exename[]. */
    vg_assert(VKI_PATH_MAX > 100); /* to ensure /proc/self/fd/%d is safe */
@@ -954,7 +954,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj,
       VG_(message)(Vg_UserMsg, "LOAD_PDB_DEBUGINFO: missing: %s", pdbname);
       goto out;
    }
-   pdb_mtime = stat_buf.st_mtime;
+   pdb_mtime = stat_buf.mtime;
    if (pdb_mtime < obj_mtime ) {
       /* PDB file is older than PE file - ignore it or we will either
          (a) print wrong stack traces or more likely (b) crash. */
@@ -971,7 +971,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj,
 
    /* Looks promising; go on to try and read stuff from it. */
    fd_pdbimage = sr_Res(sres);
-   n_pdbimage  = stat_buf.st_size;
+   n_pdbimage  = stat_buf.size;
    sres = VG_(am_mmap_file_float_valgrind)( n_pdbimage, VKI_PROT_READ,
                                             fd_pdbimage, 0 );
    if (sr_isError(sres)) {
index 6a0329de0f8a897421e9b5b46ba58a7c20b94773..f80edd6f44c111ea853ae96aa27e54817f5eeb89 100644 (file)
@@ -930,7 +930,7 @@ Addr open_debug_file( Char* name, UInt crc, /*OUT*/UWord* size )
    if (VG_(clo_verbosity) > 1)
       VG_(message)(Vg_DebugMsg, "Reading debug info from %s ..", name);
 
-   *size = stat_buf.st_size;
+   *size = stat_buf.size;
    
    sres = VG_(am_mmap_file_float_valgrind)
              ( *size, VKI_PROT_READ, sr_Res(fd), 0 );
index 87c1bc85af67dca6724820f6d60fcd868d3bd369..0a28224e144062caee021b024db703d0ced9c660 100644 (file)
@@ -162,22 +162,22 @@ OffT VG_(lseek) ( Int fd, OffT offset, Int whence )
 
 #define TRANSLATE_TO_vg_stat(_p_vgstat, _p_vkistat) \
    do { \
-      (_p_vgstat)->st_dev        = (ULong)( (_p_vkistat)->st_dev ); \
-      (_p_vgstat)->st_ino        = (ULong)( (_p_vkistat)->st_ino ); \
-      (_p_vgstat)->st_nlink      = (ULong)( (_p_vkistat)->st_nlink ); \
-      (_p_vgstat)->st_mode       = (UInt) ( (_p_vkistat)->st_mode ); \
-      (_p_vgstat)->st_uid        = (UInt) ( (_p_vkistat)->st_uid ); \
-      (_p_vgstat)->st_gid        = (UInt) ( (_p_vkistat)->st_gid ); \
-      (_p_vgstat)->st_rdev       = (ULong)( (_p_vkistat)->st_rdev ); \
-      (_p_vgstat)->st_size       = (Long) ( (_p_vkistat)->st_size ); \
-      (_p_vgstat)->st_blksize    = (ULong)( (_p_vkistat)->st_blksize ); \
-      (_p_vgstat)->st_blocks     = (ULong)( (_p_vkistat)->st_blocks ); \
-      (_p_vgstat)->st_atime      = (ULong)( (_p_vkistat)->st_atime ); \
-      (_p_vgstat)->st_atime_nsec = (ULong)( (_p_vkistat)->st_atime_nsec ); \
-      (_p_vgstat)->st_mtime      = (ULong)( (_p_vkistat)->st_mtime ); \
-      (_p_vgstat)->st_mtime_nsec = (ULong)( (_p_vkistat)->st_mtime_nsec ); \
-      (_p_vgstat)->st_ctime      = (ULong)( (_p_vkistat)->st_ctime ); \
-      (_p_vgstat)->st_ctime_nsec = (ULong)( (_p_vkistat)->st_ctime_nsec ); \
+      (_p_vgstat)->dev        = (ULong)( (_p_vkistat)->st_dev ); \
+      (_p_vgstat)->ino        = (ULong)( (_p_vkistat)->st_ino ); \
+      (_p_vgstat)->nlink      = (ULong)( (_p_vkistat)->st_nlink ); \
+      (_p_vgstat)->mode       = (UInt) ( (_p_vkistat)->st_mode ); \
+      (_p_vgstat)->uid        = (UInt) ( (_p_vkistat)->st_uid ); \
+      (_p_vgstat)->gid        = (UInt) ( (_p_vkistat)->st_gid ); \
+      (_p_vgstat)->rdev       = (ULong)( (_p_vkistat)->st_rdev ); \
+      (_p_vgstat)->size       = (Long) ( (_p_vkistat)->st_size ); \
+      (_p_vgstat)->blksize    = (ULong)( (_p_vkistat)->st_blksize ); \
+      (_p_vgstat)->blocks     = (ULong)( (_p_vkistat)->st_blocks ); \
+      (_p_vgstat)->atime      = (ULong)( (_p_vkistat)->st_atime ); \
+      (_p_vgstat)->atime_nsec = (ULong)( (_p_vkistat)->st_atime_nsec ); \
+      (_p_vgstat)->mtime      = (ULong)( (_p_vkistat)->st_mtime ); \
+      (_p_vgstat)->mtime_nsec = (ULong)( (_p_vkistat)->st_mtime_nsec ); \
+      (_p_vgstat)->ctime      = (ULong)( (_p_vkistat)->st_ctime ); \
+      (_p_vgstat)->ctime_nsec = (ULong)( (_p_vkistat)->st_ctime_nsec ); \
    } while (0)
 
 SysRes VG_(stat) ( const Char* file_name, struct vg_stat* vgbuf )
@@ -215,12 +215,12 @@ SysRes VG_(stat) ( const Char* file_name, struct vg_stat* vgbuf )
                             VKI_STX_NORMAL);
      if (!sr_isError(res)) {
         VG_(memset)(vgbuf, 0, sizeof(*vgbuf));
-        vgbuf->st_dev  = (ULong)buf.st_dev;
-        vgbuf->st_ino  = (ULong)buf.st_ino;
-        vgbuf->st_mode = (UInt)buf.st_mode;
-        vgbuf->st_uid  = (UInt)buf.st_uid;
-        vgbuf->st_gid  = (UInt)buf.st_gid;
-        vgbuf->st_size = (Long)buf.st_size;
+        vgbuf->dev  = (ULong)buf.st_dev;
+        vgbuf->ino  = (ULong)buf.st_ino;
+        vgbuf->mode = (UInt)buf.st_mode;
+        vgbuf->uid  = (UInt)buf.st_uid;
+        vgbuf->gid  = (UInt)buf.st_gid;
+        vgbuf->size = (Long)buf.st_size;
      }
      return res;
    }
@@ -271,7 +271,7 @@ Long VG_(fsize) ( Int fd )
 {
    struct vg_stat buf;
    Int res = VG_(fstat)( fd, &buf );
-   return (res == -1) ? (-1LL) : buf.st_size;
+   return (res == -1) ? (-1LL) : buf.size;
 }
 
 Bool VG_(is_dir) ( HChar* f )
@@ -279,7 +279,7 @@ Bool VG_(is_dir) ( HChar* f )
    struct vg_stat buf;
    SysRes res = VG_(stat)(f, &buf);
    return sr_isError(res) ? False
-                      : VKI_S_ISDIR(buf.st_mode) ? True : False;
+                      : VKI_S_ISDIR(buf.mode) ? True : False;
 }
 
 SysRes VG_(dup) ( Int oldfd )
@@ -464,19 +464,19 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid,
       return sr_Err(res);
    }
 
-   if ( (st.st_mode & (VKI_S_ISUID | VKI_S_ISGID)) && !allow_setuid ) {
+   if ( (st.mode & (VKI_S_ISUID | VKI_S_ISGID)) && !allow_setuid ) {
       if (is_setuid)
          *is_setuid = True;
       return VKI_EACCES;
    }
 
-   if (VG_(geteuid)() == st.st_uid) {
-      if (!(st.st_mode & VKI_S_IXUSR))
+   if (VG_(geteuid)() == st.uid) {
+      if (!(st.mode & VKI_S_IXUSR))
          return VKI_EACCES;
    } else {
       Int grpmatch = 0;
 
-      if (VG_(getegid)() == st.st_gid)
+      if (VG_(getegid)() == st.gid)
         grpmatch = 1;
       else {
         UInt groups[32];
@@ -484,7 +484,7 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid,
         Int i;
          /* ngrp will be -1 if VG_(getgroups) failed. */
          for (i = 0; i < ngrp; i++) {
-           if (groups[i] == st.st_gid) {
+           if (groups[i] == st.gid) {
               grpmatch = 1;
               break;
            }
@@ -492,10 +492,10 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid,
       }
 
       if (grpmatch) {
-        if (!(st.st_mode & VKI_S_IXGRP)) {
+        if (!(st.mode & VKI_S_IXGRP)) {
             return VKI_EACCES;
          }
-      } else if (!(st.st_mode & VKI_S_IXOTH)) {
+      } else if (!(st.mode & VKI_S_IXOTH)) {
          return VKI_EACCES;
       }
    }
index b2fb502a9ebc26c34d3687d84b09301cb8892a6b..a32bec7ee5647fce4a11ce78b85f30649e1693ef 100644 (file)
@@ -235,7 +235,7 @@ static Int do_exec_shell_followup(Int ret, HChar* exe_name, ExeInfo* info)
    
       // Was it a directory?
       res = VG_(stat)(exe_name, &st);
-      if (!sr_isError(res) && VKI_S_ISDIR(st.st_mode)) {
+      if (!sr_isError(res) && VKI_S_ISDIR(st.mode)) {
          VG_(printf)("valgrind: %s: is a directory\n", exe_name);
       
       // Was it not executable?
index 63fb0b39a5df7508b9f96c72400dd7fa67414bfa..ad1fd04dc3fa066a5b23d5bb4e5b1a4ff755e731 100644 (file)
    specific vki_stat{,64} kernel structure will work and is
    consistently available on different architectures on Linux, so we
    have to use this 'struct vg_stat' impedance-matching type
-   instead. */
+   instead.
+
+   Also note that the fieldnames aren't prefixed with "st_".  This is because
+   st_atime et al are macros in sys/stat.h on Darwin, and using those names
+   screws things up.
+*/
 struct vg_stat {
-   ULong   st_dev;
-   ULong   st_ino;
-   ULong   st_nlink;
-   UInt    st_mode;
-   UInt    st_uid;
-   UInt    st_gid;
-   ULong   st_rdev;
-   Long    st_size;
-   ULong   st_blksize;
-   ULong   st_blocks;
-   ULong   st_atime;
-   ULong   st_atime_nsec;
-   ULong   st_mtime;
-   ULong   st_mtime_nsec;
-   ULong   st_ctime;
-   ULong   st_ctime_nsec;
+   ULong   dev;
+   ULong   ino;
+   ULong   nlink;
+   UInt    mode;
+   UInt    uid;
+   UInt    gid;
+   ULong   rdev;
+   Long    size;
+   ULong   blksize;
+   ULong   blocks;
+   ULong   atime;
+   ULong   atime_nsec;
+   ULong   mtime;
+   ULong   mtime_nsec;
+   ULong   ctime;
+   ULong   ctime_nsec;
 };
 
 extern SysRes VG_(open)   ( const Char* pathname, Int flags, Int mode );