Windows 中 MAP_GROWSDOWN 的 mmap 等价物

Equivalent of mmap with MAP_GROWSDOWN in Windows

在 Linux 中,我可以使用带有 MAP_GROWSDOWN 标志的 mmap 来为自动增长的堆栈分配内存。引用联机帮助页,

   MAP_GROWSDOWN
          This flag is used for stacks.  It indicates to the kernel
          virtual memory system that the mapping should extend
          downward in memory.  The return address is one page lower
          than the memory area that is actually created in the
          process's virtual address space.  Touching an address in
          the "guard" page below the mapping will cause the mapping
          to grow by a page.  This growth can be repeated until the
          mapping grows to within a page of the high end of the next
          lower mapping, at which point touching the "guard" page
          will result in a SIGSEGV signal.

在Windows中是否有一些等效的技术?甚至像询问 OS 这样丑陋的事情会通知您有关页面错误的信息,以便您可以在下面分配一个新页面(并通过询问 OS 到 fiddle 和页表使其看起来连续)?

VirtualAlloc you can reserve a block of memory, commit the top two pages, and set the lower of the two pages with PAGE_GUARD。当堆栈向下增长并访问保护页面时,将抛出一个结构化异常,您可以处理该异常以提交下一页并在其上设置 PAGE_GUARD

以上类似于Windows进程中堆栈的处理方式。下面是使用 Sysinternals VMMAP.EXE 对堆栈的描述。您可以看到它是一个 256KB 的堆栈,其中 32K 已提交,12K 保护页和 212K 保留堆栈剩余。