Skip to content

Commit 12c15cb

Browse files
committed
Merge from rust-lang/rust
2 parents 44f3abb + 522502d commit 12c15cb

File tree

96 files changed

+1456
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1456
-662
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ environment variable. We first document the most relevant and most commonly used
342342
is enabled (the default), this is also used to emulate system entropy. The default seed is 0. You
343343
can increase test coverage by running Miri multiple times with different seeds.
344344
* `-Zmiri-strict-provenance` enables [strict
345-
provenance](https://github.com/rust-lang/rust/issues/95228) checking in Miri. This means that
346-
casting an integer to a pointer will stop execution because the provenance of the pointer
347-
cannot be determined.
345+
provenance](https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) checking in
346+
Miri. This means that casting an integer to a pointer will stop execution because the provenance
347+
of the pointer cannot be determined.
348348
* `-Zmiri-symbolic-alignment-check` makes the alignment check more strict. By default, alignment is
349349
checked by casting the pointer to an integer, and making sure that is a multiple of the alignment.
350350
This can lead to cases where a program passes the alignment check by pure chance, because things

miri-script/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository = "https://github.com/rust-lang/miri"
77
version = "0.1.0"
88
default-run = "miri-script"
99
edition = "2024"
10+
rust-version = "1.85"
1011

1112
[workspace]
1213
# We make this a workspace root so that cargo does not go looking in ../Cargo.toml for the workspace root.

