1
Fork 0

Forbid unsafe_op_in_unsafe_fn in sys/pal/windows

This commit is contained in:
Chris Denton 2024-07-24 08:28:47 +00:00
parent 9b87fbc3e5
commit 7cd25b1b11
No known key found for this signature in database
GPG key ID: 713472F2F45627DE
3 changed files with 14 additions and 10 deletions

View file

@ -134,26 +134,26 @@ compat_fn_with_fallback! {
// >= Win10 1607 // >= Win10 1607
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
pub fn SetThreadDescription(hthread: HANDLE, lpthreaddescription: PCWSTR) -> HRESULT { pub fn SetThreadDescription(hthread: HANDLE, lpthreaddescription: PCWSTR) -> HRESULT {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL }
} }
// >= Win10 1607 // >= Win10 1607
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription
pub fn GetThreadDescription(hthread: HANDLE, lpthreaddescription: *mut PWSTR) -> HRESULT { pub fn GetThreadDescription(hthread: HANDLE, lpthreaddescription: *mut PWSTR) -> HRESULT {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL }
} }
// >= Win8 / Server 2012 // >= Win8 / Server 2012
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime // https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime
#[cfg(target_vendor = "win7")] #[cfg(target_vendor = "win7")]
pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> () { pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> () {
GetSystemTimeAsFileTime(lpsystemtimeasfiletime) unsafe { GetSystemTimeAsFileTime(lpsystemtimeasfiletime) }
} }
// >= Win11 / Server 2022 // >= Win11 / Server 2022
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 { pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 {
GetTempPathW(bufferlength, buffer) unsafe { GetTempPathW(bufferlength, buffer) }
} }
} }

View file

@ -158,8 +158,10 @@ macro_rules! compat_fn_with_fallback {
static PTR: AtomicPtr<c_void> = AtomicPtr::new(load as *mut _); static PTR: AtomicPtr<c_void> = AtomicPtr::new(load as *mut _);
unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype { unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype {
let func = load_from_module(Module::new($module)); unsafe {
func($($argname),*) let func = load_from_module(Module::new($module));
func($($argname),*)
}
} }
fn load_from_module(module: Option<Module>) -> F { fn load_from_module(module: Option<Module>) -> F {
@ -182,8 +184,10 @@ macro_rules! compat_fn_with_fallback {
#[inline(always)] #[inline(always)]
pub unsafe fn call($($argname: $argtype),*) -> $rettype { pub unsafe fn call($($argname: $argtype),*) -> $rettype {
let func: F = mem::transmute(PTR.load(Ordering::Relaxed)); unsafe {
func($($argname),*) let func: F = mem::transmute(PTR.load(Ordering::Relaxed));
func($($argname),*)
}
} }
} }
#[allow(unused)] #[allow(unused)]
@ -225,7 +229,7 @@ macro_rules! compat_fn_optional {
} }
#[inline] #[inline]
pub unsafe extern "system" fn $symbol($($argname: $argtype),*) $(-> $rettype)? { pub unsafe extern "system" fn $symbol($($argname: $argtype),*) $(-> $rettype)? {
$symbol::option().unwrap()($($argname),*) unsafe { $symbol::option().unwrap()($($argname),*) }
} }
)+ )+
) )

View file

@ -1,5 +1,5 @@
#![allow(missing_docs, nonstandard_style)] #![allow(missing_docs, nonstandard_style)]
#![deny(unsafe_op_in_unsafe_fn)] #![forbid(unsafe_op_in_unsafe_fn)]
use crate::ffi::{OsStr, OsString}; use crate::ffi::{OsStr, OsString};
use crate::io::ErrorKind; use crate::io::ErrorKind;