diff options
| author | Fuwn <[email protected]> | 2022-01-03 14:27:39 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-03 14:27:39 -0800 |
| commit | 057a8eeb023ce07e971e9ed98111a269df8049bb (patch) | |
| tree | 50ee379be6d695ae7a788b3df8101f0f1a1207c2 /crates | |
| parent | fix(windows-kernel-rs): traits (diff) | |
| download | driver-057a8eeb023ce07e971e9ed98111a269df8049bb.tar.xz driver-057a8eeb023ce07e971e9ed98111a269df8049bb.zip | |
fix(windows-kernel-rs): impl Into to impl From
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/windows-kernel-rs/src/device.rs | 70 | ||||
| -rw-r--r-- | crates/windows-kernel-rs/src/ioctl.rs | 46 | ||||
| -rw-r--r-- | crates/windows-kernel-rs/src/memory.rs | 48 | ||||
| -rw-r--r-- | crates/windows-kernel-rs/src/request.rs | 29 | ||||
| -rw-r--r-- | crates/windows-kernel-rs/src/sync/push_lock.rs | 2 |
5 files changed, 163 insertions, 32 deletions
diff --git a/crates/windows-kernel-rs/src/device.rs b/crates/windows-kernel-rs/src/device.rs index 5c36d3a..1600722 100644 --- a/crates/windows-kernel-rs/src/device.rs +++ b/crates/windows-kernel-rs/src/device.rs @@ -113,9 +113,73 @@ pub enum DeviceType { WaveOut, } -impl Into<u32> for DeviceType { - fn into(self) -> u32 { - match self { +// impl Into<u32> for DeviceType { +// fn into(self) -> u32 { +// match self { +// DeviceType::Port8042 => windows_kernel_sys::base::FILE_DEVICE_8042_PORT, +// DeviceType::Acpi => windows_kernel_sys::base::FILE_DEVICE_ACPI, +// DeviceType::Battery => windows_kernel_sys::base::FILE_DEVICE_BATTERY, +// DeviceType::Beep => windows_kernel_sys::base::FILE_DEVICE_BEEP, +// DeviceType::BusExtender => windows_kernel_sys::base::FILE_DEVICE_BUS_EXTENDER, +// DeviceType::Cdrom => windows_kernel_sys::base::FILE_DEVICE_CD_ROM, +// DeviceType::CdromFileSystem => windows_kernel_sys::base::FILE_DEVICE_CD_ROM_FILE_SYSTEM, +// DeviceType::Changer => windows_kernel_sys::base::FILE_DEVICE_CHANGER, +// DeviceType::Controller => windows_kernel_sys::base::FILE_DEVICE_CONTROLLER, +// DeviceType::DataLink => windows_kernel_sys::base::FILE_DEVICE_DATALINK, +// DeviceType::Dfs => windows_kernel_sys::base::FILE_DEVICE_DFS, +// DeviceType::DfsFileSystem => windows_kernel_sys::base::FILE_DEVICE_DFS_FILE_SYSTEM, +// DeviceType::DfsVolume => windows_kernel_sys::base::FILE_DEVICE_DFS_VOLUME, +// DeviceType::Disk => windows_kernel_sys::base::FILE_DEVICE_DISK, +// DeviceType::DiskFileSystem => windows_kernel_sys::base::FILE_DEVICE_DISK_FILE_SYSTEM, +// DeviceType::Dvd => windows_kernel_sys::base::FILE_DEVICE_DVD, +// DeviceType::FileSystem => windows_kernel_sys::base::FILE_DEVICE_FILE_SYSTEM, +// DeviceType::Fips => windows_kernel_sys::base::FILE_DEVICE_FIPS, +// DeviceType::FullscreenVideo => windows_kernel_sys::base::FILE_DEVICE_FULLSCREEN_VIDEO, +// DeviceType::InportPort => windows_kernel_sys::base::FILE_DEVICE_INPORT_PORT, +// DeviceType::Keyboard => windows_kernel_sys::base::FILE_DEVICE_KEYBOARD, +// DeviceType::Ks => windows_kernel_sys::base::FILE_DEVICE_KS, +// DeviceType::Ksec => windows_kernel_sys::base::FILE_DEVICE_KSEC, +// DeviceType::Mailslot => windows_kernel_sys::base::FILE_DEVICE_MAILSLOT, +// DeviceType::MassStorage => windows_kernel_sys::base::FILE_DEVICE_MASS_STORAGE, +// DeviceType::MidiIn => windows_kernel_sys::base::FILE_DEVICE_MIDI_IN, +// DeviceType::MidiOut => windows_kernel_sys::base::FILE_DEVICE_MIDI_OUT, +// DeviceType::Modem => windows_kernel_sys::base::FILE_DEVICE_MODEM, +// DeviceType::Mouse => windows_kernel_sys::base::FILE_DEVICE_MOUSE, +// DeviceType::MultiUncProvider => windows_kernel_sys::base::FILE_DEVICE_MULTI_UNC_PROVIDER, +// DeviceType::NamedPipe => windows_kernel_sys::base::FILE_DEVICE_NAMED_PIPE, +// DeviceType::Network => windows_kernel_sys::base::FILE_DEVICE_NETWORK, +// DeviceType::NetworkBrowser => windows_kernel_sys::base::FILE_DEVICE_NETWORK_BROWSER, +// DeviceType::NetworkFileSystem => windows_kernel_sys::base::FILE_DEVICE_NETWORK_FILE_SYSTEM, +// DeviceType::NetworkRedirector => windows_kernel_sys::base::FILE_DEVICE_NETWORK_REDIRECTOR, +// DeviceType::Null => windows_kernel_sys::base::FILE_DEVICE_NULL, +// DeviceType::ParallelPort => windows_kernel_sys::base::FILE_DEVICE_PARALLEL_PORT, +// DeviceType::PhysicalNetcard => windows_kernel_sys::base::FILE_DEVICE_PHYSICAL_NETCARD, +// DeviceType::Printer => windows_kernel_sys::base::FILE_DEVICE_PRINTER, +// DeviceType::Scanner => windows_kernel_sys::base::FILE_DEVICE_SCANNER, +// DeviceType::Screen => windows_kernel_sys::base::FILE_DEVICE_SCREEN, +// DeviceType::Serenum => windows_kernel_sys::base::FILE_DEVICE_SERENUM, +// DeviceType::SerialMousePort => windows_kernel_sys::base::FILE_DEVICE_SERIAL_MOUSE_PORT, +// DeviceType::SerialPort => windows_kernel_sys::base::FILE_DEVICE_SERIAL_PORT, +// DeviceType::Smartcard => windows_kernel_sys::base::FILE_DEVICE_SMARTCARD, +// DeviceType::Smb => windows_kernel_sys::base::FILE_DEVICE_SMB, +// DeviceType::Sound => windows_kernel_sys::base::FILE_DEVICE_SOUND, +// DeviceType::Streams => windows_kernel_sys::base::FILE_DEVICE_STREAMS, +// DeviceType::Tape => windows_kernel_sys::base::FILE_DEVICE_TAPE, +// DeviceType::TapeFileSystem => windows_kernel_sys::base::FILE_DEVICE_TAPE_FILE_SYSTEM, +// DeviceType::Termsrv => windows_kernel_sys::base::FILE_DEVICE_TERMSRV, +// DeviceType::Transport => windows_kernel_sys::base::FILE_DEVICE_TRANSPORT, +// DeviceType::Unknown => windows_kernel_sys::base::FILE_DEVICE_UNKNOWN, +// DeviceType::Vdm => windows_kernel_sys::base::FILE_DEVICE_VDM, +// DeviceType::Video => windows_kernel_sys::base::FILE_DEVICE_VIDEO, +// DeviceType::VirtualDisk => windows_kernel_sys::base::FILE_DEVICE_VIRTUAL_DISK, +// DeviceType::WaveIn => windows_kernel_sys::base::FILE_DEVICE_WAVE_IN, +// DeviceType::WaveOut => windows_kernel_sys::base::FILE_DEVICE_WAVE_OUT, +// } +// } +// } +impl From<DeviceType> for u32 { + fn from(d: DeviceType) -> Self { + match d { DeviceType::Port8042 => windows_kernel_sys::base::FILE_DEVICE_8042_PORT, DeviceType::Acpi => windows_kernel_sys::base::FILE_DEVICE_ACPI, DeviceType::Battery => windows_kernel_sys::base::FILE_DEVICE_BATTERY, diff --git a/crates/windows-kernel-rs/src/ioctl.rs b/crates/windows-kernel-rs/src/ioctl.rs index c1d493f..9f1d2e7 100644 --- a/crates/windows-kernel-rs/src/ioctl.rs +++ b/crates/windows-kernel-rs/src/ioctl.rs @@ -41,13 +41,23 @@ impl From<u32> for TransferMethod { } } -impl Into<u32> for TransferMethod { - fn into(self) -> u32 { - match self { - Self::Neither => METHOD_NEITHER, - Self::InputDirect => METHOD_IN_DIRECT, - Self::OutputDirect => METHOD_OUT_DIRECT, - Self::Buffered => METHOD_BUFFERED, +// impl Into<u32> for TransferMethod { +// fn into(self) -> u32 { +// match self { +// Self::Neither => METHOD_NEITHER, +// Self::InputDirect => METHOD_IN_DIRECT, +// Self::OutputDirect => METHOD_OUT_DIRECT, +// Self::Buffered => METHOD_BUFFERED, +// } +// } +// } +impl From<TransferMethod> for u32 { + fn from(t: TransferMethod) -> Self { + match t { + TransferMethod::Neither => METHOD_NEITHER, + TransferMethod::InputDirect => METHOD_IN_DIRECT, + TransferMethod::OutputDirect => METHOD_OUT_DIRECT, + TransferMethod::Buffered => METHOD_BUFFERED, } } } @@ -99,12 +109,22 @@ impl From<u32> for ControlCode { } } -impl Into<u32> for ControlCode { - fn into(self) -> u32 { - let method = Into::<u32>::into(self.3) << Self::METHOD_SHIFT; - let num = self.2 << Self::NUM_SHIFT; - let access = self.1.bits() << Self::ACCESS_SHIFT; - let ty = Into::<u32>::into(self.0) << Self::TYPE_SHIFT; +// impl Into<u32> for ControlCode { +// fn into(self) -> u32 { +// let method = Into::<u32>::into(self.3) << Self::METHOD_SHIFT; +// let num = self.2 << Self::NUM_SHIFT; +// let access = self.1.bits() << Self::ACCESS_SHIFT; +// let ty = Into::<u32>::into(self.0) << Self::TYPE_SHIFT; +// +// ty | access | num | method +// } +// } +impl From<ControlCode> for u32 { + fn from(c: ControlCode) -> Self { + let method = Into::<u32>::into(c.3) << ControlCode::METHOD_SHIFT; + let num = c.2 << ControlCode::NUM_SHIFT; + let access = c.1.bits() << ControlCode::ACCESS_SHIFT; + let ty = Into::<u32>::into(c.0) << ControlCode::TYPE_SHIFT; ty | access | num | method } diff --git a/crates/windows-kernel-rs/src/memory.rs b/crates/windows-kernel-rs/src/memory.rs index cb5d2e9..d2ad77b 100644 --- a/crates/windows-kernel-rs/src/memory.rs +++ b/crates/windows-kernel-rs/src/memory.rs @@ -30,19 +30,33 @@ impl From<u64> for PhysicalAddress { fn from(value: u64) -> Self { Self(value) } } -impl Into<u64> for PhysicalAddress { - fn into(self) -> u64 { self.0 } +// impl Into<u64> for PhysicalAddress { +// fn into(self) -> u64 { self.0 } +// } +impl From<PhysicalAddress> for u64 { + fn from(p: PhysicalAddress) -> Self { + p.0 + } } impl From<PHYSICAL_ADDRESS> for PhysicalAddress { fn from(value: PHYSICAL_ADDRESS) -> Self { Self(unsafe { value.QuadPart } as _) } } -impl Into<PHYSICAL_ADDRESS> for PhysicalAddress { - fn into(self) -> PHYSICAL_ADDRESS { +// impl Into<PHYSICAL_ADDRESS> for PhysicalAddress { +// fn into(self) -> PHYSICAL_ADDRESS { +// let mut addr: PHYSICAL_ADDRESS = unsafe { core::mem::zeroed() }; +// +// addr.QuadPart = self.0 as _; +// +// addr +// } +// } +impl From<PhysicalAddress> for PHYSICAL_ADDRESS { + fn from(p: PhysicalAddress) -> Self { let mut addr: PHYSICAL_ADDRESS = unsafe { core::mem::zeroed() }; - addr.QuadPart = self.0 as _; + addr.QuadPart = p.0 as _; addr } @@ -57,11 +71,29 @@ pub enum CopyAddress { unsafe impl Send for CopyAddress {} unsafe impl Sync for CopyAddress {} -impl Into<(u32, MM_COPY_ADDRESS)> for CopyAddress { - fn into(self) -> (u32, MM_COPY_ADDRESS) { +// impl Into<(u32, MM_COPY_ADDRESS)> for CopyAddress { +// fn into(self) -> (u32, MM_COPY_ADDRESS) { +// let mut copy_addr: MM_COPY_ADDRESS = unsafe { core::mem::zeroed() }; +// +// let flags = match self { +// CopyAddress::Virtual(addr) => { +// copy_addr.__bindgen_anon_1.VirtualAddress = addr as _; +// MM_COPY_MEMORY_VIRTUAL +// } +// CopyAddress::Physical(addr) => { +// copy_addr.__bindgen_anon_1.PhysicalAddress = addr.into(); +// MM_COPY_MEMORY_PHYSICAL +// } +// }; +// +// (flags, copy_addr) +// } +// } +impl From<CopyAddress> for (u32, MM_COPY_ADDRESS) { + fn from(c: CopyAddress) -> Self { let mut copy_addr: MM_COPY_ADDRESS = unsafe { core::mem::zeroed() }; - let flags = match self { + let flags = match c { CopyAddress::Virtual(addr) => { copy_addr.__bindgen_anon_1.VirtualAddress = addr as _; MM_COPY_MEMORY_VIRTUAL diff --git a/crates/windows-kernel-rs/src/request.rs b/crates/windows-kernel-rs/src/request.rs index 7717071..af77fd7 100644 --- a/crates/windows-kernel-rs/src/request.rs +++ b/crates/windows-kernel-rs/src/request.rs @@ -64,7 +64,7 @@ impl IoRequest { pub fn irp_mut(&self) -> &mut IRP { unsafe { &mut *self.irp } } pub fn flags(&self) -> IrpFlags { - IrpFlags::from_bits(self.irp().Flags).unwrap_or(IrpFlags::empty()) + IrpFlags::from_bits(self.irp().Flags).unwrap_or_else(IrpFlags::empty) } pub fn stack_location(&self) -> &IO_STACK_LOCATION { @@ -142,8 +142,13 @@ impl ReadRequest { } } -impl Into<IoRequest> for ReadRequest { - fn into(self) -> IoRequest { self.inner } +// impl Into<IoRequest> for ReadRequest { +// fn into(self) -> IoRequest { self.inner } +// } +impl From<ReadRequest> for IoRequest { + fn from(r: ReadRequest) -> Self { + r.inner + } } pub struct WriteRequest { @@ -195,8 +200,13 @@ impl WriteRequest { } } -impl Into<IoRequest> for WriteRequest { - fn into(self) -> IoRequest { self.inner } +// impl Into<IoRequest> for WriteRequest { +// fn into(self) -> IoRequest { self.inner } +// } +impl From<WriteRequest> for IoRequest { + fn from(w: WriteRequest) -> Self { + w.inner + } } pub struct IoControlRequest { @@ -262,6 +272,11 @@ impl IoControlRequest { } } -impl Into<IoRequest> for IoControlRequest { - fn into(self) -> IoRequest { self.inner } +// impl Into<IoRequest> for IoControlRequest { +// fn into(self) -> IoRequest { self.inner } +// } +impl From<IoControlRequest> for IoRequest { + fn from(i: IoControlRequest) -> Self { + i.inner + } } diff --git a/crates/windows-kernel-rs/src/sync/push_lock.rs b/crates/windows-kernel-rs/src/sync/push_lock.rs index 71b016a..3579b87 100644 --- a/crates/windows-kernel-rs/src/sync/push_lock.rs +++ b/crates/windows-kernel-rs/src/sync/push_lock.rs @@ -46,7 +46,7 @@ pub struct PushLock<T: ?Sized> { pub(crate) data: UnsafeCell<T>, } -unsafe impl<T> Send for PushLock<T> {} +unsafe impl<T> Send for PushLock<T> where T: Send {} unsafe impl<T> Sync for PushLock<T> {} impl<T> PushLock<T> { |