Skip to content

Commit 9e28f11

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 4e8fd88 + ab180be commit 9e28f11

File tree

10 files changed

+163
-20
lines changed

10 files changed

+163
-20
lines changed

alloc/src/collections/btree/set.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,9 +1517,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
15171517

15181518
// use stable sort to preserve the insertion order.
15191519
arr.sort();
1520-
let iter = IntoIterator::into_iter(arr).map(|k| (k, SetValZST::default()));
1521-
let map = BTreeMap::bulk_build_from_sorted_iter(iter, Global);
1522-
BTreeSet { map }
1520+
BTreeSet::from_sorted_iter(IntoIterator::into_iter(arr), Global)
15231521
}
15241522
}
15251523

core/src/panic/location.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::ffi::CStr;
22
use crate::fmt;
3+
use crate::marker::PhantomData;
4+
use crate::ptr::NonNull;
35

46
/// A struct containing information about the location of a panic.
57
///
@@ -33,14 +35,13 @@ use crate::fmt;
3335
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
3436
#[stable(feature = "panic_hooks", since = "1.10.0")]
3537
pub struct Location<'a> {
36-
// Note: this filename will have exactly one nul byte at its end, but otherwise
37-
// it must never contain interior nul bytes. This is relied on for the conversion
38-
// to `CStr` below.
39-
//
40-
// The prefix of the string without the trailing nul byte will be a regular UTF8 `str`.
41-
file_bytes_with_nul: &'a [u8],
38+
// A raw pointer is used rather than a reference because the pointer is valid for one more byte
39+
// than the length stored in this pointer; the additional byte is the NUL-terminator used by
40+
// `Location::file_with_nul`.
41+
filename: NonNull<str>,
4242
line: u32,
4343
col: u32,
44+
_filename: PhantomData<&'a str>,
4445
}
4546

4647
#[stable(feature = "panic_hooks", since = "1.10.0")]
@@ -143,10 +144,8 @@ impl<'a> Location<'a> {
143144
#[stable(feature = "panic_hooks", since = "1.10.0")]
144145
#[rustc_const_stable(feature = "const_location_fields", since = "1.79.0")]
145146
pub const fn file(&self) -> &str {
146-
let str_len = self.file_bytes_with_nul.len() - 1;
147-
// SAFETY: `file_bytes_with_nul` without the trailing nul byte is guaranteed to be
148-
// valid UTF8.
149-
unsafe { crate::str::from_raw_parts(self.file_bytes_with_nul.as_ptr(), str_len) }
147+
// SAFETY: The filename is valid.
148+
unsafe { self.filename.as_ref() }
150149
}
151150

152151
/// Returns the name of the source file as a nul-terminated `CStr`.
@@ -157,9 +156,17 @@ impl<'a> Location<'a> {
157156
#[unstable(feature = "file_with_nul", issue = "141727")]
158157
#[inline]
159158
pub const fn file_with_nul(&self) -> &CStr {
160-
// SAFETY: `file_bytes_with_nul` is guaranteed to have a trailing nul byte and no
161-
// interior nul bytes.
162-
unsafe { CStr::from_bytes_with_nul_unchecked(self.file_bytes_with_nul) }
159+
let filename = self.filename.as_ptr();
160+
161+
// SAFETY: The filename is valid for `filename_len+1` bytes, so this addition can't
162+
// overflow.
163+
let cstr_len = unsafe { crate::mem::size_of_val_raw(filename).unchecked_add(1) };
164+
165+
// SAFETY: The filename is valid for `filename_len+1` bytes.
166+
let slice = unsafe { crate::slice::from_raw_parts(filename.cast(), cstr_len) };
167+
168+
// SAFETY: The filename is guaranteed to have a trailing nul byte and no interior nul bytes.
169+
unsafe { CStr::from_bytes_with_nul_unchecked(slice) }
163170
}
164171

165172
/// Returns the line number from which the panic originated.
@@ -220,3 +227,8 @@ impl fmt::Display for Location<'_> {
220227
write!(formatter, "{}:{}:{}", self.file(), self.line, self.col)
221228
}
222229
}
230+
231+
#[stable(feature = "panic_hooks", since = "1.10.0")]
232+
unsafe impl Send for Location<'_> {}
233+
#[stable(feature = "panic_hooks", since = "1.10.0")]
234+
unsafe impl Sync for Location<'_> {}

core/src/panicking.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,22 @@ fn panic_null_pointer_dereference() -> ! {
314314
)
315315
}
316316

317+
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold, optimize(size))]
318+
#[cfg_attr(feature = "panic_immediate_abort", inline)]
319+
#[track_caller]
320+
#[lang = "panic_invalid_enum_construction"] // needed by codegen for panic on invalid enum construction.
321+
#[rustc_nounwind] // `CheckEnums` MIR pass requires this function to never unwind
322+
fn panic_invalid_enum_construction(source: u128) -> ! {
323+
if cfg!(feature = "panic_immediate_abort") {
324+
super::intrinsics::abort()
325+
}
326+
327+
panic_nounwind_fmt(
328+
format_args!("trying to construct an enum from an invalid value {source:#x}"),
329+
/* force_no_backtrace */ false,
330+
)
331+
}
332+
317333
/// Panics because we cannot unwind out of a function.
318334
///
319335
/// This is a separate function to avoid the codesize impact of each crate containing the string to

std/src/os/illumos/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
#![stable(feature = "raw_ext", since = "1.1.0")]
44

55
pub mod fs;
6+
pub mod net;
67
pub mod raw;

