|
From: <sv...@va...> - 2009-05-04 05:55:56
|
Author: njn
Date: 2009-05-04 06:55:46 +0100 (Mon, 04 May 2009)
New Revision: 9752
Log:
Merged r9750, r9751 (remove m_aspacemgr layering violation) from the DARWIN
branch.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr-common.c
trunk/coregrind/m_aspacemgr/aspacemgr-linux.c
trunk/coregrind/m_aspacemgr/priv_aspacemgr.h
trunk/coregrind/m_libcfile.c
Modified: trunk/coregrind/m_aspacemgr/aspacemgr-common.c
===================================================================
--- trunk/coregrind/m_aspacemgr/aspacemgr-common.c 2009-05-04 05:47:42 UTC (rev 9751)
+++ trunk/coregrind/m_aspacemgr/aspacemgr-common.c 2009-05-04 05:55:46 UTC (rev 9752)
@@ -253,6 +253,12 @@
return res.isError ? -1 : res.res;
}
+Int ML_(am_fcntl) ( Int fd, Int cmd, Addr arg )
+{
+ SysRes res = VG_(do_syscall3)(__NR_fcntl, fd, cmd, arg);
+ return res.isError ? -1 : 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,
@@ -284,7 +290,41 @@
return False;
}
+Bool ML_(am_resolve_filename) ( Int fd, /*OUT*/HChar* buf, Int nbuf )
+{
+#if defined(VGO_linux)
+ Int i;
+ 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: trunk/coregrind/m_aspacemgr/aspacemgr-linux.c
===================================================================
--- trunk/coregrind/m_aspacemgr/aspacemgr-linux.c 2009-05-04 05:47:42 UTC (rev 9751)
+++ trunk/coregrind/m_aspacemgr/aspacemgr-linux.c 2009-05-04 05:55:46 UTC (rev 9752)
@@ -338,39 +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 )
-{
- 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;
- else
- return False;
-}
-
-
-/*-----------------------------------------------------------------*/
-/*--- ---*/
/*--- SegName array management. ---*/
/*--- ---*/
/*-----------------------------------------------------------------*/
@@ -1959,12 +1926,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 );
}
}
@@ -2174,12 +2141,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 );
@@ -2449,12 +2416,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: trunk/coregrind/m_aspacemgr/priv_aspacemgr.h
===================================================================
--- trunk/coregrind/m_aspacemgr/priv_aspacemgr.h 2009-05-04 05:47:42 UTC (rev 9751)
+++ trunk/coregrind/m_aspacemgr/priv_aspacemgr.h 2009-05-04 05:55:46 UTC (rev 9752)
@@ -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: trunk/coregrind/m_libcfile.c
===================================================================
--- trunk/coregrind/m_libcfile.c 2009-05-04 05:47:42 UTC (rev 9751)
+++ trunk/coregrind/m_libcfile.c 2009-05-04 05:55:46 UTC (rev 9752)
@@ -82,11 +82,13 @@
return True;
else
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
}
|