Skip to content

Commit d96ed86

Browse files
committed
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy