diff --git a/src/c_str.rs b/src/c_str.rs index 7bbf6ac6e0..62a7d29d44 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -1,8 +1,5 @@ //! Nul-terminated byte strings. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{marker::PhantomData, ptr::NonNull, str::Utf8Error}; use alloc::{ diff --git a/src/c_vec.rs b/src/c_vec.rs index 423586e9b9..6d67b58662 100644 --- a/src/c_vec.rs +++ b/src/c_vec.rs @@ -1,8 +1,5 @@ //! Equivalent of Rust's `Vec`, but using relibc's own allocator. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ io::{self, Write}, platform::{self, WriteByte, types::*}, diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index c4f7af841a..7fedfa2ad2 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ ptr, slice, str::{self, FromStr}, diff --git a/src/header/assert/mod.rs b/src/header/assert/mod.rs index 068daf4c8d..fd4790cf87 100644 --- a/src/header/assert/mod.rs +++ b/src/header/assert/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::CStr, platform::types::{c_char, c_int}, diff --git a/src/header/crypt/mod.rs b/src/header/crypt/mod.rs index acc1ad5925..00c9bb23bb 100644 --- a/src/header/crypt/mod.rs +++ b/src/header/crypt/mod.rs @@ -2,9 +2,6 @@ //! //! Non-POSIX, see . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use ::scrypt::password_hash::{Salt, SaltString}; use alloc::{ ffi::CString, diff --git a/src/header/ctype/mod.rs b/src/header/ctype/mod.rs index 9f6cd192d5..cbe2f35548 100644 --- a/src/header/ctype/mod.rs +++ b/src/header/ctype/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - // TODO: *_l functions use crate::platform::types::c_int; diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index 1d2912d332..e9c5b8300c 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{boxed::Box, vec::Vec}; use core::{mem, ptr, slice}; diff --git a/src/header/dl-tls/mod.rs b/src/header/dl-tls/mod.rs index eb338ac4be..f13dfff975 100644 --- a/src/header/dl-tls/mod.rs +++ b/src/header/dl-tls/mod.rs @@ -1,6 +1,5 @@ //! dl-tls implementation for Redox -#![deny(unsafe_op_in_unsafe_fn)] // FIXME(andypython): remove this when #![allow(warnings, unused_variables)] is // dropped from src/lib.rs. #![warn(warnings, unused_variables)] diff --git a/src/header/dlfcn/mod.rs b/src/header/dlfcn/mod.rs index 52b9bb43ef..118355b3f4 100644 --- a/src/header/dlfcn/mod.rs +++ b/src/header/dlfcn/mod.rs @@ -2,7 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] // FIXME(andypython): remove this when #![allow(warnings, unused_variables)] is // dropped from src/lib.rs. #![warn(warnings, unused_variables)] diff --git a/src/header/errno/mod.rs b/src/header/errno/mod.rs index 5ba60b1c99..6bc1451a61 100644 --- a/src/header/errno/mod.rs +++ b/src/header/errno/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::platform::{ self, types::{c_char, c_int}, diff --git a/src/header/fcntl/mod.rs b/src/header/fcntl/mod.rs index 81c7b2887d..6a4db2fafc 100644 --- a/src/header/fcntl/mod.rs +++ b/src/header/fcntl/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use core::num::NonZeroU64; use crate::{ diff --git a/src/header/float/mod.rs b/src/header/float/mod.rs index 52c36df8d8..e806f0ce91 100644 --- a/src/header/float/mod.rs +++ b/src/header/float/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::_fenv::{FE_TONEAREST, fegetround}, platform::types::c_int, diff --git a/src/header/fnmatch/mod.rs b/src/header/fnmatch/mod.rs index 2f45056482..60f6316d2c 100644 --- a/src/header/fnmatch/mod.rs +++ b/src/header/fnmatch/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{borrow::Cow, vec::Vec}; use core::slice; diff --git a/src/header/getopt/mod.rs b/src/header/getopt/mod.rs index f095753d30..062d17b6b2 100644 --- a/src/header/getopt/mod.rs +++ b/src/header/getopt/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{ stdio, string, diff --git a/src/header/glob/mod.rs b/src/header/glob/mod.rs index ff7995d0a1..4b6718445c 100644 --- a/src/header/glob/mod.rs +++ b/src/header/glob/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr; use alloc::{boxed::Box, vec::Vec}; diff --git a/src/header/grp/mod.rs b/src/header/grp/mod.rs index 73235dcf16..957d98ecc6 100644 --- a/src/header/grp/mod.rs +++ b/src/header/grp/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ cell::SyncUnsafeCell, convert::{TryFrom, TryInto}, diff --git a/src/header/ifaddrs/mod.rs b/src/header/ifaddrs/mod.rs index 5e59e8b9ad..f49a357358 100644 --- a/src/header/ifaddrs/mod.rs +++ b/src/header/ifaddrs/mod.rs @@ -1,8 +1,5 @@ //! `ifaddrs.h` implementation -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr; use crate::{ diff --git a/src/header/inttypes/mod.rs b/src/header/inttypes/mod.rs index 8678304f98..07943d3e5b 100644 --- a/src/header/inttypes/mod.rs +++ b/src/header/inttypes/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{ctype, errno::*, stdlib::*}, platform::{ diff --git a/src/header/libgen/mod.rs b/src/header/libgen/mod.rs index 4b174444eb..37d90d2def 100644 --- a/src/header/libgen/mod.rs +++ b/src/header/libgen/mod.rs @@ -2,8 +2,6 @@ //! //! See . -#![deny(unsafe_op_in_unsafe_fn)] - use crate::platform::types::c_char; use crate::header::string::strlen; diff --git a/src/header/locale/mod.rs b/src/header/locale/mod.rs index 0f135f11d2..0b55974077 100644 --- a/src/header/locale/mod.rs +++ b/src/header/locale/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{boxed::Box, ffi::CString, string::String}; use core::{ptr, str::FromStr}; diff --git a/src/header/malloc/mod.rs b/src/header/malloc/mod.rs index c3a04d930b..cc8ef5449b 100644 --- a/src/header/malloc/mod.rs +++ b/src/header/malloc/mod.rs @@ -2,9 +2,6 @@ //! //! Non-POSIX, see . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::errno::ENOMEM, platform::{ diff --git a/src/header/monetary/mod.rs b/src/header/monetary/mod.rs index 5c2f8cb9fb..1b1ca420cb 100644 --- a/src/header/monetary/mod.rs +++ b/src/header/monetary/mod.rs @@ -13,7 +13,6 @@ use libm::{fabs, floor, pow, round, trunc}; extern crate alloc; mod strfmon; -#[deny(unsafe_op_in_unsafe_fn)] #[repr(C)] struct LocaleMonetaryInfo { int_curr_symbol: &'static str, diff --git a/src/header/net_if/mod.rs b/src/header/net_if/mod.rs index beaf2f5a29..40c1ca32e2 100644 --- a/src/header/net_if/mod.rs +++ b/src/header/net_if/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr::null; use alloc::ffi::CString; diff --git a/src/header/netdb/host.rs b/src/header/netdb/host.rs index a9c30a6254..f78f39ab15 100644 --- a/src/header/netdb/host.rs +++ b/src/header/netdb/host.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{boxed::Box, str::SplitWhitespace, vec::Vec}; use core::{mem, ptr}; diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index 072cd64b11..b5ba54d1dd 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - mod dns; use core::{ diff --git a/src/header/poll/mod.rs b/src/header/poll/mod.rs index 5f4326c293..bacebf84ef 100644 --- a/src/header/poll/mod.rs +++ b/src/header/poll/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{mem, ptr, slice}; use crate::{ diff --git a/src/header/pthread/attr.rs b/src/header/pthread/attr.rs index aa2329859e..7f31d14e94 100644 --- a/src/header/pthread/attr.rs +++ b/src/header/pthread/attr.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ptr, sync::atomic::Ordering}; use super::*; diff --git a/src/header/pthread/barrier.rs b/src/header/pthread/barrier.rs index f3618bf685..6bb66d74ca 100644 --- a/src/header/pthread/barrier.rs +++ b/src/header/pthread/barrier.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::header::errno::*; use core::num::NonZeroU32; diff --git a/src/header/pthread/cond.rs b/src/header/pthread/cond.rs index 7fda576d39..ab08b6cca5 100644 --- a/src/header/pthread/cond.rs +++ b/src/header/pthread/cond.rs @@ -1,8 +1,5 @@ // Used design from https://www.remlab.net/op/futex-condvar.shtml -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::header::time::CLOCK_REALTIME; use super::*; diff --git a/src/header/pthread/mod.rs b/src/header/pthread/mod.rs index eba998a6b1..e96504551d 100644 --- a/src/header/pthread/mod.rs +++ b/src/header/pthread/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::collections::LinkedList; use core::{cell::Cell, ptr::NonNull}; diff --git a/src/header/pthread/mutex.rs b/src/header/pthread/mutex.rs index c2d7becb7d..32daa1e937 100644 --- a/src/header/pthread/mutex.rs +++ b/src/header/pthread/mutex.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use super::*; use crate::{ diff --git a/src/header/pthread/once.rs b/src/header/pthread/once.rs index f13da472c4..76348bbcf6 100644 --- a/src/header/pthread/once.rs +++ b/src/header/pthread/once.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use super::*; // PTHREAD_ONCE_INIT diff --git a/src/header/pthread/rwlock.rs b/src/header/pthread/rwlock.rs index d29cd31515..e4682f067c 100644 --- a/src/header/pthread/rwlock.rs +++ b/src/header/pthread/rwlock.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use super::*; use crate::header::errno::EBUSY; diff --git a/src/header/pthread/spin.rs b/src/header/pthread/spin.rs index cef8da6035..094a9ea31b 100644 --- a/src/header/pthread/spin.rs +++ b/src/header/pthread/spin.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::sync::atomic::{AtomicI32 as AtomicInt, Ordering}; use crate::header::errno::EBUSY; diff --git a/src/header/pthread/tls.rs b/src/header/pthread/tls.rs index e0a0276c92..6ece3e9926 100644 --- a/src/header/pthread/tls.rs +++ b/src/header/pthread/tls.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use super::*; // TODO: Hashmap? diff --git a/src/header/pty/linux.rs b/src/header/pty/linux.rs index 1ad910ba5b..5c580d612d 100644 --- a/src/header/pty/linux.rs +++ b/src/header/pty/linux.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{fcntl, sys_ioctl, unistd}, io::{Cursor, Write}, diff --git a/src/header/pty/mod.rs b/src/header/pty/mod.rs index 376a8497dd..9589c4a536 100644 --- a/src/header/pty/mod.rs +++ b/src/header/pty/mod.rs @@ -2,9 +2,6 @@ //! //! Non-POSIX, see . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{mem, ptr, slice}; use crate::{ diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index 8d0a71a8ea..21fffe5519 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{boxed::Box, vec::Vec}; use core::{ ops::{Deref, DerefMut}, diff --git a/src/header/regex/mod.rs b/src/header/regex/mod.rs index 9b4c37ffaa..e73ecb4830 100644 --- a/src/header/regex/mod.rs +++ b/src/header/regex/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::string::strlen, platform::types::{c_char, c_int, c_void, size_t}, diff --git a/src/header/semaphore/mod.rs b/src/header/semaphore/mod.rs index f9e3b1778e..0dcf2144b1 100644 --- a/src/header/semaphore/mod.rs +++ b/src/header/semaphore/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::time::{CLOCK_MONOTONIC, CLOCK_REALTIME, timespec}, platform::types::{c_char, c_int, c_long, c_uint, clockid_t}, diff --git a/src/header/shadow/mod.rs b/src/header/shadow/mod.rs index db4f514ff4..5f5ffa96dd 100644 --- a/src/header/shadow/mod.rs +++ b/src/header/shadow/mod.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ cell::SyncUnsafeCell, convert::TryInto, diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index e773350958..0b29c3b901 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{arch::global_asm, mem, ptr}; use cbitset::BitSet; diff --git a/src/header/stdio/getdelim.rs b/src/header/stdio/getdelim.rs index 19be72bb11..fd9d3efd77 100644 --- a/src/header/stdio/getdelim.rs +++ b/src/header/stdio/getdelim.rs @@ -1,8 +1,5 @@ // https://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{string::String, vec::Vec}; use core::{fmt::Write, intrinsics::unlikely, ops::Deref, ptr}; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index a38dd2de72..0f04dee481 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{ borrow::{Borrow, BorrowMut}, boxed::Box, diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs index 0c9c1c86fe..833bf8ebbc 100644 --- a/src/header/stdio/printf.rs +++ b/src/header/stdio/printf.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - // TODO: reuse more code with the wide printf impl use crate::{ c_str::{self, CStr, NulStr}, diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 3dd1dbf3d7..9633d03de1 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{convert::TryFrom, intrinsics, iter, mem, ptr, slice}; use rand::{ Rng, SeedableRng, diff --git a/src/header/stdlib/random.rs b/src/header/stdlib/random.rs index e92fdbfb29..f72efc5a8d 100644 --- a/src/header/stdlib/random.rs +++ b/src/header/stdlib/random.rs @@ -1,9 +1,6 @@ //! Helper functions for random() and friends, see https://pubs.opengroup.org/onlinepubs/7908799/xsh/initstate.html // Ported from musl's implementation (src/prng/random.c) -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ platform::types::c_uint, sync::{Mutex, MutexGuard}, diff --git a/src/header/stdlib/sort.rs b/src/header/stdlib/sort.rs index c53f4b947f..e9a00652bb 100644 --- a/src/header/stdlib/sort.rs +++ b/src/header/stdlib/sort.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::platform::types::{c_char, c_int, c_void, size_t}; pub unsafe fn introsort( diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index 9a699c8b3d..74e6468769 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -304,7 +304,7 @@ pub unsafe extern "C" fn strcoll_l(s1: *const c_char, s2: *const c_char, _loc: l /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int { - strcoll_l(s1, s2, THREAD_LOCALE as locale_t) + unsafe { strcoll_l(s1, s2, THREAD_LOCALE as locale_t) } } /// See . @@ -379,7 +379,7 @@ pub unsafe extern "C" fn strerror_l(errnum: c_int, _loc: locale_t) -> *mut c_cha /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn strerror(errnum: c_int) -> *mut c_char { - strerror_l(errnum, THREAD_LOCALE as locale_t) + unsafe { strerror_l(errnum, THREAD_LOCALE as locale_t) } } /// See . @@ -669,5 +669,5 @@ pub unsafe extern "C" fn strxfrm_l( /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn strxfrm(s1: *mut c_char, s2: *const c_char, n: size_t) -> size_t { - strxfrm_l(s1, s2, n, THREAD_LOCALE as locale_t) + unsafe { strxfrm_l(s1, s2, n, THREAD_LOCALE as locale_t) } } diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index 204e58bd40..ad1b4b9be4 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ arch, iter::{once, zip}, diff --git a/src/header/sys_epoll/mod.rs b/src/header/sys_epoll/mod.rs index 16183b3852..ec29d409b9 100644 --- a/src/header/sys_epoll/mod.rs +++ b/src/header/sys_epoll/mod.rs @@ -1,8 +1,5 @@ //! sys/epoll.h implementation for Redox, following http://man7.org/linux/man-pages/man7/epoll.7.html -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr; use crate::{ diff --git a/src/header/sys_ioctl/linux.rs b/src/header/sys_ioctl/linux.rs index e67375449f..67d15c13e9 100644 --- a/src/header/sys_ioctl/linux.rs +++ b/src/header/sys_ioctl/linux.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::ResultExt, platform::{Sys, types::*}, diff --git a/src/header/sys_ioctl/redox/drm.rs b/src/header/sys_ioctl/redox/drm.rs index ea9dad2d70..674fcffa4c 100644 --- a/src/header/sys_ioctl/redox/drm.rs +++ b/src/header/sys_ioctl/redox/drm.rs @@ -41,7 +41,7 @@ fn plane_id(i: u32) -> u32 { } unsafe fn copy_array(src: &[T], dst_ptr: *mut T, dst_len: usize) -> usize { - let dst = slice::from_raw_parts_mut(dst_ptr, dst_len); + let dst = unsafe { slice::from_raw_parts_mut(dst_ptr, dst_len) }; dst.copy_from_slice(&src[..src.len().min(dst_len)]); src.len() } @@ -61,22 +61,22 @@ impl Dev { mut buf: IoctlBuffer, func: u64, ) -> Result { - let mut data = buf.read::()?; - let mut wire = data.write(); + let mut data = unsafe { buf.read::() }?; + let mut wire = unsafe { data.write() }; let res = redox_rt::sys::sys_call( self.fd as usize, &mut wire, syscall::CallFlags::empty(), &[func], )?; - data.read_from(&wire); - buf.write(data)?; + unsafe { data.read_from(&wire) }; + (unsafe { buf.write(data) })?; Ok(res as c_int) } unsafe fn write_ioctl(&self, mut buf: IoctlBuffer, func: u64) -> Result { - let mut data = buf.read::()?; - let mut wire = data.write(); + let mut data = unsafe { buf.read::() }?; + let mut wire = unsafe { data.write() }; let res = redox_rt::sys::sys_call( self.fd as usize, &mut wire, @@ -90,26 +90,30 @@ impl Dev { pub(super) unsafe fn ioctl(fd: c_int, func: u8, buf: IoctlBuffer) -> Result { let dev = Dev::new(fd)?; match func { - 0x00 => dev.read_write_ioctl::(buf, VERSION), - 0x0C => dev.read_write_ioctl::(buf, GET_CAP), - 0x0D => dev.write_ioctl::(buf, SET_CLIENT_CAP), - 0xA0 => dev.read_write_ioctl::(buf, MODE_CARD_RES), - 0xA1 => dev.read_write_ioctl::(buf, MODE_GET_CRTC), - 0xA6 => dev.read_write_ioctl::(buf, MODE_GET_ENCODER), - 0xA7 => dev.read_write_ioctl::(buf, MODE_GET_CONNECTOR), - 0xAA => dev.read_write_ioctl::(buf, MODE_GET_PROPERTY), - 0xAB => dev.read_write_ioctl::(buf, MODE_SET_PROPERTY), - 0xAC => dev.read_write_ioctl::(buf, MODE_GET_PROP_BLOB), - 0xAD => dev.read_write_ioctl::(buf, MODE_GET_FB), - 0xAE => dev.read_write_ioctl::(buf, MODE_ADD_FB), - 0xAF => dev.read_write_ioctl::(buf, MODE_RM_FB), - 0xB2 => dev.read_write_ioctl::(buf, MODE_CREATE_DUMB), - 0xB3 => dev.read_write_ioctl::(buf, MODE_MAP_DUMB), - 0xB4 => dev.read_write_ioctl::(buf, MODE_DESTROY_DUMB), - 0xB5 => dev.read_write_ioctl::(buf, MODE_GET_PLANE_RES), - 0xB6 => dev.read_write_ioctl::(buf, MODE_GET_PLANE), - 0xB9 => dev.read_write_ioctl::(buf, MODE_OBJ_GET_PROPERTIES), - 0xCE => dev.read_write_ioctl::(buf, MODE_GET_FB2), + 0x00 => unsafe { dev.read_write_ioctl::(buf, VERSION) }, + 0x0C => unsafe { dev.read_write_ioctl::(buf, GET_CAP) }, + 0x0D => unsafe { dev.write_ioctl::(buf, SET_CLIENT_CAP) }, + 0xA0 => unsafe { dev.read_write_ioctl::(buf, MODE_CARD_RES) }, + 0xA1 => unsafe { dev.read_write_ioctl::(buf, MODE_GET_CRTC) }, + 0xA6 => unsafe { dev.read_write_ioctl::(buf, MODE_GET_ENCODER) }, + 0xA7 => unsafe { dev.read_write_ioctl::(buf, MODE_GET_CONNECTOR) }, + 0xAA => unsafe { dev.read_write_ioctl::(buf, MODE_GET_PROPERTY) }, + 0xAB => unsafe { + dev.read_write_ioctl::(buf, MODE_SET_PROPERTY) + }, + 0xAC => unsafe { dev.read_write_ioctl::(buf, MODE_GET_PROP_BLOB) }, + 0xAD => unsafe { dev.read_write_ioctl::(buf, MODE_GET_FB) }, + 0xAE => unsafe { dev.read_write_ioctl::(buf, MODE_ADD_FB) }, + 0xAF => unsafe { dev.read_write_ioctl::(buf, MODE_RM_FB) }, + 0xB2 => unsafe { dev.read_write_ioctl::(buf, MODE_CREATE_DUMB) }, + 0xB3 => unsafe { dev.read_write_ioctl::(buf, MODE_MAP_DUMB) }, + 0xB4 => unsafe { dev.read_write_ioctl::(buf, MODE_DESTROY_DUMB) }, + 0xB5 => unsafe { dev.read_write_ioctl::(buf, MODE_GET_PLANE_RES) }, + 0xB6 => unsafe { dev.read_write_ioctl::(buf, MODE_GET_PLANE) }, + 0xB9 => unsafe { + dev.read_write_ioctl::(buf, MODE_OBJ_GET_PROPERTIES) + }, + 0xCE => unsafe { dev.read_write_ioctl::(buf, MODE_GET_FB2) }, _ => { eprintln!("unimplemented DRM ioctl({}, 0x{:02x}, {:?})", fd, func, buf); Err(Errno(EINVAL)) diff --git a/src/header/sys_ioctl/redox/mod.rs b/src/header/sys_ioctl/redox/mod.rs index f7a4c77846..05134d56c3 100644 --- a/src/header/sys_ioctl/redox/mod.rs +++ b/src/header/sys_ioctl/redox/mod.rs @@ -111,7 +111,7 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result { let mut flags = Sys::fcntl(fd, fcntl::F_GETFL, 0)?; - flags = if *(out as *mut c_int) == 0 { + flags = if unsafe { *(out as *mut c_int) } == 0 { flags & !fcntl::O_NONBLOCK } else { flags | fcntl::O_NONBLOCK @@ -119,12 +119,12 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result { - let termios = &mut *(out as *mut termios::termios); + let termios = unsafe { &mut *(out as *mut termios::termios) }; dup_read(fd, "termios", termios)?; } // TODO: give these different behaviors TCSETS | TCSETSW | TCSETSF => { - let termios = &*(out as *const termios::termios); + let termios = unsafe { &*(out as *const termios::termios) }; dup_write(fd, "termios", termios)?; } TCFLSH => { @@ -135,19 +135,19 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result { - let pgrp = &mut *(out as *mut pid_t); + let pgrp = unsafe { &mut *(out as *mut pid_t) }; dup_read(fd, "pgrp", pgrp)?; } TIOCSPGRP => { - let pgrp = &*(out as *const pid_t); + let pgrp = unsafe { &*(out as *const pid_t) }; dup_write(fd, "pgrp", pgrp)?; } TIOCGWINSZ => { - let winsize = &mut *(out as *mut winsize); + let winsize = unsafe { &mut *(out as *mut winsize) }; dup_read(fd, "winsize", winsize)?; } TIOCSWINSZ => { - let winsize = &*(out as *const winsize); + let winsize = unsafe { &*(out as *const winsize) }; dup_write(fd, "winsize", winsize)?; } TIOCGPTLCK => { @@ -179,7 +179,7 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result IoctlBuffer::ReadWrite(out, size), _ => IoctlBuffer::None, }; - return drm::ioctl(fd, func, buf); + return unsafe { drm::ioctl(fd, func, buf) }; } _ => { return Err(Errno(EINVAL)); @@ -192,5 +192,5 @@ unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result c_int { - ioctl_inner(fd, request, out).or_minus_one_errno() + unsafe { ioctl_inner(fd, request, out) }.or_minus_one_errno() } diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index 8789673674..5415be294a 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::{CStr, CString}, error::{Errno, ResultExt}, diff --git a/src/header/sys_ptrace/mod.rs b/src/header/sys_ptrace/mod.rs index 4e7053d0fd..6767789d70 100644 --- a/src/header/sys_ptrace/mod.rs +++ b/src/header/sys_ptrace/mod.rs @@ -1,8 +1,5 @@ //! ptrace compatibility layer for Redox OS -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::ResultExt, platform::{PalPtrace, Sys, types::*}, diff --git a/src/header/sys_random/mod.rs b/src/header/sys_random/mod.rs index f12f4b80a9..4d3f3f1198 100644 --- a/src/header/sys_random/mod.rs +++ b/src/header/sys_random/mod.rs @@ -2,9 +2,6 @@ //! //! Non-POSIX, see . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::slice; use crate::{ diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 87e943f68d..d9259a7342 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::ResultExt, header::sys_time::timeval, diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index b97707586b..69afb10670 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::mem; use cbitset::BitSet; diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 8a0222e686..a71b57ae5c 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{mem, ptr}; use crate::{ diff --git a/src/header/sys_statvfs/mod.rs b/src/header/sys_statvfs/mod.rs index 61052e0ac7..a48d924311 100644 --- a/src/header/sys_statvfs/mod.rs +++ b/src/header/sys_statvfs/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::CStr, error::ResultExt, diff --git a/src/header/sys_syslog/mod.rs b/src/header/sys_syslog/mod.rs index dd436d4bbc..b75ebb2440 100644 --- a/src/header/sys_syslog/mod.rs +++ b/src/header/sys_syslog/mod.rs @@ -4,9 +4,6 @@ // Exported as both syslog.h and sys/syslog.h. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - #[cfg(target_os = "redox")] #[path = "redox.rs"] pub mod sys; diff --git a/src/header/sys_time/mod.rs b/src/header/sys_time/mod.rs index 3d6193996d..1de62a9da3 100644 --- a/src/header/sys_time/mod.rs +++ b/src/header/sys_time/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::CStr, error::ResultExt, diff --git a/src/header/sys_timeb/mod.rs b/src/header/sys_timeb/mod.rs index 8960ac3132..0abf94e490 100644 --- a/src/header/sys_timeb/mod.rs +++ b/src/header/sys_timeb/mod.rs @@ -7,9 +7,6 @@ //! Specifications Issue 6, and the entire `sys/timeb.h` header was removed in //! Issue 7. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr::NonNull; use crate::{ diff --git a/src/header/sys_uio/mod.rs b/src/header/sys_uio/mod.rs index 627f2a4ad1..ddd714ab17 100644 --- a/src/header/sys_uio/mod.rs +++ b/src/header/sys_uio/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::vec::Vec; use core::slice; diff --git a/src/header/sys_utsname/mod.rs b/src/header/sys_utsname/mod.rs index bde1633f7e..f9031c7b95 100644 --- a/src/header/sys_utsname/mod.rs +++ b/src/header/sys_utsname/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::ResultExt, out::Out, diff --git a/src/header/sys_wait/mod.rs b/src/header/sys_wait/mod.rs index adcb21d088..11f4bf2c64 100644 --- a/src/header/sys_wait/mod.rs +++ b/src/header/sys_wait/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::ResultExt, out::Out, diff --git a/src/header/termios/mod.rs b/src/header/termios/mod.rs index 358841c232..1615d2190d 100644 --- a/src/header/termios/mod.rs +++ b/src/header/termios/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{ errno, diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 1bb0668b1b..cc058717be 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::{CStr, CString}, error::{Errno, ResultExt}, diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index df647f0764..05ed15ae90 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -2,9 +2,6 @@ // // See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::string::String; use super::{get_offset, tm}; diff --git a/src/header/unistd/brk.rs b/src/header/unistd/brk.rs index 61ac540a70..24c9a7a7af 100644 --- a/src/header/unistd/brk.rs +++ b/src/header/unistd/brk.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr; use crate::{ diff --git a/src/header/unistd/getopt.rs b/src/header/unistd/getopt.rs index f3963c46c0..5240e429fa 100644 --- a/src/header/unistd/getopt.rs +++ b/src/header/unistd/getopt.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::ptr; use crate::{ diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 9b05bbd7d3..861f373fa8 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ convert::TryFrom, ffi::VaListImpl, diff --git a/src/header/utime/mod.rs b/src/header/utime/mod.rs index 0161773d50..97ce28bf51 100644 --- a/src/header/utime/mod.rs +++ b/src/header/utime/mod.rs @@ -5,9 +5,6 @@ //! The `utime.h` header was marked obsolescent in the Open Group Base //! Specifications Issue 7, and removed in Issue 8. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ c_str::CStr, error::ResultExt, diff --git a/src/header/utmp/mod.rs b/src/header/utmp/mod.rs index 6032fa6dc7..0b3dfdf555 100644 --- a/src/header/utmp/mod.rs +++ b/src/header/utmp/mod.rs @@ -2,9 +2,6 @@ //! //! Non-POSIX, see . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{sys_ioctl, unistd}, platform::types::{c_int, c_void}, diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index 32236b5e6d..c13079b7c8 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{char, ffi::VaList as va_list, mem, ptr, slice, usize}; use crate::{ diff --git a/src/header/wchar/utf8.rs b/src/header/wchar/utf8.rs index 31d1a8aba3..f56a0b941b 100644 --- a/src/header/wchar/utf8.rs +++ b/src/header/wchar/utf8.rs @@ -1,9 +1,6 @@ //UTF implementation parts for wchar.h. //Partially ported from the Sortix libc -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{char, slice, str, usize}; use crate::{ diff --git a/src/header/wchar/wprintf.rs b/src/header/wchar/wprintf.rs index 539585dc2f..8e0d46b9c7 100644 --- a/src/header/wchar/wprintf.rs +++ b/src/header/wchar/wprintf.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - // TODO: reuse more code with the thin printf impl use crate::{ c_str::{self, WStr}, diff --git a/src/header/wchar/wscanf.rs b/src/header/wchar/wscanf.rs index e284a6631a..8edffd841a 100644 --- a/src/header/wchar/wscanf.rs +++ b/src/header/wchar/wscanf.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use super::lookaheadreader::LookAheadReader; use crate::platform::types::*; use alloc::{string::String, vec::Vec}; diff --git a/src/header/wctype/mod.rs b/src/header/wctype/mod.rs index 610017481d..999fd40ece 100644 --- a/src/header/wctype/mod.rs +++ b/src/header/wctype/mod.rs @@ -2,9 +2,6 @@ //! //! See . -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - // TODO: *_l functions use self::casecmp::casemap; diff --git a/src/io/buffered.rs b/src/io/buffered.rs index e0a5ab28da..c29c2e0a78 100644 --- a/src/io/buffered.rs +++ b/src/io/buffered.rs @@ -10,9 +10,6 @@ //! Buffering wrappers for I/O traits -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{cmp, fmt}; use crate::io::{ diff --git a/src/io/cursor.rs b/src/io/cursor.rs index ff229bd0ce..1ba0793106 100644 --- a/src/io/cursor.rs +++ b/src/io/cursor.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::cmp; use crate::io::{self, Error, ErrorKind, Initializer, SeekFrom, prelude::*}; diff --git a/src/io/impls.rs b/src/io/impls.rs index 2168bc80ce..29009efc42 100644 --- a/src/io/impls.rs +++ b/src/io/impls.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::string::String; use core::{cmp, fmt, mem}; diff --git a/src/io/mod.rs b/src/io/mod.rs index ae4f50ab3a..7f28d2b38c 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -267,9 +267,6 @@ //! [`Result`]: ../result/enum.Result.html //! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - pub mod buffered; pub mod cursor; pub mod error; diff --git a/src/ld_so/mod.rs b/src/ld_so/mod.rs index 12532e9c38..93231989cb 100644 --- a/src/ld_so/mod.rs +++ b/src/ld_so/mod.rs @@ -3,7 +3,6 @@ // FIXME(andypython): remove this when #![allow(warnings, unused_variables)] is // dropped from src/lib.rs. #![warn(warnings, unused_variables)] -#![deny(unsafe_op_in_unsafe_fn)] use core::{mem, ptr}; use object::{ diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs index eed04d81a4..814a84498d 100644 --- a/src/ld_so/start.rs +++ b/src/ld_so/start.rs @@ -1,7 +1,5 @@ // Start code adapted from https://gitlab.redox-os.org/redox-os/relibc/blob/master/src/start.rs -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{ borrow::ToOwned, boxed::Box, diff --git a/src/ld_so/tcb.rs b/src/ld_so/tcb.rs index 7451fa4f9a..c849d8fad2 100644 --- a/src/ld_so/tcb.rs +++ b/src/ld_so/tcb.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::vec::Vec; use core::{ cell::UnsafeCell, diff --git a/src/lib.rs b/src/lib.rs index 3ea46c6a6b..1736cd073e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ #![allow(clippy::derive_hash_xor_eq)] #![allow(clippy::eval_order_dependence)] #![allow(clippy::mut_from_ref)] +#![deny(unsafe_op_in_unsafe_fn)] // TODO: fix these #![warn(unaligned_references)] diff --git a/src/macros.rs b/src/macros.rs index 3cf348fe00..0c7aeb1a8a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - /// Print to stdout #[macro_export] macro_rules! print { diff --git a/src/out.rs b/src/out.rs index 47d5cc2deb..44158b3cc5 100644 --- a/src/out.rs +++ b/src/out.rs @@ -9,9 +9,6 @@ //! requirement that `&mut` references are never aliased, which can typically not be assumed when //! getting pointers from C. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{cell::UnsafeCell, fmt, marker::PhantomData, mem::MaybeUninit, ptr::NonNull}; /// Wrapper for write-only "out pointers" that are safe to write to diff --git a/src/platform/allocator/mod.rs b/src/platform/allocator/mod.rs index bee1c7628e..1febb92f09 100644 --- a/src/platform/allocator/mod.rs +++ b/src/platform/allocator/mod.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ alloc::{GlobalAlloc, Layout}, cell::SyncUnsafeCell, diff --git a/src/platform/allocator/sys.rs b/src/platform/allocator/sys.rs index 9b720e6395..1bb446e9bb 100644 --- a/src/platform/allocator/sys.rs +++ b/src/platform/allocator/sys.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ header::{ sys_mman::{self, MAP_FAILED, MREMAP_MAYMOVE}, diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 6ac8c20964..8a51cb3429 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{arch::asm, num::NonZeroU64, ptr}; use super::{ERRNO, Pal, types::*}; diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 88b14d6eea..4922e7c622 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -1,8 +1,5 @@ //! Platform abstractions and environment. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use crate::{ error::{Errno, ResultExt}, io::{self, Read, Write}, diff --git a/src/platform/redox/epoll.rs b/src/platform/redox/epoll.rs index fe3166222b..4a1b706950 100644 --- a/src/platform/redox/epoll.rs +++ b/src/platform/redox/epoll.rs @@ -144,7 +144,7 @@ impl PalEpoll for Sys { callback() } else { // Allowset is inverse of sigset mask - let allowset = !*sigset; + let allowset = !unsafe { *sigset }; redox_rt::signal::callback_or_signal_async(allowset, callback) }?; diff --git a/src/platform/redox/event.rs b/src/platform/redox/event.rs index 3a837558cc..0ffcf9757d 100644 --- a/src/platform/redox/event.rs +++ b/src/platform/redox/event.rs @@ -40,11 +40,13 @@ pub unsafe extern "C" fn redox_event_queue_get_events_v1( size_of::(), "EOF not yet defined for event queue reads" ); - buf.write(event::raw::RawEventV1 { - fd: event.id, - flags: event::raw::EventFlags::from(event.flags).bits(), - user_data: event.data, - }); + unsafe { + buf.write(event::raw::RawEventV1 { + fd: event.id, + flags: event::raw::EventFlags::from(event.flags).bits(), + user_data: event.data, + }) + }; Ok(1) })()) diff --git a/src/platform/redox/extra.rs b/src/platform/redox/extra.rs index 35c74d40aa..c95e94847f 100644 --- a/src/platform/redox/extra.rs +++ b/src/platform/redox/extra.rs @@ -10,10 +10,9 @@ pub use redox_rt::proc::FdGuard; #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_fpath(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t { - syscall::fpath( - fd as usize, - slice::from_raw_parts_mut(buf as *mut u8, count), - ) + syscall::fpath(fd as usize, unsafe { + slice::from_raw_parts_mut(buf as *mut u8, count) + }) .map_err(Errno::from) .map(|l| l as ssize_t) .or_minus_one_errno() diff --git a/src/platform/redox/libredox.rs b/src/platform/redox/libredox.rs index 8e496a2b70..2fe8b49aaf 100644 --- a/src/platform/redox/libredox.rs +++ b/src/platform/redox/libredox.rs @@ -40,7 +40,7 @@ pub unsafe fn fstat(fd: usize, buf: *mut crate::header::sys_stat::stat) -> sysca let mut redox_buf: syscall::Stat = Default::default(); syscall::fstat(fd, &mut redox_buf)?; - if let Some(buf) = buf.as_mut() { + if let Some(buf) = unsafe { buf.as_mut() } { buf.st_dev = redox_buf.st_dev as dev_t; buf.st_ino = redox_buf.st_ino as ino_t; buf.st_nlink = redox_buf.st_nlink as nlink_t; @@ -75,18 +75,20 @@ pub unsafe fn fstatvfs( syscall::fstatvfs(fd, &mut kbuf)?; if !buf.is_null() { - (*buf).f_bsize = kbuf.f_bsize as c_ulong; - (*buf).f_frsize = kbuf.f_bsize as c_ulong; - (*buf).f_blocks = kbuf.f_blocks as c_ulong; - (*buf).f_bfree = kbuf.f_bfree as c_ulong; - (*buf).f_bavail = kbuf.f_bavail as c_ulong; - //TODO - (*buf).f_files = 0; - (*buf).f_ffree = 0; - (*buf).f_favail = 0; - (*buf).f_fsid = 0; - (*buf).f_flag = 0; - (*buf).f_namemax = 0; + unsafe { + (*buf).f_bsize = kbuf.f_bsize as c_ulong; + (*buf).f_frsize = kbuf.f_bsize as c_ulong; + (*buf).f_blocks = kbuf.f_blocks as c_ulong; + (*buf).f_bfree = kbuf.f_bfree as c_ulong; + (*buf).f_bavail = kbuf.f_bavail as c_ulong; + //TODO + (*buf).f_files = 0; + (*buf).f_ffree = 0; + (*buf).f_favail = 0; + (*buf).f_fsid = 0; + (*buf).f_flag = 0; + (*buf).f_namemax = 0; + } } Ok(()) } @@ -104,10 +106,7 @@ pub unsafe fn futimens(fd: usize, times: *const timespec) -> syscall::Result<()> }, ] } else { - times - .cast::<[timespec; 2]>() - .read() - .map(|ts| syscall::TimeSpec::from(&ts)) + unsafe { times.cast::<[timespec; 2]>().read() }.map(|ts| syscall::TimeSpec::from(&ts)) }; syscall::futimens(fd as usize, ×)?; Ok(()) @@ -130,7 +129,7 @@ pub unsafe extern "C" fn redox_open_v1( mode: u16, ) -> RawResult { Error::mux(open( - str::from_utf8_unchecked(slice::from_raw_parts(path_base, path_len)), + unsafe { str::from_utf8_unchecked(slice::from_raw_parts(path_base, path_len)) }, flags as c_int, mode as mode_t, )) @@ -144,14 +143,16 @@ pub unsafe extern "C" fn redox_openat_v1( ) -> RawResult { Error::mux(syscall::openat( fd, - str::from_utf8_unchecked(slice::from_raw_parts(path_base, path_len)), + unsafe { str::from_utf8_unchecked(slice::from_raw_parts(path_base, path_len)) }, flags as usize, 0, //TODO: openat fcntl_flags )) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_dup_v1(fd: usize, buf: *const u8, len: usize) -> RawResult { - Error::mux(syscall::dup(fd, core::slice::from_raw_parts(buf, len))) + Error::mux(syscall::dup(fd, unsafe { + core::slice::from_raw_parts(buf, len) + })) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_dup2_v1( @@ -160,15 +161,15 @@ pub unsafe extern "C" fn redox_dup2_v1( buf: *const u8, len: usize, ) -> RawResult { - Error::mux(syscall::dup2( - old_fd, - new_fd, - core::slice::from_raw_parts(buf, len), - )) + Error::mux(syscall::dup2(old_fd, new_fd, unsafe { + core::slice::from_raw_parts(buf, len) + })) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_read_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult { - Error::mux(posix_read(fd, slice::from_raw_parts_mut(dst_base, dst_len))) + Error::mux(posix_read(fd, unsafe { + slice::from_raw_parts_mut(dst_base, dst_len) + })) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_write_v1( @@ -176,7 +177,9 @@ pub unsafe extern "C" fn redox_write_v1( src_base: *const u8, src_len: usize, ) -> RawResult { - Error::mux(posix_write(fd, slice::from_raw_parts(src_base, src_len))) + Error::mux(posix_write(fd, unsafe { + slice::from_raw_parts(src_base, src_len) + })) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_fsync_v1(fd: usize) -> RawResult { @@ -197,28 +200,27 @@ pub unsafe extern "C" fn redox_fchown_v1(fd: usize, new_uid: u32, new_gid: u32) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_fpath_v1(fd: usize, dst_base: *mut u8, dst_len: usize) -> RawResult { - Error::mux(syscall::fpath( - fd, - core::slice::from_raw_parts_mut(dst_base, dst_len), - )) + Error::mux(syscall::fpath(fd, unsafe { + core::slice::from_raw_parts_mut(dst_base, dst_len) + })) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_fstat_v1( fd: usize, stat: *mut crate::header::sys_stat::stat, ) -> RawResult { - Error::mux(fstat(fd, stat).map(|()| 0)) + Error::mux(unsafe { fstat(fd, stat) }.map(|()| 0)) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_fstatvfs_v1( fd: usize, stat: *mut crate::header::sys_statvfs::statvfs, ) -> RawResult { - Error::mux(fstatvfs(fd, stat).map(|()| 0)) + Error::mux(unsafe { fstatvfs(fd, stat) }.map(|()| 0)) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_futimens_v1(fd: usize, times: *const timespec) -> RawResult { - Error::mux(futimens(fd, times).map(|()| 0)) + Error::mux(unsafe { futimens(fd, times) }.map(|()| 0)) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_close_v1(fd: usize) -> RawResult { @@ -271,7 +273,7 @@ pub unsafe extern "C" fn redox_waitpid_v1(pid: usize, status: *mut i32, options: &mut sts, WaitFlags::from_bits_truncate(options as usize), )); - status.write(sts as i32); + unsafe { status.write(sts as i32) }; res } @@ -289,9 +291,11 @@ pub unsafe extern "C" fn redox_sigaction_v1( old: *mut sigaction, ) -> RawResult { Error::mux( - Sys::sigaction(signal as c_int, new.as_ref(), old.as_mut()) - .map(|()| 0) - .map_err(Into::into), + Sys::sigaction(signal as c_int, unsafe { new.as_ref() }, unsafe { + old.as_mut() + }) + .map(|()| 0) + .map_err(Into::into), ) } @@ -302,9 +306,11 @@ pub unsafe extern "C" fn redox_sigprocmask_v1( old: *mut u64, ) -> RawResult { Error::mux( - Sys::sigprocmask(how as c_int, new.as_ref(), old.as_mut()) - .map(|()| 0) - .map_err(Into::into), + Sys::sigprocmask(how as c_int, unsafe { new.as_ref() }, unsafe { + old.as_mut() + }) + .map(|()| 0) + .map_err(Into::into), ) } #[unsafe(no_mangle)] @@ -316,26 +322,28 @@ pub unsafe extern "C" fn redox_mmap_v1( fd: usize, offset: u64, ) -> RawResult { - Error::mux(syscall::fmap( - fd, - &syscall::Map { - address: addr as usize, - offset: offset as usize, - size: unaligned_len, - flags: syscall::MapFlags::from_bits_truncate( - ((prot << 16) | (flags & 0xffff)) as usize, - ), - }, - )) + Error::mux(unsafe { + syscall::fmap( + fd, + &syscall::Map { + address: addr as usize, + offset: offset as usize, + size: unaligned_len, + flags: syscall::MapFlags::from_bits_truncate( + ((prot << 16) | (flags & 0xffff)) as usize, + ), + }, + ) + }) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_munmap_v1(addr: *mut (), unaligned_len: usize) -> RawResult { - Error::mux(syscall::funmap(addr as usize, unaligned_len)) + Error::mux(unsafe { syscall::funmap(addr as usize, unaligned_len) }) } #[unsafe(no_mangle)] pub unsafe extern "C" fn redox_clock_gettime_v1(clock: usize, ts: *mut timespec) -> RawResult { - Error::mux(clock_gettime(clock, Out::nonnull(ts)).map(|()| 0)) + Error::mux(clock_gettime(clock, unsafe { Out::nonnull(ts) }).map(|()| 0)) } #[unsafe(no_mangle)] @@ -344,7 +352,7 @@ pub unsafe extern "C" fn redox_strerror_v1( buflen: *mut usize, error: u32, ) -> RawResult { - let dst = core::slice::from_raw_parts_mut(buf, buflen.read()); + let dst = unsafe { core::slice::from_raw_parts_mut(buf, buflen.read()) }; Error::mux((|| { // TODO: Merge syscall::error::STR_ERROR into crate::header::error::? @@ -356,7 +364,7 @@ pub unsafe extern "C" fn redox_strerror_v1( // This API ensures that the returned buffer is proper UTF-8. Thus, it returns both the // copied length and the actual length. - buflen.write(src.len()); + unsafe { buflen.write(src.len()) }; let raw_len = core::cmp::min(dst.len(), src.len()); let len = match core::str::from_utf8(&src.as_bytes()[..raw_len]) { @@ -380,7 +388,7 @@ pub unsafe extern "C" fn redox_mkns_v1( return Err(Error::new(EINVAL)); } // Kernel does the UTF-8 validation. - syscall::mkns(core::slice::from_raw_parts(names.cast(), num_names)) + syscall::mkns(unsafe { core::slice::from_raw_parts(names.cast(), num_names) }) })()) } @@ -406,9 +414,9 @@ pub unsafe extern "C" fn redox_sys_call_v0( ) -> RawResult { Error::mux(redox_rt::sys::sys_call( fd, - slice::from_raw_parts_mut(payload, payload_len), + unsafe { slice::from_raw_parts_mut(payload, payload_len) }, syscall::CallFlags::from_bits_retain(flags), - slice::from_raw_parts(metadata, metadata_len), + unsafe { slice::from_raw_parts(metadata, metadata_len) }, )) } @@ -421,7 +429,7 @@ pub unsafe extern "C" fn redox_get_socket_token_v0( let metadata = [SocketCall::GetToken as u64]; Error::mux(redox_rt::sys::sys_call( fd, - slice::from_raw_parts_mut(payload, payload_len), + unsafe { slice::from_raw_parts_mut(payload, payload_len) }, syscall::CallFlags::empty(), &metadata, )) diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index a981f304a6..7003047142 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1,5 +1,3 @@ -#![allow(unsafe_op_in_unsafe_fn)] - use core::{ convert::TryFrom, mem::{self, MaybeUninit, size_of}, @@ -140,29 +138,33 @@ impl Pal for Sys { unsafe fn brk(addr: *mut c_void) -> Result<*mut c_void> { // On first invocation, allocate a buffer for brk - if BRK_CUR.is_null() { + if unsafe { BRK_CUR }.is_null() { // 4 megabytes of RAM ought to be enough for anybody const BRK_MAX_SIZE: usize = 4 * 1024 * 1024; - let allocated = Self::mmap( - ptr::null_mut(), - BRK_MAX_SIZE, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS, - 0, - 0, - )?; + let allocated = unsafe { + Self::mmap( + ptr::null_mut(), + BRK_MAX_SIZE, + PROT_READ | PROT_WRITE, + MAP_ANONYMOUS, + 0, + 0, + ) + }?; - BRK_CUR = allocated; - BRK_END = (allocated as *mut u8).add(BRK_MAX_SIZE) as *mut c_void; + unsafe { + BRK_CUR = allocated; + BRK_END = (allocated as *mut u8).add(BRK_MAX_SIZE) as *mut c_void + }; } if addr.is_null() { // Lookup what previous brk() invocations have set the address to - Ok(BRK_CUR) - } else if BRK_CUR <= addr && addr < BRK_END { + Ok(unsafe { BRK_CUR }) + } else if unsafe { BRK_CUR } <= addr && addr < unsafe { BRK_END } { // It's inside buffer, return - BRK_CUR = addr; + unsafe { BRK_CUR = addr }; Ok(addr) } else { // It was outside of valid range @@ -258,7 +260,7 @@ impl Pal for Sys { self::exec::execve( Executable::InFd { file: File::new(fildes), - arg0: CStr::from_ptr(argv.read()).to_bytes(), + arg0: unsafe { CStr::from_ptr(argv.read()) }.to_bytes(), }, self::exec::ArgEnv::C { argv, envp }, None, @@ -395,22 +397,22 @@ impl Pal for Sys { tv_sec: d.tv_sec, tv_nsec: d.tv_nsec as i32, }); - redox_rt::sys::sys_futex_wait(addr, val, deadline.as_ref())?; + (unsafe { redox_rt::sys::sys_futex_wait(addr, val, deadline.as_ref()) })?; Ok(()) } #[inline] unsafe fn futex_wake(addr: *mut u32, num: u32) -> Result { - Ok(redox_rt::sys::sys_futex_wake(addr, num)?) + Ok(unsafe { redox_rt::sys::sys_futex_wake(addr, num) }?) } unsafe fn futimens(fd: c_int, times: *const timespec) -> Result<()> { - libredox::futimens(fd as usize, times)?; + (unsafe { libredox::futimens(fd as usize, times) })?; Ok(()) } unsafe fn utimens(path: CStr, times: *const timespec) -> Result<()> { let file = File::open(path, fcntl::O_PATH | fcntl::O_CLOEXEC)?; - Self::futimens(*file, times) + unsafe { Self::futimens(*file, times) } } fn getcwd(buf: Out<[u8]>) -> Result<()> { @@ -791,9 +793,9 @@ impl Pal for Sys { }; Ok(if flags & MAP_ANONYMOUS == MAP_ANONYMOUS { - syscall::fmap(!0, &map)? + (unsafe { syscall::fmap(!0, &map) })? } else { - syscall::fmap(fildes as usize, &map)? + (unsafe { syscall::fmap(fildes as usize, &map) })? } as *mut c_void) } @@ -811,12 +813,14 @@ impl Pal for Sys { let Some(len) = round_up_to_page_size(len) else { return Err(Errno(ENOMEM)); }; - syscall::mprotect( - addr as usize, - len, - syscall::MapFlags::from_bits((prot as usize) << 16) - .expect("mprotect: invalid bit pattern"), - )?; + (unsafe { + syscall::mprotect( + addr as usize, + len, + syscall::MapFlags::from_bits((prot as usize) << 16) + .expect("mprotect: invalid bit pattern"), + ) + })?; Ok(()) } @@ -853,7 +857,7 @@ impl Pal for Sys { let Some(len) = round_up_to_page_size(len) else { return Err(Errno(ENOMEM)); }; - syscall::funmap(addr as usize, len)?; + (unsafe { syscall::funmap(addr as usize, len) })?; Ok(()) } @@ -969,7 +973,7 @@ impl Pal for Sys { os_specific: &mut OsSpecific, ) -> Result { let _guard = CLONE_LOCK.read(); - let res = clone::rlct_clone_impl(stack, os_specific); + let res = unsafe { clone::rlct_clone_impl(stack, os_specific) }; res.map(|thread_fd| crate::pthread::OsTid { thread_fd }) .map_err(|error| Errno(error.errno)) @@ -1504,6 +1508,6 @@ impl Pal for Sys { } unsafe fn exit_thread(stack_base: *mut (), stack_size: usize) -> ! { - redox_rt::thread::exit_this_thread(stack_base, stack_size) + unsafe { redox_rt::thread::exit_this_thread(stack_base, stack_size) } } } diff --git a/src/platform/redox/ptrace.rs b/src/platform/redox/ptrace.rs index 34a35346ec..e31745a24b 100644 --- a/src/platform/redox/ptrace.rs +++ b/src/platform/redox/ptrace.rs @@ -276,7 +276,7 @@ impl PalPtrace for Sys { addr: *mut c_void, data: *mut c_void, ) -> Result { - inner_ptrace(request, pid, addr, data) + unsafe { inner_ptrace(request, pid, addr, data) } .map_err(|err| Errno(err.raw_os_error().unwrap_or(EIO))) } } diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 33f0645e8a..17eaab7473 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -200,7 +200,7 @@ impl PalSignal for Sys { .transpose()?; let mut old = old_c.as_ref().map(|_| Sigaltstack::default()); - redox_rt::signal::sigaltstack(new.as_ref(), old.as_mut())?; + (unsafe { redox_rt::signal::sigaltstack(new.as_ref(), old.as_mut()) })?; if let (Some(old_c_stack), Some(old)) = (old_c, old) { let c_stack = PosixStackt::from(old); diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index d74ed1b88f..c26cae433d 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -41,17 +41,19 @@ unsafe fn bind_or_connect( return Err(Errno(EINVAL)); } - let path = match (*address).sa_family as c_int { + let path = match unsafe { (*address).sa_family } as c_int { AF_INET => { if (address_len as usize) != mem::size_of::() { return Err(Errno(EINVAL)); } - let data = &*(address as *const sockaddr_in); - let addr = slice::from_raw_parts( - &data.sin_addr.s_addr as *const _ as *const u8, - mem::size_of_val(&data.sin_addr.s_addr), - ); + let data = unsafe { &*(address as *const sockaddr_in) }; + let addr = unsafe { + slice::from_raw_parts( + &data.sin_addr.s_addr as *const _ as *const u8, + mem::size_of_val(&data.sin_addr.s_addr), + ) + }; let port = in_port_t::from_be(data.sin_port); match op { @@ -81,18 +83,19 @@ pub unsafe fn bind_or_connect_into( address_len: socklen_t, ) -> Result { // Duplicate the socket, and then duplicate the copy back to the original fd - let fd = FdGuard::new(bind_or_connect(op, socket, address, address_len)?); + let fd = FdGuard::new(unsafe { bind_or_connect(op, socket, address, address_len) }?); syscall::dup2(fd.as_raw_fd(), socket as usize, &[])?; Ok(0) } unsafe fn inner_af_unix(buf: &[u8], address: *mut sockaddr, address_len: *mut socklen_t) { - let data = &mut *(address as *mut sockaddr_un); + let data = unsafe { &mut *(address as *mut sockaddr_un) }; data.sun_family = AF_UNIX as c_ushort; - let path = - slice::from_raw_parts_mut(&mut data.sun_path as *mut _ as *mut u8, data.sun_path.len()); + let path = unsafe { + slice::from_raw_parts_mut(&mut data.sun_path as *mut _ as *mut u8, data.sun_path.len()) + }; let len = cmp::min(path.len(), buf.len()); path[..len].copy_from_slice(&buf[..len]); @@ -100,7 +103,7 @@ unsafe fn inner_af_unix(buf: &[u8], address: *mut sockaddr, address_len: *mut so path[len] = 0; } - *address_len = len as socklen_t; + unsafe { *address_len = len as socklen_t }; } unsafe fn inner_af_inet( @@ -131,7 +134,7 @@ unsafe fn inner_af_inet( let mut addr = in_addr::default(); assert_eq!( - inet_aton(raw_addr.as_ptr() as *mut c_char, &mut addr), + unsafe { inet_aton(raw_addr.as_ptr() as *mut c_char, &mut addr) }, 1, "inet_aton might be broken, failed to parse netstack address" ); @@ -143,10 +146,12 @@ unsafe fn inner_af_inet( ..sockaddr_in::default() }; - let len = cmp::min(*address_len as usize, mem::size_of_val(&ret)); + let len = cmp::min(unsafe { *address_len } as usize, mem::size_of_val(&ret)); - ptr::copy_nonoverlapping(&ret as *const _ as *const u8, address as *mut u8, len); - *address_len = len as socklen_t; + unsafe { + ptr::copy_nonoverlapping(&ret as *const _ as *const u8, address as *mut u8, len); + *address_len = len as socklen_t; + } } unsafe fn inner_get_name_inner( @@ -156,17 +161,17 @@ unsafe fn inner_get_name_inner( buf: &[u8], ) -> Result<()> { if buf.starts_with(b"tcp:") || buf.starts_with(b"udp:") { - inner_af_inet(local, &buf[4..], address, address_len); + unsafe { inner_af_inet(local, &buf[4..], address, address_len) }; } else if buf.starts_with(b"/scheme/tcp/") || buf.starts_with(b"/scheme/udp/") { - inner_af_inet(local, &buf[12..], address, address_len); + unsafe { inner_af_inet(local, &buf[12..], address, address_len) }; } else if buf.starts_with(b"chan:") { - inner_af_unix(&buf[5..], address, address_len); + unsafe { inner_af_unix(&buf[5..], address, address_len) }; } else if buf.starts_with(b"/scheme/chan/") { - inner_af_unix(&buf[13..], address, address_len); + unsafe { inner_af_unix(&buf[13..], address, address_len) }; } else if buf.starts_with(b"/scheme/uds_stream/") { - inner_af_unix(&buf[19..], address, address_len); + unsafe { inner_af_unix(&buf[19..], address, address_len) }; } else if buf.starts_with(b"/scheme/uds_dgram/") { - inner_af_unix(&buf[18..], address, address_len); + unsafe { inner_af_unix(&buf[18..], address, address_len) }; } else { // Socket doesn't belong to any scheme trace!( @@ -239,12 +244,12 @@ unsafe fn serialize_ancillary_data_to_stream( return Err(Errno(EINVAL)); } - let mut cmsg: *mut cmsghdr = CMSG_FIRSTHDR(msg); + let mut cmsg: *mut cmsghdr = unsafe { CMSG_FIRSTHDR(msg) }; let mut cmsg_count = 0; while !cmsg.is_null() { cmsg_count += 1; - let current_cmsg = &*cmsg; - let min_cmsg_len = CMSG_ALIGN(mem::size_of::()); + let current_cmsg = unsafe { &*cmsg }; + let min_cmsg_len = unsafe { CMSG_ALIGN(mem::size_of::()) }; if current_cmsg.cmsg_len < min_cmsg_len { return Err(Errno(EINVAL)); } @@ -263,8 +268,8 @@ unsafe fn serialize_ancillary_data_to_stream( // Call syscall::sendfd for each fd. if fd_count > 0 { - let fds_ptr = CMSG_DATA(cmsg) as *const c_int; - let fds_slice = slice::from_raw_parts(fds_ptr, fd_count); + let fds_ptr = unsafe { CMSG_DATA(cmsg) } as *const c_int; + let fds_slice = unsafe { slice::from_raw_parts(fds_ptr, fd_count) }; for &fd in fds_slice.iter() { let fd_to_send = FdGuard::new(syscall::dup(fd as usize, b"")?); syscall::sendfd(socket as usize, fd_to_send.as_raw_fd(), 0, 0)?; @@ -288,7 +293,7 @@ unsafe fn serialize_ancillary_data_to_stream( return Err(Errno(EOPNOTSUPP)); } } - cmsg = CMSG_NXTHDR(msg, cmsg); + cmsg = unsafe { CMSG_NXTHDR(msg, cmsg) }; } Ok(()) } @@ -309,12 +314,14 @@ unsafe fn deserialize_name_from_stream( } if !mhdr.msg_name.is_null() && mhdr.msg_namelen > 0 { let name_buffer = &msg_stream[*cursor..*cursor + name_len]; - inner_get_name_inner( - false, - mhdr.msg_name as *mut sockaddr, - &mut mhdr.msg_namelen, - name_buffer, - )?; + (unsafe { + inner_get_name_inner( + false, + mhdr.msg_name as *mut sockaddr, + &mut mhdr.msg_namelen, + name_buffer, + ) + })?; } *cursor += name_len; } else { @@ -387,7 +394,7 @@ unsafe fn deserialize_ancillary_data_from_stream( ) -> Result<()> { let mut current_cmsg_ptr_in_user_buf = if !mhdr.msg_control.is_null() && cmsg_space_provided > 0 { - CMSG_FIRSTHDR(mhdr) + unsafe { CMSG_FIRSTHDR(mhdr) } } else { ptr::null_mut() }; @@ -464,27 +471,31 @@ unsafe fn deserialize_ancillary_data_from_stream( } } - let space_needed_for_posix_cmsg = CMSG_SPACE(actual_posix_cmsg_data_len as u32) as usize; + let space_needed_for_posix_cmsg = + unsafe { CMSG_SPACE(actual_posix_cmsg_data_len as u32) } as usize; if !current_cmsg_ptr_in_user_buf.is_null() && remaining_user_cmsg_buf_len >= space_needed_for_posix_cmsg { - let cmsg_ref = &mut *current_cmsg_ptr_in_user_buf; - cmsg_ref.cmsg_len = CMSG_LEN(actual_posix_cmsg_data_len as u32) as usize; + let cmsg_ref = unsafe { &mut *current_cmsg_ptr_in_user_buf }; + cmsg_ref.cmsg_len = unsafe { CMSG_LEN(actual_posix_cmsg_data_len as u32) } as usize; cmsg_ref.cmsg_level = cmsg_level; cmsg_ref.cmsg_type = cmsg_type; - let data_ptr_in_user_cmsg = CMSG_DATA(cmsg_ref); - ptr::copy_nonoverlapping( - temp_posix_cmsg_data_buf.as_ptr(), - data_ptr_in_user_cmsg as *mut u8, - actual_posix_cmsg_data_len, - ); + let data_ptr_in_user_cmsg = unsafe { CMSG_DATA(cmsg_ref) }; + unsafe { + ptr::copy_nonoverlapping( + temp_posix_cmsg_data_buf.as_ptr(), + data_ptr_in_user_cmsg as *mut u8, + actual_posix_cmsg_data_len, + ) + }; - let aligned_len_written = CMSG_ALIGN(cmsg_ref.cmsg_len); + let aligned_len_written = unsafe { CMSG_ALIGN(cmsg_ref.cmsg_len) }; total_csmg_bytes_written_to_user_buf += aligned_len_written; remaining_user_cmsg_buf_len -= aligned_len_written; - current_cmsg_ptr_in_user_buf = CMSG_NXTHDR(mhdr, current_cmsg_ptr_in_user_buf); + current_cmsg_ptr_in_user_buf = + unsafe { CMSG_NXTHDR(mhdr, current_cmsg_ptr_in_user_buf) }; } else { mhdr.msg_flags |= MSG_CTRUNC; break; @@ -502,7 +513,7 @@ impl PalSocket for Sys { ) -> Result { let stream = syscall::dup(socket as usize, b"listen")?; if address != ptr::null_mut() && address_len != ptr::null_mut() { - if let Err(err) = Self::getpeername(stream as c_int, address, address_len) { + if let Err(err) = unsafe { Self::getpeername(stream as c_int, address, address_len) } { let _ = syscall::close(stream); return Err(err); } @@ -511,12 +522,12 @@ impl PalSocket for Sys { } unsafe fn bind(socket: c_int, address: *const sockaddr, address_len: socklen_t) -> Result<()> { - match (*address).sa_family as c_int { + match unsafe { (*address).sa_family } as c_int { AF_INET => { - bind_or_connect_into(SocketCall::Bind, socket, address, address_len)?; + (unsafe { bind_or_connect_into(SocketCall::Bind, socket, address, address_len) })?; } AF_UNIX => { - let data = &*(address as *const sockaddr_un); + let data = unsafe { &*(address as *const sockaddr_un) }; // NOTE: It's UB to access data in given address that exceeds // the given address length. @@ -531,10 +542,11 @@ impl PalSocket for Sys { // The maximum length of the address maxlen, // The first NUL byte, if any - strnlen(&data.sun_path as *const _, maxlen as size_t), + unsafe { strnlen(&data.sun_path as *const _, maxlen as size_t) }, ); - let addr = slice::from_raw_parts(&data.sun_path as *const _ as *const u8, len); + let addr = + unsafe { slice::from_raw_parts(&data.sun_path as *const _ as *const u8, len) }; let path = format!("{}", str::from_utf8(addr).unwrap()); trace!("path: {:?}", path); @@ -542,7 +554,7 @@ impl PalSocket for Sys { redox_rt::sys::sys_call( socket as usize, - fd_path.as_bytes_mut(), + unsafe { fd_path.as_bytes_mut() }, CallFlags::empty(), &[SocketCall::Bind as u64], )?; @@ -586,10 +598,12 @@ impl PalSocket for Sys { address: *const sockaddr, address_len: socklen_t, ) -> Result { - match (*address).sa_family as c_int { - AF_INET => bind_or_connect_into(SocketCall::Connect, socket, address, address_len), + match unsafe { (*address).sa_family } as c_int { + AF_INET => unsafe { + bind_or_connect_into(SocketCall::Connect, socket, address, address_len) + }, AF_UNIX => { - let data = &*(address as *const sockaddr_un); + let data = unsafe { &*(address as *const sockaddr_un) }; // NOTE: It's UB to access data in given address that exceeds // the given address length. @@ -604,10 +618,11 @@ impl PalSocket for Sys { // The maximum length of the address maxlen, // The first NUL byte, if any - strnlen(&data.sun_path as *const _, maxlen as size_t), + unsafe { strnlen(&data.sun_path as *const _, maxlen as size_t) }, ); - let addr = slice::from_raw_parts(&data.sun_path as *const _ as *const u8, len); + let addr = + unsafe { slice::from_raw_parts(&data.sun_path as *const _ as *const u8, len) }; let mut path = format!("{}", str::from_utf8(addr).unwrap()); trace!("path: {:?}", path); @@ -652,7 +667,7 @@ impl PalSocket for Sys { &[SocketCall::GetPeerName as u64], )?; - inner_get_name_inner(false, address, address_len, &buf[..len]) + unsafe { inner_get_name_inner(false, address, address_len, &buf[..len]) } } unsafe fn getsockname( @@ -663,7 +678,7 @@ impl PalSocket for Sys { let mut buf = [0; 256]; let len = syscall::fpath(socket as usize, &mut buf)?; - inner_get_name_inner(true, address, address_len, &buf[..len]) + unsafe { inner_get_name_inner(true, address, address_len, &buf[..len]) } } unsafe fn getsockopt( @@ -676,7 +691,7 @@ impl PalSocket for Sys { if option_len_ptr.is_null() { return Err(Errno(EFAULT)); } - let option_len = (*option_len_ptr) as usize; + let option_len = (unsafe { *option_len_ptr }) as usize; let option_c_int = || -> Result<&mut c_int> { if option_value.is_null() { @@ -695,32 +710,35 @@ impl PalSocket for Sys { SO_DOMAIN => { let option = option_c_int()?; *option = socket_domain_type(socket)?.0; - *option_len_ptr = mem::size_of::() as socklen_t; + unsafe { *option_len_ptr = mem::size_of::() as socklen_t }; return Ok(()); } SO_ERROR => { let option = option_c_int()?; //TODO: Socket nonblock connection error *option = 0; - *option_len_ptr = mem::size_of::() as socklen_t; + unsafe { *option_len_ptr = mem::size_of::() as socklen_t }; return Ok(()); } SO_TYPE => { let option = option_c_int()?; *option = socket_domain_type(socket)?.1; - *option_len_ptr = mem::size_of::() as socklen_t; + unsafe { *option_len_ptr = mem::size_of::() as socklen_t }; return Ok(()); } _ => { let metadata = [SocketCall::GetSockOpt as u64, option_name as u64]; - let payload = slice::from_raw_parts_mut(option_value as *mut u8, option_len); + let payload = + unsafe { slice::from_raw_parts_mut(option_value as *mut u8, option_len) }; let call_flags = CallFlags::empty(); - *option_len_ptr = redox_rt::sys::sys_call( - socket as usize, - payload, - CallFlags::empty(), - &metadata, - )? as socklen_t; + unsafe { + *option_len_ptr = redox_rt::sys::sys_call( + socket as usize, + payload, + CallFlags::empty(), + &metadata, + )? as socklen_t; + } return Ok(()); } }, @@ -756,7 +774,7 @@ impl PalSocket for Sys { let mut msg = msghdr { msg_name: address as *mut c_void, msg_namelen: if !address_len.is_null() { - *address_len + unsafe { *address_len } } else { 0 }, @@ -766,26 +784,30 @@ impl PalSocket for Sys { msg_controllen: 0, msg_flags: 0, }; - let count = Self::recvmsg(socket, &mut msg, flags)?; + let count = unsafe { Self::recvmsg(socket, &mut msg, flags) }?; if !address_len.is_null() { - *address_len = msg.msg_namelen; + unsafe { *address_len = msg.msg_namelen }; } return Ok(count); } if address.is_null() || address_len.is_null() { - Self::read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) + Self::read(socket, unsafe { + slice::from_raw_parts_mut(buf as *mut u8, len) + }) } else { // TODO: in UDS dgram getpeername on listener always return ENOTCONN, // it probably the expected error on usual getpeername call, but not here. - if let Err(e) = Self::getpeername(socket, address, address_len) { + if let Err(e) = unsafe { Self::getpeername(socket, address, address_len) } { if e.0 != ENOTCONN { return Err(e); } - let data = &mut *(address as *mut sockaddr); + let data = unsafe { &mut *(address as *mut sockaddr) }; data.sa_family = AF_UNSPEC as u16; - *address_len = 0; + unsafe { *address_len = 0 }; } - Self::read(socket, slice::from_raw_parts_mut(buf as *mut u8, len)) + Self::read(socket, unsafe { + slice::from_raw_parts_mut(buf as *mut u8, len) + }) } } @@ -793,7 +815,7 @@ impl PalSocket for Sys { if msg.is_null() { return Err(Errno(EINVAL)); } - let mut mhdr = &mut *msg; + let mut mhdr = unsafe { &mut *msg }; let iovs_slice: &[iovec] = if mhdr.msg_iov.is_null() || mhdr.msg_iovlen == 0 { &[] } else { @@ -843,29 +865,33 @@ impl PalSocket for Sys { mhdr.msg_flags = 0; // Read sender name. - deserialize_name_from_stream(&mut mhdr, &msg_stream, &mut cursor)?; + (unsafe { deserialize_name_from_stream(&mut mhdr, &msg_stream, &mut cursor) })?; // Read payload data. - let actual_payload_bytes_written_to_iov = deserialize_payload_from_stream( - &mut mhdr, - &msg_stream, - iovs_slice, - whole_iov_size, - &mut cursor, - 0u8, - )?; + let actual_payload_bytes_written_to_iov = unsafe { + deserialize_payload_from_stream( + &mut mhdr, + &msg_stream, + iovs_slice, + whole_iov_size, + &mut cursor, + 0u8, + ) + }?; // Reconstruct the ancillary data in the user-provided buffer. let has_cmsg_buffer = !mhdr.msg_control.is_null() && cmsg_space_provided_by_user > 0; let has_ancillary_data = cursor < msg_stream.len(); if has_cmsg_buffer && has_ancillary_data { - deserialize_ancillary_data_from_stream( - mhdr, - socket, - &msg_stream, - &mut cursor, - cmsg_space_provided_by_user as usize, - )?; + (unsafe { + deserialize_ancillary_data_from_stream( + mhdr, + socket, + &msg_stream, + &mut cursor, + cmsg_space_provided_by_user as usize, + ) + })?; } else { mhdr.msg_controllen = 0; // No ancillary data } @@ -876,7 +902,7 @@ impl PalSocket for Sys { if msg.is_null() { return Err(Errno(EINVAL)); } - let mhdr = &*msg; + let mhdr = unsafe { &*msg }; // Reserve space for the message stream. // [payload_len(usize)][payload_data_buffer] @@ -900,12 +926,13 @@ impl PalSocket for Sys { // Write the message to the msg_stream. let mut actual_payload_bytes_serialized = 0; if !mhdr.msg_iov.is_null() && mhdr.msg_iovlen > 0 { - actual_payload_bytes_serialized = - serialize_payload_to_stream(&mut msg_stream, &iovs_slice, whole_iov_size)?; + actual_payload_bytes_serialized = unsafe { + serialize_payload_to_stream(&mut msg_stream, &iovs_slice, whole_iov_size) + }?; } // Process Control Messages from msghdr and serialize them. if mhdr.msg_controllen > 0 { - serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream)?; + (unsafe { serialize_ancillary_data_to_stream(msg, mhdr, socket, &mut msg_stream) })?; } // Send the message stream. @@ -944,21 +971,19 @@ impl PalSocket for Sys { msg_controllen: 0, msg_flags: 0, }; - return Self::sendmsg(socket, &msg, flags); + return unsafe { Self::sendmsg(socket, &msg, flags) }; } if dest_addr == ptr::null() || dest_len == 0 { - Self::write(socket, slice::from_raw_parts(buf as *const u8, len)) + Self::write(socket, unsafe { + slice::from_raw_parts(buf as *const u8, len) + }) } else { - let fd = FdGuard::new(bind_or_connect( - SocketCall::Connect, - socket, - dest_addr, - dest_len, - )?); - Self::write( - fd.as_c_fd().unwrap(), - slice::from_raw_parts(buf as *const u8, len), - ) + let fd = FdGuard::new(unsafe { + bind_or_connect(SocketCall::Connect, socket, dest_addr, dest_len) + }?); + Self::write(fd.as_c_fd().unwrap(), unsafe { + slice::from_raw_parts(buf as *const u8, len) + }) } } @@ -1001,8 +1026,9 @@ impl PalSocket for Sys { SO_SNDTIMEO => return set_timeout(b"write_timeout"), _ => { let metadata = [SocketCall::SetSockOpt as u64, option_name as u64]; - let payload = - slice::from_raw_parts_mut(option_value as *mut u8, option_len as usize); + let payload = unsafe { + slice::from_raw_parts_mut(option_value as *mut u8, option_len as usize) + }; let call_flags = CallFlags::empty(); redox_rt::sys::sys_call( socket as usize, diff --git a/src/pthread/mod.rs b/src/pthread/mod.rs index ad49f731cf..de5d92b78a 100644 --- a/src/pthread/mod.rs +++ b/src/pthread/mod.rs @@ -1,8 +1,5 @@ //! Relibc Threads, or RLCT. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::{ cell::UnsafeCell, mem::MaybeUninit, diff --git a/src/raw_cell.rs b/src/raw_cell.rs index 3f311f9d6d..998fccdca0 100644 --- a/src/raw_cell.rs +++ b/src/raw_cell.rs @@ -1,6 +1,3 @@ -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use core::cell::UnsafeCell; /// Wrapper over `UnsafeCell` that can directly be used in statics, where all modifications require diff --git a/src/start.rs b/src/start.rs index 4d5257b693..eb72e34ce6 100644 --- a/src/start.rs +++ b/src/start.rs @@ -1,8 +1,5 @@ //! Startup code. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - use alloc::{boxed::Box, vec::Vec}; use core::{intrinsics, ptr}; use generic_rt::ExpectTlsFree; diff --git a/src/sync/mod.rs b/src/sync/mod.rs index dfbdf5a584..8681145c7d 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1,8 +1,5 @@ //! Synchronization primitives. -// TODO: set this for entire crate when possible -#![deny(unsafe_op_in_unsafe_fn)] - pub mod barrier; pub mod cond; // TODO: Merge with pthread_mutex