From: Tom Hughes Date: Wed, 5 Jul 2006 17:47:46 +0000 (+0000) Subject: Use fstat64 to work out the size of a file if it is available as it X-Git-Tag: svn/VALGRIND_3_3_0~730 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab63c4397bd639df7c598cd4757abea22f4fdd68;p=thirdparty%2Fvalgrind.git Use fstat64 to work out the size of a file if it is available as it copes with a wider range of filesystems than the old fstat call. Fixes bug #130020. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5979 --- diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index be0d75fc3c..e3318e6b71 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -821,7 +821,6 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) Addr dimage = 0; UInt n_dimage = 0; OffT offset_dimage = 0; - struct vki_stat stat_buf; oimage = (Addr)NULL; if (VG_(clo_verbosity) > 1 || VG_(clo_trace_redir)) @@ -832,16 +831,16 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) line number info out of it. It will be munmapped immediately thereafter; it is only aboard transiently. */ - fd = VG_(stat)(si->filename, &stat_buf); + fd = VG_(open)(si->filename, VKI_O_RDONLY, 0); if (fd.isError) { - ML_(symerr)("Can't stat .so/.exe (to determine its size)?!"); + ML_(symerr)("Can't open .so/.exe to read symbols?!"); return False; } - n_oimage = stat_buf.st_size; - fd = VG_(open)(si->filename, VKI_O_RDONLY, 0); - if (fd.isError) { - ML_(symerr)("Can't open .so/.exe to read symbols?!"); + n_oimage = VG_(fsize)(fd.val); + if (n_oimage < 0) { + ML_(symerr)("Can't stat .so/.exe (to determine its size)?!"); + VG_(close)(fd.val); return False; } diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index 82e2972280..f84a1c24c0 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -133,8 +133,13 @@ Int VG_(fstat) ( Int fd, struct vki_stat* buf ) Int VG_(fsize) ( Int fd ) { +#ifdef __NR_fstat64 + struct vki_stat64 buf; + SysRes res = VG_(do_syscall2)(__NR_fstat64, fd, (UWord)&buf); +#else struct vki_stat buf; SysRes res = VG_(do_syscall2)(__NR_fstat, fd, (UWord)&buf); +#endif return res.isError ? (-1) : buf.st_size; }