Index: trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-heap-posix.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-heap-posix.cpp	(revision 78333)
+++ trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-heap-posix.cpp	(revision 78334)
@@ -130,6 +130,6 @@
     /** Non-null on success.  */
     void           *pvAlloc;
-    /** Whether the pages should be zeroed or not. */
-    bool            fZero;
+    /** RTMEMPAGEALLOC_F_XXX. */
+    uint32_t        fFlags;
 } RTHEAPPAGEALLOCARGS;
 
@@ -234,4 +234,36 @@
 
 /**
+ * Applies flags to an allocation.
+ *
+ * @param   pv              The allocation.
+ * @param   cb              The size of the allocation (page aligned).
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
+ */
+DECLINLINE(void) rtMemPagePosixApplyFlags(void *pv, size_t cb, uint32_t fFlags)
+{
+#ifndef RT_OS_OS2
+    if (fFlags & RTMEMPAGEALLOC_F_ADVISE_LOCKED)
+    {
+        int rc = mlock(pv, cb);
+        AssertMsg(rc == 0, ("mlock %p LB %#zx -> %d errno=%d\n", pv, cb, rc, errno));
+        NOREF(rc);
+    }
+
+# ifdef MADV_DONTDUMP
+    if (fFlags & RTMEMPAGEALLOC_F_ADVISE_NO_DUMP)
+    {
+        int rc = madvise(pv, cb, MADV_DONTDUMP);
+        AssertMsg(rc == 0, ("madvice %p LB %#zx MADV_DONTDUMP -> %d errno=%d\n", pv, cb, rc, errno));
+        NOREF(rc);
+    }
+# endif
+#endif
+
+    if (fFlags & RTMEMPAGEALLOC_F_ZERO)
+        RT_BZERO(pv, cb);
+}
+
+
+/**
  * Avoids some gotos in rtHeapPageAllocFromBlock.
  *
@@ -240,8 +272,8 @@
  * @param   iPage           The page to start allocating at.
  * @param   cPages          The number of pages.
- * @param   fZero           Whether to clear them.
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
  * @param   ppv             Where to return the allocation address.
  */
