From: Nicholas Nethercote Date: Fri, 10 Sep 2004 13:56:13 +0000 (+0000) Subject: To get 32-bit programs working on Opteron, VG_(valgrind_end) was recently X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15779f7ff6f51a4f660f9c56f014296b09393e23;p=thirdparty%2Fvalgrind.git To get 32-bit programs working on Opteron, VG_(valgrind_end) was recently changed to name the last byte in Valgrind's section, rather than one past the last byte. This was because the last byte is 0xffffffff, and so one past gave 0x0, which screwed things up. However, when this change was made, all the places where VG_(valgrind_end) is used weren't adjusted appropriately. So this commit makes those adjustments. It also renames the variable as VG_(valgrind_last), which makes the difference between it and the other VG_(*_end) variables much clearer. MERGED FROM HEAD git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_2_2_0_BRANCH@2680 --- diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h index 27b95e4649..3c882c6a76 100644 --- a/coregrind/vg_include.h +++ b/coregrind/vg_include.h @@ -1274,7 +1274,7 @@ extern Addr VG_(brk_limit); /* current brk */ extern Addr VG_(shadow_base); /* tool's shadow memory */ extern Addr VG_(shadow_end); extern Addr VG_(valgrind_base); /* valgrind's address range */ -extern Addr VG_(valgrind_end); +extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end extern vki_rlimit VG_(client_rlimit_data); /* client's original rlimit data */ diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index 70b8dfb680..aac4411634 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -109,11 +109,9 @@ Addr VG_(shadow_end); Addr VG_(valgrind_base); /* valgrind's address range */ -// VG_(valgrind_end) has a slightly different meaning to all the other -// VG_(*_end) vars -- ie. it names the last byte, whereas the others -// go one byte past the end. - -Addr VG_(valgrind_end); +// Note that VG_(valgrind_last) names the last byte of the section, whereas +// the VG_(*_end) vars name the byte one past the end of the section. +Addr VG_(valgrind_last); vki_rlimit VG_(client_rlimit_data); @@ -437,12 +435,7 @@ static void layout_remaining_space(Addr argc_addr, float ratio) addr_t client_size, shadow_size; VG_(valgrind_base) = (addr_t)&kickstart_base; - - // VG_(valgrind_end) has a slightly different meaning to all the other - // VG_(*_end) vars -- ie. it names the last byte, whereas the others - // go one byte past the end. - - VG_(valgrind_end) = ROUNDUP(argc_addr, 0x10000) - 1; // stack + VG_(valgrind_last) = ROUNDUP(argc_addr, 0x10000) - 1; // stack // This gives the client the largest possible address space while // taking into account the tool's shadow needs. @@ -468,14 +461,14 @@ static void layout_remaining_space(Addr argc_addr, float ratio) "shadow_base %8x (%dMB)\n" "shadow_end %8x (%dMB)\n" "valgrind_base %8x (%dMB)\n" - "valgrind_end %8x\n", + "valgrind_last %8x\n", VG_(client_base), SEGSIZE(client_base, client_mapbase), VG_(client_mapbase), SEGSIZE(client_mapbase, client_end), VG_(client_end), SEGSIZE(client_end, shadow_base), VG_(shadow_base), SEGSIZE(shadow_base, shadow_end), VG_(shadow_end), SEGSIZE(shadow_end, valgrind_base), - VG_(valgrind_base), SEGSIZE(valgrind_base, valgrind_end), - VG_(valgrind_end) + VG_(valgrind_base), SEGSIZE(valgrind_base, valgrind_last), + VG_(valgrind_last) ); #undef SEGSIZE @@ -2564,7 +2557,7 @@ static void build_valgrind_map_callback symbols. This is so we know where the free space is before we start allocating more memory (note: heap is OK, it's just mmap which is the problem here). */ - if (start >= VG_(valgrind_base) && (start+size) <= VG_(valgrind_end)) { + if (start >= VG_(valgrind_base) && (start+size-1) <= VG_(valgrind_last)) { flags |= SF_VALGRIND; VG_(map_file_segment)(start, size, prot, flags, dev, ino, foffset, filename); } @@ -2597,7 +2590,7 @@ static void build_segment_map_callback if (filename != NULL) flags |= SF_FILE; - if (start >= VG_(valgrind_base) && (start+size) <= VG_(valgrind_end)) + if (start >= VG_(valgrind_base) && (start+size-1) <= VG_(valgrind_last)) flags |= SF_VALGRIND; VG_(map_file_segment)(start, size, prot, flags, dev, ino, foffset, filename); @@ -2726,7 +2719,7 @@ void VG_(sanity_check_general) ( Bool force_expensive ) | and mappings | - - | valgrind stack ^^^^^^^^^| - valgrind_end +-------------------------+ + valgrind_last +-------------------------+ : kernel : Nb: Before we can do general allocations with VG_(arena_malloc)() and diff --git a/coregrind/vg_memory.c b/coregrind/vg_memory.c index d1a10c0715..fcf04a5bf2 100644 --- a/coregrind/vg_memory.c +++ b/coregrind/vg_memory.c @@ -493,7 +493,7 @@ Addr VG_(find_map_space)(Addr addr, UInt len, Bool for_client) static const Bool debug = False || mem_debug; Segment *s; Addr ret; - Addr limit = (for_client ? VG_(client_end) : VG_(valgrind_end)); + Addr limit = (for_client ? VG_(client_end)-1 : VG_(valgrind_last)); if (addr == 0) addr = for_client ? VG_(client_mapbase) : VG_(valgrind_base); @@ -537,7 +537,7 @@ Addr VG_(find_map_space)(Addr addr, UInt len, Bool for_client) VG_(printf)(" s == NULL\n"); } - if ((limit - len) < ret) + if (((limit - len)+1) < ret) ret = 0; /* no space */ else ret += VKI_BYTES_PER_PAGE; /* skip leading redzone */ @@ -550,7 +550,7 @@ Addr VG_(find_map_space)(Addr addr, UInt len, Bool for_client) } /* Pad the entire process address space, from VG_(client_base) - to VG_(valgrind_end) by creating an anonymous and inaccessible + to VG_(valgrind_last) by creating an anonymous and inaccessible mapping over any part of the address space which is not covered by an entry in the segment list. @@ -572,7 +572,7 @@ void VG_(pad_address_space)(void) args[4] = -1; args[5] = 0; - while (s && addr < VG_(valgrind_end)) { + while (s && addr <= VG_(valgrind_last)) { if (addr < s->addr) { args[0] = (UInt)addr; args[1] = s->addr - addr; @@ -584,9 +584,9 @@ void VG_(pad_address_space)(void) s = VG_(SkipNode_Next)(&sk_segments, s); } - if (addr < VG_(valgrind_end)) { + if (addr <= VG_(valgrind_last)) { args[0] = (UInt)addr; - args[1] = VG_(valgrind_end) - addr; + args[1] = VG_(valgrind_last) - addr + 1; ret = VG_(do_syscall)(__NR_mmap, (UInt)args); } @@ -602,7 +602,7 @@ void VG_(unpad_address_space)(void) Segment *s = VG_(SkipNode_First)(&sk_segments); Int ret; - while (s && addr < VG_(valgrind_end)) { + while (s && addr <= VG_(valgrind_last)) { if (addr < s->addr) { ret = VG_(do_syscall)(__NR_munmap, (UInt)addr, s->addr - addr); } @@ -611,8 +611,8 @@ void VG_(unpad_address_space)(void) s = VG_(SkipNode_Next)(&sk_segments, s); } - if (addr < VG_(valgrind_end)) { - ret = VG_(do_syscall)(__NR_munmap, (UInt)addr, VG_(valgrind_end) - addr); + if (addr <= VG_(valgrind_last)) { + ret = VG_(do_syscall)(__NR_munmap, addr, (VG_(valgrind_last) - addr) + 1); } return; @@ -793,7 +793,7 @@ Bool VG_(is_shadow_addr)(Addr a) Bool VG_(is_valgrind_addr)(Addr a) { - return a >= VG_(valgrind_base) && a < VG_(valgrind_end); + return a >= VG_(valgrind_base) && a <= VG_(valgrind_last); } Addr VG_(get_client_base)(void) diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c index 3dd68df87e..fad7cd9517 100644 --- a/coregrind/vg_mylibc.c +++ b/coregrind/vg_mylibc.c @@ -284,7 +284,7 @@ void* VG_(mmap)( void* start, UInt length, if (flags & VKI_MAP_CLIENT) { vg_assert(VG_(client_base) <= res && res+length < VG_(client_end)); } else { - vg_assert(VG_(valgrind_base) <= res && res+length < VG_(valgrind_end)); + vg_assert(VG_(valgrind_base) <= res && res+length-1 <= VG_(valgrind_last)); } sf_flags |= SF_MMAP; @@ -1092,7 +1092,7 @@ static inline ExeContext *get_real_execontext(Addr ret) Addr stacktop, sigstack_low, sigstack_high; asm("movl %%ebp, %0; movl %%esp, %1" : "=r" (ebp), "=r" (esp)); - stacktop = VG_(valgrind_end); + stacktop = VG_(valgrind_last); VG_(get_sigstack_bounds)( &sigstack_low, &sigstack_high ); if (esp >= sigstack_low && esp < sigstack_high) stacktop = sigstack_high; @@ -1663,7 +1663,7 @@ void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who ) VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS, 0, -1, 0); if (p != ((void*)(-1))) { - vg_assert(p >= (void*)VG_(valgrind_base) && p < (void*)VG_(valgrind_end)); + vg_assert((void*)VG_(valgrind_base) <= p && p <= (void*)VG_(valgrind_last)); tot_alloc += (UInt)nBytes; if (0) VG_(printf)(