|
From: Nicholas N. <nj...@ca...> - 2004-07-10 16:50:17
|
CVS commit by nethercote:
Removed the 'place-holder' behaviour of VG_(mmap). Previously, VG_(mmap) would
add a segment mapping to the segment skip-list, and then often the caller of
VG_(mmap) would do another one for the same segment, just to change the SF_*
flags. Now VG_(mmap) gets passed the appropriate SF_* flags so it can do it
directly. This results in shorter, simpler code, and less work at runtime.
Also, strengthened checking in VG_(mmap), POST(mmap), POST(mmap2) -- now if the
result is not in the right place, it aborts rather than unmapping and
continuing. This is because if it's not in the right place, something has
gone badly wrong.
M +2 -2 vg_include.h 1.200
M +4 -6 vg_memory.c 1.54
M +17 -29 vg_mylibc.c 1.78
M +7 -9 vg_signals.c 1.71
M +5 -2 vg_symtab2.c 1.81
M +9 -16 vg_syscalls.c 1.104
--- valgrind/coregrind/vg_include.h #1.199:1.200
@@ -1151,6 +1151,6 @@ extern Int VG_(nanosleep)( const struct
/* system/mman.h */
-extern void* VG_(mmap)( void* start, UInt length,
- UInt prot, UInt flags, UInt fd, UInt offset );
+extern void* VG_(mmap)( void* start, UInt length, UInt prot, UInt flags,
+ UInt sf_flags, UInt fd, UInt offset );
extern Int VG_(munmap)( void* start, Int length );
extern Int VG_(mprotect)( void *start, Int length, UInt prot );
--- valgrind/coregrind/vg_memory.c #1.53:1.54
@@ -678,9 +678,9 @@ Bool VG_(is_addressable)(Addr p, Int siz
// Returns 0 on failure.
-Addr VG_(client_alloc)(Addr addr, UInt len, UInt prot, UInt flags)
+Addr VG_(client_alloc)(Addr addr, UInt len, UInt prot, UInt sf_flags)
{
len = PGROUNDUP(len);
- if (!(flags & SF_FIXED))
+ if (!(sf_flags & SF_FIXED))
addr = VG_(find_map_space)(addr, len, True);
@@ -689,10 +689,8 @@ Addr VG_(client_alloc)(Addr addr, UInt l
return 0;
- flags |= SF_CORE;
-
if (VG_(mmap)((void *)addr, len, prot,
VKI_MAP_FIXED | VKI_MAP_PRIVATE | VKI_MAP_ANONYMOUS | VKI_MAP_CLIENT,
- -1, 0) == (void *)addr) {
- VG_(map_segment)(addr, len, prot, flags);
+ sf_flags | SF_CORE, -1, 0) == (void *)addr)
+ {
return addr;
}
--- valgrind/coregrind/vg_mylibc.c #1.77:1.78
@@ -266,5 +266,5 @@ static Addr mmap_inner(void *start, UInt
/* Returns -1 on failure. */
void* VG_(mmap)( void* start, UInt length,
- UInt prot, UInt flags, UInt fd, UInt offset)
+ UInt prot, UInt flags, UInt sf_flags, UInt fd, UInt offset)
{
Addr res;
@@ -272,43 +272,31 @@ void* VG_(mmap)( void* start, UInt lengt
if (!(flags & VKI_MAP_FIXED)) {
start = (void *)VG_(find_map_space)((Addr)start, length, !!(flags & VKI_MAP_CLIENT));
- if (start == 0)
- return (void *)-1;
flags |= VKI_MAP_FIXED;
}
+ if (start == 0)
+ return (void *)-1;
res = mmap_inner(start, length, prot, flags, fd, offset);
+ // Check it ended up in the right place.
if (!VG_(is_kerror)(res)) {
- UInt sf_flags = SF_MMAP;
-
- if (flags & VKI_MAP_FIXED)
- sf_flags |= SF_FIXED;
- if (flags & VKI_MAP_SHARED)
- sf_flags |= SF_SHARED;
- if (!(flags & VKI_MAP_ANONYMOUS))
- sf_flags |= SF_FILE;
- if (!(flags & VKI_MAP_CLIENT))
- sf_flags |= SF_VALGRIND;
- if (flags & VKI_MAP_NOSYMS)
- sf_flags |= SF_NOSYMS;
-
- /* placeholder - caller will update flags etc if they want */
- VG_(map_fd_segment)(res, length, prot, sf_flags, fd, offset, NULL);
-
if (flags & VKI_MAP_CLIENT) {
- if (res < VG_(client_base) || res >= VG_(client_end)) {
- VG_(munmap)((void *)res, length);
- res = -1;
- }
+ vg_assert(VG_(client_base) <= res && res+length < VG_(client_end));
} else {
- if (res < VG_(valgrind_base) || res >= VG_(valgrind_end)) {
- VG_(munmap)((void *)res, length);
- res = -1;
- }
+ vg_assert(VG_(valgrind_base) <= res && res+length < VG_(valgrind_end));
}
}
+ if (!VG_(is_kerror)(res)) {
+ sf_flags |= SF_MMAP;
+ if ( flags & VKI_MAP_FIXED) sf_flags |= SF_FIXED;
+ if ( flags & VKI_MAP_SHARED) sf_flags |= SF_SHARED;
+ if (!(flags & VKI_MAP_ANONYMOUS)) sf_flags |= SF_FILE;
+ if (!(flags & VKI_MAP_CLIENT)) sf_flags |= SF_VALGRIND;
+ if ( flags & VKI_MAP_NOSYMS) sf_flags |= SF_NOSYMS;
+ VG_(map_fd_segment)(res, length, prot, sf_flags, fd, offset, NULL);
+ }
return VG_(is_kerror)(res) ? ((void*)(-1)) : (void*)res;
--- valgrind/coregrind/vg_signals.c #1.70:1.71
@@ -2142,13 +2142,11 @@ void vg_sync_signalhandler ( Int sigNo,
*/
Addr base = PGROUNDDN(esp);
- Char *ret = VG_(mmap)((Char *)base, seg->addr - base,
- VKI_PROT_READ | VKI_PROT_WRITE | VKI_PROT_EXEC,
- VKI_MAP_PRIVATE | VKI_MAP_FIXED | VKI_MAP_ANONYMOUS | VKI_MAP_CLIENT,
- -1, 0);
- if ((Addr)ret == base) {
- VG_(map_segment)(base, seg->addr - base,
+ if ((void*)-1 != VG_(mmap)((Char *)base, seg->addr - base,
VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,
- SF_STACK|SF_GROWDOWN);
- return; /* restart instruction */
+ VKI_MAP_PRIVATE|VKI_MAP_FIXED|VKI_MAP_ANONYMOUS|VKI_MAP_CLIENT,
+ SF_STACK|SF_GROWDOWN,
+ -1, 0))
+ {
+ return; // extension succeeded, restart instruction
}
/* Otherwise fall into normal signal handling */
--- valgrind/coregrind/vg_symtab2.c #1.80:1.81
@@ -1096,5 +1096,7 @@ Addr open_debug_file( Char* name, UInt c
if ((addr = (Addr)VG_(mmap)(NULL, *size, VKI_PROT_READ,
- VKI_MAP_PRIVATE|VKI_MAP_NOSYMS, fd, 0)) == (Addr)-1) {
+ VKI_MAP_PRIVATE|VKI_MAP_NOSYMS,
+ 0, fd, 0)) == (Addr)-1)
+ {
VG_(close)(fd);
return 0;
@@ -1183,5 +1185,6 @@ Bool vg_read_lib_symbols ( SegInfo* si )
oimage = (Addr)VG_(mmap)( NULL, n_oimage,
- VKI_PROT_READ, VKI_MAP_PRIVATE|VKI_MAP_NOSYMS, fd, 0 );
+ VKI_PROT_READ, VKI_MAP_PRIVATE|VKI_MAP_NOSYMS,
+ 0, fd, 0 );
VG_(close)(fd);
--- valgrind/coregrind/vg_syscalls.c #1.103:1.104
@@ -1021,10 +1021,9 @@ static Addr do_brk(Addr newbrk)
if (newaddr == current) {
ret = newbrk;
- } else if (VG_(mmap)((void *)current , newaddr-current,
- VKI_PROT_READ | VKI_PROT_WRITE | VKI_PROT_EXEC,
- VKI_MAP_PRIVATE | VKI_MAP_ANONYMOUS | VKI_MAP_FIXED | VKI_MAP_CLIENT,
- -1, 0) >= 0) {
- VG_(map_segment)(current, newaddr-current, VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,
- SF_FIXED|SF_BRK);
+ } else if ((void*)-1 != VG_(mmap)((void*)current, newaddr-current,
+ VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC,
+ VKI_MAP_PRIVATE|VKI_MAP_ANONYMOUS|VKI_MAP_FIXED|VKI_MAP_CLIENT,
+ SF_FIXED|SF_BRK, -1, 0))
+ {
ret = newbrk;
}
@@ -3993,8 +3992,5 @@ POST(mmap2)
{
if (!VG_(is_kerror)(res)) {
- if (!valid_client_addr(res, arg2, tid, "mmap2")) {
- VG_(munmap)((void *)res, arg2);
- res = -VKI_ENOMEM;
- } else
+ vg_assert(valid_client_addr(res, arg2, tid, "mmap2"));
mmap_segment( (Addr)res, arg2, arg3, arg4, arg5, arg6 * (ULong)VKI_BYTES_PER_PAGE );
}
@@ -4047,8 +4043,5 @@ PRE(mmap)
if (!VG_(is_kerror)(res)) {
- if (!valid_client_addr(res, a2, tid, "mmap")) {
- VG_(munmap)((void *)res, a2);
- res = -VKI_ENOMEM;
- } else
+ vg_assert(valid_client_addr(res, a2, tid, "mmap"));
mmap_segment( (Addr)res, a2, a3, a4, a5, a6 );
}
|