From 5bf4e3319da4a9c11cf2767bf71b494ffd5f8cb1 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 9 May 2002 17:38:13 +0000 Subject: [PATCH] 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 --- coregrind/vg_include.h | 3 +++ coregrind/vg_kerneliface.h | 26 ++++++++++++++++++++++++++ coregrind/vg_memory.c | 6 +----- coregrind/vg_mylibc.c | 16 +++++++++++++++- coregrind/vg_symtab2.c | 8 ++++---- vg_include.h | 3 +++ vg_kerneliface.h | 26 ++++++++++++++++++++++++++ vg_memory.c | 6 +----- vg_mylibc.c | 16 +++++++++++++++- vg_symtab2.c | 8 ++++---- 10 files changed, 98 insertions(+), 20 deletions(-) diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 4794cd0dc5..5dca560c60 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -744,6 +744,7 @@ extern Int VG_(create_and_write) ( Char* pathname ); 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 void* VG_(mmap)( void* start, UInt length, 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 02dabc0cb8..362a553f29 100644 --- a/coregrind/vg_kerneliface.h +++ b/coregrind/vg_kerneliface.h @@ -271,6 +271,32 @@ struct vki_timespec { }; +/* 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 f39592a16e..cd8eba12fa 100644 --- a/coregrind/vg_memory.c +++ b/coregrind/vg_memory.c @@ -1650,10 +1650,6 @@ void init_memory_audit_callback ( } - -/* ONLY HERE for sbrk() */ -#include - /* Initialise the memory audit system. */ void VGM_(init_memory_audit) ( void ) { @@ -1697,7 +1693,7 @@ void VGM_(init_memory_audit) ( void ) /* 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 77dd153a2e..fec258af74 100644 --- a/coregrind/vg_mylibc.c +++ b/coregrind/vg_mylibc.c @@ -288,7 +288,6 @@ Int VG_(select)( Int n, 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 @@ Int VG_(nanosleep)( const struct vki_timespec *req, 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 @@ Int VG_(write) ( Int fd, void* buf, Int count) 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 0987f34d0b..c781751985 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 defns */ #include /* stabs defns */ @@ -625,7 +624,7 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 ); diff --git a/vg_include.h b/vg_include.h index 4794cd0dc5..5dca560c60 100644 --- a/vg_include.h +++ b/vg_include.h @@ -744,6 +744,7 @@ extern Int VG_(create_and_write) ( Char* pathname ); 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 void* VG_(mmap)( void* start, UInt length, 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/vg_kerneliface.h b/vg_kerneliface.h index 02dabc0cb8..362a553f29 100644 --- a/vg_kerneliface.h +++ b/vg_kerneliface.h @@ -271,6 +271,32 @@ struct vki_timespec { }; +/* 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/vg_memory.c b/vg_memory.c index f39592a16e..cd8eba12fa 100644 --- a/vg_memory.c +++ b/vg_memory.c @@ -1650,10 +1650,6 @@ void init_memory_audit_callback ( } - -/* ONLY HERE for sbrk() */ -#include - /* Initialise the memory audit system. */ void VGM_(init_memory_audit) ( void ) { @@ -1697,7 +1693,7 @@ void VGM_(init_memory_audit) ( void ) /* 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/vg_mylibc.c b/vg_mylibc.c index 77dd153a2e..fec258af74 100644 --- a/vg_mylibc.c +++ b/vg_mylibc.c @@ -288,7 +288,6 @@ Int VG_(select)( Int n, 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 @@ Int VG_(nanosleep)( const struct vki_timespec *req, 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 @@ Int VG_(write) ( Int fd, void* buf, Int count) 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/vg_symtab2.c b/vg_symtab2.c index 0987f34d0b..c781751985 100644 --- a/vg_symtab2.c +++ b/vg_symtab2.c @@ -29,7 +29,6 @@ */ #include "vg_include.h" -#include "vg_unsafe.h" #include /* ELF defns */ #include /* stabs defns */ @@ -625,7 +624,7 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 @@ void vg_read_lib_symbols ( SegInfo* si ) 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 ); -- 2.47.3