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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 4bd4ce8..1c6d921 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -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"
@@ -74,6 +73,47 @@
 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 @@
 
    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 @@
 /*--- 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 @@
    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);
 
diff --git a/coregrind/m_libcmman.c b/coregrind/m_libcmman.c
index a2265d3..cf4fd3a 100644
--- a/coregrind/m_libcmman.c
+++ b/coregrind/m_libcmman.c
@@ -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 @@
    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 @@
    }
 }
 
-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);
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index a41b48f..9e1c1b5 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -1885,28 +1885,8 @@
 	 } 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
diff --git a/coregrind/m_tooliface.c b/coregrind/m_tooliface.c
index d6242c7..a13f3ef 100644
--- a/coregrind/m_tooliface.c
+++ b/coregrind/m_tooliface.c
@@ -322,8 +322,6 @@
 DEF(track_pre_deliver_signal,    ThreadId, Int sigNo, Bool)
 DEF(track_post_deliver_signal,   ThreadId, Int sigNo)
 
-DEF(track_init_shadow_page,      Addr)
-
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h
index 703f146..7f5af75 100644
--- a/coregrind/pub_core_aspacemgr.h
+++ b/coregrind/pub_core_aspacemgr.h
@@ -59,6 +59,12 @@
 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)
 
diff --git a/coregrind/pub_core_libcmman.h b/coregrind/pub_core_libcmman.h
index a537405..6bc8f05 100644
--- a/coregrind/pub_core_libcmman.h
+++ b/coregrind/pub_core_libcmman.h
@@ -43,11 +43,6 @@
 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);
 
diff --git a/coregrind/pub_core_tooliface.h b/coregrind/pub_core_tooliface.h
index 5cf9989..df9fe26 100644
--- a/coregrind/pub_core_tooliface.h
+++ b/coregrind/pub_core_tooliface.h
@@ -201,8 +201,6 @@
    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);
diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h
index b2b4236..92c102f 100644
--- a/include/pub_tool_aspacemgr.h
+++ b/include/pub_tool_aspacemgr.h
@@ -39,12 +39,6 @@
 
 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
diff --git a/include/pub_tool_tooliface.h b/include/pub_tool_tooliface.h
index 1d16683..92e413a 100644
--- a/include/pub_tool_tooliface.h
+++ b/include/pub_tool_tooliface.h
@@ -398,9 +398,7 @@
 
 /* Others... condition variables...
    ...
-   Shadow memory management
  */
-void VG_(track_init_shadow_page)(void(*f)(Addr p));
 
 #endif   // __PUB_TOOL_TOOLIFACE_H