-
Notifications
You must be signed in to change notification settings - Fork 737
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IO_STATUS_BLOCK/AFD_POLL_INFO reference counting
- Loading branch information
1 parent
cc1fd15
commit 1522d5f
Showing
6 changed files
with
75 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
use ntapi::ntioapi::{IO_STATUS_BLOCK_u, IO_STATUS_BLOCK}; | ||
use std::cell::UnsafeCell; | ||
use std::fmt; | ||
use ntapi::ntioapi::IO_STATUS_BLOCK; | ||
use std::fmt::{self, Debug, Formatter}; | ||
use std::mem::MaybeUninit; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
pub struct IoStatusBlock(UnsafeCell<IO_STATUS_BLOCK>); | ||
|
||
// There is a pointer field in `IO_STATUS_BLOCK_u`, which we don't use that. Thus it is safe to implement Send here. | ||
unsafe impl Send for IoStatusBlock {} | ||
pub struct IoStatusBlock(IO_STATUS_BLOCK); | ||
|
||
impl IoStatusBlock { | ||
pub fn zeroed() -> IoStatusBlock { | ||
let iosb = IO_STATUS_BLOCK { | ||
u: IO_STATUS_BLOCK_u { Status: 0 }, | ||
Information: 0, | ||
}; | ||
IoStatusBlock(UnsafeCell::new(iosb)) | ||
pub fn zeroed() -> Self { | ||
Self(unsafe { MaybeUninit::<IO_STATUS_BLOCK>::zeroed().assume_init() }) | ||
} | ||
} | ||
|
||
unsafe impl Send for IoStatusBlock {} | ||
|
||
pub fn as_ptr(&self) -> *const IO_STATUS_BLOCK { | ||
self.0.get() | ||
impl Debug for IoStatusBlock { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("IoStatusBlock").finish() | ||
} | ||
} | ||
|
||
pub fn as_mut_ptr(&self) -> *mut IO_STATUS_BLOCK { | ||
self.0.get() | ||
impl Deref for IoStatusBlock { | ||
type Target = IO_STATUS_BLOCK; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl fmt::Debug for IoStatusBlock { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("IoStatusBlock").finish() | ||
impl DerefMut for IoStatusBlock { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.