|
From: <sv...@va...> - 2009-05-04 05:41:01
|
Author: njn
Date: 2009-05-04 06:40:58 +0100 (Mon, 04 May 2009)
New Revision: 9750
Log:
Fix a layering violation -- add a local implemenatation of
resolve_filename() to m_aspacem.
Modified:
branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-common.c
branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-linux.c
branches/DARWIN/coregrind/m_aspacemgr/priv_aspacemgr.h
branches/DARWIN/coregrind/m_libcfile.c
Modified: branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-common.c
===================================================================
--- branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-common.c 2009-05-04 05:17:02 UTC (rev 9749)
+++ branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-common.c 2009-05-04 05:40:58 UTC (rev 9750)
@@ -270,6 +270,16 @@
return sr_isError(res) ? -1 : sr_Res(res);
}
+Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg )
+{
+# if defined(VGO_darwin)
+ SysRes res = VG_(do_syscall3)(__NR_fcntl_nocancel, fd, cmd, arg);
+# else
+ SysRes res = VG_(do_syscall3)(__NR_fcntl, fd, cmd, arg);
+# endif
+ return sr_isError(res) ? -1 : sr_Res(res);
+}
+
/* Get the dev, inode and mode info for a file descriptor, if
possible. Returns True on success. */
Bool ML_(am_get_fd_d_i_m)( Int fd,
@@ -301,7 +311,40 @@
return False;
}
+Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf )
+{
+#if defined(VGO_linux)
+ HChar tmp[64];
+ for (i = 0; i < nbuf; i++) buf[i] = 0;
+ ML_(am_sprintf)(tmp, "/proc/self/fd/%d", fd);
+ if (ML_(am_readlink)(tmp, buf, nbuf) > 0 && buf[0] == '/')
+ return True;
+ else
+ return False;
+#elif defined(VGO_aix5)
+ I_die_here; /* maybe just return False? */
+ return False;
+
+#elif defined(VGO_darwin)
+ HChar tmp[VKI_MAXPATHLEN+1];
+ if (0 == ML_(am_fcntl)(fd, VKI_F_GETPATH, (UWord)tmp)) {
+ if (nbuf > 0) {
+ VG_(strncpy)( buf, tmp, nbuf < sizeof(tmp) ? nbuf : sizeof(tmp) );
+ buf[nbuf-1] = 0;
+ }
+ if (tmp[0] == '/') return True;
+ }
+ return False;
+
+# else
+# error Unknown OS
+# endif
+}
+
+
+
+
/*-----------------------------------------------------------------*/
/*--- ---*/
/*--- Manage stacks for Valgrind itself. ---*/
Modified: branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-linux.c
===================================================================
--- branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-linux.c 2009-05-04 05:17:02 UTC (rev 9749)
+++ branches/DARWIN/coregrind/m_aspacemgr/aspacemgr-linux.c 2009-05-04 05:40:58 UTC (rev 9750)
@@ -338,54 +338,6 @@
/*-----------------------------------------------------------------*/
/*--- ---*/
-/*--- Functions for finding information about file descriptors. ---*/
-/*--- ---*/
-/*-----------------------------------------------------------------*/
-
-/* Extract the device, inode and mode numbers for a fd. */
-static
-Bool get_inode_for_fd ( Int fd, /*OUT*/ULong* dev,
- /*OUT*/ULong* ino, /*OUT*/UInt* mode )
-{
- return ML_(am_get_fd_d_i_m)(fd, dev, ino, mode);
-}
-
-/* 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 )
-{
-#if HAVE_PROC
- // Try /proc/self/fd/#
- {
- Int i;
- HChar tmp[64];
-
- ML_(am_sprintf)(tmp, "/proc/self/fd/%d", fd);
- for (i = 0; i < nbuf; i++) buf[i] = 0;
-
- if (ML_(am_readlink)(tmp, buf, nbuf) > 0 && buf[0] == '/')
- return True;
- }
-#endif
-
-#if defined(VGO_darwin)
- // GrP fixme layering violation?
- // Try fcntl(F_GETPATH)
- extern Bool VG_(resolve_filename)(Int _fd, HChar *_buf, Int _nbuf);
- if (VG_(resolve_filename)(fd, buf, nbuf)) {
- return True;
- }
-#endif
-
- // Bummer.
- return False;
-}
-
-
-/*-----------------------------------------------------------------*/
-/*--- ---*/
/*--- SegName array management. ---*/
/*--- ---*/
/*-----------------------------------------------------------------*/
@@ -2011,12 +1963,12 @@
if (!(flags & VKI_MAP_ANONYMOUS)) {
// Nb: We ignore offset requests in anonymous mmaps (see bug #126722)
seg.offset = offset;
- if (get_inode_for_fd(fd, &dev, &ino, &mode)) {
+ if (ML_(am_get_fd_d_i_m)(fd, &dev, &ino, &mode)) {
seg.dev = dev;
seg.ino = ino;
seg.mode = mode;
}
- if (get_name_for_fd(fd, buf, VKI_PATH_MAX)) {
+ if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = allocate_segname( buf );
}
}
@@ -2233,14 +2185,14 @@
seg.hasR = toBool(prot & VKI_PROT_READ);
seg.hasW = toBool(prot & VKI_PROT_WRITE);
seg.hasX = toBool(prot & VKI_PROT_EXEC);
- if (get_inode_for_fd(fd, &dev, &ino, &mode)) {
+ if (ML_(am_get_fd_d_i_m)(fd, &dev, &ino, &mode)) {
seg.dev = dev;
seg.ino = ino;
seg.mode = mode;
}
if (name) {
seg.fnIdx = allocate_segname( name );
- } else if (get_name_for_fd(fd, buf, VKI_PATH_MAX)) {
+ } else if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = allocate_segname( buf );
}
add_segment( &seg );
@@ -2523,12 +2475,12 @@
seg.hasR = toBool(prot & VKI_PROT_READ);
seg.hasW = toBool(prot & VKI_PROT_WRITE);
seg.hasX = toBool(prot & VKI_PROT_EXEC);
- if (get_inode_for_fd(fd, &dev, &ino, &mode)) {
+ if (ML_(am_get_fd_d_i_m)(fd, &dev, &ino, &mode)) {
seg.dev = dev;
seg.ino = ino;
seg.mode = mode;
}
- if (get_name_for_fd(fd, buf, VKI_PATH_MAX)) {
+ if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = allocate_segname( buf );
}
add_segment( &seg );
Modified: branches/DARWIN/coregrind/m_aspacemgr/priv_aspacemgr.h
===================================================================
--- branches/DARWIN/coregrind/m_aspacemgr/priv_aspacemgr.h 2009-05-04 05:17:02 UTC (rev 9749)
+++ branches/DARWIN/coregrind/m_aspacemgr/priv_aspacemgr.h 2009-05-04 05:40:58 UTC (rev 9750)
@@ -43,7 +43,7 @@
#include "pub_core_debuglog.h" // VG_(debugLog)
-#include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp)
+#include "pub_core_libcbase.h" // VG_(strlen), VG_(strcmp), VG_(strncpy)
// VG_IS_PAGE_ALIGNED
// VG_PGROUNDDN, VG_PGROUNDUP
@@ -109,14 +109,18 @@
extern void ML_(am_close) ( Int fd );
extern Int ML_(am_read) ( Int fd, void* buf, Int count);
extern Int ML_(am_readlink) ( HChar* path, HChar* buf, UInt bufsiz );
+extern Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg );
/* Get the dev, inode and mode info for a file descriptor, if
possible. Returns True on success. */
extern
Bool ML_(am_get_fd_d_i_m)( Int fd,
- /*OUT*/ULong* dev,
- /*OUT*/ULong* ino, /*OUT*/UInt* mode );
+ /*OUT*/ULong* dev,
+ /*OUT*/ULong* ino, /*OUT*/UInt* mode );
+extern
+Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf );
+
/* ------ Implemented seperately in aspacemgr-{linux,aix5}.c ------ */
/* Do a sanity check (/proc/self/maps sync check) */
Modified: branches/DARWIN/coregrind/m_libcfile.c
===================================================================
--- branches/DARWIN/coregrind/m_libcfile.c 2009-05-04 05:17:02 UTC (rev 9749)
+++ branches/DARWIN/coregrind/m_libcfile.c 2009-05-04 05:40:58 UTC (rev 9750)
@@ -87,6 +87,11 @@
return True;
else
return False;
+
+# elif defined(VGO_aix5)
+ I_die_here; /* maybe just return False? */
+ return False;
+
# elif defined(VGO_darwin)
HChar tmp[VKI_MAXPATHLEN+1];
if (0 == VG_(fcntl)(fd, VKI_F_GETPATH, (UWord)tmp)) {
@@ -97,11 +102,9 @@
if (tmp[0] == '/') return True;
}
return False;
-# elif defined(VGO_aix5)
- I_die_here; /* maybe just return False? */
- return False;
+
# else
-# error "need fd-to-filename for this OS"
+# error Unknown OS
# endif
}
|