Remove valgrind's use of libc-supplied stat() and sbrk().  Now the only
sysbols we need from libc are __umoddi3 and __udivdi3 ; other than that
valgrind.so is completely self-contained.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@244 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h
index 4794cd0..5dca560 100644
--- a/coregrind/vg_include.h
+++ b/coregrind/vg_include.h
@@ -744,6 +744,7 @@
 extern void VG_(close)     ( Int fd );
 extern Int  VG_(read)      ( Int fd, void* buf, Int count);
 extern Int  VG_(write)     ( Int fd, void* buf, Int count);
+extern Int  VG_(stat) ( Char* file_name, struct vki_stat* buf );
 
 extern Int  VG_(fcntl) ( Int fd, Int cmd, Int arg );
 
@@ -762,6 +763,8 @@
 
 extern Int  VG_(munmap)( void* start, Int length );
 
+extern void* VG_(brk) ( void* end_data_segment );
+
 
 /* Print a (panic) message, and abort. */
 extern void VG_(panic) ( Char* str )
diff --git a/coregrind/vg_kerneliface.h b/coregrind/vg_kerneliface.h
index 02dabc0..362a553 100644
--- a/coregrind/vg_kerneliface.h
+++ b/coregrind/vg_kerneliface.h
@@ -271,6 +271,32 @@
 };
 
 
+/* STAT stuff 
+   from /usr/src/linux-2.4.9-31/include/asm-i386/stat.h */
+struct vki_stat {
+        unsigned short st_dev;
+        unsigned short __pad1;
+        unsigned long st_ino;
+        unsigned short st_mode;
+        unsigned short st_nlink;
+        unsigned short st_uid;
+        unsigned short st_gid;
+        unsigned short st_rdev;
+        unsigned short __pad2;
+        unsigned long  st_size;
+        unsigned long  st_blksize;
+        unsigned long  st_blocks;
+        unsigned long  st_atime;
+        unsigned long  __unused1;
+        unsigned long  st_mtime;
+        unsigned long  __unused2;
+        unsigned long  st_ctime;
+        unsigned long  __unused3;
+        unsigned long  __unused4;
+        unsigned long  __unused5;
+};
+
+
 #endif /* ndef __VG_KERNELIFACE_H */
 
 /*--------------------------------------------------------------------*/
diff --git a/coregrind/vg_memory.c b/coregrind/vg_memory.c
index f39592a..cd8eba1 100644
--- a/coregrind/vg_memory.c
+++ b/coregrind/vg_memory.c
@@ -1650,10 +1650,6 @@
 }
 
 
-
-/* ONLY HERE for sbrk() */
-#include <unistd.h>
-
 /* Initialise the memory audit system. */
 void VGM_(init_memory_audit) ( void )
 {
@@ -1697,7 +1693,7 @@
    /* Record the end of the data segment, so that vg_syscall_mem.c
       can make sense of calls to brk(). 
    */
-   VGM_(curr_dataseg_end) = (Addr)sbrk(0);
+   VGM_(curr_dataseg_end) = (Addr)VG_(brk)(0);
    if (VGM_(curr_dataseg_end) == (Addr)(-1))
       VG_(panic)("vgm_init_memory_audit: can't determine data-seg end");
 
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index 77dd153..fec258a 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -288,7 +288,6 @@
    args[4] = (UInt)timeout;
    res = vg_do_syscall1(__NR_select, (UInt)(&(args[0])) );
    return VG_(is_kerror)(res) ? -1 : res;
-   return res;
 }
 
 /* Returns -1 on error, 0 if ok, 1 if interrupted. */
@@ -302,6 +301,13 @@
    return 0;
 }
 
+void* VG_(brk) ( void* end_data_segment )
+{
+   Int res;
+   res = vg_do_syscall1(__NR_brk, (UInt)end_data_segment);
+   return (void*)(  VG_(is_kerror)(res) ? -1 : res  );
+}
+
 
 /* ---------------------------------------------------------------------
    printf implementation.  The key function, vg_vprintf(), emits chars 
@@ -953,6 +959,14 @@
    return res;
 }
 
+Int VG_(stat) ( Char* file_name, struct vki_stat* buf )
+{
+   Int res;
+   res = vg_do_syscall2(__NR_stat, (UInt)file_name, (UInt)buf);
+   return
+      VG_(is_kerror)(res) ? (-1) : 0;
+}
+
 /* Misc functions looking for a proper home. */
 
 /* We do getenv without libc's help by snooping around in
diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c
index 0987f34..c781751 100644
--- a/coregrind/vg_symtab2.c
+++ b/coregrind/vg_symtab2.c
@@ -29,7 +29,6 @@
 */
 
 #include "vg_include.h"
-#include "vg_unsafe.h"
 
 #include <elf.h>          /* ELF defns                      */
 #include <a.out.h>        /* stabs defns                    */
@@ -625,7 +624,7 @@
    Bool          ok;
    Addr          oimage;
    Int           n_oimage;
-   struct stat   stat_buf;
+   struct vki_stat stat_buf;
 
    /* for the .stabs reader */
    Int    curr_filenmoff;
@@ -644,7 +643,7 @@
       line number info out of it.  It will be munmapped immediately
       thereafter; it is only aboard transiently. */
 
-   i = stat(si->filename, &stat_buf);
+   i = VG_(stat)(si->filename, &stat_buf);
    if (i != 0) {
       vg_symerr("Can't stat .so/.exe (to determine its size)?!");
       return;
@@ -657,7 +656,8 @@
       return;
    }
 
-   oimage = (Addr)VG_(mmap)( NULL, n_oimage, PROT_READ, MAP_PRIVATE, fd, 0 );
+   oimage = (Addr)VG_(mmap)( NULL, n_oimage, 
+                             VKI_PROT_READ, VKI_MAP_PRIVATE, fd, 0 );
    if (oimage == ((Addr)(-1))) {
       VG_(message)(Vg_UserMsg,
                    "mmap failed on %s", si->filename );