Add a facility for tracking open file descriptors.  Information about
still open files is dumped out exit.  Enabled using the --track-fds
switch.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2031 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/include/vg_kerneliface.h b/include/vg_kerneliface.h
index fcfc71d..0be5f2b 100644
--- a/include/vg_kerneliface.h
+++ b/include/vg_kerneliface.h
@@ -330,6 +330,10 @@
 #define VKI_O_DIRECTORY     0200000 /* must be a directory */
 #define VKI_O_NOFOLLOW      0400000 /* don't follow links */
 
+#define VKI_SEEK_SET              0
+#define VKI_SEEK_CUR              1
+#define VKI_SEEK_END              2
+
 /* Copied from linux-2.4.19/include/linux/stat.h */
 
 #define VKI_S_IRWXU 00700
@@ -633,6 +637,41 @@
 #define VKI_CLONE_UNTRACED	0x00800000	/* set if the tracing process can't force VKI_CLONE_PTRACE on this clone */
 #define VKI_CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
 
+/* This is the structure passed to the getdents syscall. */
+/*
+ * linux/dirent.h
+ */
+typedef struct vki_dirent {
+	long           d_ino;
+	long           d_off;
+	unsigned short d_reclen;
+	char           d_name[256];
+} vki_dirent;
+
+
+
+/* This is the structure passed to the getrlimit syscall. */
+/*
+ * bits/resource.h
+ */
+typedef struct vki_rlimit {
+	unsigned long rlim_cur;
+	unsigned long rlim_max;
+} vki_rlimit;
+
+#define VKI_RLIMIT_NOFILE 7
+
+/* Socket stuff. */
+/*
+ * sys/socket.h
+ */
+typedef unsigned short vki_sa_family_t;
+struct vki_sockaddr {
+  vki_sa_family_t sa_family;     /* Address family. */
+  char            sa_data[14];   /* Address data. */
+};
+
+
 #endif /* ndef __VG_KERNELIFACE_H */
 
 /*--------------------------------------------------------------------*/
diff --git a/include/vg_skin.h b/include/vg_skin.h
index 0101eaa..ba23074 100644
--- a/include/vg_skin.h
+++ b/include/vg_skin.h
@@ -362,6 +362,9 @@
 /* Looks up VG_(client_envp) */
 extern Char* VG_(getenv) ( Char* name );
 
+/* Get client resource limit*/
+extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
+
 /* Crude stand-in for the glibc system() call. */
 extern Int   VG_(system) ( Char* cmd );
 
@@ -420,6 +423,8 @@
 
 /* ------------------------------------------------------------------ */
 /* 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 );
@@ -429,6 +434,7 @@
 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 Int  VG_(lseek)  ( Int fd, Long offset, Int whence);
 extern void VG_(close)  ( Int fd );
 
 extern Int  VG_(pipe)   ( Int fd[2] );
@@ -514,6 +520,14 @@
 extern Int VG_(waitpid)	     ( Int pid, Int *status, Int options );
 
 /* ------------------------------------------------------------------ */
+/* socket.h. */
+
+extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
+extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
+extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
+                             Int *optlen);
+
+/* ------------------------------------------------------------------ */
 /* other, randomly useful functions */
 extern UInt VG_(read_millisecond_timer) ( void );