Moved the mman VG_(*_native)() functions into m_aspacemgr, and removed

the unused init_shadow_page() function.  As a result, m_aspacemgr no longer
depends on m_libcmman, breaking a circular module dependency, good!


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4015
This commit is contained in:
Nicholas Nethercote 2005-06-24 22:17:38 +00:00
parent 5986d3e25f
commit 63bf761416
9 changed files with 49 additions and 101 deletions

View File

@ -36,7 +36,6 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h" // For VG_(fstat), VG_(resolve_filename_nodup)
#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_syscall.h"
#include "pub_core_tooliface.h"
@ -73,6 +72,47 @@ Addr VG_(valgrind_base); /* valgrind's address range */
// the VG_(*_end) vars name the byte one past the end of the section.
Addr VG_(valgrind_last);
/*--------------------------------------------------------------*/
/*--- The raw mman syscalls ---*/
/*--------------------------------------------------------------*/
SysRes VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags,
UInt fd, OffT offset)
{
SysRes res;
#if defined(VGP_x86_linux)
{
UWord args[6];
args[0] = (UWord)start;
args[1] = length;
args[2] = prot;
args[3] = flags;
args[4] = fd;
args[5] = offset;
res = VG_(do_syscall1)(__NR_mmap, (UWord)args );
}
#elif defined(VGP_amd64_linux)
res = VG_(do_syscall6)(__NR_mmap, (UWord)start, length,
prot, flags, fd, offset);
#elif defined(VGP_ppc32_linux)
res = VG_(do_syscall6)(__NR_mmap, (UWord)(start), (length),
prot, flags, fd, offset);
#else
# error Unknown platform
#endif
return res;
}
SysRes VG_(munmap_native)(void *start, SizeT length)
{
return VG_(do_syscall2)(__NR_munmap, (UWord)start, length );
}
SysRes VG_(mprotect_native)( void *start, SizeT length, UInt prot )
{
return VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, prot );
}
/*--------------------------------------------------------------*/
/*--- A simple, self-contained ordered array of segments. ---*/
/*--------------------------------------------------------------*/
@ -1021,6 +1061,7 @@ void VG_(unpad_address_space)(Addr start)
while (s && addr <= VG_(valgrind_last)) {
if (addr < s->addr) {
//ret = VG_(do_syscall2)(__NR_munmap, addr, s->addr - addr);
ret = VG_(do_syscall2)(__NR_munmap, addr, s->addr - addr);
}
addr = s->addr + s->len;
@ -1153,30 +1194,6 @@ Bool VG_(is_shadow_addr)(Addr a)
/*--- Handling shadow memory ---*/
/*--------------------------------------------------------------------*/
void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init)
{
vg_assert(0);
if (0)
VG_(printf)("init_shadow_range(%p, %d)\n", p, sz);
vg_assert(VG_(needs).shadow_memory);
vg_assert(VG_(tdict).track_init_shadow_page);
sz = VG_PGROUNDUP(p+sz) - VG_PGROUNDDN(p);
p = VG_PGROUNDDN(p);
VG_(mprotect)((void *)p, sz, VKI_PROT_READ|VKI_PROT_WRITE);
if (call_init)
while(sz) {
/* ask the tool to initialize each page */
VG_TRACK( init_shadow_page, VG_PGROUNDDN(p) );
p += VKI_PAGE_SIZE;
sz -= VKI_PAGE_SIZE;
}
}
void *VG_(shadow_alloc)(UInt size)
{
static Addr shadow_alloc = 0;
@ -1186,7 +1203,6 @@ void *VG_(shadow_alloc)(UInt size)
if (0) show_segments("shadow_alloc(before)");
vg_assert(VG_(needs).shadow_memory);
vg_assert(!VG_(tdict).track_init_shadow_page);
size = VG_PGROUNDUP(size);

View File

@ -38,33 +38,6 @@
#include "pub_core_syscall.h"
#include "vki_unistd.h"
SysRes VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags,
UInt fd, OffT offset)
{
SysRes res;
#if defined(VGP_x86_linux)
{
UWord args[6];
args[0] = (UWord)start;
args[1] = length;
args[2] = prot;
args[3] = flags;
args[4] = fd;
args[5] = offset;
res = VG_(do_syscall1)(__NR_mmap, (UWord)args );
}
#elif defined(VGP_amd64_linux)
res = VG_(do_syscall6)(__NR_mmap, (UWord)start, length,
prot, flags, fd, offset);
#elif defined(VGP_ppc32_linux)
res = VG_(do_syscall6)(__NR_mmap, (UWord)(start), (length),
prot, flags, fd, offset);
#else
# error Unknown platform
#endif
return res;
}
/* Returns -1 on failure. */
void* VG_(mmap)( void* start, SizeT length,
UInt prot, UInt flags, UInt sf_flags, UInt fd, OffT offset)
@ -106,11 +79,6 @@ void* VG_(mmap)( void* start, SizeT length,
return res.isError ? (void*)-1 : (void*)res.val;
}
SysRes VG_(munmap_native)(void *start, SizeT length)
{
return VG_(do_syscall2)(__NR_munmap, (UWord)start, length );
}
/* Returns -1 on failure. */
Int VG_(munmap)( void* start, SizeT length )
{
@ -123,11 +91,6 @@ Int VG_(munmap)( void* start, SizeT length )
}
}
SysRes VG_(mprotect_native)( void *start, SizeT length, UInt prot )
{
return VG_(do_syscall3)(__NR_mprotect, (UWord)start, length, prot );
}
Int VG_(mprotect)( void *start, SizeT length, UInt prot )
{
SysRes res = VG_(mprotect_native)(start, length, prot);

View File

@ -1885,28 +1885,8 @@ void sync_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *u
} else
VG_(message)(Vg_UserMsg, "Stack overflow in thread %d: can't grow stack to %p",
tid, fault);
/* Fall into normal signal handling for all other cases */
} else if (info->si_code == 2 && /* SEGV_ACCERR */
VG_(needs).shadow_memory &&
VG_(is_shadow_addr)(fault)) {
/* If there's a fault within the shadow memory range, and it
is a permissions fault, then it means that the client is
using some memory which had not previously been used.
This catches those faults, makes the memory accessible,
and calls the tool to initialize that page.
*/
static Int recursion = 0;
if (recursion++ == 0) {
VG_(init_shadow_range)(VG_PGROUNDDN(fault), VKI_PAGE_SIZE, True);
recursion--;
return;
} else {
/* otherwise fall into normal SEGV handling */
recursion--;
}
}
/* Fall into normal signal handling for all other cases */
}
/* OK, this is a signal we really have to deal with. If it came

View File

@ -322,8 +322,6 @@ DEF(track_post_mutex_unlock, ThreadId, void*)
DEF(track_pre_deliver_signal, ThreadId, Int sigNo, Bool)
DEF(track_post_deliver_signal, ThreadId, Int sigNo)
DEF(track_init_shadow_page, Addr)
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/

View File

@ -59,6 +59,12 @@ extern Addr VG_(shadow_end);
extern Addr VG_(valgrind_base); // valgrind's address range
extern Addr VG_(valgrind_last); // Nb: last byte, rather than one past the end
// Direct access to these system calls.
extern SysRes VG_(mmap_native) ( void* start, SizeT length, UInt prot,
UInt flags, UInt fd, OffT offset );
extern SysRes VG_(munmap_native) ( void* start, SizeT length );
extern SysRes VG_(mprotect_native) ( void *start, SizeT length, UInt prot );
/* A Segment is mapped piece of client memory. This covers all kinds
of mapped memory (exe, brk, mmap, .so, shm, stack, etc)

View File

@ -43,11 +43,6 @@ extern void* VG_(mmap) ( void* start, SizeT length, UInt prot, UInt flags,
extern Int VG_(munmap) ( void* start, SizeT length );
extern Int VG_(mprotect) ( void *start, SizeT length, UInt prot );
extern SysRes VG_(mmap_native) ( void* start, SizeT length, UInt prot,
UInt flags, UInt fd, OffT offset );
extern SysRes VG_(munmap_native) ( void* start, SizeT length );
extern SysRes VG_(mprotect_native) ( void *start, SizeT length, UInt prot );
extern Addr VG_(get_memory_from_mmap_for_client)
(Addr base, SizeT len, UInt prot, UInt flags);

View File

@ -201,8 +201,6 @@ typedef struct {
void (*track_pre_deliver_signal) (ThreadId, Int sigNo, Bool);
void (*track_post_deliver_signal)(ThreadId, Int sigNo);
void (*track_init_shadow_page)(Addr);
} VgToolInterface;
extern VgToolInterface VG_(tdict);

View File

@ -39,12 +39,6 @@ extern void *VG_(shadow_alloc)(UInt size);
extern Bool VG_(is_addressable)(Addr p, SizeT sz, UInt prot);
/* initialize shadow pages in the range [p, p+sz) This calls
init_shadow_page for each one. It should be a lot more efficient
for bulk-initializing shadow pages than faulting on each one.
*/
extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
/* Calls into the core used by leak-checking */
/* Calls "add_rootrange" with each range of memory which looks like a

View File

@ -398,9 +398,7 @@ void VG_(track_post_deliver_signal)(void(*f)(ThreadId tid, Int sigNo));
/* Others... condition variables...
...
Shadow memory management
*/
void VG_(track_init_shadow_page)(void(*f)(Addr p));
#endif // __PUB_TOOL_TOOLIFACE_H