|
From: <sv...@va...> - 2009-08-25 20:15:57
|
Author: bart
Date: 2009-08-25 21:15:41 +0100 (Tue, 25 Aug 2009)
New Revision: 10868
Log:
Switched back from dynamic detection of whether the proc filesystem
is mounted to compile-time logic in order to minimize the differences
in behavior with Valgrind version 3.5.0.
Modified:
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_main.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/pub_core_libcfile.h
Modified: trunk/coregrind/m_libcfile.c
===================================================================
--- trunk/coregrind/m_libcfile.c 2009-08-25 17:34:58 UTC (rev 10867)
+++ trunk/coregrind/m_libcfile.c 2009-08-25 20:15:41 UTC (rev 10868)
@@ -1083,24 +1083,7 @@
return buf;
}
-/* ---------------------------------------------------------------------
- proc filesystem
- ------------------------------------------------------------------ */
-Bool VG_(is_procfs_mounted)(void)
-{
- static int have_proc_fs = -1;
- if (have_proc_fs < 0)
- {
- have_proc_fs
- = VG_(access)("/proc/self/fd", 1, 0, 0) == 0
- && VG_(access)("/proc/self/exe", 1, 0, 0) == 0
- && VG_(access)("/proc/self/maps", 1, 0, 0) == 0;
- }
- return have_proc_fs;
-}
-
-
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_main.c
===================================================================
--- trunk/coregrind/m_main.c 2009-08-25 17:34:58 UTC (rev 10867)
+++ trunk/coregrind/m_main.c 2009-08-25 20:15:41 UTC (rev 10868)
@@ -1802,48 +1802,48 @@
// when it tries to open /proc/<pid>/cmdline for itself.
// p: setup file descriptors
//--------------------------------------------------------------
- if (! VG_(is_procfs_mounted)()) {
- // client shouldn't be using /proc!
- VG_(cl_cmdline_fd) = -1;
- } else {
- if (!need_help) {
- HChar buf[50], buf2[50+64];
- HChar nul[1];
- Int fd, r;
- HChar* exename;
+#if !defined(VGO_linux)
+ // client shouldn't be using /proc!
+ VG_(cl_cmdline_fd) = -1;
+#else
+ if (!need_help) {
+ HChar buf[50], buf2[50+64];
+ HChar nul[1];
+ Int fd, r;
+ HChar* exename;
- VG_(debugLog)(1, "main", "Create fake /proc/<pid>/cmdline\n");
+ VG_(debugLog)(1, "main", "Create fake /proc/<pid>/cmdline\n");
- VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)());
- fd = VG_(mkstemp)( buf, buf2 );
- if (fd == -1)
- VG_(err_config_error)("Can't create client cmdline file in /tmp.");
+ VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)());
+ fd = VG_(mkstemp)( buf, buf2 );
+ if (fd == -1)
+ VG_(err_config_error)("Can't create client cmdline file in /tmp.");
- nul[0] = 0;
- exename = VG_(args_the_exename) ? VG_(args_the_exename)
- : "unknown_exename";
- VG_(write)(fd, VG_(args_the_exename),
- VG_(strlen)( VG_(args_the_exename) ));
+ nul[0] = 0;
+ exename = VG_(args_the_exename) ? VG_(args_the_exename)
+ : "unknown_exename";
+ VG_(write)(fd, VG_(args_the_exename),
+ VG_(strlen)( VG_(args_the_exename) ));
+ VG_(write)(fd, nul, 1);
+
+ for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
+ HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
+ VG_(write)(fd, arg, VG_(strlen)( arg ));
VG_(write)(fd, nul, 1);
+ }
- for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) {
- HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i );
- VG_(write)(fd, arg, VG_(strlen)( arg ));
- VG_(write)(fd, nul, 1);
- }
+ /* Don't bother to seek the file back to the start; instead do
+ it every time a copy of it is given out (by PRE(sys_open)).
+ That is probably more robust across fork() etc. */
- /* Don't bother to seek the file back to the start; instead do
- it every time a copy of it is given out (by PRE(sys_open)).
- That is probably more robust across fork() etc. */
+ /* Now delete it, but hang on to the fd. */
+ r = VG_(unlink)( buf2 );
+ if (r)
+ VG_(err_config_error)("Can't delete client cmdline file in /tmp.");
- /* Now delete it, but hang on to the fd. */
- r = VG_(unlink)( buf2 );
- if (r)
- VG_(err_config_error)("Can't delete client cmdline file in /tmp.");
-
- VG_(cl_cmdline_fd) = fd;
- }
+ VG_(cl_cmdline_fd) = fd;
}
+#endif
//--------------------------------------------------------------
// Init tool part 1: pre_clo_init
Modified: trunk/coregrind/m_syswrap/syswrap-generic.c
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-generic.c 2009-08-25 17:34:58 UTC (rev 10867)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2009-08-25 20:15:41 UTC (rev 10868)
@@ -3526,12 +3526,12 @@
}
PRE_MEM_RASCIIZ( "open(filename)", ARG1 );
- if (VG_(is_procfs_mounted)())
+#if defined(VGO_linux)
+ /* Handle the case where the open is of /proc/self/cmdline or
+ /proc/<pid>/cmdline, and just give it a copy of the fd for the
+ fake file we cooked up at startup (in m_main). Also, seek the
+ cloned fd back to the start. */
{
- /* Handle the case where the open is of /proc/self/cmdline or
- /proc/<pid>/cmdline, and just give it a copy of the fd for the
- fake file we cooked up at startup (in m_main). Also, seek the
- cloned fd back to the start. */
HChar name[30];
Char* arg1s = (Char*) ARG1;
SysRes sres;
@@ -3551,6 +3551,7 @@
return;
}
}
+#endif // defined(VGO_linux)
/* Otherwise handle normally */
*flags |= SfMayBlock;
@@ -3673,6 +3674,7 @@
PRE_MEM_WRITE( "readlink(buf)", ARG2,ARG3 );
{
+#if defined(VGO_linux)
/*
* Handle the case where readlink is looking at /proc/self/exe or
* /proc/<pid>/exe.
@@ -3680,7 +3682,7 @@
HChar name[25];
Char* arg1s = (Char*) ARG1;
VG_(sprintf)(name, "/proc/%d/exe", VG_(getpid)());
- if (VG_(is_procfs_mounted()) && ML_(safe_to_deref)(arg1s, 1) &&
+ if (ML_(safe_to_deref)(arg1s, 1) &&
(VG_STREQ(arg1s, name) || VG_STREQ(arg1s, "/proc/self/exe"))
)
{
@@ -3688,6 +3690,7 @@
SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, (UWord)name,
ARG2, ARG3));
} else
+#endif // defined(VGO_linux)
{
/* Normal case */
SET_STATUS_from_SysRes( VG_(do_syscall3)(saved, ARG1, ARG2, ARG3));
Modified: trunk/coregrind/pub_core_libcfile.h
===================================================================
--- trunk/coregrind/pub_core_libcfile.h 2009-08-25 17:34:58 UTC (rev 10867)
+++ trunk/coregrind/pub_core_libcfile.h 2009-08-25 20:15:41 UTC (rev 10868)
@@ -98,10 +98,6 @@
calling VG_(get_startup_wd) (in pub_tool_libcfile.h). */
extern Bool VG_(record_startup_wd) ( void );
-/* Whether or not the proc filesystem has been mounted at the /proc
- mountpoint. */
-extern Bool VG_(is_procfs_mounted)(void);
-
#endif // __PUB_CORE_LIBCFILE_H
/*--------------------------------------------------------------------*/
|