From 3951a8e01945d262cdd6ebbe4e1548ddf8e3c02a Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 7 Apr 2025 23:36:04 +0000 Subject: [PATCH] 8353365: TOUCH_ASSERT_POISON clears GetLastError() Reviewed-by: kbarrett, stuefe, jwaters --- src/hotspot/os/windows/os_windows.cpp | 1 + test/hotspot/gtest/utilities/test_vmerror.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 06fe8a826cd..ec03a45594c 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -2600,6 +2600,7 @@ static inline void report_error(Thread* t, DWORD exception_code, //----------------------------------------------------------------------------- JNIEXPORT LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { + PreserveLastError ple; if (InterceptOSException) return EXCEPTION_CONTINUE_SEARCH; PEXCEPTION_RECORD exception_record = exceptionInfo->ExceptionRecord; DWORD exception_code = exception_record->ExceptionCode; diff --git a/test/hotspot/gtest/utilities/test_vmerror.cpp b/test/hotspot/gtest/utilities/test_vmerror.cpp index a779133b711..ad2f2c3004f 100644 --- a/test/hotspot/gtest/utilities/test_vmerror.cpp +++ b/test/hotspot/gtest/utilities/test_vmerror.cpp @@ -28,6 +28,17 @@ #ifdef ASSERT +#ifdef _WINDOWS + +#include + +TEST_VM_ASSERT_MSG(vmErrorTest, fatalWithError, + "fatal error: GetLastError should be 6 - actually: 6") { + SetLastError(6); + fatal("GetLastError should be 6 - actually: %lu", GetLastError()); +} +#endif // WINDOWS + TEST_VM_ASSERT_MSG(vmErrorTest, resourceMark, "fatal error: memory leak: allocating without ResourceMark") {