Skip to content

Commit 983587b

Browse files
committed
Auto merge of #122331 - jhpratt:rollup-cbl8xsy, r=jhpratt
Rollup of 9 pull requests Successful merges: - #121148 (Add slice::try_range) - #121633 (Win10: Use `GetSystemTimePreciseAsFileTime` directly) - #121840 (Expose the Freeze trait again (unstably) and forbid implementing it manually) - #121907 (skip sanity check for non-host targets in `check` builds) - #122002 (std::threads: revisit stack address calculation on netbsd.) - #122108 (Add `target.*.runner` configuration for targets) - #122298 (RawVec::into_box: avoid unnecessary intermediate reference) - #122315 (Allow multiple `impl Into<{D,Subd}iagMessage>` parameters in a function.) - #122326 (Optimize `process_heap_alloc`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fb65261 + a376e94 commit 983587b

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/shims/time.rs

+3-2
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

+2-2
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/box-custom-alloc-aliasing.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ unsafe impl Allocator for MyAllocator {
9292
}
9393

9494
unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) {
95+
// Make sure accesses via `self` don't disturb anything.
96+
let _val = self.bins[0].top.get();
9597
// Since manually finding the corresponding bin of `ptr` is very expensive,
9698
// doing pointer arithmetics is preferred.
9799
// But this means we access `top` via `ptr` rather than `self`!
@@ -101,22 +103,30 @@ unsafe impl Allocator for MyAllocator {
101103
if self.thread_id == thread_id {
102104
unsafe { (*their_bin).push(ptr) };
103105
} else {
104-
todo!("Deallocating from another thread")
106+
todo!("Deallocating from another thread");
105107
}
108+
// Make sure we can also still access this via `self` after the rest is done.
109+
let _val = self.bins[0].top.get();
106110
}
107111
}
108112

109113
// Make sure to involve `Box` in allocating these,
110114
// as that's where `noalias` may come from.
111-
fn v<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
115+
fn v1<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
112116
(Box::new_in([t], a) as Box<[T], A>).into_vec()
113117
}
118+
fn v2<T, A: Allocator>(t: T, a: A) -> Vec<T, A> {
119+
let v = v1(t, a);
120+
// There was a bug in `into_boxed_slice` that caused aliasing issues,
121+
// so round-trip through that as well.
122+
v.into_boxed_slice().into_vec()
123+
}
114124

115125
fn main() {
116126
assert!(mem::size_of::<MyBin>() <= 128); // if it grows bigger, the trick to access the "header" no longer works
117127
let my_alloc = MyAllocator::new();
118-
let a = v(1usize, &my_alloc);
119-
let b = v(2usize, &my_alloc);
128+
let a = v1(1usize, &my_alloc);
129+
let b = v2(2usize, &my_alloc);
120130
assert_eq!(a[0] + 1, b[0]);
121131
assert_eq!(addr_of!(a[0]).wrapping_add(1), addr_of!(b[0]));
122132
drop((a, b));

0 commit comments

Comments
 (0)