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 */
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);
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.
"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
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);
}
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);
| and mappings |
- -
| valgrind stack ^^^^^^^^^|
- valgrind_end +-------------------------+
+ valgrind_last +-------------------------+
: kernel :
Nb: Before we can do general allocations with VG_(arena_malloc)() and
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);
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 */
}
/* 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.
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;
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);
}
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);
}
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;
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)
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;
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;
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)(