miri-script/src/commands.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,6 @@ impl Command {
702702
let mut early_flags = Vec::<OsString>::new();
703703

704704
// In `dep` mode, the target is already passed via `MIRI_TEST_TARGET`
705-
#[expect(clippy::collapsible_if)] // we need to wait until this is stable
706705
if !dep {
707706
if let Some(target) = &target {
708707
early_flags.push("--target".into());
@@ -735,7 +734,6 @@ impl Command {
735734
// Add Miri flags
736735
let mut cmd = cmd.args(&miri_flags).args(&early_flags).args(&flags);
737736
// For `--dep` we also need to set the target in the env var.
738-
#[expect(clippy::collapsible_if)] // we need to wait until this is stable
739737
if dep {
740738
if let Some(target) = &target {
741739
cmd = cmd.env("MIRI_TEST_TARGET", target);

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
733b47ea4b1b86216f14ef56e49440c33933f230
1+
7f2065a4bae1faed5bab928c670964eafbf43b55

src/alloc/isolated_alloc.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,31 +302,28 @@ impl IsolatedAlloc {
302302
}
303303
}
304304

305-
/// Returns a vector of page addresses managed by the allocator.
306-
pub fn pages(&self) -> Vec<usize> {
307-
let mut pages: Vec<usize> =
308-
self.page_ptrs.iter().map(|p| p.expose_provenance().get()).collect();
309-
for (ptr, size) in self.huge_ptrs.iter() {
310-
for i in 0..size / self.page_size {
311-
pages.push(ptr.expose_provenance().get().strict_add(i * self.page_size));
312-
}
313-
}
314-
pages
305+
/// Returns a list of page addresses managed by the allocator.
306+
pub fn pages(&self) -> impl Iterator<Item = usize> {
307+
let pages = self.page_ptrs.iter().map(|p| p.expose_provenance().get());
308+
pages.chain(self.huge_ptrs.iter().flat_map(|(ptr, size)| {
309+
(0..size / self.page_size)
310+
.map(|i| ptr.expose_provenance().get().strict_add(i * self.page_size))
311+
}))
315312
}
316313

317314
/// Protects all owned memory as `PROT_NONE`, preventing accesses.
318315
///
319316
/// SAFETY: Accessing memory after this point will result in a segfault
320317
/// unless it is first unprotected.
321-
pub unsafe fn prepare_ffi(&mut self) -> Result<(), nix::errno::Errno> {
318+
pub unsafe fn start_ffi(&mut self) -> Result<(), nix::errno::Errno> {
322319
let prot = mman::ProtFlags::PROT_NONE;
323320
unsafe { self.mprotect(prot) }
324321
}
325322

326323
/// Deprotects all owned memory by setting it to RW. Erroring here is very
327324
/// likely unrecoverable, so it may panic if applying those permissions
328325
/// fails.
329-
pub fn unprep_ffi(&mut self) {
326+
pub fn end_ffi(&mut self) {
330327
let prot = mman::ProtFlags::PROT_READ | mman::ProtFlags::PROT_WRITE;
331328
unsafe {
332329
self.mprotect(prot).unwrap();

src/alloc_addresses/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
157157
this.get_alloc_bytes_unchecked_raw(alloc_id)?
158158
}
159159
}
160-
AllocKind::Function | AllocKind::VTable => {
160+
AllocKind::Function | AllocKind::Virtual => {
161161
// Allocate some dummy memory to get a unique address for this function/vtable.
162162
let alloc_bytes = MiriAllocBytes::from_bytes(
163163
&[0u8; 1],

src/bin/log/tracing_chrome.rs

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// SPDX-License-Identifier: MIT
22
// SPDX-FileCopyrightText: Copyright (c) 2020 Thoren Paulson
3-
//! This file is taken unmodified from the following link, except for file attributes and
4-
//! `extern crate` at the top.
5-
//! https://github.com/thoren-d/tracing-chrome/blob/7e2625ab4aeeef2f0ef9bde9d6258dd181c04472/src/lib.rs
3+
//! This file was initially taken from the following link:
4+
//! <https://github.com/thoren-d/tracing-chrome/blob/7e2625ab4aeeef2f0ef9bde9d6258dd181c04472/src/lib.rs>
5+
//!
6+
//! The precise changes that were made to the original file can be found in git history
7+
//! (`git log -- path/to/tracing_chrome.rs`), but in summary:
8+
//! - the file attributes were changed and `extern crate` was added at the top
9+
//! - if a tracing span has a field called "tracing_separate_thread", it will be given a separate
10+
//! span ID even in [TraceStyle::Threaded] mode, to make it appear on a separate line when viewing
11+
//! the trace in <https://ui.perfetto.dev>. This is the syntax to trigger this behavior:
12+
//! ```rust
13+
//! tracing::info_span!("my_span", tracing_separate_thread = tracing::field::Empty, /* ... */)
14+
//! ```
15+
//!
616
//! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it
717
//! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would
818
//! not be possible to use the [ChromeLayer] in a context that expects a [Layer] from
@@ -79,14 +89,26 @@ where
7989
}
8090

8191
/// Decides how traces will be recorded.
92+
/// Also see <https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1>
8293
#[derive(Default)]
8394
pub enum TraceStyle {
84-
/// Traces will be recorded as a group of threads.
95+
/// Traces will be recorded as a group of threads, and all spans on the same thread will appear
96+
/// on a single trace line in <https://ui.perfetto.dev>.
8597
/// In this style, spans should be entered and exited on the same thread.
98+
///
99+
/// If a tracing span has a field called "tracing_separate_thread", it will be given a separate
100+
/// span ID even in this mode, to make it appear on a separate line when viewing the trace in
101+
/// <https://ui.perfetto.dev>. This is the syntax to trigger this behavior:
102+
/// ```rust
103+
/// tracing::info_span!("my_span", tracing_separate_thread = tracing::field::Empty, /* ... */)
104+
/// ```
105+
/// [tracing::field::Empty] is used so that other tracing layers (e.g. the logger) will ignore
106+
/// the "tracing_separate_thread" argument and not print out anything for it.
86107
#[default]
87108
Threaded,
88109

89-
/// Traces will recorded as a group of asynchronous operations.
110+
/// Traces will recorded as a group of asynchronous operations. All spans will be given separate
111+
/// span IDs and will appear on separate trace lines in <https://ui.perfetto.dev>.
90112
Async,
91113
}
92114

@@ -497,31 +519,39 @@ where
497519
}
498520
}
499521

500-
fn get_root_id(span: SpanRef<S>) -> u64 {
501-
span.scope()
502-
.from_root()
503-
.take(1)
504-
.next()
505-
.unwrap_or(span)
506-
.id()
507-
.into_u64()
522+
fn get_root_id(&self, span: SpanRef<S>) -> Option<u64> {
523+
match self.trace_style {
524+
TraceStyle::Threaded => {
525+
if span.fields().field("tracing_separate_thread").is_some() {
526+
// assign an independent "id" to spans with argument "tracing_separate_thread",
527+
// so they appear a separate trace line in trace visualization tools, see
528+
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1
529+
Some(span.id().into_u64())
530+
} else {
531+
None
532+
}
533+
},
534+
TraceStyle::Async => Some(
535+
span.scope()
536+
.from_root()
537+
.take(1)
538+
.next()
539+
.unwrap_or(span)
540+
.id()
541+
.into_u64()
542+
),
543+
}
508544
}
509545

510546
fn enter_span(&self, span: SpanRef<S>, ts: f64) {
511547
let callsite = self.get_callsite(EventOrSpan::Span(&span));
512-
let root_id = match self.trace_style {
513-
TraceStyle::Async => Some(ChromeLayer::get_root_id(span)),
514-
_ => None,
515-
};
548+
let root_id = self.get_root_id(span);
516549
self.send_message(Message::Enter(ts, callsite, root_id));
517550
}
518551

519552
fn exit_span(&self, span: SpanRef<S>, ts: f64) {
520553
let callsite = self.get_callsite(EventOrSpan::Span(&span));
521-
let root_id = match self.trace_style {
522-
TraceStyle::Async => Some(ChromeLayer::get_root_id(span)),
523-
_ => None,
524-
};
554+
let root_id = self.get_root_id(span);
525555
self.send_message(Message::Exit(ts, callsite, root_id));
526556
}
527557

src/bin/miri.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
233233
} else {
234234
let return_code = miri::eval_entry(tcx, entry_def_id, entry_type, &config, None)
235235
.unwrap_or_else(|| {
236-
//#[cfg(target_os = "linux")]
237-
//miri::native_lib::register_retcode_sv(rustc_driver::EXIT_FAILURE);
238236
tcx.dcx().abort_if_errors();
239237
rustc_driver::EXIT_FAILURE
240238
});
@@ -337,6 +335,9 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
337335
fn exit(exit_code: i32) -> ! {
338336
// Drop the tracing guard before exiting, so tracing calls are flushed correctly.
339337
deinit_loggers();
338+
// Make sure the supervisor knows about the code code.
339+
#[cfg(target_os = "linux")]
340+
miri::native_lib::register_retcode_sv(exit_code);
340341
std::process::exit(exit_code);
341342
}
342343

@@ -355,6 +356,11 @@ fn run_compiler_and_exit(
355356
args: &[String],
356357
callbacks: &mut (dyn rustc_driver::Callbacks + Send),
357358
) -> ! {
359+
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
360+
// MIRI_BE_RUSTC is set. We do this late so that when `native_lib::init_sv` is called,
361+
// there are no other threads.
362+
rustc_driver::install_ctrlc_handler();
363+
358364
// Invoke compiler, catch any unwinding panics and handle return code.
359365
let exit_code =
360366
rustc_driver::catch_with_exit_code(move || rustc_driver::run_compiler(args, callbacks));
@@ -439,10 +445,6 @@ fn main() {
439445
let args = rustc_driver::catch_fatal_errors(|| rustc_driver::args::raw_args(&early_dcx))
440446
.unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
441447

442-
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
443-
// MIRI_BE_RUSTC is set.
444-
rustc_driver::install_ctrlc_handler();
445-
446448
// If the environment asks us to actually be rustc, then do that.
447449
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
448450
// Earliest rustc setup.
@@ -750,15 +752,15 @@ fn main() {
750752

751753
debug!("rustc arguments: {:?}", rustc_args);
752754
debug!("crate arguments: {:?}", miri_config.args);
753-
#[cfg(target_os = "linux")]
754755
if !miri_config.native_lib.is_empty() && miri_config.native_lib_enable_tracing {
755-
// FIXME: This should display a diagnostic / warning on error
756-
// SAFETY: If any other threads exist at this point (namely for the ctrlc
757-
// handler), they will not interact with anything on the main rustc/Miri
758-
// thread in an async-signal-unsafe way such as by accessing shared
759-
// semaphores, etc.; the handler only calls `sleep()` and `exit()`, which
760-
// are async-signal-safe, as is accessing atomics
761-
//let _ = unsafe { miri::native_lib::init_sv() };
756+
// SAFETY: No other threads are running
757+
#[cfg(target_os = "linux")]
758+
if unsafe { miri::native_lib::init_sv() }.is_err() {
759+
eprintln!(
760+
"warning: The native-lib tracer could not be started. Is this an x86 Linux system, and does Miri have permissions to ptrace?\n\
761+
Falling back to non-tracing native-lib mode."
762+
);
763+
}
762764
}
763765
run_compiler_and_exit(
764766
&rustc_args,

src/borrow_tracker/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ impl GlobalStateInner {
260260
kind: MemoryKind,
261261
machine: &MiriMachine<'_>,
262262
) -> AllocState {
263+
let _span = enter_trace_span!(borrow_tracker::new_allocation, ?id, ?alloc_size, ?kind);
263264
match self.borrow_tracker_method {
264265
BorrowTrackerMethod::StackedBorrows =>
265266
AllocState::StackedBorrows(Box::new(RefCell::new(Stacks::new_allocation(
@@ -280,6 +281,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
280281
kind: RetagKind,
281282
val: &ImmTy<'tcx>,
282283
) -> InterpResult<'tcx, ImmTy<'tcx>> {
284+
let _span = enter_trace_span!(borrow_tracker::retag_ptr_value, ?kind, ?val.layout);
283285
let this = self.eval_context_mut();
284286
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
285287
match method {
@@ -293,6 +295,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
293295
kind: RetagKind,
294296
place: &PlaceTy<'tcx>,
295297
) -> InterpResult<'tcx> {
298+
let _span = enter_trace_span!(borrow_tracker::retag_place_contents, ?kind, ?place);
296299
let this = self.eval_context_mut();
297300
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
298301
match method {
@@ -302,6 +305,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
302305
}
303306

304307
fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
308+
let _span = enter_trace_span!(borrow_tracker::protect_place, ?place);
305309
let this = self.eval_context_mut();
306310
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
307311
match method {
@@ -311,6 +315,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
311315
}
312316

313317
fn expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
318+
let _span =
319+
enter_trace_span!(borrow_tracker::expose_tag, alloc_id = alloc_id.0, tag = tag.0);
314320
let this = self.eval_context_ref();
315321
let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method;
316322
match method {
@@ -354,6 +360,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354360
&self,
355361
frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>,
356362
) -> InterpResult<'tcx> {
363+
let _span = enter_trace_span!(borrow_tracker::on_stack_pop);
357364
let this = self.eval_context_ref();
358365
let borrow_tracker = this.machine.borrow_tracker.as_ref().unwrap();
359366
// The body of this loop needs `borrow_tracker` immutably
@@ -431,6 +438,7 @@ impl AllocState {
431438
range: AllocRange,
432439
machine: &MiriMachine<'tcx>,
433440
) -> InterpResult<'tcx> {
441+
let _span = enter_trace_span!(borrow_tracker::before_memory_read, alloc_id = alloc_id.0);
434442
match self {
435443
AllocState::StackedBorrows(sb) =>
436444
sb.borrow_mut().before_memory_read(alloc_id, prov_extra, range, machine),
@@ -452,6 +460,7 @@ impl AllocState {
452460
range: AllocRange,
453461
machine: &MiriMachine<'tcx>,
454462
) -> InterpResult<'tcx> {
463+
let _span = enter_trace_span!(borrow_tracker::before_memory_write, alloc_id = alloc_id.0);
455464
match self {
456465
AllocState::StackedBorrows(sb) =>
457466
sb.get_mut().before_memory_write(alloc_id, prov_extra, range, machine),
@@ -473,6 +482,8 @@ impl AllocState {
473482
size: Size,
474483
machine: &MiriMachine<'tcx>,
475484
) -> InterpResult<'tcx> {
485+
let _span =
486+
enter_trace_span!(borrow_tracker::before_memory_deallocation, alloc_id = alloc_id.0);
476487
match self {
477488
AllocState::StackedBorrows(sb) =>
478489
sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine),
@@ -482,6 +493,7 @@ impl AllocState {
482493
}
483494

484495
pub fn remove_unreachable_tags(&self, tags: &FxHashSet<BorTag>) {
496+
let _span = enter_trace_span!(borrow_tracker::remove_unreachable_tags);
485497
match self {
486498
AllocState::StackedBorrows(sb) => sb.borrow_mut().remove_unreachable_tags(tags),
487499
AllocState::TreeBorrows(tb) => tb.borrow_mut().remove_unreachable_tags(tags),
@@ -496,6 +508,11 @@ impl AllocState {
496508
tag: BorTag,
497509
alloc_id: AllocId, // diagnostics
498510
) -> InterpResult<'tcx> {
511+
let _span = enter_trace_span!(
512+
borrow_tracker::release_protector,
513+
alloc_id = alloc_id.0,
514+
tag = tag.0
515+
);
499516
match self {
500517
AllocState::StackedBorrows(_sb) => interp_ok(()),
501518
AllocState::TreeBorrows(tb) =>
@@ -506,6 +523,7 @@ impl AllocState {
506523

507524
impl VisitProvenance for AllocState {
508525
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
526+
let _span = enter_trace_span!(borrow_tracker::visit_provenance);
509527
match self {
510528
AllocState::StackedBorrows(sb) => sb.visit_provenance(visit),
511529
AllocState::TreeBorrows(tb) => tb.visit_provenance(visit),

0 commit comments

Comments
 (0)