}
return EXCEPTION_CONTINUE_SEARCH;
}
+
+static void
+_PyErr_SetFromNTSTATUS(ULONG status)
+{
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+ PyErr_SetFromWindowsErr(LsaNtStatusToWinError((NTSTATUS)status));
+#else
+ if (status & 0x80000000) {
+ // HRESULT-shaped codes are supported by PyErr_SetFromWindowsErr
+ PyErr_SetFromWindowsErr((int)status);
+ }
+ else {
+ // No mapping for NTSTATUS values, so just return it for diagnostic purposes
+ // If we provide it as winerror it could incorrectly change the type of the exception.
+ PyErr_Format(PyExc_OSError, "Operating system error NTSTATUS=0x%08lX", status);
+ }
+#endif
+}
#endif
#if defined(MS_WINDOWS) && !defined(DONT_USE_SEH)
assert(record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR || \
record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION); \
if (record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR) { \
- NTSTATUS status = (NTSTATUS) record.ExceptionInformation[2]; \
- ULONG code = LsaNtStatusToWinError(status); \
- PyErr_SetFromWindowsErr(code); \
+ _PyErr_SetFromNTSTATUS((ULONG)record.ExceptionInformation[2]); \
} \
else if (record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { \
PyErr_SetFromWindowsErr(ERROR_NOACCESS); \
assert(record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR || \
record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION); \
if (record.ExceptionCode == EXCEPTION_IN_PAGE_ERROR) { \
- NTSTATUS status = (NTSTATUS) record.ExceptionInformation[2]; \
- ULONG code = LsaNtStatusToWinError(status); \
- PyErr_SetFromWindowsErr(code); \
+ _PyErr_SetFromNTSTATUS((ULONG)record.ExceptionInformation[2]); \
} \
else if (record.ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { \
PyErr_SetFromWindowsErr(ERROR_NOACCESS); \