Skip to content

Commit 34fafd3

Browse files
committed
Windows: No panic if function not (yet) available
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.
1 parent 7fe2c4b commit 34fafd3

File tree

1 file changed

+5
-4
lines changed
  • library/std/src/sys/windows

1 file changed

+5
-4
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ pub const STATUS_INVALID_PARAMETER: NTSTATUS = 0xc000000d_u32 as _;
276276

277277
pub const STATUS_PENDING: NTSTATUS = 0x103 as _;
278278
pub const STATUS_END_OF_FILE: NTSTATUS = 0xC0000011_u32 as _;
279+
pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _;
279280

280281
// Equivalent to the `NT_SUCCESS` C preprocessor macro.
281282
// See: https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values
@@ -1264,7 +1265,7 @@ compat_fn! {
12641265
EaBuffer: *mut c_void,
12651266
EaLength: ULONG
12661267
) -> NTSTATUS {
1267-
panic!("`NtCreateFile` not available");
1268+
STATUS_NOT_IMPLEMENTED
12681269
}
12691270
pub fn NtReadFile(
12701271
FileHandle: BorrowedHandle<'_>,
@@ -1277,7 +1278,7 @@ compat_fn! {
12771278
ByteOffset: Option<&LARGE_INTEGER>,
12781279
Key: Option<&ULONG>
12791280
) -> NTSTATUS {
1280-
panic!("`NtReadFile` not available");
1281+
STATUS_NOT_IMPLEMENTED
12811282
}
12821283
pub fn NtWriteFile(
12831284
FileHandle: BorrowedHandle<'_>,
@@ -1290,12 +1291,12 @@ compat_fn! {
12901291
ByteOffset: Option<&LARGE_INTEGER>,
12911292
Key: Option<&ULONG>
12921293
) -> NTSTATUS {
1293-
panic!("`NtWriteFile` not available");
1294+
STATUS_NOT_IMPLEMENTED
12941295
}
12951296
pub fn RtlNtStatusToDosError(
12961297
Status: NTSTATUS
12971298
) -> ULONG {
1298-
panic!("`RtlNtStatusToDosError` not available");
1299+
Status as ULONG
12991300
}
13001301
pub fn NtCreateKeyedEvent(
13011302
KeyedEventHandle: LPHANDLE,

0 commit comments

Comments
 (0)