|
From: <sv...@va...> - 2014-08-29 14:28:46
|
Author: mjw
Date: Fri Aug 29 14:28:30 2014
New Revision: 14384
Log:
Use getdents64 syscall on linux.
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.
Modified:
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/include/pub_tool_libcfile.h
trunk/include/vki/vki-linux.h
Modified: trunk/coregrind/m_libcfile.c
==============================================================================
--- trunk/coregrind/m_libcfile.c (original)
+++ trunk/coregrind/m_libcfile.c Fri Aug 29 14:28:30 2014
@@ -522,12 +522,12 @@
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;
Modified: trunk/coregrind/m_syswrap/syswrap-generic.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-generic.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c Fri Aug 29 14:28:30 2014
@@ -837,7 +837,7 @@
// 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 @@
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;
Modified: trunk/include/pub_tool_libcfile.h
==============================================================================
--- trunk/include/pub_tool_libcfile.h (original)
+++ trunk/include/pub_tool_libcfile.h Fri Aug 29 14:28:30 2014
@@ -92,7 +92,7 @@
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 );
Modified: trunk/include/vki/vki-linux.h
==============================================================================
--- trunk/include/vki/vki-linux.h (original)
+++ trunk/include/vki/vki-linux.h Fri Aug 29 14:28:30 2014
@@ -1373,6 +1373,7 @@
// 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 @@
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
//----------------------------------------------------------------------
|