Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid transmute where possible #3421

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/types/cpp_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,14 @@ impl CppMethod {
quote! { #name.param().abi(), }
}
ParamHint::Optional => {
quote! { core::mem::transmute(#name.unwrap_or(core::mem::zeroed())), }
quote! { #name.unwrap_or(core::mem::zeroed()) as _, }
}
ParamHint::Bool => {
quote! { #name.into(), }
}
ParamHint::ValueType => {
if flags.contains(ParamAttributes::Out) {
quote! { core::mem::transmute(#name), }
quote! { #name as _, }
} else {
quote! { #name, }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub unsafe fn VhfAsyncOperationComplete(vhfoperationhandle: *const core::ffi::c_
#[inline]
pub unsafe fn VhfCreate(vhfconfig: *const VHF_CONFIG, vhfhandle: *mut *mut core::ffi::c_void) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("vhfum.dll" "system" fn VhfCreate(vhfconfig : *const VHF_CONFIG, vhfhandle : *mut *mut core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { VhfCreate(vhfconfig, core::mem::transmute(vhfhandle)) }
unsafe { VhfCreate(vhfconfig, vhfhandle as _) }
}
#[inline]
pub unsafe fn VhfDelete(vhfhandle: *const core::ffi::c_void, wait: bool) {
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/windows/src/Windows/Wdk/Foundation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub unsafe fn NtClose(handle: super::super::Win32::Foundation::HANDLE) -> super:
#[inline]
pub unsafe fn NtQueryObject(handle: Option<super::super::Win32::Foundation::HANDLE>, objectinformationclass: OBJECT_INFORMATION_CLASS, objectinformation: Option<*mut core::ffi::c_void>, objectinformationlength: u32, returnlength: Option<*mut u32>) -> super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtQueryObject(handle : super::super::Win32::Foundation:: HANDLE, objectinformationclass : OBJECT_INFORMATION_CLASS, objectinformation : *mut core::ffi::c_void, objectinformationlength : u32, returnlength : *mut u32) -> super::super::Win32::Foundation:: NTSTATUS);
unsafe { NtQueryObject(core::mem::transmute(handle.unwrap_or(core::mem::zeroed())), objectinformationclass, core::mem::transmute(objectinformation.unwrap_or(core::mem::zeroed())), objectinformationlength, core::mem::transmute(returnlength.unwrap_or(core::mem::zeroed()))) }
unsafe { NtQueryObject(handle.unwrap_or(core::mem::zeroed()) as _, objectinformationclass, objectinformation.unwrap_or(core::mem::zeroed()) as _, objectinformationlength, returnlength.unwrap_or(core::mem::zeroed()) as _) }
}
#[repr(C)]
#[cfg(all(feature = "Wdk_System_SystemServices", feature = "Win32_Security"))]
Expand Down
182 changes: 91 additions & 91 deletions crates/libs/windows/src/Windows/Wdk/Graphics/Direct3D/mod.rs

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions crates/libs/windows/src/Windows/Wdk/NetworkManagement/Ndis/mod.rs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

416 changes: 174 additions & 242 deletions crates/libs/windows/src/Windows/Wdk/Storage/FileSystem/Minifilters/mod.rs

Large diffs are not rendered by default.

944 changes: 417 additions & 527 deletions crates/libs/windows/src/Windows/Wdk/Storage/FileSystem/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/libs/windows/src/Windows/Wdk/System/IO/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#[inline]
pub unsafe fn NtDeviceIoControlFile(filehandle: super::super::super::Win32::Foundation::HANDLE, event: Option<super::super::super::Win32::Foundation::HANDLE>, apcroutine: Option<super::super::super::Win32::System::IO::PIO_APC_ROUTINE>, apccontext: Option<*const core::ffi::c_void>, iostatusblock: *mut super::super::super::Win32::System::IO::IO_STATUS_BLOCK, iocontrolcode: u32, inputbuffer: Option<*const core::ffi::c_void>, inputbufferlength: u32, outputbuffer: Option<*mut core::ffi::c_void>, outputbufferlength: u32) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtDeviceIoControlFile(filehandle : super::super::super::Win32::Foundation:: HANDLE, event : super::super::super::Win32::Foundation:: HANDLE, apcroutine : super::super::super::Win32::System::IO:: PIO_APC_ROUTINE, apccontext : *const core::ffi::c_void, iostatusblock : *mut super::super::super::Win32::System::IO:: IO_STATUS_BLOCK, iocontrolcode : u32, inputbuffer : *const core::ffi::c_void, inputbufferlength : u32, outputbuffer : *mut core::ffi::c_void, outputbufferlength : u32) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { NtDeviceIoControlFile(filehandle, core::mem::transmute(event.unwrap_or(core::mem::zeroed())), core::mem::transmute(apcroutine.unwrap_or(core::mem::zeroed())), core::mem::transmute(apccontext.unwrap_or(core::mem::zeroed())), core::mem::transmute(iostatusblock), iocontrolcode, core::mem::transmute(inputbuffer.unwrap_or(core::mem::zeroed())), inputbufferlength, core::mem::transmute(outputbuffer.unwrap_or(core::mem::zeroed())), outputbufferlength) }
unsafe { NtDeviceIoControlFile(filehandle, event.unwrap_or(core::mem::zeroed()) as _, apcroutine.unwrap_or(core::mem::zeroed()) as _, apccontext.unwrap_or(core::mem::zeroed()) as _, iostatusblock as _, iocontrolcode, inputbuffer.unwrap_or(core::mem::zeroed()) as _, inputbufferlength, outputbuffer.unwrap_or(core::mem::zeroed()) as _, outputbufferlength) }
}
12 changes: 6 additions & 6 deletions crates/libs/windows/src/Windows/Wdk/System/Memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#[inline]
pub unsafe fn NtMapViewOfSection(sectionhandle: super::super::super::Win32::Foundation::HANDLE, processhandle: super::super::super::Win32::Foundation::HANDLE, baseaddress: *mut *mut core::ffi::c_void, zerobits: usize, commitsize: usize, sectionoffset: Option<*mut i64>, viewsize: *mut usize, inheritdisposition: SECTION_INHERIT, allocationtype: u32, win32protect: u32) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtMapViewOfSection(sectionhandle : super::super::super::Win32::Foundation:: HANDLE, processhandle : super::super::super::Win32::Foundation:: HANDLE, baseaddress : *mut *mut core::ffi::c_void, zerobits : usize, commitsize : usize, sectionoffset : *mut i64, viewsize : *mut usize, inheritdisposition : SECTION_INHERIT, allocationtype : u32, win32protect : u32) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { NtMapViewOfSection(sectionhandle, processhandle, core::mem::transmute(baseaddress), zerobits, commitsize, core::mem::transmute(sectionoffset.unwrap_or(core::mem::zeroed())), core::mem::transmute(viewsize), inheritdisposition, allocationtype, win32protect) }
unsafe { NtMapViewOfSection(sectionhandle, processhandle, baseaddress as _, zerobits, commitsize, sectionoffset.unwrap_or(core::mem::zeroed()) as _, viewsize as _, inheritdisposition, allocationtype, win32protect) }
}
#[cfg(all(feature = "Wdk_Foundation", feature = "Win32_Security"))]
#[inline]
pub unsafe fn NtOpenSection(sectionhandle: *mut super::super::super::Win32::Foundation::HANDLE, desiredaccess: u32, objectattributes: *const super::super::Foundation::OBJECT_ATTRIBUTES) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtOpenSection(sectionhandle : *mut super::super::super::Win32::Foundation:: HANDLE, desiredaccess : u32, objectattributes : *const super::super::Foundation:: OBJECT_ATTRIBUTES) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { NtOpenSection(core::mem::transmute(sectionhandle), desiredaccess, objectattributes) }
unsafe { NtOpenSection(sectionhandle as _, desiredaccess, objectattributes) }
}
#[inline]
pub unsafe fn NtUnmapViewOfSection(processhandle: super::super::super::Win32::Foundation::HANDLE, baseaddress: Option<*const core::ffi::c_void>) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn NtUnmapViewOfSection(processhandle : super::super::super::Win32::Foundation:: HANDLE, baseaddress : *const core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { NtUnmapViewOfSection(processhandle, core::mem::transmute(baseaddress.unwrap_or(core::mem::zeroed()))) }
unsafe { NtUnmapViewOfSection(processhandle, baseaddress.unwrap_or(core::mem::zeroed()) as _) }
}
#[inline]
pub unsafe fn ZwMapViewOfSection(sectionhandle: super::super::super::Win32::Foundation::HANDLE, processhandle: super::super::super::Win32::Foundation::HANDLE, baseaddress: *mut *mut core::ffi::c_void, zerobits: usize, commitsize: usize, sectionoffset: Option<*mut i64>, viewsize: *mut usize, inheritdisposition: SECTION_INHERIT, allocationtype: u32, win32protect: u32) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn ZwMapViewOfSection(sectionhandle : super::super::super::Win32::Foundation:: HANDLE, processhandle : super::super::super::Win32::Foundation:: HANDLE, baseaddress : *mut *mut core::ffi::c_void, zerobits : usize, commitsize : usize, sectionoffset : *mut i64, viewsize : *mut usize, inheritdisposition : SECTION_INHERIT, allocationtype : u32, win32protect : u32) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { ZwMapViewOfSection(sectionhandle, processhandle, core::mem::transmute(baseaddress), zerobits, commitsize, core::mem::transmute(sectionoffset.unwrap_or(core::mem::zeroed())), core::mem::transmute(viewsize), inheritdisposition, allocationtype, win32protect) }
unsafe { ZwMapViewOfSection(sectionhandle, processhandle, baseaddress as _, zerobits, commitsize, sectionoffset.unwrap_or(core::mem::zeroed()) as _, viewsize as _, inheritdisposition, allocationtype, win32protect) }
}
#[cfg(all(feature = "Wdk_Foundation", feature = "Win32_Security"))]
#[inline]
pub unsafe fn ZwOpenSection(sectionhandle: *mut super::super::super::Win32::Foundation::HANDLE, desiredaccess: u32, objectattributes: *const super::super::Foundation::OBJECT_ATTRIBUTES) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn ZwOpenSection(sectionhandle : *mut super::super::super::Win32::Foundation:: HANDLE, desiredaccess : u32, objectattributes : *const super::super::Foundation:: OBJECT_ATTRIBUTES) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { ZwOpenSection(core::mem::transmute(sectionhandle), desiredaccess, objectattributes) }
unsafe { ZwOpenSection(sectionhandle as _, desiredaccess, objectattributes) }
}
#[inline]
pub unsafe fn ZwUnmapViewOfSection(processhandle: super::super::super::Win32::Foundation::HANDLE, baseaddress: Option<*const core::ffi::c_void>) -> super::super::super::Win32::Foundation::NTSTATUS {
windows_targets::link!("ntdll.dll" "system" fn ZwUnmapViewOfSection(processhandle : super::super::super::Win32::Foundation:: HANDLE, baseaddress : *const core::ffi::c_void) -> super::super::super::Win32::Foundation:: NTSTATUS);
unsafe { ZwUnmapViewOfSection(processhandle, core::mem::transmute(baseaddress.unwrap_or(core::mem::zeroed()))) }
unsafe { ZwUnmapViewOfSection(processhandle, baseaddress.unwrap_or(core::mem::zeroed()) as _) }
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
Expand Down
Loading
Loading