From: Julian Seward Date: Mon, 18 Aug 2008 21:47:11 +0000 (+0000) Subject: The address space manager, and in particular the NSegment type, X-Git-Tag: svn/VALGRIND_3_4_0~289 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=811f1023887913f989a1041419ae339d73086cc0;p=thirdparty%2Fvalgrind.git The address space manager, and in particular the NSegment type, hardwire the assumption that an inode number is a UWord, that is, a host word. There's no reason for that assumption to be valid; an inode number could be a 64-bit int even on a 32 bit platform (eg w.r.t sys_stat64). This commit changes inode numbers and, for good measure, dev numbers, to be 64-bit regardless. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8521 --- diff --git a/coregrind/m_aspacemgr/aspacemgr-common.c b/coregrind/m_aspacemgr/aspacemgr-common.c index 83ac5738d8..9a664858e4 100644 --- a/coregrind/m_aspacemgr/aspacemgr-common.c +++ b/coregrind/m_aspacemgr/aspacemgr-common.c @@ -255,8 +255,8 @@ Int ML_(am_readlink)(HChar* path, HChar* buf, UInt bufsiz) /* Get the dev, inode and mode info for a file descriptor, if possible. Returns True on success. */ Bool ML_(am_get_fd_d_i_m)( Int fd, - /*OUT*/UWord* dev, - /*OUT*/UWord* ino, /*OUT*/UInt* mode ) + /*OUT*/ULong* dev, + /*OUT*/ULong* ino, /*OUT*/UInt* mode ) { SysRes res; struct vki_stat buf; @@ -267,17 +267,17 @@ Bool ML_(am_get_fd_d_i_m)( Int fd, struct vki_stat64 buf64; res = VG_(do_syscall2)(__NR_fstat64, fd, (UWord)&buf64); if (!res.isError) { - *dev = buf64.st_dev; - *ino = buf64.st_ino; - *mode = buf64.st_mode; + *dev = (ULong)buf64.st_dev; + *ino = (ULong)buf64.st_ino; + *mode = (UInt) buf64.st_mode; return True; } # endif res = VG_(do_syscall2)(__NR_fstat, fd, (UWord)&buf); if (!res.isError) { - *dev = buf.st_dev; - *ino = buf.st_ino; - *mode = buf.st_mode; + *dev = (ULong)buf.st_dev; + *ino = (ULong)buf.st_ino; + *mode = (UInt) buf.st_mode; return True; } return False; diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 3962a38e0e..5f30c96d6b 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -329,7 +329,7 @@ static Int find_nsegment_idx ( Addr a ); static void parse_procselfmaps ( void (*record_mapping)( Addr addr, SizeT len, UInt prot, - UInt dev, UInt ino, ULong offset, + ULong dev, ULong ino, ULong offset, const UChar* filename ), void (*record_gap)( Addr addr, SizeT len ) ); @@ -343,8 +343,8 @@ static void parse_procselfmaps ( /* Extract the device, inode and mode numbers for a fd. */ static -Bool get_inode_for_fd ( Int fd, /*OUT*/UWord* dev, - /*OUT*/UWord* ino, /*OUT*/UInt* mode ) +Bool get_inode_for_fd ( Int fd, /*OUT*/ULong* dev, + /*OUT*/ULong* ino, /*OUT*/UInt* mode ) { return ML_(am_get_fd_d_i_m)(fd, dev, ino, mode); } @@ -503,7 +503,7 @@ static void __attribute__ ((unused)) (ULong)seg->start, (ULong)seg->end, show_ShrinkMode(seg->smode), - (ULong)seg->dev, (ULong)seg->ino, (ULong)seg->offset, seg->fnIdx, + seg->dev, seg->ino, seg->offset, seg->fnIdx, (Int)seg->hasR, (Int)seg->hasW, (Int)seg->hasX, (Int)seg->hasT, (Int)seg->mark, name @@ -552,7 +552,7 @@ static void show_nsegment ( Int logLevel, Int segNo, NSegment* seg ) seg->hasR ? 'r' : '-', seg->hasW ? 'w' : '-', seg->hasX ? 'x' : '-', seg->hasT ? 'T' : '-', seg->isCH ? 'H' : '-', - (ULong)seg->dev, (ULong)seg->ino, (Long)seg->offset, seg->fnIdx + seg->dev, seg->ino, (Long)seg->offset, seg->fnIdx ); break; @@ -871,7 +871,7 @@ static Bool preen_nsegments ( void ) static Bool sync_check_ok = False; static void sync_check_mapping_callback ( Addr addr, SizeT len, UInt prot, - UInt dev, UInt ino, ULong offset, + ULong dev, ULong ino, ULong offset, const UChar* filename ) { Int iLo, iHi, i; @@ -908,7 +908,7 @@ static void sync_check_mapping_callback ( Addr addr, SizeT len, UInt prot, These kernels report which mappings are really executable in the /proc/self/maps output rather than mirroring what was asked for when each mapping was created. In order to cope with this we - have a slopyXcheck mode which we enable on x86 - in this mode we + have a sloppyXcheck mode which we enable on x86 - in this mode we allow the kernel to report execute permission when we weren't expecting it but not vice versa. */ sloppyXcheck = False; @@ -988,7 +988,7 @@ static void sync_check_mapping_callback ( Addr addr, SizeT len, UInt prot, "segment mismatch: kernel's seg:\n"); VG_(debugLog)(0,"aspacem", "start=0x%llx end=0x%llx prot=%u " - "dev=%u ino=%u offset=%lld name=\"%s\"\n", + "dev=%llu ino=%llu offset=%lld name=\"%s\"\n", (ULong)addr, ((ULong)addr) + ((ULong)len) - 1, prot, dev, ino, offset, filename ? (HChar*)filename : "(none)" ); @@ -1469,7 +1469,7 @@ static void init_resvn ( /*OUT*/NSegment* seg, Addr start, Addr end ) /*-----------------------------------------------------------------*/ static void read_maps_callback ( Addr addr, SizeT len, UInt prot, - UInt dev, UInt ino, ULong offset, + ULong dev, ULong ino, ULong offset, const UChar* filename ) { NSegment seg; @@ -1517,13 +1517,12 @@ Addr VG_(am_startup) ( Addr sp_at_startup ) aspacem_assert(sizeof(SizeT) == sizeof(void*)); aspacem_assert(sizeof(SSizeT) == sizeof(void*)); - { - /* If these fail, we'd better change the type of dev and ino in - NSegment accordingly. */ - struct vki_stat buf; - aspacem_assert(sizeof(buf.st_dev) == sizeof(seg.dev)); - aspacem_assert(sizeof(buf.st_ino) == sizeof(seg.ino)); - } + /* Check that we can store the largest imaginable dev, ino and + offset numbers in an NSegment. */ + aspacem_assert(sizeof(seg.dev) == 8); + aspacem_assert(sizeof(seg.ino) == 8); + aspacem_assert(sizeof(seg.offset) == 8); + aspacem_assert(sizeof(seg.mode) == 4); /* Add a single interval covering the entire address space. */ init_nsegment(&seg); @@ -1878,7 +1877,7 @@ VG_(am_notify_client_mmap)( Addr a, SizeT len, UInt prot, UInt flags, Int fd, Off64T offset ) { HChar buf[VKI_PATH_MAX]; - UWord dev, ino; + ULong dev, ino; UInt mode; NSegment seg; Bool needDiscard; @@ -2070,7 +2069,7 @@ SysRes VG_(am_mmap_file_fixed_client) Addr advised; Bool ok; MapRequest req; - UWord dev, ino; + ULong dev, ino; UInt mode; HChar buf[VKI_PATH_MAX]; @@ -2347,7 +2346,7 @@ SysRes VG_(am_mmap_file_float_valgrind) ( SizeT length, UInt prot, Addr advised; Bool ok; MapRequest req; - UWord dev, ino; + ULong dev, ino; UInt mode; HChar buf[VKI_PATH_MAX]; @@ -2935,7 +2934,7 @@ static Int readhex64 ( const Char* buf, ULong* val ) return n; } -static Int readdec ( const Char* buf, UInt* val ) +static Int readdec64 ( const Char* buf, ULong* val ) { Int n = 0; *val = 0; @@ -3003,7 +3002,7 @@ static void read_procselfmaps_into_buf ( void ) */ static void parse_procselfmaps ( void (*record_mapping)( Addr addr, SizeT len, UInt prot, - UInt dev, UInt ino, ULong offset, + ULong dev, ULong ino, ULong offset, const UChar* filename ), void (*record_gap)( Addr addr, SizeT len ) ) @@ -3012,9 +3011,9 @@ static void parse_procselfmaps ( Addr start, endPlusOne, gapStart; UChar* filename; UChar rr, ww, xx, pp, ch, tmp; - UInt ino, prot; - UWord maj, min, dev; - ULong foffset; + UInt prot; + UWord maj, min; + ULong foffset, dev, ino; foffset = ino = 0; /* keep gcc-4.1.0 happy */ @@ -3072,7 +3071,7 @@ static void parse_procselfmaps ( j = readchar(&procmap_buf[i], &ch); if (j == 1 && ch == ' ') i += j; else goto syntaxerror; - j = readdec(&procmap_buf[i], &ino); + j = readdec64(&procmap_buf[i], &ino); if (j > 0) i += j; else goto syntaxerror; goto read_line_ok; diff --git a/coregrind/m_aspacemgr/priv_aspacemgr.h b/coregrind/m_aspacemgr/priv_aspacemgr.h index 2dd1c05ae4..838fa2aa6a 100644 --- a/coregrind/m_aspacemgr/priv_aspacemgr.h +++ b/coregrind/m_aspacemgr/priv_aspacemgr.h @@ -112,8 +112,8 @@ extern Int ML_(am_readlink) ( HChar* path, HChar* buf, UInt bufsiz ); possible. Returns True on success. */ extern Bool ML_(am_get_fd_d_i_m)( Int fd, - /*OUT*/UWord* dev, - /*OUT*/UWord* ino, /*OUT*/UInt* mode ); + /*OUT*/ULong* dev, + /*OUT*/ULong* ino, /*OUT*/UInt* mode ); /* ------ Implemented seperately in aspacemgr-{linux,aix5}.c ------ */ diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h index 7edf4b0a81..6144d270ee 100644 --- a/include/pub_tool_aspacemgr.h +++ b/include/pub_tool_aspacemgr.h @@ -99,10 +99,10 @@ typedef /* Shrinkable? (SkResvn only) */ ShrinkMode smode; /* Associated file (SkFile{C,V} only) */ - UWord dev; - UWord ino; - UInt mode; + ULong dev; + ULong ino; ULong offset; + UInt mode; Int fnIdx; // file name table index, if name is known /* Permissions (SkAnon{C,V}, SkFile{C,V} only) */ Bool hasR;