-DECLINLINE(int) rtHeapPageAllocFromBlockSuccess(PRTHEAPPAGEBLOCK pBlock, uint32_t iPage,  size_t cPages, bool fZero, void **ppv)
+DECLINLINE(int) rtHeapPageAllocFromBlockSuccess(PRTHEAPPAGEBLOCK pBlock, uint32_t iPage, size_t cPages, uint32_t fFlags, void **ppv)
 {
     PRTHEAPPAGE pHeap = pBlock->pHeap;
@@ -256,6 +288,7 @@
     void *pv = (uint8_t *)pBlock->Core.Key + (iPage << PAGE_SHIFT);
     *ppv = pv;
-    if (fZero)
-        RT_BZERO(pv, cPages << PAGE_SHIFT);
+
+    if (fFlags)
+        rtMemPagePosixApplyFlags(pv, cPages << PAGE_SHIFT, fFlags);
 
     return VINF_SUCCESS;
@@ -291,8 +324,8 @@
  * @param   pBlock          The block to allocate from.
  * @param   cPages          The size of the allocation.
- * @param   fZero           Whether it should be zeroed or not.
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
  * @param   ppv             Where to return the allocation address on success.
  */
-DECLINLINE(int) rtHeapPageAllocFromBlock(PRTHEAPPAGEBLOCK pBlock, size_t cPages, bool fZero, void **ppv)
+DECLINLINE(int) rtHeapPageAllocFromBlock(PRTHEAPPAGEBLOCK pBlock, size_t cPages, uint32_t fFlags, void **ppv)
 {
     if (pBlock->cFreePages >= cPages)
@@ -305,5 +338,5 @@
         {
             ASMBitSet(&pBlock->bmAlloc[0], iPage);
-            return rtHeapPageAllocFromBlockSuccess(pBlock, iPage, cPages, fZero, ppv);
+            return rtHeapPageAllocFromBlockSuccess(pBlock, iPage, cPages, fFlags, ppv);
         }
 
@@ -314,5 +347,5 @@
             {
                 ASMBitSetRange(&pBlock->bmAlloc[0], iPage, iPage + cPages);
-                return rtHeapPageAllocFromBlockSuccess(pBlock, iPage, cPages, fZero, ppv);
+                return rtHeapPageAllocFromBlockSuccess(pBlock, iPage, cPages, fFlags, ppv);
             }
 
@@ -340,5 +373,5 @@
     PRTHEAPPAGEBLOCK        pBlock = RT_FROM_MEMBER(pNode,  RTHEAPPAGEBLOCK, Core);
     RTHEAPPAGEALLOCARGS    *pArgs  = (RTHEAPPAGEALLOCARGS *)pvUser;
-    int rc = rtHeapPageAllocFromBlock(pBlock, pArgs->cPages, pArgs->fZero, &pArgs->pvAlloc);
+    int rc = rtHeapPageAllocFromBlock(pBlock, pArgs->cPages, pArgs->fFlags, &pArgs->pvAlloc);
     return RT_SUCCESS(rc) ? 1 : 0;
 }
@@ -349,12 +382,12 @@
  *
  * @returns IPRT status code
- * @param   pHeap               The heap - locked.
- * @param   cPages              The page count.
- * @param   pszTag              The tag.
- * @param   fZero               Whether to zero the memory.
- * @param   ppv                 Where to return the address of the allocation
- *                              on success.
- */
-static int rtHeapPageAllocLocked(PRTHEAPPAGE pHeap, size_t cPages, const char *pszTag, bool fZero, void **ppv)
+ * @param   pHeap           The heap - locked.
+ * @param   cPages          The page count.
+ * @param   pszTag          The tag.
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
+ * @param   ppv             Where to return the address of the allocation
+ *                          on success.
+ */
+static int rtHeapPageAllocLocked(PRTHEAPPAGE pHeap, size_t cPages, const char *pszTag, uint32_t fFlags, void **ppv)
 {
     int rc;
@@ -366,5 +399,5 @@
     if (pHeap->pHint1)
     {
-        rc = rtHeapPageAllocFromBlock(pHeap->pHint1, cPages, fZero, ppv);
+        rc = rtHeapPageAllocFromBlock(pHeap->pHint1, cPages, fFlags, ppv);
         if (rc != VERR_NO_MEMORY)
             return rc;
@@ -372,5 +405,5 @@
     if (pHeap->pHint2)
     {
-        rc = rtHeapPageAllocFromBlock(pHeap->pHint2, cPages, fZero, ppv);
+        rc = rtHeapPageAllocFromBlock(pHeap->pHint2, cPages, fFlags, ppv);
         if (rc != VERR_NO_MEMORY)
             return rc;
@@ -388,5 +421,5 @@
         Args.cPages  = cPages;
         Args.pvAlloc = NULL;
-        Args.fZero   = fZero;
+        Args.fFlags  = fFlags;
         RTAvlrPVDoWithAll(&pHeap->BlockTree, true /*fFromLeft*/, rtHeapPageAllocCallback, &Args);
         if (Args.pvAlloc)
@@ -442,5 +475,5 @@
      * Grab memory from the new block (cannot fail).
      */
-    rc = rtHeapPageAllocFromBlock(pBlock, cPages, fZero, ppv);
+    rc = rtHeapPageAllocFromBlock(pBlock, cPages, fFlags, ppv);
     Assert(rc == VINF_SUCCESS);
 
@@ -456,8 +489,8 @@
  * @param   cPages          The number of pages to allocate.
  * @param   pszTag          The allocation tag.
- * @param   fZero           Set if the pages should be zeroed or not.
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
  * @param   ppv             Where to return the pointer to the pages.
  */
-int RTHeapPageAlloc(PRTHEAPPAGE pHeap, size_t cPages, const char *pszTag, bool fZero, void **ppv)
+int RTHeapPageAlloc(PRTHEAPPAGE pHeap, size_t cPages, const char *pszTag, uint32_t fFlags, void **ppv)
 {
     /*
@@ -476,5 +509,5 @@
     if (RT_SUCCESS(rc))
     {
-        rc = rtHeapPageAllocLocked(pHeap, cPages, pszTag, fZero, ppv);
+        rc = rtHeapPageAllocLocked(pHeap, cPages, pszTag, fFlags, ppv);
         RTCritSectLeave(&pHeap->CritSect);
     }
@@ -561,4 +594,6 @@
                     pHeap->pHint1 = pBlock;
 
+                /** @todo Add bitmaps for tracking madvice and mlock so we can undo those. */
+
                 /*
                  * Shrink the heap. Not very efficient because of the AVL tree.
@@ -641,8 +676,8 @@
  * @param   cb                  The number of bytes to allocate.
  * @param   pszTag              The tag.
- * @param   fZero               Whether to zero the memory or not.
+ * @param   fFlags              RTMEMPAGEALLOC_F_XXX.
  * @param   pHeap               The heap to use.
  */
-static void *rtMemPagePosixAlloc(size_t cb, const char *pszTag, bool fZero, PRTHEAPPAGE pHeap)
+static void *rtMemPagePosixAlloc(size_t cb, const char *pszTag, uint32_t fFlags, PRTHEAPPAGE pHeap)
 {
     /*
@@ -667,6 +702,7 @@
         {
             AssertPtr(pv);
-            if (fZero)
-                RT_BZERO(pv, cb);
+
+            if (fFlags)
+                rtMemPagePosixApplyFlags(pv, cb, fFlags);
         }
         else
@@ -677,5 +713,5 @@
         int rc = RTOnce(&g_MemPagePosixInitOnce, rtMemPagePosixInitOnce, NULL);
         if (RT_SUCCESS(rc))
-            rc = RTHeapPageAlloc(pHeap, cb >> PAGE_SHIFT, pszTag, fZero, &pv);
+            rc = RTHeapPageAlloc(pHeap, cb >> PAGE_SHIFT, pszTag, fFlags, &pv);
         if (RT_FAILURE(rc))
             pv = NULL;
@@ -726,5 +762,5 @@
 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, false /*fZero*/, &g_MemPagePosixHeap);
+    return rtMemPagePosixAlloc(cb, pszTag, 0, &g_MemPagePosixHeap);
 }
 
@@ -732,5 +768,12 @@
 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, true /*fZero*/, &g_MemPagePosixHeap);
+    return rtMemPagePosixAlloc(cb, pszTag, RTMEMPAGEALLOC_F_ZERO, &g_MemPagePosixHeap);
+}
+
+
+RTDECL(void *) RTMemPageAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW_DEF
+{
+    AssertReturn(!(fFlags & RTMEMPAGEALLOC_F_VALID_MASK), NULL);
+    return rtMemPagePosixAlloc(cb, pszTag, fFlags, 0);
 }
 
@@ -747,5 +790,5 @@
 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, false /*fZero*/, &g_MemExecPosixHeap);
+    return rtMemPagePosixAlloc(cb, pszTag, 0, &g_MemExecPosixHeap);
 }
 
