]> git.lizzy.rs Git - rust.git/commitdiff
Windows: No panic if function not (yet) available
authorChris Denton <christophersdenton@gmail.com>
Tue, 7 Jun 2022 20:22:53 +0000 (21:22 +0100)
committerChris Denton <christophersdenton@gmail.com>
Tue, 7 Jun 2022 20:22:53 +0000 (21:22 +0100)
In some situations it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes.

library/std/src/sys/windows/c.rs

index 27776fdf533ee41f1ea60d07dcc11151ba1c90fe..5469487df1eed31d2d10b5d298e2024e06e00d18 100644 (file)
@@ -276,6 +276,7 @@ pub struct ipv6_mreq {
 
 pub const STATUS_PENDING: NTSTATUS = 0x103 as _;
 pub const STATUS_END_OF_FILE: NTSTATUS = 0xC0000011_u32 as _;
+pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _;
 
 // Equivalent to the `NT_SUCCESS` C preprocessor macro.
 // See: https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values
@@ -1264,7 +1265,7 @@ pub fn NtCreateFile(
         EaBuffer: *mut c_void,
         EaLength: ULONG
     ) -> NTSTATUS {
-        panic!("`NtCreateFile` not available");
+        STATUS_NOT_IMPLEMENTED
     }
     pub fn NtReadFile(
         FileHandle: BorrowedHandle<'_>,
@@ -1277,7 +1278,7 @@ pub fn NtReadFile(
         ByteOffset: Option<&LARGE_INTEGER>,
         Key: Option<&ULONG>
     ) -> NTSTATUS {
-        panic!("`NtReadFile` not available");
+        STATUS_NOT_IMPLEMENTED
     }
     pub fn NtWriteFile(
         FileHandle: BorrowedHandle<'_>,
@@ -1290,12 +1291,12 @@ pub fn NtWriteFile(
         ByteOffset: Option<&LARGE_INTEGER>,
         Key: Option<&ULONG>
     ) -> NTSTATUS {
-        panic!("`NtWriteFile` not available");
+        STATUS_NOT_IMPLEMENTED
     }
     pub fn RtlNtStatusToDosError(
         Status: NTSTATUS
     ) -> ULONG {
-        panic!("`RtlNtStatusToDosError` not available");
+        Status as ULONG
     }
     pub fn NtCreateKeyedEvent(
         KeyedEventHandle: LPHANDLE,