This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
library/std/src/sys/windows Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -325,7 +325,9 @@ union IO_STATUS_BLOCK_union {
325
325
}
326
326
impl Default for IO_STATUS_BLOCK_union {
327
327
fn default ( ) -> Self {
328
- Self { Pointer : ptr:: null_mut ( ) }
328
+ let mut this = Self { Pointer : ptr:: null_mut ( ) } ;
329
+ this. Status = STATUS_PENDING ;
330
+ this
329
331
}
330
332
}
331
333
#[ repr( C ) ]
@@ -334,6 +336,16 @@ pub struct IO_STATUS_BLOCK {
334
336
u : IO_STATUS_BLOCK_union ,
335
337
pub Information : usize ,
336
338
}
339
+ impl IO_STATUS_BLOCK {
340
+ pub fn status ( & self ) -> NTSTATUS {
341
+ // SAFETY: If `self.u.Status` was set then this is obviously safe.
342
+ // If `self.u.Pointer` was set then this is the equivalent to converting
343
+ // the pointer to an integer, which is also safe.
344
+ // Currently the only safe way to construct `IO_STATUS_BLOCK` outside of
345
+ // this module is to call the `default` method, which sets the `Status`.
346
+ unsafe { self . u . Status }
347
+ }
348
+ }
337
349
338
350
pub type LPOVERLAPPED_COMPLETION_ROUTINE = unsafe extern "system" fn (
339
351
dwErrorCode : DWORD ,
Original file line number Diff line number Diff line change @@ -248,6 +248,13 @@ impl Handle {
248
248
offset. map ( |n| n as _ ) . as_ref ( ) ,
249
249
None ,
250
250
) ;
251
+
252
+ let status = if status == c:: STATUS_PENDING {
253
+ c:: WaitForSingleObject ( self . as_raw_handle ( ) , c:: INFINITE ) ;
254
+ io_status. status ( )
255
+ } else {
256
+ status
257
+ } ;
251
258
match status {
252
259
// If the operation has not completed then abort the process.
253
260
// Doing otherwise means that the buffer and stack may be written to
@@ -291,6 +298,12 @@ impl Handle {
291
298
None ,
292
299
)
293
300
} ;
301
+ let status = if status == c:: STATUS_PENDING {
302
+ unsafe { c:: WaitForSingleObject ( self . as_raw_handle ( ) , c:: INFINITE ) } ;
303
+ io_status. status ( )
304
+ } else {
305
+ status
306
+ } ;
294
307
match status {
295
308
// If the operation has not completed then abort the process.
296
309
// Doing otherwise means that the buffer may be read and the stack
You can’t perform that action at this time.
0 commit comments