On Wed, 4 Nov 2026 17:33:21 GMT, Ashay Rane <[email protected]> wrote:
> Without this patch, HotSpot uses `VirtualAlloc()` with `MEM_COMMIT` to > make Windows convert stack pages from "reserved" to "committed", but > doing so does not update the `StackLimit` field in the Thread > Environment Block (TEB) tracked by Windows. Subsequent use of the stack > by HotSpot can cause the stack pointer to be _below_ `StackLimit`, which > breaks the invariant expected by the Win32 API functions like > `__chkstk()`. > > To fix this problem, this patch touches pages one by one, starting from > `StackLimit` down to the target address. This has the intended effect > of commiting the pages, but it also correctly updates `StackLimit`. > > The included test reliably fails without this patch, and it passes with > this patch. I validated this patch using Tier 1 through 3 tests in the > JDK, HotSpot, and LangTools test groups. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). src/hotspot/os/windows/os_windows.cpp line 2787: > 2785: // If it's a legal stack address map the entire region in > 2786: if (thread->is_in_usable_stack(addr)) { > 2787: addr = (address)((uintptr_t)addr & Update the comment. src/hotspot/os/windows/os_windows.cpp line 2810: > 2808: // If it's a legal stack address map the entire region in > 2809: if (thread->is_in_usable_stack(addr)) { > 2810: grow_windows_stack_to(align_down(addr, os::vm_page_size())); You don't check result of `grow_windows_stack_to`. Should we report error and exit by fall through to VMError below if it returns false?: if (thread->is_in_usable_stack(addr) && grow_windows_stack_to(align_down(addr, os::vm_page_size()))) { return EXCEPTION_CONTINUE_EXECUTION; } test/hotspot/jtreg/runtime/StackGuardPages/TestWindowsStackLimit.java line 26: > 24: /* > 25: * @test > 26: * @summary Verifies that on Windows, HotSpot's access-violation recovery > for Add @bug 8394484 test/hotspot/jtreg/runtime/StackGuardPages/TestWindowsStackLimit.java line 31: > 29: * @requires os.family == "windows" > 30: * @library /test/lib > 31: * @run main/othervm/native TestWindowsStackLimit Add `--enable-native-access=ALL-UNNAMED` test/hotspot/jtreg/runtime/StackGuardPages/TestWindowsStackLimit.java line 48: > 46: > 47: // `Linker.Option.critical()` keeps the calling thread's state as > 48: // `_thread_in_java` for the whole native call, which is a > prerequisite `_thread_in_Java` ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4498808016 PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4498826494 PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4498791971 PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4498803412 PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4498803804
