library: use addr_of!
This commit is contained in:
parent
8f359beca4
commit
ff187a92d8
@ -176,7 +176,7 @@ fn data(&self) -> *mut u8 {
|
||||
|
||||
fn with_header(&self) -> &WithHeader<<T as Pointee>::Metadata> {
|
||||
// SAFETY: both types are transparent to `NonNull<u8>`
|
||||
unsafe { &*((&self.ptr) as *const WithOpaqueHeader as *const WithHeader<_>) }
|
||||
unsafe { &*(core::ptr::addr_of!(self.ptr) as *const WithHeader<_>) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1969,7 +1969,7 @@ fn from_box_in(src: Box<T, A>) -> Rc<T, A> {
|
||||
|
||||
// Copy value as bytes
|
||||
ptr::copy_nonoverlapping(
|
||||
&*src as *const T as *const u8,
|
||||
core::ptr::addr_of!(*src) as *const u8,
|
||||
ptr::addr_of_mut!((*ptr).value) as *mut u8,
|
||||
value_size,
|
||||
);
|
||||
@ -2440,7 +2440,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized, A: Allocator> fmt::Pointer for Rc<T, A> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Pointer::fmt(&(&**self as *const T), f)
|
||||
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1914,7 +1914,7 @@ fn from_box_in(src: Box<T, A>) -> Arc<T, A> {
|
||||
|
||||
// Copy value as bytes
|
||||
ptr::copy_nonoverlapping(
|
||||
&*src as *const T as *const u8,
|
||||
core::ptr::addr_of!(*src) as *const u8,
|
||||
ptr::addr_of_mut!((*ptr).data) as *mut u8,
|
||||
value_size,
|
||||
);
|
||||
@ -3265,7 +3265,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized, A: Allocator> fmt::Pointer for Arc<T, A> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Pointer::fmt(&(&**self as *const T), f)
|
||||
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
use crate::fmt;
|
||||
use crate::intrinsics;
|
||||
use crate::ops;
|
||||
use crate::ptr::addr_of;
|
||||
use crate::slice;
|
||||
use crate::slice::memchr;
|
||||
use crate::str;
|
||||
@ -603,7 +604,7 @@ pub const fn to_bytes(&self) -> &[u8] {
|
||||
pub const fn to_bytes_with_nul(&self) -> &[u8] {
|
||||
// SAFETY: Transmuting a slice of `c_char`s to a slice of `u8`s
|
||||
// is safe on all supported targets.
|
||||
unsafe { &*(&self.inner as *const [c_char] as *const [u8]) }
|
||||
unsafe { &*(addr_of!(self.inner) as *const [u8]) }
|
||||
}
|
||||
|
||||
/// Yields a <code>&[str]</code> slice if the `CStr` contains valid UTF-8.
|
||||
|
@ -2,6 +2,7 @@
|
||||
use crate::mem::{ManuallyDrop, MaybeUninit};
|
||||
use crate::num::NonZero;
|
||||
use crate::ops::{ControlFlow, Try};
|
||||
use crate::ptr::addr_of;
|
||||
use crate::{array, fmt};
|
||||
|
||||
/// An iterator that uses `f` to both filter and map elements from `iter`.
|
||||
@ -98,9 +99,8 @@ fn drop(&mut self) {
|
||||
// SAFETY: Loop conditions ensure the index is in bounds.
|
||||
|
||||
unsafe {
|
||||
let opt_payload_at: *const MaybeUninit<B> = (&val as *const Option<B>)
|
||||
.byte_add(core::mem::offset_of!(Option<B>, Some.0))
|
||||
.cast();
|
||||
let opt_payload_at: *const MaybeUninit<B> =
|
||||
addr_of!(val).byte_add(core::mem::offset_of!(Option<B>, Some.0)).cast();
|
||||
let dst = guard.array.as_mut_ptr().add(idx);
|
||||
crate::ptr::copy_nonoverlapping(opt_payload_at, dst, 1);
|
||||
crate::mem::forget(val);
|
||||
|
@ -1553,7 +1553,7 @@ macro_rules! attempt_swap_as_chunks {
|
||||
// `dst` cannot overlap `src` because the caller has mutable access
|
||||
// to `dst` while `src` is owned by this function.
|
||||
unsafe {
|
||||
copy_nonoverlapping(&src as *const T as *const u8, dst as *mut u8, mem::size_of::<T>());
|
||||
copy_nonoverlapping(addr_of!(src) as *const u8, dst as *mut u8, mem::size_of::<T>());
|
||||
// We are calling the intrinsic directly to avoid function calls in the generated code.
|
||||
intrinsics::forget(src);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ mod libc {
|
||||
fn sun_path_offset(addr: &libc::sockaddr_un) -> usize {
|
||||
// Work with an actual instance of the type since using a null pointer is UB
|
||||
let base = (addr as *const libc::sockaddr_un).addr();
|
||||
let path = (&addr.sun_path as *const libc::c_char).addr();
|
||||
let path = core::ptr::addr_of!(addr.sun_path).addr();
|
||||
path - base
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ pub(super) fn new<F>(f: F) -> io::Result<SocketAddr>
|
||||
unsafe {
|
||||
let mut addr: libc::sockaddr_un = mem::zeroed();
|
||||
let mut len = mem::size_of::<libc::sockaddr_un>() as libc::socklen_t;
|
||||
cvt(f(&mut addr as *mut _ as *mut _, &mut len))?;
|
||||
cvt(f(core::ptr::addr_of_mut!(addr) as *mut _, &mut len))?;
|
||||
SocketAddr::from_parts(addr, len)
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ pub(super) fn recv_vectored_with_ancillary_from(
|
||||
unsafe {
|
||||
let mut msg_name: libc::sockaddr_un = zeroed();
|
||||
let mut msg: libc::msghdr = zeroed();
|
||||
msg.msg_name = &mut msg_name as *mut _ as *mut _;
|
||||
msg.msg_name = core::ptr::addr_of_mut!(msg_name) as *mut _;
|
||||
msg.msg_namelen = size_of::<libc::sockaddr_un>() as libc::socklen_t;
|
||||
msg.msg_iov = bufs.as_mut_ptr().cast();
|
||||
msg.msg_iovlen = bufs.len() as _;
|
||||
@ -70,7 +70,7 @@ pub(super) fn send_vectored_with_ancillary_to(
|
||||
if let Some(path) = path { sockaddr_un(path)? } else { (zeroed(), 0) };
|
||||
|
||||
let mut msg: libc::msghdr = zeroed();
|
||||
msg.msg_name = &mut msg_name as *mut _ as *mut _;
|
||||
msg.msg_name = core::ptr::addr_of_mut!(msg_name) as *mut _;
|
||||
msg.msg_namelen = msg_namelen;
|
||||
msg.msg_iov = bufs.as_ptr() as *mut _;
|
||||
msg.msg_iovlen = bufs.len() as _;
|
||||
|
@ -91,7 +91,7 @@ pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
|
||||
let socket = UnixDatagram::unbound()?;
|
||||
let (addr, len) = sockaddr_un(path.as_ref())?;
|
||||
|
||||
cvt(libc::bind(socket.as_raw_fd(), &addr as *const _ as *const _, len as _))?;
|
||||
cvt(libc::bind(socket.as_raw_fd(), core::ptr::addr_of!(addr) as *const _, len as _))?;
|
||||
|
||||
Ok(socket)
|
||||
}
|
||||
@ -124,7 +124,7 @@ pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixDatagram> {
|
||||
let socket = UnixDatagram::unbound()?;
|
||||
cvt(libc::bind(
|
||||
socket.as_raw_fd(),
|
||||
&socket_addr.addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(socket_addr.addr) as *const _,
|
||||
socket_addr.len as _,
|
||||
))?;
|
||||
Ok(socket)
|
||||
@ -206,7 +206,7 @@ pub fn connect<P: AsRef<Path>>(&self, path: P) -> io::Result<()> {
|
||||
unsafe {
|
||||
let (addr, len) = sockaddr_un(path.as_ref())?;
|
||||
|
||||
cvt(libc::connect(self.as_raw_fd(), &addr as *const _ as *const _, len))?;
|
||||
cvt(libc::connect(self.as_raw_fd(), core::ptr::addr_of!(addr) as *const _, len))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -238,7 +238,7 @@ pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> {
|
||||
unsafe {
|
||||
cvt(libc::connect(
|
||||
self.as_raw_fd(),
|
||||
&socket_addr.addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(socket_addr.addr) as *const _,
|
||||
socket_addr.len,
|
||||
))?;
|
||||
}
|
||||
@ -505,7 +505,7 @@ pub fn send_to<P: AsRef<Path>>(&self, buf: &[u8], path: P) -> io::Result<usize>
|
||||
buf.as_ptr() as *const _,
|
||||
buf.len(),
|
||||
MSG_NOSIGNAL,
|
||||
&addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(addr) as *const _,
|
||||
len,
|
||||
))?;
|
||||
Ok(count as usize)
|
||||
@ -540,7 +540,7 @@ pub fn send_to_addr(&self, buf: &[u8], socket_addr: &SocketAddr) -> io::Result<u
|
||||
buf.as_ptr() as *const _,
|
||||
buf.len(),
|
||||
MSG_NOSIGNAL,
|
||||
&socket_addr.addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(socket_addr.addr) as *const _,
|
||||
socket_addr.len,
|
||||
))?;
|
||||
Ok(count as usize)
|
||||
|
@ -99,7 +99,11 @@ pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
|
||||
)))]
|
||||
const backlog: libc::c_int = libc::SOMAXCONN;
|
||||
|
||||
cvt(libc::bind(inner.as_inner().as_raw_fd(), &addr as *const _ as *const _, len as _))?;
|
||||
cvt(libc::bind(
|
||||
inner.as_inner().as_raw_fd(),
|
||||
core::ptr::addr_of!(addr) as *const _,
|
||||
len as _,
|
||||
))?;
|
||||
cvt(libc::listen(inner.as_inner().as_raw_fd(), backlog))?;
|
||||
|
||||
Ok(UnixListener(inner))
|
||||
@ -139,7 +143,7 @@ pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
|
||||
const backlog: libc::c_int = 128;
|
||||
cvt(libc::bind(
|
||||
inner.as_raw_fd(),
|
||||
&socket_addr.addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(socket_addr.addr) as *const _,
|
||||
socket_addr.len as _,
|
||||
))?;
|
||||
cvt(libc::listen(inner.as_raw_fd(), backlog))?;
|
||||
@ -174,7 +178,7 @@ pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
|
||||
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
|
||||
let mut storage: libc::sockaddr_un = unsafe { mem::zeroed() };
|
||||
let mut len = mem::size_of_val(&storage) as libc::socklen_t;
|
||||
let sock = self.0.accept(&mut storage as *mut _ as *mut _, &mut len)?;
|
||||
let sock = self.0.accept(core::ptr::addr_of_mut!(storage) as *mut _, &mut len)?;
|
||||
let addr = SocketAddr::from_parts(storage, len)?;
|
||||
Ok((UnixStream(sock), addr))
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
|
||||
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
|
||||
let (addr, len) = sockaddr_un(path.as_ref())?;
|
||||
|
||||
cvt(libc::connect(inner.as_raw_fd(), &addr as *const _ as *const _, len))?;
|
||||
cvt(libc::connect(inner.as_raw_fd(), core::ptr::addr_of!(addr) as *const _, len))?;
|
||||
Ok(UnixStream(inner))
|
||||
}
|
||||
}
|
||||
@ -130,7 +130,7 @@ pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result<UnixStream> {
|
||||
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
|
||||
cvt(libc::connect(
|
||||
inner.as_raw_fd(),
|
||||
&socket_addr.addr as *const _ as *const _,
|
||||
core::ptr::addr_of!(socket_addr.addr) as *const _,
|
||||
socket_addr.len,
|
||||
))?;
|
||||
Ok(UnixStream(inner))
|
||||
|
@ -62,7 +62,7 @@ pub fn peer_cred(socket: &UnixStream) -> io::Result<UCred> {
|
||||
socket.as_raw_fd(),
|
||||
SOL_SOCKET,
|
||||
SO_PEERCRED,
|
||||
&mut ucred as *mut ucred as *mut c_void,
|
||||
core::ptr::addr_of_mut!(ucred) as *mut c_void,
|
||||
&mut ucred_size,
|
||||
);
|
||||
|
||||
@ -122,7 +122,7 @@ pub fn peer_cred(socket: &UnixStream) -> io::Result<UCred> {
|
||||
socket.as_raw_fd(),
|
||||
SOL_LOCAL,
|
||||
LOCAL_PEERPID,
|
||||
&mut pid as *mut pid_t as *mut c_void,
|
||||
core::ptr::addr_of_mut!(pid) as *mut c_void,
|
||||
&mut pid_size,
|
||||
);
|
||||
|
||||
|
@ -502,7 +502,7 @@ union Data<F, R> {
|
||||
// method of calling a catch panic whilst juggling ownership.
|
||||
let mut data = Data { f: ManuallyDrop::new(f) };
|
||||
|
||||
let data_ptr = &mut data as *mut _ as *mut u8;
|
||||
let data_ptr = core::ptr::addr_of_mut!(data) as *mut u8;
|
||||
// SAFETY:
|
||||
//
|
||||
// Access to the union's fields: this is `std` and we know that the `r#try`
|
||||
|
@ -182,7 +182,11 @@ pub(crate) fn send(
|
||||
// Prepare for blocking until a receiver wakes us up.
|
||||
let oper = Operation::hook(token);
|
||||
let mut packet = Packet::<T>::message_on_stack(msg);
|
||||
inner.senders.register_with_packet(oper, &mut packet as *mut Packet<T> as *mut (), cx);
|
||||
inner.senders.register_with_packet(
|
||||
oper,
|
||||
core::ptr::addr_of_mut!(packet) as *mut (),
|
||||
cx,
|
||||
);
|
||||
inner.receivers.notify();
|
||||
drop(inner);
|
||||
|
||||
@ -251,7 +255,7 @@ pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutErr
|
||||
let mut packet = Packet::<T>::empty_on_stack();
|
||||
inner.receivers.register_with_packet(
|
||||
oper,
|
||||
&mut packet as *mut Packet<T> as *mut (),
|
||||
core::ptr::addr_of_mut!(packet) as *mut (),
|
||||
cx,
|
||||
);
|
||||
inner.senders.notify();
|
||||
|
@ -207,7 +207,7 @@ fn recv_from_with_flags(&self, buf: &mut [u8], flags: i32) -> io::Result<(usize,
|
||||
buf.as_mut_ptr(),
|
||||
buf.len(),
|
||||
flags,
|
||||
&mut storage as *mut _ as *mut _,
|
||||
core::ptr::addr_of_mut!(storage) as *mut _,
|
||||
&mut addrlen,
|
||||
)
|
||||
})?;
|
||||
@ -323,7 +323,7 @@ pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
||||
netc::ioctl(
|
||||
self.as_raw_fd(),
|
||||
netc::FIONBIO,
|
||||
&mut nonblocking as *mut _ as *mut core::ffi::c_void,
|
||||
core::ptr::addr_of_mut!(nonblocking) as *mut core::ffi::c_void,
|
||||
)
|
||||
})
|
||||
.map(drop)
|
||||
|
@ -100,7 +100,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
impl Instant {
|
||||
pub fn now() -> Instant {
|
||||
let mut time: Timespec = Timespec::zero();
|
||||
let _ = unsafe { abi::clock_gettime(CLOCK_MONOTONIC, &mut time.t as *mut timespec) };
|
||||
let _ = unsafe { abi::clock_gettime(CLOCK_MONOTONIC, core::ptr::addr_of_mut!(time.t)) };
|
||||
|
||||
Instant(time)
|
||||
}
|
||||
@ -197,7 +197,7 @@ fn sub(self, other: Instant) -> Duration {
|
||||
impl SystemTime {
|
||||
pub fn now() -> SystemTime {
|
||||
let mut time: Timespec = Timespec::zero();
|
||||
let _ = unsafe { abi::clock_gettime(CLOCK_REALTIME, &mut time.t as *mut timespec) };
|
||||
let _ = unsafe { abi::clock_gettime(CLOCK_REALTIME, core::ptr::addr_of_mut!(time.t)) };
|
||||
|
||||
SystemTime(time)
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ pub unsafe fn activate(&self) -> ActiveTls<'_> {
|
||||
#[allow(unused)]
|
||||
pub unsafe fn activate_persistent(self: Box<Self>) {
|
||||
// FIXME: Needs safety information. See entry.S for `set_tls_ptr` definition.
|
||||
unsafe { set_tls_ptr((&*self) as *const Tls as _) };
|
||||
unsafe { set_tls_ptr(core::ptr::addr_of!(*self) as _) };
|
||||
mem::forget(self);
|
||||
}
|
||||
|
||||
|
@ -1344,7 +1344,7 @@ pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
|
||||
}
|
||||
cvt(unsafe { libc::fsetattrlist(
|
||||
self.as_raw_fd(),
|
||||
(&attrlist as *const libc::attrlist).cast::<libc::c_void>().cast_mut(),
|
||||
core::ptr::addr_of!(attrlist).cast::<libc::c_void>().cast_mut(),
|
||||
buf.as_ptr().cast::<libc::c_void>().cast_mut(),
|
||||
num_times * mem::size_of::<libc::timespec>(),
|
||||
0
|
||||
@ -1744,7 +1744,7 @@ fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)>
|
||||
#[cfg(target_os = "espidf")]
|
||||
fn open_to_and_set_permissions(
|
||||
to: &Path,
|
||||
reader_metadata: crate::fs::Metadata,
|
||||
_reader_metadata: crate::fs::Metadata,
|
||||
) -> io::Result<(crate::fs::File, crate::fs::Metadata)> {
|
||||
use crate::fs::OpenOptions;
|
||||
let writer = OpenOptions::new().open(to)?;
|
||||
@ -1918,7 +1918,7 @@ fn fclonefileat(
|
||||
copyfile_state_get(
|
||||
state.0,
|
||||
COPYFILE_STATE_COPIED,
|
||||
&mut bytes_copied as *mut libc::off_t as *mut libc::c_void,
|
||||
core::ptr::addr_of_mut!(bytes_copied) as *mut libc::c_void,
|
||||
)
|
||||
})?;
|
||||
Ok(bytes_copied as u64)
|
||||
|
@ -38,7 +38,7 @@
|
||||
pub mod time;
|
||||
|
||||
#[cfg(target_os = "espidf")]
|
||||
pub fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {}
|
||||
pub fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}
|
||||
|
||||
#[cfg(not(target_os = "espidf"))]
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
|
@ -316,7 +316,7 @@ fn recv_from_with_flags(
|
||||
buf.as_mut_ptr() as *mut c_void,
|
||||
buf.len(),
|
||||
flags,
|
||||
&mut storage as *mut _ as *mut _,
|
||||
core::ptr::addr_of_mut!(storage) as *mut _,
|
||||
&mut addrlen,
|
||||
)
|
||||
})?;
|
||||
|
@ -182,7 +182,7 @@ pub fn wait(&mut self) -> io::Result<ExitStatus> {
|
||||
zx_cvt(zx_object_get_info(
|
||||
self.handle.raw(),
|
||||
ZX_INFO_PROCESS,
|
||||
&mut proc_info as *mut _ as *mut libc::c_void,
|
||||
core::ptr::addr_of_mut!(proc_info) as *mut libc::c_void,
|
||||
mem::size_of::<zx_info_process_t>(),
|
||||
&mut actual,
|
||||
&mut avail,
|
||||
@ -219,7 +219,7 @@ pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
|
||||
zx_cvt(zx_object_get_info(
|
||||
self.handle.raw(),
|
||||
ZX_INFO_PROCESS,
|
||||
&mut proc_info as *mut _ as *mut libc::c_void,
|
||||
core::ptr::addr_of_mut!(proc_info) as *mut libc::c_void,
|
||||
mem::size_of::<zx_info_process_t>(),
|
||||
&mut actual,
|
||||
&mut avail,
|
||||
|
@ -694,15 +694,15 @@ union Cmsg {
|
||||
let mut iov = [IoSlice::new(b"")];
|
||||
let mut msg: libc::msghdr = mem::zeroed();
|
||||
|
||||
msg.msg_iov = &mut iov as *mut _ as *mut _;
|
||||
msg.msg_iov = core::ptr::addr_of_mut!(iov) as *mut _;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
// only attach cmsg if we successfully acquired the pidfd
|
||||
if pidfd >= 0 {
|
||||
msg.msg_controllen = mem::size_of_val(&cmsg.buf) as _;
|
||||
msg.msg_control = &mut cmsg.buf as *mut _ as *mut _;
|
||||
msg.msg_control = core::ptr::addr_of_mut!(cmsg.buf) as *mut _;
|
||||
|
||||
let hdr = CMSG_FIRSTHDR(&mut msg as *mut _ as *mut _);
|
||||
let hdr = CMSG_FIRSTHDR(core::ptr::addr_of_mut!(msg) as *mut _);
|
||||
(*hdr).cmsg_level = SOL_SOCKET;
|
||||
(*hdr).cmsg_type = SCM_RIGHTS;
|
||||
(*hdr).cmsg_len = CMSG_LEN(SCM_MSG_LEN as _) as _;
|
||||
@ -744,17 +744,17 @@ union Cmsg {
|
||||
|
||||
let mut msg: libc::msghdr = mem::zeroed();
|
||||
|
||||
msg.msg_iov = &mut iov as *mut _ as *mut _;
|
||||
msg.msg_iov = core::ptr::addr_of_mut!(iov) as *mut _;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_controllen = mem::size_of::<Cmsg>() as _;
|
||||
msg.msg_control = &mut cmsg as *mut _ as *mut _;
|
||||
msg.msg_control = core::ptr::addr_of_mut!(cmsg) as *mut _;
|
||||
|
||||
match cvt_r(|| libc::recvmsg(sock.as_raw(), &mut msg, libc::MSG_CMSG_CLOEXEC)) {
|
||||
Err(_) => return -1,
|
||||
Ok(_) => {}
|
||||
}
|
||||
|
||||
let hdr = CMSG_FIRSTHDR(&mut msg as *mut _ as *mut _);
|
||||
let hdr = CMSG_FIRSTHDR(core::ptr::addr_of_mut!(msg) as *mut _);
|
||||
if hdr.is_null()
|
||||
|| (*hdr).cmsg_level != SOL_SOCKET
|
||||
|| (*hdr).cmsg_type != SCM_RIGHTS
|
||||
|
@ -239,7 +239,7 @@ pub fn sleep(dur: Duration) {
|
||||
tv_nsec: nsecs,
|
||||
};
|
||||
secs -= ts.tv_sec as u64;
|
||||
let ts_ptr = &mut ts as *mut _;
|
||||
let ts_ptr = core::ptr::addr_of_mut!(ts);
|
||||
if libc::nanosleep(ts_ptr, ts_ptr) == -1 {
|
||||
assert_eq!(os::errno(), libc::EINTR);
|
||||
secs += ts.tv_sec as u64;
|
||||
@ -418,8 +418,8 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
|
||||
libc::sysctl(
|
||||
mib.as_mut_ptr(),
|
||||
2,
|
||||
&mut cpus as *mut _ as *mut _,
|
||||
&mut cpus_size as *mut _ as *mut _,
|
||||
core::ptr::addr_of_mut!(cpus) as *mut _,
|
||||
core::ptr::addr_of_mut!(cpus_size) as *mut _,
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
)
|
||||
@ -864,7 +864,7 @@ pub unsafe fn init() -> Option<Guard> {
|
||||
.unwrap();
|
||||
match sysctlbyname.get() {
|
||||
Some(fcn) => {
|
||||
if fcn(oid.as_ptr(), &mut guard as *mut _ as *mut _, &mut size as *mut _ as *mut _, crate::ptr::null_mut(), 0) == 0 {
|
||||
if fcn(oid.as_ptr(), core::ptr::addr_of_mut!(guard) as *mut _, core::ptr::addr_of_mut!(size) as *mut _, crate::ptr::null_mut(), 0) == 0 {
|
||||
return guard;
|
||||
}
|
||||
return 1;
|
||||
|
@ -58,7 +58,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
unsafe extern "C" fn(*mut libc::c_void),
|
||||
>(dtor),
|
||||
t.cast(),
|
||||
&__dso_handle as *const _ as *mut _,
|
||||
core::ptr::addr_of!(__dso_handle) as *mut _,
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
@ -166,7 +166,7 @@ pub fn abort_internal() -> ! {
|
||||
pub fn hashmap_random_keys() -> (u64, u64) {
|
||||
let mut ret = (0u64, 0u64);
|
||||
unsafe {
|
||||
let base = &mut ret as *mut (u64, u64) as *mut u8;
|
||||
let base = core::ptr::addr_of_mut!(ret) as *mut u8;
|
||||
let len = mem::size_of_val(&ret);
|
||||
wasi::random_get(base, len).expect("random_get failure");
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ pub fn file_attr(&self) -> io::Result<FileAttr> {
|
||||
cvt(c::GetFileInformationByHandleEx(
|
||||
self.handle.as_raw_handle(),
|
||||
c::FileBasicInfo,
|
||||
&mut info as *mut _ as *mut c_void,
|
||||
core::ptr::addr_of_mut!(info) as *mut c_void,
|
||||
size as c::DWORD,
|
||||
))?;
|
||||
let mut attr = FileAttr {
|
||||
@ -422,7 +422,7 @@ pub fn file_attr(&self) -> io::Result<FileAttr> {
|
||||
cvt(c::GetFileInformationByHandleEx(
|
||||
self.handle.as_raw_handle(),
|
||||
c::FileStandardInfo,
|
||||
&mut info as *mut _ as *mut c_void,
|
||||
core::ptr::addr_of_mut!(info) as *mut c_void,
|
||||
size as c::DWORD,
|
||||
))?;
|
||||
attr.file_size = info.AllocationSize as u64;
|
||||
@ -638,7 +638,7 @@ fn basic_info(&self) -> io::Result<c::FILE_BASIC_INFO> {
|
||||
cvt(c::GetFileInformationByHandleEx(
|
||||
self.handle.as_raw_handle(),
|
||||
c::FileBasicInfo,
|
||||
&mut info as *mut _ as *mut c_void,
|
||||
core::ptr::addr_of_mut!(info) as *mut c_void,
|
||||
size as c::DWORD,
|
||||
))?;
|
||||
Ok(info)
|
||||
@ -1438,7 +1438,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
|
||||
pfrom.as_ptr(),
|
||||
pto.as_ptr(),
|
||||
Some(callback),
|
||||
&mut size as *mut _ as *mut _,
|
||||
core::ptr::addr_of_mut!(size) as *mut _,
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
)
|
||||
|
@ -122,7 +122,7 @@ struct FILE_NAME_INFO {
|
||||
let res = c::GetFileInformationByHandleEx(
|
||||
handle,
|
||||
c::FileNameInfo,
|
||||
&mut name_info as *mut _ as *mut c_void,
|
||||
core::ptr::addr_of_mut!(name_info) as *mut c_void,
|
||||
size_of::<FILE_NAME_INFO>() as u32,
|
||||
);
|
||||
if res == 0 {
|
||||
|
@ -310,7 +310,7 @@ fn recv_from_with_flags(
|
||||
buf.as_mut_ptr() as *mut _,
|
||||
length,
|
||||
flags,
|
||||
&mut storage as *mut _ as *mut _,
|
||||
core::ptr::addr_of_mut!(storage) as *mut _,
|
||||
&mut addrlen,
|
||||
)
|
||||
};
|
||||
|
@ -375,7 +375,7 @@ struct AsyncResult {
|
||||
let mut overlapped: c::OVERLAPPED = crate::mem::zeroed();
|
||||
// `hEvent` is unused by `ReadFileEx` and `WriteFileEx`.
|
||||
// Therefore the documentation suggests using it to smuggle a pointer to the callback.
|
||||
overlapped.hEvent = &mut async_result as *mut _ as *mut _;
|
||||
overlapped.hEvent = core::ptr::addr_of_mut!(async_result) as *mut _;
|
||||
|
||||
// Asynchronous read of the pipe.
|
||||
// If successful, `callback` will be called once it completes.
|
||||
|
@ -350,10 +350,10 @@ pub fn spawn(
|
||||
StartupInfo: si,
|
||||
lpAttributeList: proc_thread_attribute_list.0.as_mut_ptr() as _,
|
||||
};
|
||||
si_ptr = &mut si_ex as *mut _ as _;
|
||||
si_ptr = core::ptr::addr_of_mut!(si_ex) as _;
|
||||
} else {
|
||||
si.cb = mem::size_of::<c::STARTUPINFOW>() as c::DWORD;
|
||||
si_ptr = &mut si as *mut _ as _;
|
||||
si_ptr = core::ptr::addr_of_mut!(si) as _;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
@ -935,7 +935,7 @@ fn make_proc_thread_attribute_list(
|
||||
// It's theoretically possible for the attribute count to exceed a u32 value.
|
||||
// Therefore, we ensure that we don't add more attributes than the buffer was initialized for.
|
||||
for (&attribute, value) in attributes.iter().take(attribute_count as usize) {
|
||||
let value_ptr = &*value.data as *const (dyn Send + Sync) as _;
|
||||
let value_ptr = core::ptr::addr_of!(*value.data) as _;
|
||||
cvt(unsafe {
|
||||
c::UpdateProcThreadAttribute(
|
||||
proc_thread_attribute_list.0.as_mut_ptr() as _,
|
||||
|
@ -7,7 +7,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
|
||||
let ret = unsafe {
|
||||
c::BCryptGenRandom(
|
||||
ptr::null_mut(),
|
||||
&mut v as *mut _ as *mut u8,
|
||||
core::ptr::addr_of_mut!(v) as *mut u8,
|
||||
mem::size_of_val(&v) as c::ULONG,
|
||||
c::BCRYPT_USE_SYSTEM_PREFERRED_RNG,
|
||||
)
|
||||
@ -28,7 +28,7 @@ fn fallback_rng() -> (u64, u64) {
|
||||
|
||||
let mut v = (0, 0);
|
||||
let ret = unsafe {
|
||||
c::RtlGenRandom(&mut v as *mut _ as *mut c_void, mem::size_of_val(&v) as c::ULONG)
|
||||
c::RtlGenRandom(core::ptr::addr_of_mut!(v) as *mut c_void, mem::size_of_val(&v) as c::ULONG)
|
||||
};
|
||||
|
||||
if ret != 0 { v } else { panic!("fallback RNG broken: {}", io::Error::last_os_error()) }
|
||||
|
@ -215,7 +215,7 @@ pub fn unpark(self: Pin<&Self>) {
|
||||
}
|
||||
|
||||
fn ptr(&self) -> c::LPVOID {
|
||||
&self.state as *const _ as c::LPVOID
|
||||
core::ptr::addr_of!(self.state) as c::LPVOID
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ pub fn setsockopt<T>(
|
||||
sock.as_raw(),
|
||||
level,
|
||||
option_name,
|
||||
&option_value as *const T as *const _,
|
||||
core::ptr::addr_of!(option_value) as *const _,
|
||||
mem::size_of::<T>() as c::socklen_t,
|
||||
))?;
|
||||
Ok(())
|
||||
@ -85,7 +85,7 @@ pub fn getsockopt<T: Copy>(sock: &Socket, level: c_int, option_name: c_int) -> i
|
||||
sock.as_raw(),
|
||||
level,
|
||||
option_name,
|
||||
&mut option_value as *mut T as *mut _,
|
||||
core::ptr::addr_of_mut!(option_value) as *mut _,
|
||||
&mut option_len,
|
||||
))?;
|
||||
Ok(option_value)
|
||||
@ -99,7 +99,7 @@ fn sockname<F>(f: F) -> io::Result<SocketAddr>
|
||||
unsafe {
|
||||
let mut storage: c::sockaddr_storage = mem::zeroed();
|
||||
let mut len = mem::size_of_val(&storage) as c::socklen_t;
|
||||
cvt(f(&mut storage as *mut _ as *mut _, &mut len))?;
|
||||
cvt(f(core::ptr::addr_of_mut!(storage) as *mut _, &mut len))?;
|
||||
sockaddr_to_addr(&storage, len as usize)
|
||||
}
|
||||
}
|
||||
@ -444,7 +444,7 @@ pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
|
||||
let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() };
|
||||
let mut len = mem::size_of_val(&storage) as c::socklen_t;
|
||||
let sock = self.inner.accept(&mut storage as *mut _ as *mut _, &mut len)?;
|
||||
let sock = self.inner.accept(core::ptr::addr_of_mut!(storage) as *mut _, &mut len)?;
|
||||
let addr = sockaddr_to_addr(&storage, len as usize)?;
|
||||
Ok((TcpStream { inner: sock }, addr))
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ fn wait(state_and_queue: &AtomicPtr<Masked>, mut current_state: *mut Masked) {
|
||||
signaled: AtomicBool::new(false),
|
||||
next: current_state.with_addr(current_state.addr() & !STATE_MASK) as *const Waiter,
|
||||
};
|
||||
let me = &node as *const Waiter as *const Masked as *mut Masked;
|
||||
let me = core::ptr::addr_of!(node) as *const Masked as *mut Masked;
|
||||
|
||||
// Try to slide in the node at the head of the linked list, making sure
|
||||
// that another thread didn't just replace the head of the linked list.
|
||||
|
@ -219,14 +219,14 @@ fn _Unwind_VRS_Set(ctx: *mut _Unwind_Context,
|
||||
pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
|
||||
let mut val: _Unwind_Word = core::ptr::null();
|
||||
_Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
|
||||
&mut val as *mut _ as *mut c_void);
|
||||
core::ptr::addr_of_mut!(val) as *mut c_void);
|
||||
val
|
||||
}
|
||||
|
||||
pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
|
||||
let mut value = value;
|
||||
_Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
|
||||
&mut value as *mut _ as *mut c_void);
|
||||
core::ptr::addr_of_mut!(value) as *mut c_void);
|
||||
}
|
||||
|
||||
pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
|
||||
|
Loading…
Reference in New Issue
Block a user