diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs index 43508983609a5..ad48e8e74d52a 100644 --- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs +++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.NtStatus.cs @@ -5,6 +5,10 @@ internal static partial class Interop { internal static class StatusOptions { + // See the NT_SUCCESS macro in the Windows SDK, and + // https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values + internal static bool NT_SUCCESS(uint ntStatus) => (int)ntStatus >= 0; + // Error codes from ntstatus.h internal const uint STATUS_SUCCESS = 0x00000000; internal const uint STATUS_SOME_NOT_MAPPED = 0x00000107; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs index 2d1a37ca13108..fdf37dcd20a08 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs @@ -257,7 +257,7 @@ public static void Invoke(Event e) // The NtStatus code for the operation is in the InternalLow field uint ntStatus = (uint)(nint)e.nativeOverlapped->InternalLow; uint errorCode = Interop.Errors.ERROR_SUCCESS; - if (ntStatus != Interop.StatusOptions.STATUS_SUCCESS) + if (!Interop.StatusOptions.NT_SUCCESS(ntStatus)) { errorCode = Interop.NtDll.RtlNtStatusToDosError((int)ntStatus); }