Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d96ed86

Browse files
committedJul 15, 2024
Make pal/windows default to deny unsafe in unsafe
1 parent d7aa7cf commit d96ed86

File tree

12 files changed

+26
-11
lines changed

12 files changed

+26
-11
lines changed
 

‎std/src/sys/pal/windows/api.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ pub fn set_file_information_by_handle<T: SetFileInformation>(
227227
info: *const c_void,
228228
size: u32,
229229
) -> Result<(), WinError> {
230-
let result = c::SetFileInformationByHandle(handle, class, info, size);
231-
(result != 0).then_some(()).ok_or_else(get_last_error)
230+
unsafe {
231+
let result = c::SetFileInformationByHandle(handle, class, info, size);
232+
(result != 0).then_some(()).ok_or_else(get_last_error)
233+
}
232234
}
233235
// SAFETY: The `SetFileInformation` trait ensures that this is safe.
234236
unsafe { set_info(handle, T::CLASS, info.as_ptr(), info.size()) }

‎std/src/sys/pal/windows/c.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![cfg_attr(test, allow(dead_code))]
55
#![unstable(issue = "none", feature = "windows_c")]
66
#![allow(clippy::style)]
7+
#![allow(unsafe_op_in_unsafe_fn)]
78

89
use crate::ffi::CStr;
910
use crate::mem;

‎std/src/sys/pal/windows/compat.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ impl Module {
111111
/// This should only be use for modules that exist for the lifetime of std
112112
/// (e.g. kernel32 and ntdll).
113113
pub unsafe fn new(name: &CStr) -> Option<Self> {
114-
// SAFETY: A CStr is always null terminated.
115-
let module = c::GetModuleHandleA(name.as_ptr().cast::<u8>());
116-
NonNull::new(module).map(Self)
114+
unsafe {
115+
// SAFETY: A CStr is always null terminated.
116+
let module = c::GetModuleHandleA(name.as_ptr().cast::<u8>());
117+
NonNull::new(module).map(Self)
118+
}
117119
}
118120

119121
// Try to get the address of a function.

‎std/src/sys/pal/windows/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unsafe_op_in_unsafe_fn)]
12
use core::ptr::addr_of;
23

34
use crate::os::windows::prelude::*;

‎std/src/sys/pal/windows/handle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![unstable(issue = "none", feature = "windows_handle")]
2+
#![allow(unsafe_op_in_unsafe_fn)]
23

34
#[cfg(test)]
45
mod tests;

‎std/src/sys/pal/windows/io.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unsafe_op_in_unsafe_fn)]
12
use crate::marker::PhantomData;
23
use crate::mem::size_of;
34
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};

‎std/src/sys/pal/windows/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(missing_docs, nonstandard_style)]
2+
#![deny(unsafe_op_in_unsafe_fn)]
23

34
use crate::ffi::{OsStr, OsString};
45
use crate::io::ErrorKind;
@@ -54,11 +55,13 @@ impl<T> IoResult<T> for Result<T, api::WinError> {
5455
// SAFETY: must be called only once during runtime initialization.
5556
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
5657
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {
57-
stack_overflow::init();
58+
unsafe {
59+
stack_overflow::init();
5860

59-
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
60-
// exists, we have to call it ourselves.
61-
thread::Thread::set_name_wide(wide_str!("main"));
61+
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
62+
// exists, we have to call it ourselves.
63+
thread::Thread::set_name_wide(wide_str!("main"));
64+
}
6265
}
6366

6467
// SAFETY: must be called only once during runtime cleanup.

‎std/src/sys/pal/windows/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl Socket {
436436
pub unsafe fn from_raw(raw: c::SOCKET) -> Self {
437437
debug_assert_eq!(mem::size_of::<c::SOCKET>(), mem::size_of::<RawSocket>());
438438
debug_assert_eq!(mem::align_of::<c::SOCKET>(), mem::align_of::<RawSocket>());
439-
Self::from_raw_socket(raw as RawSocket)
439+
unsafe { Self::from_raw_socket(raw as RawSocket) }
440440
}
441441
}
442442

@@ -486,6 +486,6 @@ impl IntoRawSocket for Socket {
486486

487487
impl FromRawSocket for Socket {
488488
unsafe fn from_raw_socket(raw_socket: RawSocket) -> Self {
489-
Self(FromRawSocket::from_raw_socket(raw_socket))
489+
unsafe { Self(FromRawSocket::from_raw_socket(raw_socket)) }
490490
}
491491
}

‎std/src/sys/pal/windows/os.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Implementation of `std::os` functionality for Windows.
22
33
#![allow(nonstandard_style)]
4+
#![allow(unsafe_op_in_unsafe_fn)]
45

56
#[cfg(test)]
67
mod tests;

‎std/src/sys/pal/windows/pipe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unsafe_op_in_unsafe_fn)]
12
use crate::os::windows::prelude::*;
23

34
use crate::ffi::OsStr;

‎std/src/sys/pal/windows/stack_overflow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg_attr(test, allow(dead_code))]
2+
#![allow(unsafe_op_in_unsafe_fn)]
23

34
use crate::sys::c;
45
use crate::thread;

‎std/src/sys/pal/windows/thread.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unsafe_op_in_unsafe_fn)]
12
use crate::ffi::CStr;
23
use crate::io;
34
use crate::num::NonZero;

0 commit comments

Comments
 (0)
Failed to load comments.