std/src/os/illumos/net.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! illumos-specific networking functionality.
2+
3+
#![unstable(feature = "unix_socket_exclbind", issue = "123481")]
4+
5+
use crate::io;
6+
use crate::os::unix::net;
7+
use crate::sealed::Sealed;
8+
use crate::sys_common::AsInner;
9+
10+
/// illumos-specific functionality for `AF_UNIX` sockets [`UnixDatagram`]
11+
/// and [`UnixStream`].
12+
///
13+
/// [`UnixDatagram`]: net::UnixDatagram
14+
/// [`UnixStream`]: net::UnixStream
15+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
16+
pub trait UnixSocketExt: Sealed {
17+
/// Enables exclusive binding on the socket.
18+
///
19+
/// If true and if the socket had been set with `SO_REUSEADDR`,
20+
/// it neutralises its effect.
21+
/// See [`man 3 tcp`](https://docs.oracle.com/cd/E88353_01/html/E37843/setsockopt-3c.html)
22+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
23+
fn so_exclbind(&self, excl: bool) -> io::Result<()>;
24+
25+
/// Get the bind exclusivity bind state of the socket.
26+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
27+
fn exclbind(&self) -> io::Result<bool>;
28+
}
29+
30+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
31+
impl UnixSocketExt for net::UnixDatagram {
32+
fn exclbind(&self) -> io::Result<bool> {
33+
self.as_inner().exclbind()
34+
}
35+
36+
fn so_exclbind(&self, excl: bool) -> io::Result<()> {
37+
self.as_inner().set_exclbind(excl)
38+
}
39+
}
40+
41+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
42+
impl UnixSocketExt for net::UnixStream {
43+
fn exclbind(&self) -> io::Result<bool> {
44+
self.as_inner().exclbind()
45+
}
46+
47+
fn so_exclbind(&self, excl: bool) -> io::Result<()> {
48+
self.as_inner().set_exclbind(excl)
49+
}
50+
}

std/src/os/solaris/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
#![stable(feature = "raw_ext", since = "1.1.0")]
44

55
pub mod fs;
6+
pub mod net;
67
pub mod raw;

std/src/os/solaris/net.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//! solaris-specific networking functionality.
2+
3+
#![unstable(feature = "unix_socket_exclbind", issue = "123481")]
4+
5+
use crate::io;
6+
use crate::os::unix::net;
7+
use crate::sealed::Sealed;
8+
use crate::sys_common::AsInner;
9+
10+
/// solaris-specific functionality for `AF_UNIX` sockets [`UnixDatagram`]
11+
/// and [`UnixStream`].
12+
///
13+
/// [`UnixDatagram`]: net::UnixDatagram
14+
/// [`UnixStream`]: net::UnixStream
15+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
16+
pub trait UnixSocketExt: Sealed {
17+
/// Enables exclusive binding on the socket.
18+
///
19+
/// If true and if the socket had been set with `SO_REUSEADDR`,
20+
/// it neutralises its effect.
21+
/// See [`man 3 tcp`](https://docs.oracle.com/cd/E88353_01/html/E37843/setsockopt-3c.html)
22+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
23+
fn so_exclbind(&self, excl: bool) -> io::Result<()>;
24+
25+
/// Get the bind exclusivity bind state of the socket.
26+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
27+
fn exclbind(&self) -> io::Result<bool>;
28+
}
29+
30+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
31+
impl UnixSocketExt for net::UnixDatagram {
32+
fn exclbind(&self) -> io::Result<bool> {
33+
self.as_inner().exclbind()
34+
}
35+
36+
fn so_exclbind(&self, excl: bool) -> io::Result<()> {
37+
self.as_inner().set_exclbind(excl)
38+
}
39+
}
40+
41+
#[unstable(feature = "unix_socket_exclbind", issue = "123481")]
42+
impl UnixSocketExt for net::UnixStream {
43+
fn exclbind(&self) -> io::Result<bool> {
44+
self.as_inner().exclbind()
45+
}
46+
47+
fn so_exclbind(&self, excl: bool) -> io::Result<()> {
48+
self.as_inner().set_exclbind(excl)
49+
}
50+
}

std/src/sys/net/connection/socket/unix.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,21 @@ impl Socket {
522522
Ok(name)
523523
}
524524

525+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
526+
pub fn set_exclbind(&self, excl: bool) -> io::Result<()> {
527+
// not yet on libc crate
528+
const SO_EXCLBIND: i32 = 0x1015;
529+
setsockopt(self, libc::SOL_SOCKET, SO_EXCLBIND, excl)
530+
}
531+
532+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
533+
pub fn exclbind(&self) -> io::Result<bool> {
534+
// not yet on libc crate
535+
const SO_EXCLBIND: i32 = 0x1015;
536+
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, SO_EXCLBIND)?;
537+
Ok(raw != 0)
538+
}
539+
525540
#[cfg(any(target_os = "android", target_os = "linux",))]
526541
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
527542
setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int)

std/src/sys/process/unix/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ impl Process {
968968
}
969969

970970
pub(crate) fn send_signal(&self, signal: i32) -> io::Result<()> {
971-
// If we've already waited on this process then the pid can be recycled
972-
// and used for another process, and we probably shouldn't be signaling
971+
// If we've already waited on this process then the pid can be recycled and
972+
// used for another process, and we probably shouldn't be sending signals to
973973
// random processes, so return Ok because the process has exited already.
974974
if self.status.is_some() {
975975
return Ok(());

std/src/sys/process/unix/vxworks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ impl Process {
151151
}
152152

153153
pub fn send_signal(&self, signal: i32) -> io::Result<()> {
154-
// If we've already waited on this process then the pid can be recycled
155-
// and used for another process, and we probably shouldn't be killing
154+
// If we've already waited on this process then the pid can be recycled and
155+
// used for another process, and we probably shouldn't be sending signals to
156156
// random processes, so return Ok because the process has exited already.
157157
if self.status.is_some() {
158158
Ok(())

0 commit comments

Comments
 (0)