|
From: <sv...@va...> - 2005-06-23 02:26:50
|
Author: njn
Date: 2005-06-23 03:26:47 +0100 (Thu, 23 Jun 2005)
New Revision: 4001
Log:
Removed some repetition in the way VG_(record_fd_open)() is called.
As part of this, VG_(resolve_filename)() no longer calls VG_(malloc)()
and so m_libcfile no longer depends on m_mallocfree.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_signals.c
trunk/coregrind/m_syswrap/priv_syswrap-generic.h
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/m_syswrap/syswrap-linux.c
trunk/coregrind/pub_core_libcfile.h
Modified: trunk/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
--- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-23 01:02:53 UTC (rev =
4000)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-23 02:26:47 UTC (rev =
4001)
@@ -785,8 +785,8 @@
void VG_(map_fd_segment)(Addr addr, SizeT len, UInt prot, UInt flags,=20
Int fd, ULong off, const Char *filename)
{
+ Char buf[VKI_PATH_MAX];
struct vki_stat st;
- Char *name =3D NULL;
=20
st.st_dev =3D 0;
st.st_ino =3D 0;
@@ -799,11 +799,9 @@
}
=20
if ((flags & SF_FILE) && filename =3D=3D NULL && fd !=3D -1)
- name =3D VG_(resolve_filename_nodup)(fd);
+ if (VG_(resolve_filename)(fd, buf, VKI_PATH_MAX))
+ filename =3D buf;
=20
- if (filename =3D=3D NULL)
- filename =3D name;
-
VG_(map_file_segment)(addr, len, prot, flags,=20
st.st_dev, st.st_ino, off, filename);
}
Modified: trunk/coregrind/m_libcfile.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
--- trunk/coregrind/m_libcfile.c 2005-06-23 01:02:53 UTC (rev 4000)
+++ trunk/coregrind/m_libcfile.c 2005-06-23 02:26:47 UTC (rev 4001)
@@ -33,7 +33,6 @@
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h" // For VG_(sprintf)()
-#include "pub_core_mallocfree.h"
#include "pub_core_syscall.h"
#include "vki_unistd.h"
=20
@@ -71,34 +70,20 @@
=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 just return NULL. The caller is
- responsible for copying the contents of buf out immediately. */
-static HChar resolve_filename_buf[VKI_PATH_MAX];
-HChar* VG_(resolve_filename_nodup) ( Int fd )
+ or if it doesn't exist, we return False. */
+Bool VG_(resolve_filename) ( Int fd, HChar* buf, Int n_buf )
{
HChar tmp[64];
=20
VG_(sprintf)(tmp, "/proc/self/fd/%d", fd);
- VG_(memset)(resolve_filename_buf, 0, VKI_PATH_MAX);
+ VG_(memset)(buf, 0, n_buf);
=20
- if (VG_(readlink)(tmp, resolve_filename_buf, VKI_PATH_MAX) =3D=3D -1)
- return NULL;
-
- return (resolve_filename_buf[0] =3D=3D '/')=20
- ? resolve_filename_buf=20
- : NULL;
+ if (VG_(readlink)(tmp, buf, VKI_PATH_MAX) > 0 && buf[0] =3D=3D '/')
+ return True;
+ else
+ return False;
}
=20
-/* Same as resolve_filename_nodup, except that the result is copied=20
- into new memory which the caller is responsible for freeing. */
-HChar* VG_(resolve_filename) ( Int fd )
-{
- HChar* transient =3D VG_(resolve_filename_nodup)(fd);
- return transient
- ? VG_(arena_strdup)(VG_AR_CORE, transient)
- : NULL;
-}
-
/* Returns -1 on failure. */
Int VG_(open) ( const Char* pathname, Int flags, Int mode )
{ =20
Modified: trunk/coregrind/m_signals.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
--- trunk/coregrind/m_signals.c 2005-06-23 01:02:53 UTC (rev 4000)
+++ trunk/coregrind/m_signals.c 2005-06-23 02:26:47 UTC (rev 4001)
@@ -1022,7 +1022,8 @@
=20
static void fill_prpsinfo(const ThreadState *tst, struct vki_elf_prpsinf=
o *prpsinfo)
{
- Char *name;
+ static Char name[VKI_PATH_MAX];
+ Bool res;
=20
VG_(memset)(prpsinfo, 0, sizeof(*prpsinfo));
=20
@@ -1049,12 +1050,10 @@
prpsinfo->pr_uid =3D 0;
prpsinfo->pr_gid =3D 0;
=20
- name =3D VG_(resolve_filename)(VG_(clexecfd));
-
- if (name !=3D NULL) {
+ if (VG_(resolve_filename)(VG_(clexecfd), name, VKI_PATH_MAX)) {
Char *n =3D name+VG_(strlen)(name)-1;
=20
- while(n > name && *n !=3D '/')
+ while (n > name && *n !=3D '/')
n--;
if (n !=3D name)
n++;
Modified: trunk/coregrind/m_syswrap/priv_syswrap-generic.h
=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
--- trunk/coregrind/m_syswrap/priv_syswrap-generic.h 2005-06-23 01:02:53 =
UTC (rev 4000)
+++ trunk/coregrind/m_syswrap/priv_syswrap-generic.h 2005-06-23 02:26:47 =
UTC (rev 4001)
@@ -48,7 +48,7 @@
Bool ML_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool=
soft);
=20
extern
-void ML_(record_fd_open)(ThreadId tid, Int fd, char *pathname);
+void ML_(record_fd_open_nameless)(ThreadId tid, Int fd);
=20
// Used when killing threads -- we must not kill a thread if it's the th=
read
// that would do Valgrind's final cleanup and output.
Modified: trunk/coregrind/m_syswrap/syswrap-generic.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
--- trunk/coregrind/m_syswrap/syswrap-generic.c 2005-06-23 01:02:53 UTC (=
rev 4000)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2005-06-23 02:26:47 UTC (=
rev 4001)
@@ -345,7 +345,7 @@
some such thing) or that we don't know the filename. If the fd is
already open, then we're probably doing a dup2() to an existing fd,
so just overwrite the existing one. */
-void ML_(record_fd_open)(ThreadId tid, Int fd, char *pathname)
+static void record_fd_open_with_given_name(ThreadId tid, Int fd, char *p=
athname)
{
OpenFd *i;
=20
@@ -374,10 +374,29 @@
}
=20
i->fd =3D fd;
- i->pathname =3D pathname;
+ i->pathname =3D VG_(arena_strdup)(VG_AR_CORE, pathname);
i->where =3D (tid =3D=3D -1) ? NULL : VG_(record_ExeContext)(tid);
}
=20
+// Record opening of an fd, and find its name.
+static void record_fd_open_named(ThreadId tid, Int fd)
+{
+ static HChar buf[VKI_PATH_MAX];
+ Char* name;
+ if (VG_(resolve_filename)(fd, buf, VKI_PATH_MAX))
+ name =3D buf;
+ else
+ name =3D NULL;
+ =20
+ record_fd_open_with_given_name(tid, fd, name);
+}
+
+// Record opening of a nameless fd.
+void ML_(record_fd_open_nameless)(ThreadId tid, Int fd)
+{
+ record_fd_open_with_given_name(tid, fd, NULL);
+}
+
static
Char *unix2name(struct vki_sockaddr_un *sa, UInt len, Char *name)
{
@@ -521,7 +540,7 @@
=20
for (i =3D 0; i < count; i++)
if(VG_(fcntl)(i, VKI_F_GETFL, 0) !=3D -1)
- ML_(record_fd_open)(-1, i, NULL);
+ ML_(record_fd_open_nameless)(-1, i);
}
=20
/* Initialize the list of open file descriptors with the file descriptor=
s
@@ -539,15 +558,15 @@
}
=20
while((ret =3D VG_(getdents)(f, &d, sizeof(d))) !=3D 0) {
- if(ret =3D=3D -1)
+ if (ret =3D=3D -1)
goto out;
=20
- if(VG_(strcmp)(d.d_name, ".") && VG_(strcmp)(d.d_name, "..")) {
+ if (VG_(strcmp)(d.d_name, ".") && VG_(strcmp)(d.d_name, "..")) {
int fno =3D VG_(atoll)(d.d_name);
=20
- if(fno !=3D f)
- if(VG_(clo_track_fds))
- ML_(record_fd_open)(-1, fno, VG_(resolve_filename)(fno));
+ if (fno !=3D f)
+ if (VG_(clo_track_fds))
+ record_fd_open_named(-1, fno);
}
=20
VG_(lseek)(f, d.d_off, VKI_SEEK_SET);
@@ -646,7 +665,7 @@
if(VG_(clo_track_fds))
// XXX: must we check the range on these fds with
// VG_(fd_allowed)()?
- ML_(record_fd_open) (tid, fds[i], VG_(resolve_filename)(f=
ds[i]));
+ record_fd_open_named(tid, fds[i]);
}
=20
cm =3D VKI_CMSG_NXTHDR(msg, cm);
@@ -901,8 +920,8 @@
} else {
POST_MEM_WRITE( arg3, 2*sizeof(int) );
if (VG_(clo_track_fds)) {
- ML_(record_fd_open)(tid, fd1, NULL);
- ML_(record_fd_open)(tid, fd2, NULL);
+ ML_(record_fd_open_nameless)(tid, fd1);
+ ML_(record_fd_open_nameless)(tid, fd2);
}
}
return r;
@@ -920,7 +939,7 @@
r =3D VG_(mk_SysRes_Error)( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, res.val, NULL);
+ ML_(record_fd_open_nameless)(tid, res.val);
}
return r;
}
@@ -971,7 +990,7 @@
buf_and_len_post_check ( tid, res, addr_p, addrlen_p,
"socketcall.accept(addrlen_out)" );
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, res.val, NULL);
+ ML_(record_fd_open_nameless)(tid, res.val);
}
return r;
}
@@ -2511,7 +2530,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(resolve_filename)(RES));
+ record_fd_open_named(tid, RES);
}
}
=20
@@ -2527,7 +2546,7 @@
{
vg_assert(SUCCESS);
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(resolve_filename)(RES));
+ record_fd_open_named(tid, RES);
}
=20
PRE(sys_fchdir)
@@ -2612,7 +2631,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(resolve_filename)(RES));
+ record_fd_open_named(tid, RES);
}
}
}
@@ -2678,8 +2697,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES,=20
- VG_(resolve_filename)(RES));
+ record_fd_open_named(tid, RES);
}
}
}
@@ -4564,8 +4582,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES,=20
- VG_(arena_strdup)(VG_AR_CORE, (Char*)A=
RG1));
+ record_fd_open_with_given_name(tid, RES, (Char*)ARG1);
}
}
=20
@@ -4616,7 +4633,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(arena_strdup)(VG_AR_CORE, (Ch=
ar*)ARG1));
+ record_fd_open_with_given_name(tid, RES, (Char*)ARG1);
}
}
=20
@@ -4640,8 +4657,8 @@
} else {
POST_MEM_WRITE( ARG1, 2*sizeof(int) );
if (VG_(clo_track_fds)) {
- ML_(record_fd_open)(tid, p[0], NULL);
- ML_(record_fd_open)(tid, p[1], NULL);
+ ML_(record_fd_open_nameless)(tid, p[0]);
+ ML_(record_fd_open_nameless)(tid, p[1]);
}
}
}
@@ -5412,7 +5429,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(arena_strdup)(VG_AR_CORE, (Ch=
ar*)ARG1));
+ record_fd_open_with_given_name(tid, RES, (Char*)ARG1);
}
}
=20
Modified: trunk/coregrind/m_syswrap/syswrap-linux.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
--- trunk/coregrind/m_syswrap/syswrap-linux.c 2005-06-23 01:02:53 UTC (re=
v 4000)
+++ trunk/coregrind/m_syswrap/syswrap-linux.c 2005-06-23 02:26:47 UTC (re=
v 4001)
@@ -535,7 +535,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open)(tid, RES, VG_(arena_strdup)(VG_AR_CORE, =
(Char*)ARG1));
+ ML_(record_fd_open_nameless)(tid, RES);
}
}
}
@@ -553,7 +553,7 @@
SET_STATUS_Failure( VKI_EMFILE );
} else {
if (VG_(clo_track_fds))
- ML_(record_fd_open) (tid, RES, NULL);
+ ML_(record_fd_open_nameless) (tid, RES);
}
}
=20
Modified: trunk/coregrind/pub_core_libcfile.h
=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
--- trunk/coregrind/pub_core_libcfile.h 2005-06-23 01:02:53 UTC (rev 4000=
)
+++ trunk/coregrind/pub_core_libcfile.h 2005-06-23 02:26:47 UTC (rev 4001=
)
@@ -47,8 +47,7 @@
extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
=20
/* Convert an fd into a filename */
-extern HChar* VG_(resolve_filename_nodup) ( Int fd );
-extern HChar* VG_(resolve_filename) ( Int fd );
+extern Bool VG_(resolve_filename) ( Int fd, HChar* buf, Int n_buf );
=20
/* Default destination port to be used in logging over a network, if
none specified. */
|