Skip to content

Commit 41d6fbf

Browse files
committed
Fix unsafe_op_in_unsafe_fn for Unix fd and weak
1 parent 26187f1 commit 41d6fbf

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

library/std/src/sys/fd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Platform-dependent file descriptor abstraction.
22
3-
#![deny(unsafe_op_in_unsafe_fn)]
3+
#![forbid(unsafe_op_in_unsafe_fn)]
44

55
cfg_if::cfg_if! {
66
if #[cfg(target_family = "unix")] {

library/std/src/sys/fd/unix.rs

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

43
#[cfg(test)]
54
mod tests;
@@ -674,6 +673,6 @@ impl IntoRawFd for FileDesc {
674673

675674
impl FromRawFd for FileDesc {
676675
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
677-
Self(FromRawFd::from_raw_fd(raw_fd))
676+
Self(unsafe { FromRawFd::from_raw_fd(raw_fd) })
678677
}
679678
}

library/std/src/sys/pal/unix/weak.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// each instance of `weak!` and `syscall!`. Rather than trying to unify all of
2121
// that, we'll just allow that some unix targets don't use this module at all.
2222
#![allow(dead_code, unused_macros)]
23+
#![forbid(unsafe_op_in_unsafe_fn)]
2324

2425
use crate::ffi::CStr;
2526
use crate::marker::PhantomData;
@@ -131,11 +132,15 @@ impl<F> DlsymWeak<F> {
131132
unsafe fn initialize(&self) -> Option<F> {
132133
assert_eq!(size_of::<F>(), size_of::<*mut libc::c_void>());
133134

134-
let val = fetch(self.name);
135+
let val = unsafe { fetch(self.name) };
135136
// This synchronizes with the acquire fence in `get`.
136137
self.func.store(val, Ordering::Release);
137138

138-
if val.is_null() { None } else { Some(mem::transmute_copy::<*mut libc::c_void, F>(&val)) }
139+
if val.is_null() {
140+
None
141+
} else {
142+
Some(unsafe { mem::transmute_copy::<*mut libc::c_void, F>(&val) })
143+
}
139144
}
140145
}
141146

@@ -144,7 +149,7 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
144149
Ok(cstr) => cstr,
145150
Err(..) => return ptr::null_mut(),
146151
};
147-
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr())
152+
unsafe { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) }
148153
}
149154

150155
#[cfg(not(any(target_os = "linux", target_os = "android")))]
@@ -157,7 +162,7 @@ pub(crate) macro syscall {
157162
weak!(fn $name($($param: $t),*) -> $ret;);
158163

159164
if let Some(fun) = $name.get() {
160-
fun($($param),*)
165+
unsafe { fun($($param),*) }
161166
} else {
162167
super::os::set_errno(libc::ENOSYS);
163168
-1
@@ -177,9 +182,9 @@ pub(crate) macro syscall {
177182
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
178183
// interposition, but if it's not found just use a raw syscall.
179184
if let Some(fun) = $name.get() {
180-
fun($($param),*)
185+
unsafe { fun($($param),*) }
181186
} else {
182-
libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret
187+
unsafe { libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret }
183188
}
184189
}
185190
)
@@ -189,7 +194,7 @@ pub(crate) macro syscall {
189194
pub(crate) macro raw_syscall {
190195
(fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => (
191196
unsafe fn $name($($param: $t),*) -> $ret {
192-
libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret
197+
unsafe { libc::syscall(libc::${concat(SYS_, $name)}, $($param),*) as $ret }
193198
}
194199
)
195200
}

0 commit comments

Comments
 (0)