Author: njn
Date: 2005-06-04 21:03:55 +0100 (Sat, 04 Jun 2005)
New Revision: 3844
Added:
trunk/coregrind/m_libcfile.c
trunk/coregrind/pub_core_libcfile.h
trunk/include/pub_tool_libcfile.h
Modified:
trunk/cachegrind/cg_main.c
trunk/coregrind/Makefile.am
trunk/coregrind/core.h
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_aspacemgr/read_procselfmaps.c
trunk/coregrind/m_debuginfo/symtab.c
trunk/coregrind/m_errormgr.c
trunk/coregrind/m_libcprint.c
trunk/coregrind/m_main.c
trunk/coregrind/m_scheduler/sema.c
trunk/coregrind/m_syscalls/syscalls-linux.c
trunk/coregrind/m_syscalls/syscalls.c
trunk/coregrind/vg_mylibc.c
trunk/include/Makefile.am
trunk/include/tool.h
trunk/massif/ms_main.c
Log:
Modularised file and socket libc stuff in m_libcfile.
Modified: trunk/cachegrind/cg_main.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/cachegrind/cg_main.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/cachegrind/cg_main.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -34,6 +34,7 @@
#include "pub_tool_hashtable.h"
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
+#include "pub_tool_libcfile.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
Modified: trunk/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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/Makefile.am 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/Makefile.am 2005-06-04 20:03:55 UTC (rev 3844)
@@ -48,6 +48,7 @@
pub_core_hashtable.h \
pub_core_libcbase.h \
pub_core_libcassert.h \
+ pub_core_libcfile.h \
pub_core_libcprint.h \
pub_core_main.h \
pub_core_mallocfree.h \
@@ -92,6 +93,7 @@
m_hashtable.c \
m_libcbase.c \
m_libcassert.c \
+ m_libcfile.c \
m_libcprint.c \
m_main.c \
m_mallocfree.c \
Modified: trunk/coregrind/core.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/core.h 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/core.h 2005-06-04 20:03:55 UTC (rev 3844)
@@ -112,14 +112,6 @@
extern Int VG_(mprotect_native)( void *start, SizeT length, UInt prot );
=20
=20
-/* Move an fd into the Valgrind-safe range */
-Int VG_(safe_fd)(Int oldfd);
-
-extern Int VG_(write_socket)( Int sd, void *msg, Int count );
-
-/* --- Connecting over the network --- */
-extern Int VG_(connect_via_socket)( UChar* str );
-
/* Environment manipulations */
extern Char **VG_(env_setenv) ( Char ***envp, const Char* varname,
const Char *val );
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-04 19:36:34 UTC (rev =
3843)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-04 20:03:55 UTC (rev =
3844)
@@ -34,6 +34,7 @@
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h" // For VG_(fstat)()
#include "pub_core_libcprint.h"
#include "pub_core_options.h"
#include "pub_core_syscalls.h"
Modified: trunk/coregrind/m_aspacemgr/read_procselfmaps.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/read_procselfmaps.c 2005-06-04 19:36:34 U=
TC (rev 3843)
+++ trunk/coregrind/m_aspacemgr/read_procselfmaps.c 2005-06-04 20:03:55 U=
TC (rev 3844)
@@ -34,6 +34,7 @@
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
=20
/* Size of a smallish table used to read /proc/self/map entries. */
Modified: trunk/coregrind/m_debuginfo/symtab.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_debuginfo/symtab.c 2005-06-04 19:36:34 UTC (rev 384=
3)
+++ trunk/coregrind/m_debuginfo/symtab.c 2005-06-04 20:03:55 UTC (rev 384=
4)
@@ -34,6 +34,7 @@
#include "pub_core_demangle.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_options.h"
#include "pub_core_profile.h"
Modified: trunk/coregrind/m_errormgr.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_errormgr.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/m_errormgr.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -34,6 +34,7 @@
#include "pub_core_execontext.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_main.h" // for VG_(start_debugger)()
#include "pub_core_options.h"
@@ -1107,5 +1108,5 @@
}
=20
/*--------------------------------------------------------------------*/
-/*--- end m_errormgr.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
Added: 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-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/m_libcfile.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -0,0 +1,446 @@
+
+/*--------------------------------------------------------------------*/
+/*--- File- and socket-related libc stuff. m_libcfile.c ---*/
+/*--------------------------------------------------------------------*/
+=20
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "core.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
+#include "pub_core_options.h"
+#include "pub_core_syscalls.h" // For VG_(is_kerror)()
+#include "vki_unistd.h"
+
+/* ---------------------------------------------------------------------
+ File stuff
+ ------------------------------------------------------------------ */
+
+static inline Bool fd_exists(Int fd)
+{
+ struct vki_stat st;
+
+ return VG_(fstat)(fd, &st) =3D=3D 0;
+}
+
+/* Move an fd into the Valgrind-safe range */
+Int VG_(safe_fd)(Int oldfd)
+{
+ Int newfd;
+
+ vg_assert(VG_(fd_hard_limit) !=3D -1);
+
+ newfd =3D VG_(fcntl)(oldfd, VKI_F_DUPFD, VG_(fd_hard_limit));
+ if (newfd !=3D -1)
+ VG_(close)(oldfd);
+
+ VG_(fcntl)(newfd, VKI_F_SETFD, VKI_FD_CLOEXEC);
+
+ vg_assert(newfd >=3D VG_(fd_hard_limit));
+ return newfd;
+}
+
+/* Returns -1 on failure. */
+Int VG_(open) ( const Char* pathname, Int flags, Int mode )
+{ =20
+ Int fd =3D VG_(do_syscall3)(__NR_open, (UWord)pathname, flags, mode);
+ return fd;
+}
+
+void VG_(close) ( Int fd )
+{
+ VG_(do_syscall1)(__NR_close, fd);
+}
+
+Int VG_(read) ( Int fd, void* buf, Int count)
+{
+ Int res;
+ res =3D VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count);
+ return res;
+}
+
+Int VG_(write) ( Int fd, const void* buf, Int count)
+{
+ Int res;
+ res =3D VG_(do_syscall3)(__NR_write, fd, (UWord)buf, count);
+ return res;
+}
+
+Int VG_(pipe) ( Int fd[2] )
+{
+ Int ret =3D VG_(do_syscall1)(__NR_pipe, (UWord)fd);
+ return VG_(is_kerror)(ret) ? -1 : 0;
+}
+
+OffT VG_(lseek) ( Int fd, OffT offset, Int whence)
+{
+ Int res;
+ res =3D VG_(do_syscall3)(__NR_lseek, fd, offset, whence);
+ if (VG_(is_kerror)(res)) res =3D -1;
+ return res;
+}
+
+Int VG_(stat) ( Char* file_name, struct vki_stat* buf )
+{
+ Int res;
+ res =3D VG_(do_syscall2)(__NR_stat, (UWord)file_name, (UWord)buf);
+ return res; /* return -ve error */
+}
+
+Int VG_(fstat) ( Int fd, struct vki_stat* buf )
+{
+ Int res;
+ res =3D VG_(do_syscall2)(__NR_fstat, fd, (UWord)buf);
+ return VG_(is_kerror)(res) ? (-1) : 0;
+}
+
+Int VG_(dup2) ( Int oldfd, Int newfd )
+{
+ Int res;
+ res =3D VG_(do_syscall2)(__NR_dup2, oldfd, newfd);
+ return VG_(is_kerror)(res) ? (-1) : res;
+}
+
+Int VG_(rename) ( Char* old_name, Char* new_name )
+{
+ Int res;
+ res =3D VG_(do_syscall2)(__NR_rename, (UWord)old_name, (UWord)new_nam=
e);
+ return VG_(is_kerror)(res) ? (-1) : 0;
+}
+
+Int VG_(unlink) ( Char* file_name )
+{
+ Int res;
+ res =3D VG_(do_syscall1)(__NR_unlink, (UWord)file_name);
+ return VG_(is_kerror)(res) ? (-1) : 0;
+}
+
+/* Nb: we do not allow the Linux extension which malloc()s memory for th=
e
+ buffer if buf=3D=3DNULL, because we don't want Linux calling malloc()=
*/
+Char* VG_(getcwd) ( Char* buf, SizeT size )
+{
+ Word res;
+ vg_assert(buf !=3D NULL);
+ res =3D VG_(do_syscall2)(__NR_getcwd, (UWord)buf, size);
+ return VG_(is_kerror)(res) ? ((Char*)NULL) : (Char*)res;
+}
+
+/* Alternative version that does allocate the memory. Easier to use. */
+Bool VG_(getcwd_alloc) ( Char** out )
+{
+ SizeT size =3D 4;
+
+ *out =3D NULL;
+ while (True) {
+ *out =3D VG_(malloc)(size);
+ if (NULL =3D=3D VG_(getcwd)(*out, size)) {
+ VG_(free)(*out);
+ if (size > 65535)
+ return False;
+ size *=3D 2;
+ } else {
+ return True;
+ }
+ }
+}
+
+Int VG_(readlink) (Char* path, Char* buf, UInt bufsiz)
+{
+ Int res;
+ /* res =3D readlink( path, buf, bufsiz ); */
+ res =3D VG_(do_syscall3)(__NR_readlink, (UWord)path, (UWord)buf, bufs=
iz);
+ if (VG_(is_kerror)(res)) res =3D -1;
+ return res;
+}
+
+Int VG_(getdents) (UInt fd, struct vki_dirent *dirp, UInt count)
+{
+ Int res;
+ /* res =3D getdents( fd, dirp, count ); */
+ res =3D VG_(do_syscall3)(__NR_getdents, fd, (UWord)dirp, count);
+ if (VG_(is_kerror)(res)) res =3D -1;
+ return res;
+}
+
+/* ---------------------------------------------------------------------
+ Socket-related stuff. This is very Linux-kernel specific.
+ ------------------------------------------------------------------ */
+
+static
+Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port )=
;
+
+static
+Int my_socket ( Int domain, Int type, Int protocol );
+
+static
+Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr,=20
+ Int addrlen );
+
+static=20
+UInt my_htonl ( UInt x )
+{
+ return
+ (((x >> 24) & 0xFF) << 0) | (((x >> 16) & 0xFF) << 8)
+ | (((x >> 8) & 0xFF) << 16) | (((x >> 0) & 0xFF) << 24);
+}
+
+static
+UShort my_htons ( UShort x )
+{
+ return
+ (((x >> 8) & 0xFF) << 0) | (((x >> 0) & 0xFF) << 8);
+}
+
+
+/* The main function.=20
+
+ Supplied string contains either an ip address "192.168.0.1" or
+ an ip address and port pair, "192.168.0.1:1500". Parse these,
+ and return:
+ -1 if there is a parse error
+ -2 if no parse error, but specified host:port cannot be opened
+ the relevant file (socket) descriptor, otherwise.
+ is used.
+*/
+Int VG_(connect_via_socket)( UChar* str )
+{
+ Int sd, res;
+ struct vki_sockaddr_in servAddr;
+ UInt ip =3D 0;
+ UShort port =3D VG_CLO_DEFAULT_LOGPORT;
+ Bool ok =3D parse_inet_addr_and_port(str, &ip, &port);
+ if (!ok)=20
+ return -1;
+
+ //if (0)
+ // VG_(printf)("ip =3D %d.%d.%d.%d, port %d\n",
+ // (ip >> 24) & 0xFF, (ip >> 16) & 0xFF,=20
+ // (ip >> 8) & 0xFF, ip & 0xFF,=20
+ // (UInt)port );
+
+ servAddr.sin_family =3D VKI_AF_INET;
+ servAddr.sin_addr.s_addr =3D my_htonl(ip);
+ servAddr.sin_port =3D my_htons(port);
+
+ /* create socket */
+ sd =3D my_socket(VKI_AF_INET, VKI_SOCK_STREAM, 0 /* IPPROTO_IP ? */);
+ if (sd < 0) {
+ /* this shouldn't happen ... nevertheless */
+ return -2;
+ }
+ =09
+ /* connect to server */
+ res =3D my_connect(sd, (struct vki_sockaddr_in *) &servAddr,=20
+ sizeof(servAddr));
+ if (res < 0) {
+ /* connection failed */
+ return -2;
+ }
+
+ return sd;
+}
+
+
+/* Let d =3D one or more digits. Accept either:
+ d.d.d.d or d.d.d.d:d
+*/
+Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port )
+{
+# define GET_CH ((*str) ? (*str++) : 0)
+ UInt ipa, i, j, c, any;
+ ipa =3D 0;
+ for (i =3D 0; i < 4; i++) {
+ j =3D 0;
+ any =3D 0;
+ while (1) {
+ c =3D GET_CH;=20
+ if (c < '0' || c > '9') break;
+ j =3D 10 * j + (int)(c - '0');
+ any =3D 1;
+ }
+ if (any =3D=3D 0 || j > 255) goto syntaxerr;
+ ipa =3D (ipa << 8) + j;
+ if (i <=3D 2 && c !=3D '.') goto syntaxerr;
+ }
+ if (c =3D=3D 0 || c =3D=3D ':')=20
+ *ip_addr =3D ipa;
+ if (c =3D=3D 0) goto ok;
+ if (c !=3D ':') goto syntaxerr;
+ j =3D 0;
+ any =3D 0;
+ while (1) {
+ c =3D GET_CH;=20
+ if (c < '0' || c > '9') break;
+ j =3D j * 10 + (int)(c - '0');
+ any =3D 1;
+ if (j > 65535) goto syntaxerr;
+ }
+ if (any =3D=3D 0 || c !=3D 0) goto syntaxerr;
+ if (j < 1024) goto syntaxerr;
+ *port =3D (UShort)j;
+ ok:
+ return 1;
+ syntaxerr:
+ return 0;
+# undef GET_CH
+}
+
+
+static
+Int my_socket ( Int domain, Int type, Int protocol )
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ Int res;
+ UWord args[3];
+ args[0] =3D domain;
+ args[1] =3D type;
+ args[2] =3D protocol;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SOCKET, (UWord)&arg=
s);
+ if (VG_(is_kerror)(res))=20
+ res =3D -1;
+ return res;
+#endif
+}
+
+static
+Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr,=20
+ Int addrlen )
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ Int res;
+ UWord args[3];
+ args[0] =3D sockfd;
+ args[1] =3D (UWord)serv_addr;
+ args[2] =3D addrlen;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_CONNECT, (UWord)&ar=
gs);
+ if (VG_(is_kerror)(res))=20
+ res =3D -1;
+ return res;
+#endif
+}
+
+Int VG_(write_socket)( Int sd, void *msg, Int count )
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ /* This is actually send(). */
+
+ /* Requests not to send SIGPIPE on errors on stream oriented
+ sockets when the other end breaks the connection. The EPIPE
+ error is still returned. */
+ Int flags =3D VKI_MSG_NOSIGNAL;
+
+ Int res;
+ UWord args[4];
+ args[0] =3D sd;
+ args[1] =3D (UWord)msg;
+ args[2] =3D count;
+ args[3] =3D flags;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SEND, (UWord)&args)=
;
+ if (VG_(is_kerror)(res))=20
+ res =3D -1;
+ return res;
+#endif
+}
+
+Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen)
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ Int res;
+ UWord args[3];
+ args[0] =3D sd;
+ args[1] =3D (UWord)name;
+ args[2] =3D (UWord)namelen;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKNAME, (UWord=
)&args);
+ if(VG_(is_kerror)(res))
+ res =3D -1;
+ return res;
+#endif
+}
+
+Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen)
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ Int res;
+ UWord args[3];
+ args[0] =3D sd;
+ args[1] =3D (UWord)name;
+ args[2] =3D (UWord)namelen;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETPEERNAME, (UWord=
)&args);
+ if(VG_(is_kerror)(res))
+ res =3D -1;
+ return res;
+#endif
+}
+
+Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
+ Int *optlen)
+{
+// AMD64/Linux doesn't define __NR_socketcall... see comment above
+// VG_(sigpending)() for more details.
+#ifdef __amd64__
+ I_die_here;
+#else
+ Int res;
+ UWord args[5];
+ args[0] =3D sd;
+ args[1] =3D level;
+ args[2] =3D optname;
+ args[3] =3D (UWord)optval;
+ args[4] =3D (UWord)optlen;
+ res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKOPT, (UWord)=
&args);
+ if(VG_(is_kerror)(res))
+ res =3D -1;
+ return res;
+#endif
+}
+
+
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
Modified: trunk/coregrind/m_libcprint.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_libcprint.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/m_libcprint.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -32,6 +32,7 @@
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_options.h"
#include "valgrind.h" // for RUNNING_ON_VALGRIND
Modified: trunk/coregrind/m_main.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_main.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/m_main.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -38,6 +38,7 @@
#include "pub_core_execontext.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_main.h"
#include "pub_core_options.h"
Modified: trunk/coregrind/m_scheduler/sema.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_scheduler/sema.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/m_scheduler/sema.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -30,6 +30,7 @@
=20
#include "core.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "priv_sema.h"
=20
/*=20
Modified: trunk/coregrind/m_syscalls/syscalls-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_syscalls/syscalls-linux.c 2005-06-04 19:36:34 UTC (=
rev 3843)
+++ trunk/coregrind/m_syscalls/syscalls-linux.c 2005-06-04 20:03:55 UTC (=
rev 3844)
@@ -31,6 +31,7 @@
#include "core.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_tooliface.h"
#include "priv_syscalls.h"
Modified: trunk/coregrind/m_syscalls/syscalls.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_syscalls/syscalls.c 2005-06-04 19:36:34 UTC (rev 38=
43)
+++ trunk/coregrind/m_syscalls/syscalls.c 2005-06-04 20:03:55 UTC (rev 38=
44)
@@ -33,6 +33,7 @@
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_main.h"
#include "pub_core_profile.h"
Added: 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-04 19:36:34 UTC (rev 3843=
)
+++ trunk/coregrind/pub_core_libcfile.h 2005-06-04 20:03:55 UTC (rev 3844=
)
@@ -0,0 +1,55 @@
+
+/*--------------------------------------------------------------------*/
+/*--- File/socket-related libc stuff. pub_core_libcfile.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_LIBCFILE_H
+#define __PUB_CORE_LIBCFILE_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains all the libc code that relates to
+// files and sockets: opening, reading, writing, etc.
+//--------------------------------------------------------------------
+
+#include "pub_tool_libcfile.h"
+
+/* Move an fd into the Valgrind-safe range */
+extern Int VG_(safe_fd)(Int oldfd);
+
+extern Int VG_(write_socket)( Int sd, void *msg, Int count );
+extern Int VG_(connect_via_socket)( UChar* str );
+extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *na=
melen );
+extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *na=
melen );
+extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optv=
al,
+ Int *optlen );
+
+#endif // __PUB_CORE_LIBCFILE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/vg_mylibc.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/vg_mylibc.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/coregrind/vg_mylibc.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -439,142 +439,6 @@
}
=20
/* ---------------------------------------------------------------------
- Primitive support for reading files.
- ------------------------------------------------------------------ */
-
-static inline Bool fd_exists(Int fd)
-{
- struct vki_stat st;
-
- return VG_(fstat)(fd, &st) =3D=3D 0;
-}
-
-/* Move an fd into the Valgrind-safe range */
-Int VG_(safe_fd)(Int oldfd)
-{
- Int newfd;
-
- vg_assert(VG_(fd_hard_limit) !=3D -1);
-
- newfd =3D VG_(fcntl)(oldfd, VKI_F_DUPFD, VG_(fd_hard_limit));
- if (newfd !=3D -1)
- VG_(close)(oldfd);
-
- VG_(fcntl)(newfd, VKI_F_SETFD, VKI_FD_CLOEXEC);
-
- vg_assert(newfd >=3D VG_(fd_hard_limit));
- return newfd;
-}
-
-
-
-/* Returns -1 on failure. */
-Int VG_(open) ( const Char* pathname, Int flags, Int mode )
-{ =20
- Int fd =3D VG_(do_syscall3)(__NR_open, (UWord)pathname, flags, mode);
- return fd;
-}
-
-Int VG_(pipe) ( Int fd[2] )
-{
- Int ret =3D VG_(do_syscall1)(__NR_pipe, (UWord)fd);
- return VG_(is_kerror)(ret) ? -1 : 0;
-}
-
-void VG_(close) ( Int fd )
-{
- VG_(do_syscall1)(__NR_close, fd);
-}
-
-
-Int VG_(read) ( Int fd, void* buf, Int count)
-{
- Int res;
- res =3D VG_(do_syscall3)(__NR_read, fd, (UWord)buf, count);
- return res;
-}
-
-Int VG_(write) ( Int fd, const void* buf, Int count)
-{
- Int res;
- res =3D VG_(do_syscall3)(__NR_write, fd, (UWord)buf, count);
- return res;
-}
-
-OffT VG_(lseek) ( Int fd, OffT offset, Int whence)
-{
- Int res;
- res =3D VG_(do_syscall3)(__NR_lseek, fd, offset, whence);
- if (VG_(is_kerror)(res)) res =3D -1;
- return res;
-}
-
-Int VG_(stat) ( Char* file_name, struct vki_stat* buf )
-{
- Int res;
- res =3D VG_(do_syscall2)(__NR_stat, (UWord)file_name, (UWord)buf);
- return res; /* return -ve error */
-}
-
-Int VG_(fstat) ( Int fd, struct vki_stat* buf )
-{
- Int res;
- res =3D VG_(do_syscall2)(__NR_fstat, fd, (UWord)buf);
- return VG_(is_kerror)(res) ? (-1) : 0;
-}
-
-Int VG_(dup2) ( Int oldfd, Int newfd )
-{
- Int res;
- res =3D VG_(do_syscall2)(__NR_dup2, oldfd, newfd);
- return VG_(is_kerror)(res) ? (-1) : res;
-}
-
-Int VG_(rename) ( Char* old_name, Char* new_name )
-{
- Int res;
- res =3D VG_(do_syscall2)(__NR_rename, (UWord)old_name, (UWord)new_nam=
e);
- return VG_(is_kerror)(res) ? (-1) : 0;
-}
-
-Int VG_(unlink) ( Char* file_name )
-{
- Int res;
- res =3D VG_(do_syscall1)(__NR_unlink, (UWord)file_name);
- return VG_(is_kerror)(res) ? (-1) : 0;
-}
-
-/* Nb: we do not allow the Linux extension which malloc()s memory for th=
e
- buffer if buf=3D=3DNULL, because we don't want Linux calling malloc()=
*/
-Char* VG_(getcwd) ( Char* buf, SizeT size )
-{
- Word res;
- vg_assert(buf !=3D NULL);
- res =3D VG_(do_syscall2)(__NR_getcwd, (UWord)buf, size);
- return VG_(is_kerror)(res) ? ((Char*)NULL) : (Char*)res;
-}
-
-/* Alternative version that does allocate the memory. Easier to use. */
-Bool VG_(getcwd_alloc) ( Char** out )
-{
- SizeT size =3D 4;
-
- *out =3D NULL;
- while (True) {
- *out =3D VG_(malloc)(size);
- if (NULL =3D=3D VG_(getcwd)(*out, size)) {
- VG_(free)(*out);
- if (size > 65535)
- return False;
- size *=3D 2;
- } else {
- return True;
- }
- }
-}
-
-
-/* ---------------------------------------------------------------------
Misc functions looking for a proper home.
------------------------------------------------------------------ */
=20
@@ -702,26 +566,6 @@
}
=20
=20
-/* Support for getdents. */
-Int VG_(getdents) (UInt fd, struct vki_dirent *dirp, UInt count)
-{
- Int res;
- /* res =3D getdents( fd, dirp, count ); */
- res =3D VG_(do_syscall3)(__NR_getdents, fd, (UWord)dirp, count);
- if (VG_(is_kerror)(res)) res =3D -1;
- return res;
-}
-
-/* Support for a readlink. */
-Int VG_(readlink) (Char* path, Char* buf, UInt bufsiz)
-{
- Int res;
- /* res =3D readlink( path, buf, bufsiz ); */
- res =3D VG_(do_syscall3)(__NR_readlink, (UWord)path, (UWord)buf, bufs=
iz);
- if (VG_(is_kerror)(res)) res =3D -1;
- return res;
-}
-
/* You'd be amazed how many places need to know the current pid. */
Int VG_(getpid) ( void )
{
@@ -951,259 +795,6 @@
VG_(exit)(1);
}
=20
-/* ---------------------------------------------------------------------
- Gruesome hackery for connecting to a logging server over the network.
- This is all very Linux-kernel specific.
- ------------------------------------------------------------------ */
-
-static
-Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port )=
;
-
-static
-Int my_socket ( Int domain, Int type, Int protocol );
-
-static
-Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr,=20
- Int addrlen );
-
-static=20
-UInt my_htonl ( UInt x )
-{
- return
- (((x >> 24) & 0xFF) << 0) | (((x >> 16) & 0xFF) << 8)
- | (((x >> 8) & 0xFF) << 16) | (((x >> 0) & 0xFF) << 24);
-}
-
-static
-UShort my_htons ( UShort x )
-{
- return
- (((x >> 8) & 0xFF) << 0) | (((x >> 0) & 0xFF) << 8);
-}
-
-
-/* The main function.=20
-
- Supplied string contains either an ip address "192.168.0.1" or
- an ip address and port pair, "192.168.0.1:1500". Parse these,
- and return:
- -1 if there is a parse error
- -2 if no parse error, but specified host:port cannot be opened
- the relevant file (socket) descriptor, otherwise.
- is used.
-*/
-Int VG_(connect_via_socket)( UChar* str )
-{
- Int sd, res;
- struct vki_sockaddr_in servAddr;
- UInt ip =3D 0;
- UShort port =3D VG_CLO_DEFAULT_LOGPORT;
- Bool ok =3D parse_inet_addr_and_port(str, &ip, &port);
- if (!ok)=20
- return -1;
-
- if (0)
- VG_(printf)("ip =3D %d.%d.%d.%d, port %d\n",
- (ip >> 24) & 0xFF, (ip >> 16) & 0xFF,=20
- (ip >> 8) & 0xFF, ip & 0xFF,=20
- (UInt)port );
-
- servAddr.sin_family =3D VKI_AF_INET;
- servAddr.sin_addr.s_addr =3D my_htonl(ip);
- servAddr.sin_port =3D my_htons(port);
-
- /* create socket */
- sd =3D my_socket(VKI_AF_INET, VKI_SOCK_STREAM, 0 /* IPPROTO_IP ? */);
- if (sd < 0) {
- /* this shouldn't happen ... nevertheless */
- return -2;
- }
- =09
- /* connect to server */
- res =3D my_connect(sd, (struct vki_sockaddr_in *) &servAddr,=20
- sizeof(servAddr));
- if (res < 0) {
- /* connection failed */
- return -2;
- }
-
- return sd;
-}
-
-
-/* Let d =3D one or more digits. Accept either:
- d.d.d.d or d.d.d.d:d
-*/
-Int parse_inet_addr_and_port ( UChar* str, UInt* ip_addr, UShort* port )
-{
-# define GET_CH ((*str) ? (*str++) : 0)
- UInt ipa, i, j, c, any;
- ipa =3D 0;
- for (i =3D 0; i < 4; i++) {
- j =3D 0;
- any =3D 0;
- while (1) {
- c =3D GET_CH;=20
- if (c < '0' || c > '9') break;
- j =3D 10 * j + (int)(c - '0');
- any =3D 1;
- }
- if (any =3D=3D 0 || j > 255) goto syntaxerr;
- ipa =3D (ipa << 8) + j;
- if (i <=3D 2 && c !=3D '.') goto syntaxerr;
- }
- if (c =3D=3D 0 || c =3D=3D ':')=20
- *ip_addr =3D ipa;
- if (c =3D=3D 0) goto ok;
- if (c !=3D ':') goto syntaxerr;
- j =3D 0;
- any =3D 0;
- while (1) {
- c =3D GET_CH;=20
- if (c < '0' || c > '9') break;
- j =3D j * 10 + (int)(c - '0');
- any =3D 1;
- if (j > 65535) goto syntaxerr;
- }
- if (any =3D=3D 0 || c !=3D 0) goto syntaxerr;
- if (j < 1024) goto syntaxerr;
- *port =3D (UShort)j;
- ok:
- return 1;
- syntaxerr:
- return 0;
-# undef GET_CH
-}
-
-
-static
-Int my_socket ( Int domain, Int type, Int protocol )
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- Int res;
- UWord args[3];
- args[0] =3D domain;
- args[1] =3D type;
- args[2] =3D protocol;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SOCKET, (UWord)&arg=
s);
- if (VG_(is_kerror)(res))=20
- res =3D -1;
- return res;
-#endif
-}
-
-static
-Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr,=20
- Int addrlen )
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- Int res;
- UWord args[3];
- args[0] =3D sockfd;
- args[1] =3D (UWord)serv_addr;
- args[2] =3D addrlen;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_CONNECT, (UWord)&ar=
gs);
- if (VG_(is_kerror)(res))=20
- res =3D -1;
- return res;
-#endif
-}
-
-Int VG_(write_socket)( Int sd, void *msg, Int count )
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- /* This is actually send(). */
-
- /* Requests not to send SIGPIPE on errors on stream oriented
- sockets when the other end breaks the connection. The EPIPE
- error is still returned. */
- Int flags =3D VKI_MSG_NOSIGNAL;
-
- Int res;
- UWord args[4];
- args[0] =3D sd;
- args[1] =3D (UWord)msg;
- args[2] =3D count;
- args[3] =3D flags;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_SEND, (UWord)&args)=
;
- if (VG_(is_kerror)(res))=20
- res =3D -1;
- return res;
-#endif
-}
-
-Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen)
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- Int res;
- UWord args[3];
- args[0] =3D sd;
- args[1] =3D (UWord)name;
- args[2] =3D (UWord)namelen;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKNAME, (UWord=
)&args);
- if(VG_(is_kerror)(res))
- res =3D -1;
- return res;
-#endif
-}
-
-Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen)
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- Int res;
- UWord args[3];
- args[0] =3D sd;
- args[1] =3D (UWord)name;
- args[2] =3D (UWord)namelen;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETPEERNAME, (UWord=
)&args);
- if(VG_(is_kerror)(res))
- res =3D -1;
- return res;
-#endif
-}
-
-Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
- Int *optlen)
-{
-// AMD64/Linux doesn't define __NR_socketcall... see comment above
-// VG_(sigpending)() for more details.
-#ifdef __amd64__
- I_die_here;
-#else
- Int res;
- UWord args[5];
- args[0] =3D sd;
- args[1] =3D level;
- args[2] =3D optname;
- args[3] =3D (UWord)optval;
- args[4] =3D (UWord)optlen;
- res =3D VG_(do_syscall2)(__NR_socketcall, VKI_SYS_GETSOCKOPT, (UWord)=
&args);
- if(VG_(is_kerror)(res))
- res =3D -1;
- return res;
-#endif
-}
-
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/include/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=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/include/Makefile.am 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/include/Makefile.am 2005-06-04 20:03:55 UTC (rev 3844)
@@ -10,6 +10,7 @@
pub_tool_hashtable.h \
pub_tool_libcbase.h \
pub_tool_libcassert.h \
+ pub_tool_libcfile.h \
pub_tool_libcprint.h \
pub_tool_mallocfree.h \
pub_tool_options.h \
Added: trunk/include/pub_tool_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/include/pub_tool_libcfile.h 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/include/pub_tool_libcfile.h 2005-06-04 20:03:55 UTC (rev 3844)
@@ -0,0 +1,65 @@
+
+/*--------------------------------------------------------------------*/
+/*--- File/socket-related libc stuff. pub_tool_libcfile.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_LIBCFILE_H
+#define __PUB_TOOL_LIBCFILE_H
+
+/* ---------------------------------------------------------------------
+ File-related functions.
+ ------------------------------------------------------------------ */
+
+extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
+extern void VG_(close) ( Int fd );
+extern Int VG_(read) ( Int fd, void* buf, Int count);
+extern Int VG_(write) ( Int fd, const void* buf, Int count);
+extern Int VG_(pipe) ( Int fd[2] );
+extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
+
+extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
+extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
+extern Int VG_(dup2) ( Int oldfd, Int newfd );
+extern Int VG_(rename) ( Char* old_name, Char* new_name );
+extern Int VG_(unlink) ( Char* file_name );
+
+extern Char* VG_(getcwd) ( Char* buf, SizeT size );
+
+/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
+ String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
+ Returns False if it fails. Will fail if the pathname is > 65535 byte=
s. */
+extern Bool VG_(getcwd_alloc) ( Char** cwd );
+
+extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
+extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count =
);
+
+#endif // __PUB_TOOL_LIBCFILE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/include/tool.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/include/tool.h 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/include/tool.h 2005-06-04 20:03:55 UTC (rev 3844)
@@ -112,11 +112,6 @@
#endif
=20
/* ------------------------------------------------------------------ */
-/* stdio.h */
-
-extern Int VG_(rename) ( Char* old_name, Char* new_name );
-
-/* ------------------------------------------------------------------ */
/* stdlib.h */
=20
/* terminate everything */
@@ -142,35 +137,12 @@
=20
/* ------------------------------------------------------------------ */
/* unistd.h, fcntl.h, sys/stat.h */
-extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count =
);
-extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
extern Int VG_(getpid) ( void );
extern Int VG_(getppid) ( void );
extern Int VG_(getpgrp) ( void );
extern Int VG_(gettid) ( void );
extern Int VG_(setpgid) ( Int pid, Int pgrp );
=20
-extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
-extern Int VG_(read) ( Int fd, void* buf, Int count);
-extern Int VG_(write) ( Int fd, const void* buf, Int count);
-extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
-extern void VG_(close) ( Int fd );
-
-extern Int VG_(pipe) ( Int fd[2] );
-
-/* Nb: VG_(rename)() declared in stdio.h section above */
-extern Int VG_(unlink) ( Char* file_name );
-extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
-extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
-extern Int VG_(dup2) ( Int oldfd, Int newfd );
-
-extern Char* VG_(getcwd) ( Char* buf, SizeT size );
-
-/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
- String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
- Returns False if it fails. Will fail if the pathname is > 65535 byte=
s. */
-extern Bool VG_(getcwd_alloc) ( Char** cwd );
-
/* ------------------------------------------------------------------ */
/* Get memory by anonymous mmap. */
extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
@@ -248,14 +220,6 @@
extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
=20
/* ------------------------------------------------------------------ */
-/* socket.h. */
-
-extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *na=
melen);
-extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *na=
melen);
-extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optva=
l,
- Int *optlen);
-
-/* ------------------------------------------------------------------ */
/* other, randomly useful functions */
extern UInt VG_(read_millisecond_timer) ( void );
=20
Modified: trunk/massif/ms_main.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/massif/ms_main.c 2005-06-04 19:36:34 UTC (rev 3843)
+++ trunk/massif/ms_main.c 2005-06-04 20:03:55 UTC (rev 3844)
@@ -39,6 +39,7 @@
#include "pub_tool_hashtable.h"
#include "pub_tool_libcbase.h"
#include "pub_tool_libcassert.h"
+#include "pub_tool_libcfile.h"
#include "pub_tool_libcprint.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
|