Index: trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-posix.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-posix.cpp	(revision 78333)
+++ trunk/src/VBox/Runtime/r3/posix/rtmempage-exec-mmap-posix.cpp	(revision 78334)
@@ -47,4 +47,36 @@
 
 /**
+ * Applies flags to an allocation.
+ *
+ * @param   pv              The allocation.
+ * @param   cb              The size of the allocation (page aligned).
+ * @param   fFlags          RTMEMPAGEALLOC_F_XXX.
+ */
+DECLINLINE(void) rtMemPagePosixApplyFlags(void *pv, size_t cb, uint32_t fFlags)
+{
+#ifndef RT_OS_OS2
+    if (fFlags & RTMEMPAGEALLOC_F_ADVISE_LOCKED)
+    {
+        int rc = mlock(pv, cb);
+        AssertMsg(rc == 0, ("mlock %p LB %#zx -> %d errno=%d\n", pv, cb, rc, errno));
+        NOREF(rc);
+    }
+
+# ifdef MADV_DONTDUMP
+    if (fFlags & RTMEMPAGEALLOC_F_ADVISE_NO_DUMP)
+    {
+        int rc = madvise(pv, cb, MADV_DONTDUMP);
+        AssertMsg(rc == 0, ("madvice %p LB %#zx MADV_DONTDUMP -> %d errno=%d\n", pv, cb, rc, errno));
+        NOREF(rc);
+    }
+# endif
+#endif
+
+    if (fFlags & RTMEMPAGEALLOC_F_ZERO)
+        RT_BZERO(pv, cb);
+}
+
+
+/**
  * Allocates memory from the specified heap.
  *
@@ -52,8 +84,8 @@
  * @param   cb                  The number of bytes to allocate.
  * @param   pszTag              The tag.
- * @param   fZero               Whether to zero the memory or not.
+ * @param   fFlags              RTMEMPAGEALLOC_F_XXX.
  * @param   fProtExec           PROT_EXEC or 0.
  */
