]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Use getdents64 syscall on linux.
authorMark Wielaard <mark@klomp.org>
Fri, 29 Aug 2014 14:28:30 +0000 (14:28 +0000)
committerMark Wielaard <mark@klomp.org>
Fri, 29 Aug 2014 14:28:30 +0000 (14:28 +0000)
getdents has been deprecated since linux 2.4 and newer arches (arm64)
might no longer provide the getdents syscall. Use getdents64 for reading
the /proc/self/fd/ dir so --track-fds=yes works reliable on all arches.
Without this the none/tests/fdleak*vgtest might fail.

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

coregrind/m_libcfile.c
coregrind/m_syswrap/syswrap-generic.c
include/pub_tool_libcfile.h
include/vki/vki-linux.h

index ccac5bb5311bb6e0706958aa0d20116fc4cb7d5f..a019dd845a663a962d27d2d3ea0b5b3893d298d1 100644 (file)
@@ -522,12 +522,12 @@ Int VG_(readlink) (const HChar* path, HChar* buf, UInt bufsiz)
    return sr_isError(res) ? -1 : sr_Res(res);
 }
 
-Int VG_(getdents) (Int fd, struct vki_dirent *dirp, UInt count)
+Int VG_(getdents64) (Int fd, struct vki_dirent64 *dirp, UInt count)
 {
 #  if defined(VGO_linux)
    SysRes res;
    /* res = getdents( fd, dirp, count ); */
-   res = VG_(do_syscall3)(__NR_getdents, fd, (UWord)dirp, count);
+   res = VG_(do_syscall3)(__NR_getdents64, fd, (UWord)dirp, count);
    return sr_isError(res) ? -1 : sr_Res(res);
 #  elif defined(VGO_darwin)
    I_die_here;
index 8bd42aa4be7aba894984ad2edbfe11531c0c0d81..d9df953dc6f497ef4aa3da3afce9969bd70f4db9 100644 (file)
@@ -837,7 +837,7 @@ void VG_(init_preopened_fds)(void)
 // DDD: should probably use HAVE_PROC here or similar, instead.
 #if defined(VGO_linux)
    Int ret;
-   struct vki_dirent d;
+   struct vki_dirent64 d;
    SysRes f;
 
    f = VG_(open)("/proc/self/fd", VKI_O_RDONLY, 0);
@@ -846,7 +846,7 @@ void VG_(init_preopened_fds)(void)
       return;
    }
 
-   while ((ret = VG_(getdents)(sr_Res(f), &d, sizeof(d))) != 0) {
+   while ((ret = VG_(getdents64)(sr_Res(f), &d, sizeof(d))) != 0) {
       if (ret == -1)
          goto out;
 
index 00505fda9073cc6730860d9599b3243a363e02eb..e93e6655a8517f1f43057853daf523e62a531223 100644 (file)
@@ -92,7 +92,7 @@ extern Int    VG_(unlink) ( const HChar* file_name );
 extern SysRes VG_(poll) (struct vki_pollfd *fds, Int nfds, Int timeout);
 
 extern Int    VG_(readlink)( const HChar* path, HChar* buf, UInt bufsize );
-extern Int    VG_(getdents)( Int fd, struct vki_dirent *dirp, UInt count );
+extern Int    VG_(getdents64)( Int fd, struct vki_dirent64 *dirp, UInt count );
 
 extern const HChar* VG_(basename)( const HChar* path );
 extern const HChar* VG_(dirname) ( const HChar* path );
index aba2fae708fbb2b3471c10af34dad9204c379afb..c78e00ffec20ac1db6843d6f5081886d507242c0 100644 (file)
@@ -1373,6 +1373,7 @@ struct vki_robust_list_head {
 // From linux-2.6.8.1/include/linux/dirent.h
 //----------------------------------------------------------------------
 
+/* This is the old compat structure to use with the old dirent syscall. */
 struct vki_dirent {
        long            d_ino;
        __vki_kernel_off_t      d_off;
@@ -1380,6 +1381,15 @@ struct vki_dirent {
        char            d_name[256]; /* We must not include limits.h! */
 };
 
+/* This is the new structure to use with the dirent64 syscall. */
+struct vki_dirent64 {
+       __vki_u64 d_ino;
+       __vki_s64 d_off;
+       unsigned short d_reclen;
+       unsigned char d_type;
+       char d_name[256]; /* Note we hard code a max file length here. */
+};
+
 //----------------------------------------------------------------------
 // From linux-2.6.8.1/include/linux/fcntl.h
 //----------------------------------------------------------------------