|
From: <sv...@va...> - 2005-09-13 18:08:08
|
Author: sewardj
Date: 2005-09-13 19:08:05 +0100 (Tue, 13 Sep 2005)
New Revision: 4642
Log:
Reinstate fd-to-filename resolution.
Modified:
branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
Modified: branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-13 16:47:0=
0 UTC (rev 4641)
+++ branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-13 18:08:0=
5 UTC (rev 4642)
@@ -1469,8 +1469,8 @@
=20
=20
//--------------------------------------------------------------
-// Direct access to the kernel's mmap/munmap syscalls. This
-// avoids dependence on m_libcmman.
+// Direct access to a handful of syscalls. This avoids dependence on
+// m_libc*.
=20
SysRes VG_(am_do_mmap_NO_NOTIFY)( Addr start, SizeT length, UInt prot,=20
UInt flags, UInt fd, OffT offset)
@@ -1505,7 +1505,15 @@
return VG_(do_syscall2)(__NR_munmap, (UWord)start, length );
}
=20
+static
+Int aspacem_readlink(HChar* path, HChar* buf, UInt bufsiz)
+{
+ SysRes res;
+ res =3D VG_(do_syscall3)(__NR_readlink, (UWord)path, (UWord)buf, bufs=
iz);
+ return res.isError ? -1 : res.val;
+}
=20
+
//--------------------------------------------------------------
// Functions for extracting information about file descriptors.
=20
@@ -1515,10 +1523,22 @@
return False;
}
=20
+/* Given a file descriptor, attempt to deduce its filename. To do
+ this, we use /proc/self/fd/<FD>. If this doesn't point to a file,
+ or if it doesn't exist, we return False. */
static
Bool get_name_for_fd ( Int fd, /*OUT*/HChar* buf, Int nbuf )
{
- return False;
+ Int i;
+ HChar tmp[64];
+
+ aspacem_sprintf(tmp, "/proc/self/fd/%d", fd);
+ for (i =3D 0; i < nbuf; i++) buf[i] =3D 0;
+ =20
+ if (aspacem_readlink(tmp, buf, nbuf) > 0 && buf[0] =3D=3D '/')
+ return True;
+ else
+ return False;
}
=20
=20
|