mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Forbid unsafe_op_in_unsafe_fn in sys/pal/windows
This commit is contained in:
parent
9b87fbc3e5
commit
7cd25b1b11
@ -134,26 +134,26 @@ compat_fn_with_fallback! {
|
||||
// >= Win10 1607
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
|
||||
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
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription
|
||||
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
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsystemtimepreciseasfiletime
|
||||
#[cfg(target_vendor = "win7")]
|
||||
pub fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime: *mut FILETIME) -> () {
|
||||
GetSystemTimeAsFileTime(lpsystemtimeasfiletime)
|
||||
unsafe { GetSystemTimeAsFileTime(lpsystemtimeasfiletime) }
|
||||
}
|
||||
|
||||
// >= Win11 / Server 2022
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
|
||||
pub fn GetTempPath2W(bufferlength: u32, buffer: PWSTR) -> u32 {
|
||||
GetTempPathW(bufferlength, buffer)
|
||||
unsafe { GetTempPathW(bufferlength, buffer) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,8 +158,10 @@ macro_rules! compat_fn_with_fallback {
|
||||
static PTR: AtomicPtr<c_void> = AtomicPtr::new(load as *mut _);
|
||||
|
||||
unsafe extern "system" fn load($($argname: $argtype),*) -> $rettype {
|
||||
let func = load_from_module(Module::new($module));
|
||||
func($($argname),*)
|
||||
unsafe {
|
||||
let func = load_from_module(Module::new($module));
|
||||
func($($argname),*)
|
||||
}
|
||||
}
|
||||
|
||||
fn load_from_module(module: Option<Module>) -> F {
|
||||
@ -182,8 +184,10 @@ macro_rules! compat_fn_with_fallback {
|
||||
|
||||
#[inline(always)]
|
||||
pub unsafe fn call($($argname: $argtype),*) -> $rettype {
|
||||
let func: F = mem::transmute(PTR.load(Ordering::Relaxed));
|
||||
func($($argname),*)
|
||||
unsafe {
|
||||
let func: F = mem::transmute(PTR.load(Ordering::Relaxed));
|
||||
func($($argname),*)
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(unused)]
|
||||
@ -225,7 +229,7 @@ macro_rules! compat_fn_optional {
|
||||
}
|
||||
#[inline]
|
||||
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)]
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use crate::ffi::{OsStr, OsString};
|
||||
use crate::io::ErrorKind;
|
||||
|
Loading…
Reference in New Issue
Block a user