]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
To get 32-bit programs working on Opteron, VG_(valgrind_end) was recently
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 7 Sep 2004 23:04:49 +0000 (23:04 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 7 Sep 2004 23:04:49 +0000 (23:04 +0000)
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.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2672

coregrind/core.h
coregrind/vg_main.c
coregrind/vg_memory.c
coregrind/vg_mylibc.c

index 7144a56140038d114cf6b64a081afa71ac87c75e..17d428066c7b20af4b7a4c355658fe5150923fb4 100644 (file)
@@ -1245,7 +1245,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 */
 
index b80e286dbb2332bc25341bd0a18b5a0ce0e66938..8ef52cce478e58417d079936d755d138dffe5c91 100644 (file)
@@ -108,11 +108,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);
 
@@ -403,12 +401,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.
@@ -434,14 +427,14 @@ static void layout_remaining_space(Addr argc_addr, float ratio)
          "shadow_base        %8x (%dMB)\n"
          "shadow_end         %8x\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),
-         VG_(valgrind_base),     SEGSIZE(valgrind_base,     valgrind_end),
-         VG_(valgrind_end)
+         VG_(valgrind_base),     SEGSIZE(valgrind_base,     valgrind_last),
+         VG_(valgrind_last)
       );
 
 #undef SEGSIZE
@@ -2277,7 +2270,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);
    }
@@ -2310,7 +2303,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);
@@ -2438,7 +2431,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
index 588297ed161d77406f99cdcf555ff38839fa4f24..995a697e2dd885ea5a3a9c69d0e1d8e6c0381ccf 100644 (file)
@@ -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)
index 0b70234aed52c8f1e03dd32d70a44213c21c6ce7..b79b8da3109647e417bccef4d0ec309bbbe5d7fc 100644 (file)
@@ -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 <= 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(p >= (void*)VG_(valgrind_base) && p <= (void*)VG_(valgrind_last));
       tot_alloc += (UInt)nBytes;
       if (0)
          VG_(printf)(