Skip to content

Commit ade7d0c

Browse files
committed
Auto merge of #3375 - rust-lang:rustup-2024-03-12, r=oli-obk
Automatic Rustup
2 parents 6f1fc72 + b96c441 commit ade7d0c

File tree

6 files changed

+82
-9
lines changed

6 files changed

+82
-9
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
768408af123a455fb27ad8af8055becd5b95d36f
1+
5aad51d015b8d3f6d823a6bf9dbc8ae3b9fd10c5

src/shims/time.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
110110
#[allow(non_snake_case, clippy::arithmetic_side_effects)]
111111
fn GetSystemTimeAsFileTime(
112112
&mut self,
113+
shim_name: &str,
113114
LPFILETIME_op: &OpTy<'tcx, Provenance>,
114115
) -> InterpResult<'tcx> {
115116
let this = self.eval_context_mut();
116117

117-
this.assert_target_os("windows", "GetSystemTimeAsFileTime");
118-
this.check_no_isolation("`GetSystemTimeAsFileTime`")?;
118+
this.assert_target_os("windows", shim_name);
119+
this.check_no_isolation(shim_name)?;
119120

120121
let filetime = this.deref_pointer_as(LPFILETIME_op, this.windows_ty_layout("FILETIME"))?;
121122

src/shims/windows/foreign_items.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
257257
}
258258

259259
// Time related shims
260-
"GetSystemTimeAsFileTime" => {
260+
"GetSystemTimeAsFileTime" | "GetSystemTimePreciseAsFileTime" => {
261261
#[allow(non_snake_case)]
262262
let [LPFILETIME] =
263263
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
264-
this.GetSystemTimeAsFileTime(LPFILETIME)?;
264+
this.GetSystemTimeAsFileTime(link_name.as_str(), LPFILETIME)?;
265265
}
266266
"QueryPerformanceCounter" => {
267267
#[allow(non_snake_case)]

tests/pass/alloc-access-tracking.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(start)]
2+
#![no_std]
3+
//@compile-flags: -Zmiri-track-alloc-id=17 -Zmiri-track-alloc-accesses -Cpanic=abort
4+
//@only-target-linux: alloc IDs differ between OSes for some reason
5+
6+
extern "Rust" {
7+
fn miri_alloc(size: usize, align: usize) -> *mut u8;
8+
fn miri_dealloc(ptr: *mut u8, size: usize, align: usize);
9+
}
10+
11+
#[start]
12+
fn start(_: isize, _: *const *const u8) -> isize {
13+
unsafe {
14+
let ptr = miri_alloc(123, 1);
15+
*ptr = 42; // Crucially, only a write is printed here, no read!
16+
assert_eq!(*ptr, 42);
17+
miri_dealloc(ptr, 123, 1);
18+
}
19+
0
20+
}
21+
22+
#[panic_handler]
23+
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
24+
loop {}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
note: tracking was triggered
2+
--> $DIR/alloc-access-tracking.rs:LL:CC
3+
|
4+
LL | let ptr = miri_alloc(123, 1);
5+
| ^^^^^^^^^^^^^^^^^^ created Miri bare-metal heap allocation of 123 bytes (alignment ALIGN bytes) with id 17
6+
|
7+
= note: BACKTRACE:
8+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
9+
10+
note: tracking was triggered
11+
--> $DIR/alloc-access-tracking.rs:LL:CC
12+
|
13+
LL | *ptr = 42; // Crucially, only a write is printed here, no read!
14+
| ^^^^^^^^^ write access to allocation with id 17
15+
|
16+
= note: BACKTRACE:
17+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
18+
19+
note: tracking was triggered
20+
--> $DIR/alloc-access-tracking.rs:LL:CC
21+
|
22+
LL | assert_eq!(*ptr, 42);
23+
| ^^^^^^^^^^^^^^^^^^^^ read access to allocation with id 17
24+
|
25+
= note: BACKTRACE:
26+
= note: inside `start` at RUSTLIB/core/src/macros/mod.rs:LL:CC
27+
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
28+
29+
note: tracking was triggered
30+
--> $DIR/alloc-access-tracking.rs:LL:CC
31+
|
32+
LL | miri_dealloc(ptr, 123, 1);
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ freed allocation with id 17
34+
|
35+
= note: BACKTRACE:
36+
= note: inside `start` at $DIR/alloc-access-tracking.rs:LL:CC
37+

tests/pass/box-custom-alloc-aliasing.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ unsafe impl Allocator for MyAllocator {
8484
}
8585

8686
unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) {
87+
// Make sure accesses via `self` don't disturb anything.
88+
let _val = self.bins[0].top.get();
8789
// Since manually finding the corresponding bin of `ptr` is very expensive,
8890
// doing pointer arithmetics is preferred.
8991
// But this means we access `top` via `ptr` rather than `self`!
@@ -93,22 +95,30 @@ unsafe impl Allocator for MyAllocator {
9395
if self.thread_id == thread_id {
9496
unsafe { (*their_bin).push(ptr) };
9597
} else {
96-
todo!("Deallocating from another thread")
98+
todo!("Deallocating from another thread");
9799
}
100+
// Make sure we can also still access this via `self` after the rest is done.
101+
let _val = self.bins[0].top.get();
98102
}
99103
}
100104

101105
// Make sure to involve `Box` in allocating these,
102106
// as that's where `noalias` may come from.
103-
fn v<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
107+
fn v1<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
104108
(Box::new_in([t], a) as Box<[T], A>).into_vec()
105109
}
110+
fn v2<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
111+
let v = v1(t, a);
112+
// There was a bug in `into_boxed_slice` that caused aliasing issues,
113+
// so round-trip through that as well.
114+
v.into_boxed_slice().into_vec()
115+
}
106116

107117
fn main() {
108118
assert!(mem::size_of::<MyBin>() <= 128); // if it grows bigger, the trick to access the "header" no longer works
109119
let my_alloc = MyAllocator::new();
110-
let a = v(1usize, &my_alloc);
111-
let b = v(2usize, &my_alloc);
120+
let a = v1(1usize, &my_alloc);
121+
let b = v2(2usize, &my_alloc);
112122
assert_eq!(a[0] + 1, b[0]);
113123
assert_eq!(addr_of!(a[0]).wrapping_add(1), addr_of!(b[0]));
114124
drop((a, b));

0 commit comments

Comments
 (0)