Skip to content

Commit a77ff2e

Browse files
authored
Merge pull request rust-lang#4029 from YohDeadfall/ecx
Renamed this arguments to ecx
2 parents e2b7027 + e43a5c0 commit a77ff2e

File tree

12 files changed

+382
-383
lines changed

12 files changed

+382
-383
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10091009
let this = self.eval_context_ref();
10101010

10111011
fn float_to_int_inner<'tcx, F: rustc_apfloat::Float>(
1012-
this: &MiriInterpCx<'tcx>,
1012+
ecx: &MiriInterpCx<'tcx>,
10131013
src: F,
10141014
cast_to: TyAndLayout<'tcx>,
10151015
round: rustc_apfloat::Round,
@@ -1029,7 +1029,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10291029
// Nothing else
10301030
_ =>
10311031
span_bug!(
1032-
this.cur_span(),
1032+
ecx.cur_span(),
10331033
"attempted float-to-int conversion with non-int output type {}",
10341034
cast_to.ty,
10351035
),

src/tools/miri/src/machine.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,20 +730,20 @@ impl<'tcx> MiriMachine<'tcx> {
730730
}
731731

732732
pub(crate) fn late_init(
733-
this: &mut MiriInterpCx<'tcx>,
733+
ecx: &mut MiriInterpCx<'tcx>,
734734
config: &MiriConfig,
735735
on_main_stack_empty: StackEmptyCallback<'tcx>,
736736
) -> InterpResult<'tcx> {
737-
EnvVars::init(this, config)?;
738-
MiriMachine::init_extern_statics(this)?;
739-
ThreadManager::init(this, on_main_stack_empty);
737+
EnvVars::init(ecx, config)?;
738+
MiriMachine::init_extern_statics(ecx)?;
739+
ThreadManager::init(ecx, on_main_stack_empty);
740740
interp_ok(())
741741
}
742742

