#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"
// 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. ---*/
/*--------------------------------------------------------------*/
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;
/*--- 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;
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);
#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)
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 )
{
}
}
-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);
} 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
DEF(track_pre_deliver_signal, ThreadId, Int sigNo, Bool)
DEF(track_post_deliver_signal, ThreadId, Int sigNo)
-DEF(track_init_shadow_page, Addr)
-
/*--------------------------------------------------------------------*/
/*--- 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)
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);
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);
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
/* Others... condition variables...
...
- Shadow memory management
*/
-void VG_(track_init_shadow_page)(void(*f)(Addr p));
#endif // __PUB_TOOL_TOOLIFACE_H