-static void *rtMemPagePosixAlloc(size_t cb, const char *pszTag, bool fZero, int fProtExec)
+static void *rtMemPagePosixAlloc(size_t cb, const char *pszTag, uint32_t fFlags, int fProtExec)
 {
     /*
@@ -73,6 +105,7 @@
     {
         AssertPtr(pv);
-        if (fZero)
-            RT_BZERO(pv, cb);
+
+        if (fFlags)
+            rtMemPagePosixApplyFlags(pv, cb, fFlags);
     }
     else
@@ -114,5 +147,5 @@
 RTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, false /*fZero*/, 0);
+    return rtMemPagePosixAlloc(cb, pszTag, 0, 0);
 }
 
@@ -120,5 +153,12 @@
 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, true /*fZero*/, 0);
+    return rtMemPagePosixAlloc(cb, pszTag, RTMEMPAGEALLOC_F_ZERO, 0);
+}
+
+
+RTDECL(void *) RTMemPageAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW_DEF
+{
+    AssertReturn(!(fFlags & RTMEMPAGEALLOC_F_VALID_MASK), NULL);
+    return rtMemPagePosixAlloc(cb, pszTag, fFlags, 0);
 }
 
@@ -135,5 +175,5 @@
 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
-    return rtMemPagePosixAlloc(cb, pszTag, false /*fZero*/, PROT_EXEC);
+    return rtMemPagePosixAlloc(cb, pszTag, 0, PROT_EXEC);
 }
 
Index: trunk/src/VBox/Runtime/r3/win/alloc-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/alloc-win.cpp	(revision 78333)
+++ trunk/src/VBox/Runtime/r3/win/alloc-win.cpp	(revision 78334)
@@ -96,4 +96,31 @@
 
 
+RTDECL(void *) RTMemPageAllocExTag(size_t cb, uint32_t fFlags, const char *pszTag) RT_NO_THROW_DEF
+{
+    size_t const cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
+    RT_NOREF_PV(pszTag);
+    AssertReturn(!(fFlags & ~RTMEMPAGEALLOC_F_VALID_MASK), NULL);
+
+#ifdef USE_VIRTUAL_ALLOC
+    void *pv = VirtualAlloc(NULL, cbAligned, MEM_COMMIT, PAGE_READWRITE);
+#else
+    void *pv = _aligned_malloc(cbAligned, PAGE_SIZE);
+#endif
+    AssertMsgReturn(pv, ("cb=%d lasterr=%d\n", cb, GetLastError()), NULL);
+
+    if (fFlags & RTMEMPAGEALLOC_F_ADVISE_LOCKED)
+    {
+        BOOL const fOkay = VirtualLock(pv, cbAligned);
+        AssertMsg(fOkay, ("pv=%p cb=%d lasterr=%d\n", pv, cb, GetLastError()));
+        NOREF(fOkay);
+    }
+
+    if (fFlags & RTMEMPAGEALLOC_F_ZERO)
+        RT_BZERO(pv, cbAligned);
+
+    return pv;
+}
+
+
 RTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW_DEF
 {