743-
pub(crate) fn add_extern_static(this: &mut MiriInterpCx<'tcx>, name: &str, ptr: Pointer) {
743+
pub(crate) fn add_extern_static(ecx: &mut MiriInterpCx<'tcx>, name: &str, ptr: Pointer) {
744744
// This got just allocated, so there definitely is a pointer here.
745745
let ptr = ptr.into_pointer_or_addr().unwrap();
746-
this.machine.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap();
746+
ecx.machine.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap();
747747
}
748748

749749
pub(crate) fn communicate(&self) -> bool {

src/tools/miri/src/provenance_gc.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,27 @@ impl LiveAllocs<'_, '_> {
195195
}
196196
}
197197

198-
fn remove_unreachable_tags<'tcx>(this: &mut MiriInterpCx<'tcx>, tags: FxHashSet<BorTag>) {
198+
fn remove_unreachable_tags<'tcx>(ecx: &mut MiriInterpCx<'tcx>, tags: FxHashSet<BorTag>) {
199199
// Avoid iterating all allocations if there's no borrow tracker anyway.
200-
if this.machine.borrow_tracker.is_some() {
201-
this.memory.alloc_map().iter(|it| {
200+
if ecx.machine.borrow_tracker.is_some() {
201+
ecx.memory.alloc_map().iter(|it| {
202202
for (_id, (_kind, alloc)) in it {
203203
alloc.extra.borrow_tracker.as_ref().unwrap().remove_unreachable_tags(&tags);
204204
}
205205
});
206206
}
207207
}
208208

209-
fn remove_unreachable_allocs<'tcx>(this: &mut MiriInterpCx<'tcx>, allocs: FxHashSet<AllocId>) {
210-
let allocs = LiveAllocs { ecx: this, collected: allocs };
211-
this.machine.allocation_spans.borrow_mut().retain(|id, _| allocs.is_live(*id));
212-
this.machine.symbolic_alignment.borrow_mut().retain(|id, _| allocs.is_live(*id));
213-
this.machine.alloc_addresses.borrow_mut().remove_unreachable_allocs(&allocs);
214-
if let Some(borrow_tracker) = &this.machine.borrow_tracker {
209+
fn remove_unreachable_allocs<'tcx>(ecx: &mut MiriInterpCx<'tcx>, allocs: FxHashSet<AllocId>) {
210+
let allocs = LiveAllocs { ecx, collected: allocs };
211+
ecx.machine.allocation_spans.borrow_mut().retain(|id, _| allocs.is_live(*id));
212+
ecx.machine.symbolic_alignment.borrow_mut().retain(|id, _| allocs.is_live(*id));
213+
ecx.machine.alloc_addresses.borrow_mut().remove_unreachable_allocs(&allocs);
214+
if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
215215
borrow_tracker.borrow_mut().remove_unreachable_allocs(&allocs);
216216
}
217217
// Clean up core (non-Miri-specific) state.
218-
this.remove_unreachable_allocs(&allocs.collected);
218+
ecx.remove_unreachable_allocs(&allocs.collected);
219219
}
220220

221221
impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}

src/tools/miri/src/shims/foreign_items.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -496,28 +496,28 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
496496

497497
// Rust allocation
498498
"__rust_alloc" | "miri_alloc" => {
499-
let default = |this: &mut MiriInterpCx<'tcx>| {
499+
let default = |ecx: &mut MiriInterpCx<'tcx>| {
500500
// Only call `check_shim` when `#[global_allocator]` isn't used. When that
501501
// macro is used, we act like no shim exists, so that the exported function can run.
502-
let [size, align] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
503-
let size = this.read_target_usize(size)?;
504-
let align = this.read_target_usize(align)?;
502+
let [size, align] = ecx.check_shim(abi, ExternAbi::Rust, link_name, args)?;
503+
let size = ecx.read_target_usize(size)?;
504+
let align = ecx.read_target_usize(align)?;
505505

506-
this.check_rustc_alloc_request(size, align)?;
506+
ecx.check_rustc_alloc_request(size, align)?;
507507

508508
let memory_kind = match link_name.as_str() {
509509
"__rust_alloc" => MiriMemoryKind::Rust,
510510
"miri_alloc" => MiriMemoryKind::Miri,
511511
_ => unreachable!(),
512512
};
513513

514-
let ptr = this.allocate_ptr(
514+
let ptr = ecx.allocate_ptr(
515515
Size::from_bytes(size),
516516
Align::from_bytes(align).unwrap(),
517517
memory_kind.into(),
518518
)?;
519519

520-
this.write_pointer(ptr, dest)
520+
ecx.write_pointer(ptr, dest)
521521
};
522522

523523
match link_name.as_str() {
@@ -555,14 +555,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
555555
});
556556
}
557557
"__rust_dealloc" | "miri_dealloc" => {
558-
let default = |this: &mut MiriInterpCx<'tcx>| {
558+
let default = |ecx: &mut MiriInterpCx<'tcx>| {
559559
// See the comment for `__rust_alloc` why `check_shim` is only called in the
560560
// default case.
561561
let [ptr, old_size, align] =
562-
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
563-
let ptr = this.read_pointer(ptr)?;
564-
let old_size = this.read_target_usize(old_size)?;
565-
let align = this.read_target_usize(align)?;
562+
ecx.check_shim(abi, ExternAbi::Rust, link_name, args)?;
563+
let ptr = ecx.read_pointer(ptr)?;
564+
let old_size = ecx.read_target_usize(old_size)?;
565+
let align = ecx.read_target_usize(align)?;
566566

567567
let memory_kind = match link_name.as_str() {
568568
"__rust_dealloc" => MiriMemoryKind::Rust,
@@ -571,7 +571,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
571571
};
572572

573573
// No need to check old_size/align; we anyway check that they match the allocation.
574-
this.deallocate_ptr(
574+
ecx.deallocate_ptr(
575575
ptr,
576576
Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())),
577577
memory_kind.into(),

src/tools/miri/src/shims/unix/android/thread.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,49 @@ use crate::*;
88
const TASK_COMM_LEN: usize = 16;
99

1010
pub fn prctl<'tcx>(
11-
this: &mut MiriInterpCx<'tcx>,
11+
ecx: &mut MiriInterpCx<'tcx>,
1212
link_name: Symbol,
1313
abi: ExternAbi,
1414
args: &[OpTy<'tcx>],
1515
dest: &MPlaceTy<'tcx>,
1616
) -> InterpResult<'tcx> {
1717
// We do not use `check_shim` here because `prctl` is variadic. The argument
1818
// count is checked bellow.
19-
this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?;
19+
ecx.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?;
2020

2121
// FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch.
2222
let pr_set_name = 15;
2323
let pr_get_name = 16;
2424

2525
let [op] = check_min_arg_count("prctl", args)?;
26-
let res = match this.read_scalar(op)?.to_i32()? {
26+
let res = match ecx.read_scalar(op)?.to_i32()? {
2727
op if op == pr_set_name => {
2828
let [_, name] = check_min_arg_count("prctl(PR_SET_NAME, ...)", args)?;
29-
let name = this.read_scalar(name)?;
30-
let thread = this.pthread_self()?;
29+
let name = ecx.read_scalar(name)?;
30+
let thread = ecx.pthread_self()?;
3131
// The Linux kernel silently truncates long names.
3232
// https://www.man7.org/linux/man-pages/man2/PR_SET_NAME.2const.html
3333
let res =
34-
this.pthread_setname_np(thread, name, TASK_COMM_LEN, /* truncate */ true)?;
34+
ecx.pthread_setname_np(thread, name, TASK_COMM_LEN, /* truncate */ true)?;
3535
assert_eq!(res, ThreadNameResult::Ok);
3636
Scalar::from_u32(0)
3737
}
3838
op if op == pr_get_name => {
3939
let [_, name] = check_min_arg_count("prctl(PR_GET_NAME, ...)", args)?;
40-
let name = this.read_scalar(name)?;
41-
let thread = this.pthread_self()?;
42-
let len = Scalar::from_target_usize(TASK_COMM_LEN as u64, this);
43-
this.check_ptr_access(
44-
name.to_pointer(this)?,
40+
let name = ecx.read_scalar(name)?;
41+
let thread = ecx.pthread_self()?;
42+
let len = Scalar::from_target_usize(TASK_COMM_LEN as u64, ecx);
43+
ecx.check_ptr_access(
44+
name.to_pointer(ecx)?,
4545
Size::from_bytes(TASK_COMM_LEN),
4646
CheckInAllocMsg::MemoryAccessTest,
4747
)?;
48-
let res = this.pthread_getname_np(thread, name, len, /* truncate*/ false)?;
48+
let res = ecx.pthread_getname_np(thread, name, len, /* truncate*/ false)?;
4949
assert_eq!(res, ThreadNameResult::Ok);
5050
Scalar::from_u32(0)
5151
}
5252
op => throw_unsup_format!("Miri does not support `prctl` syscall with op={}", op),
5353
};
54-
this.write_scalar(res, dest)?;
54+
ecx.write_scalar(res, dest)?;
5555
interp_ok(())
5656
}

src/tools/miri/src/shims/unix/linux/sync.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct LinuxFutex {
99
/// Implementation of the SYS_futex syscall.
1010
/// `args` is the arguments *including* the syscall number.
1111
pub fn futex<'tcx>(
12-
this: &mut MiriInterpCx<'tcx>,
12+
ecx: &mut MiriInterpCx<'tcx>,
1313
args: &[OpTy<'tcx>],
1414
dest: &MPlaceTy<'tcx>,
1515
) -> InterpResult<'tcx> {
@@ -26,19 +26,19 @@ pub fn futex<'tcx>(
2626
// The first three arguments (after the syscall number itself) are the same to all futex operations:
2727
// (int *addr, int op, int val).
2828
// We checked above that these definitely exist.
29-
let addr = this.read_pointer(addr)?;
30-
let op = this.read_scalar(op)?.to_i32()?;
31-
let val = this.read_scalar(val)?.to_i32()?;
29+
let addr = ecx.read_pointer(addr)?;
30+
let op = ecx.read_scalar(op)?.to_i32()?;
31+
let val = ecx.read_scalar(val)?.to_i32()?;
3232

3333
// This is a vararg function so we have to bring our own type for this pointer.
34-
let addr = this.ptr_to_mplace(addr, this.machine.layouts.i32);
34+
let addr = ecx.ptr_to_mplace(addr, ecx.machine.layouts.i32);
3535

36-
let futex_private = this.eval_libc_i32("FUTEX_PRIVATE_FLAG");
37-
let futex_wait = this.eval_libc_i32("FUTEX_WAIT");
38-
let futex_wait_bitset = this.eval_libc_i32("FUTEX_WAIT_BITSET");
39-
let futex_wake = this.eval_libc_i32("FUTEX_WAKE");
40-
let futex_wake_bitset = this.eval_libc_i32("FUTEX_WAKE_BITSET");
41-
let futex_realtime = this.eval_libc_i32("FUTEX_CLOCK_REALTIME");
36+
let futex_private = ecx.eval_libc_i32("FUTEX_PRIVATE_FLAG");
37+
let futex_wait = ecx.eval_libc_i32("FUTEX_WAIT");
38+
let futex_wait_bitset = ecx.eval_libc_i32("FUTEX_WAIT_BITSET");
39+
let futex_wake = ecx.eval_libc_i32("FUTEX_WAKE");
40+
let futex_wake_bitset = ecx.eval_libc_i32("FUTEX_WAKE_BITSET");
41+
let futex_realtime = ecx.eval_libc_i32("FUTEX_CLOCK_REALTIME");
4242

4343
// FUTEX_PRIVATE enables an optimization that stops it from working across processes.
4444
// Miri doesn't support that anyway, so we ignore that flag.
@@ -57,31 +57,31 @@ pub fn futex<'tcx>(
5757
let (timeout, bitset) = if wait_bitset {
5858
let [_, _, _, _, timeout, uaddr2, bitset] =
5959
check_min_arg_count("`syscall(SYS_futex, FUTEX_WAIT_BITSET, ...)`", args)?;
60-
let _timeout = this.read_pointer(timeout)?;
61-
let _uaddr2 = this.read_pointer(uaddr2)?;
62-
(timeout, this.read_scalar(bitset)?.to_u32()?)
60+
let _timeout = ecx.read_pointer(timeout)?;
61+
let _uaddr2 = ecx.read_pointer(uaddr2)?;
62+
(timeout, ecx.read_scalar(bitset)?.to_u32()?)
6363
} else {
6464
let [_, _, _, _, timeout] =
6565
check_min_arg_count("`syscall(SYS_futex, FUTEX_WAIT, ...)`", args)?;
6666
(timeout, u32::MAX)
6767
};
6868

6969
if bitset == 0 {
70-
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
70+
return ecx.set_last_error_and_return(LibcError("EINVAL"), dest);
7171
}
7272

73-
let timeout = this.deref_pointer_as(timeout, this.libc_ty_layout("timespec"))?;
74-
let timeout = if this.ptr_is_null(timeout.ptr())? {
73+
let timeout = ecx.deref_pointer_as(timeout, ecx.libc_ty_layout("timespec"))?;
74+
let timeout = if ecx.ptr_is_null(timeout.ptr())? {
7575
None
7676
} else {
77-
let duration = match this.read_timespec(&timeout)? {
77+
let duration = match ecx.read_timespec(&timeout)? {
7878
Some(duration) => duration,
7979
None => {
80-
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
80+
return ecx.set_last_error_and_return(LibcError("EINVAL"), dest);
8181
}
8282
};
8383
let timeout_clock = if op & futex_realtime == futex_realtime {
84-
this.check_no_isolation(
84+
ecx.check_no_isolation(
8585
"`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`",
8686
)?;
8787
TimeoutClock::RealTime
@@ -139,36 +139,36 @@ pub fn futex<'tcx>(
139139
//
140140
// Thankfully, preemptions cannot happen inside a Miri shim, so we do not need to
141141
// do anything special to guarantee fence-load-comparison atomicity.
142-
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
142+
ecx.atomic_fence(AtomicFenceOrd::SeqCst)?;
143143
// Read an `i32` through the pointer, regardless of any wrapper types.
144144
// It's not uncommon for `addr` to be passed as another type than `*mut i32`, such as `*const AtomicI32`.
145145
// We do an acquire read -- it only seems reasonable that if we observe a value here, we
146146
// actually establish an ordering with that value.
147-
let futex_val = this.read_scalar_atomic(&addr, AtomicReadOrd::Acquire)?.to_i32()?;
147+
let futex_val = ecx.read_scalar_atomic(&addr, AtomicReadOrd::Acquire)?.to_i32()?;
148148
if val == futex_val {
149149
// The value still matches, so we block the thread and make it wait for FUTEX_WAKE.
150150

151151
// This cannot fail since we already did an atomic acquire read on that pointer.
152152
// Acquire reads are only allowed on mutable memory.
153-
let futex_ref = this
153+
let futex_ref = ecx
154154
.get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() })
155155
.unwrap()
156156
.futex
157157
.clone();
158158

159-
this.futex_wait(
159+
ecx.futex_wait(
160160
futex_ref,
161161
bitset,
162162
timeout,
163-
Scalar::from_target_isize(0, this), // retval_succ
164-
Scalar::from_target_isize(-1, this), // retval_timeout
163+
Scalar::from_target_isize(0, ecx), // retval_succ
164+
Scalar::from_target_isize(-1, ecx), // retval_timeout
165165
dest.clone(),
166166
LibcError("ETIMEDOUT"), // errno_timeout
167167
);
168168
} else {
169169
// The futex value doesn't match the expected value, so we return failure
170170
// right away without sleeping: -1 and errno set to EAGAIN.
171-
return this.set_last_error_and_return(LibcError("EAGAIN"), dest);
171+
return ecx.set_last_error_and_return(LibcError("EAGAIN"), dest);
172172
}
173173
}
174174
// FUTEX_WAKE: (int *addr, int op = FUTEX_WAKE, int val)
@@ -179,42 +179,42 @@ pub fn futex<'tcx>(
179179
// Same as FUTEX_WAKE, but allows you to specify a bitset to select which threads to wake up.
180180
op if op == futex_wake || op == futex_wake_bitset => {
181181
let Some(futex_ref) =
182-
this.get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() })
182+
ecx.get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() })
183183
else {
184184
// No AllocId, or no live allocation at that AllocId.
185185
// Return an error code. (That seems nicer than silently doing something non-intuitive.)
186186
// This means that if an address gets reused by a new allocation,
187187
// we'll use an independent futex queue for this... that seems acceptable.
188-
return this.set_last_error_and_return(LibcError("EFAULT"), dest);
188+
return ecx.set_last_error_and_return(LibcError("EFAULT"), dest);
189189
};
190190
let futex_ref = futex_ref.futex.clone();
191191

192192
let bitset = if op == futex_wake_bitset {
193193
let [_, _, _, _, timeout, uaddr2, bitset] =
194194
check_min_arg_count("`syscall(SYS_futex, FUTEX_WAKE_BITSET, ...)`", args)?;
195-
let _timeout = this.read_pointer(timeout)?;
196-
let _uaddr2 = this.read_pointer(uaddr2)?;
197-
this.read_scalar(bitset)?.to_u32()?
195+
let _timeout = ecx.read_pointer(timeout)?;
196+
let _uaddr2 = ecx.read_pointer(uaddr2)?;
197+
ecx.read_scalar(bitset)?.to_u32()?
198198
} else {
199199
u32::MAX
200200
};
201201
if bitset == 0 {
202-
return this.set_last_error_and_return(LibcError("EINVAL"), dest);
202+
return ecx.set_last_error_and_return(LibcError("EINVAL"), dest);
203203
}
204204
// Together with the SeqCst fence in futex_wait, this makes sure that futex_wait
205205
// will see the latest value on addr which could be changed by our caller
206206
// before doing the syscall.
207-
this.atomic_fence(AtomicFenceOrd::SeqCst)?;
207+
ecx.atomic_fence(AtomicFenceOrd::SeqCst)?;
208208
let mut n = 0;
209209
#[expect(clippy::arithmetic_side_effects)]
210210
for _ in 0..val {
211-
if this.futex_wake(&futex_ref, bitset)? {
211+
if ecx.futex_wake(&futex_ref, bitset)? {
212212
n += 1;
213213
} else {
214214
break;
215215
}
216216
}
217-
this.write_scalar(Scalar::from_target_isize(n, this), dest)?;
217+
ecx.write_scalar(Scalar::from_target_isize(n, ecx), dest)?;
218218
}
219219
op => throw_unsup_format!("Miri does not support `futex` syscall with op={}", op),
220220
}

0 commit comments

Comments
 (0)