Forbid unsafe_op_in_unsafe_fn in sys/pal/windows
This commit is contained in:
parent
9b87fbc3e5
commit
7cd25b1b11
3 changed files with 14 additions and 10 deletions
|
@ -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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,9 +158,11 @@ 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 {
|
||||||
|
unsafe {
|
||||||
let func = load_from_module(Module::new($module));
|
let func = load_from_module(Module::new($module));
|
||||||
func($($argname),*)
|
func($($argname),*)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn load_from_module(module: Option<Module>) -> F {
|
fn load_from_module(module: Option<Module>) -> F {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -182,10 +184,12 @@ macro_rules! compat_fn_with_fallback {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn call($($argname: $argtype),*) -> $rettype {
|
pub unsafe fn call($($argname: $argtype),*) -> $rettype {
|
||||||
|
unsafe {
|
||||||
let func: F = mem::transmute(PTR.load(Ordering::Relaxed));
|
let func: F = mem::transmute(PTR.load(Ordering::Relaxed));
|
||||||
func($($argname),*)
|
func($($argname),*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
$(#[$meta])*
|
$(#[$meta])*
|
||||||
$vis use $symbol::call as $symbol;
|
$vis use $symbol::call as $symbol;
|
||||||
|
@ -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),*) }
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
)
|
)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue