Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 61d496e

Browse files
authored
Merge pull request rust-lang#4030 from YohDeadfall/ecx
Renamed `this` to `ecx` in `extern_static`
2 parents a77ff2e + bd7772d commit 61d496e

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

src/tools/miri/src/shims/extern_static.rs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,83 @@ use crate::*;
44

55
impl<'tcx> MiriMachine<'tcx> {
66
fn alloc_extern_static(
7-
this: &mut MiriInterpCx<'tcx>,
7+
ecx: &mut MiriInterpCx<'tcx>,
88
name: &str,
99
val: ImmTy<'tcx>,
1010
) -> InterpResult<'tcx> {
11-
let place = this.allocate(val.layout, MiriMemoryKind::ExternStatic.into())?;
12-
this.write_immediate(*val, &place)?;
13-
Self::add_extern_static(this, name, place.ptr());
11+
let place = ecx.allocate(val.layout, MiriMemoryKind::ExternStatic.into())?;
12+
ecx.write_immediate(*val, &place)?;
13+
Self::add_extern_static(ecx, name, place.ptr());
1414
interp_ok(())
1515
}
1616

1717
/// Zero-initialized pointer-sized extern statics are pretty common.
1818
/// Most of them are for weak symbols, which we all set to null (indicating that the
1919
/// symbol is not supported, and triggering fallback code which ends up calling
2020
/// some other shim that we do support).
21-
fn null_ptr_extern_statics(
22-
this: &mut MiriInterpCx<'tcx>,
23-
names: &[&str],
24-
) -> InterpResult<'tcx> {
21+
fn null_ptr_extern_statics(ecx: &mut MiriInterpCx<'tcx>, names: &[&str]) -> InterpResult<'tcx> {
2522
for name in names {
26-
let val = ImmTy::from_int(0, this.machine.layouts.usize);
27-
Self::alloc_extern_static(this, name, val)?;
23+
let val = ImmTy::from_int(0, ecx.machine.layouts.usize);
24+
Self::alloc_extern_static(ecx, name, val)?;
2825
}
2926
interp_ok(())
3027
}
3128

3229
/// Extern statics that are initialized with function pointers to the symbols of the same name.
3330
fn weak_symbol_extern_statics(
34-
this: &mut MiriInterpCx<'tcx>,
31+
ecx: &mut MiriInterpCx<'tcx>,
3532
names: &[&str],
3633
) -> InterpResult<'tcx> {
3734
for name in names {
38-
assert!(this.is_dyn_sym(name), "{name} is not a dynamic symbol");
39-
let layout = this.machine.layouts.const_raw_ptr;
40-
let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str(name)));
41-
let val = ImmTy::from_scalar(Scalar::from_pointer(ptr, this), layout);
42-
Self::alloc_extern_static(this, name, val)?;
35+
assert!(ecx.is_dyn_sym(name), "{name} is not a dynamic symbol");
36+
let layout = ecx.machine.layouts.const_raw_ptr;
37+
let ptr = ecx.fn_ptr(FnVal::Other(DynSym::from_str(name)));
38+
let val = ImmTy::from_scalar(Scalar::from_pointer(ptr, ecx), layout);
39+
Self::alloc_extern_static(ecx, name, val)?;
4340
}
4441
interp_ok(())
4542
}
4643

4744
/// Sets up the "extern statics" for this machine.
48-
pub fn init_extern_statics(this: &mut MiriInterpCx<'tcx>) -> InterpResult<'tcx> {
45+
pub fn init_extern_statics(ecx: &mut MiriInterpCx<'tcx>) -> InterpResult<'tcx> {
4946
// "__rust_no_alloc_shim_is_unstable"
50-
let val = ImmTy::from_int(0, this.machine.layouts.u8); // always 0, value does not matter
51-
Self::alloc_extern_static(this, "__rust_no_alloc_shim_is_unstable", val)?;
47+
let val = ImmTy::from_int(0, ecx.machine.layouts.u8); // always 0, value does not matter
48+
Self::alloc_extern_static(ecx, "__rust_no_alloc_shim_is_unstable", val)?;
5249

5350
// "__rust_alloc_error_handler_should_panic"
54-
let val = this.tcx.sess.opts.unstable_opts.oom.should_panic();
55-
let val = ImmTy::from_int(val, this.machine.layouts.u8);
56-
Self::alloc_extern_static(this, "__rust_alloc_error_handler_should_panic", val)?;
51+
let val = ecx.tcx.sess.opts.unstable_opts.oom.should_panic();
52+
let val = ImmTy::from_int(val, ecx.machine.layouts.u8);
53+
Self::alloc_extern_static(ecx, "__rust_alloc_error_handler_should_panic", val)?;
5754

58-
if this.target_os_is_unix() {
55+
if ecx.target_os_is_unix() {
5956
// "environ" is mandated by POSIX.
60-
let environ = this.machine.env_vars.unix().environ();
61-
Self::add_extern_static(this, "environ", environ);
57+
let environ = ecx.machine.env_vars.unix().environ();
58+
Self::add_extern_static(ecx, "environ", environ);
6259
}
6360

64-
match this.tcx.sess.target.os.as_ref() {
61+
match ecx.tcx.sess.target.os.as_ref() {
6562
"linux" => {
66-
Self::null_ptr_extern_statics(this, &[
63+
Self::null_ptr_extern_statics(ecx, &[
6764
"__cxa_thread_atexit_impl",
6865
"__clock_gettime64",
6966
])?;
70-
Self::weak_symbol_extern_statics(this, &["getrandom", "statx"])?;
67+
Self::weak_symbol_extern_statics(ecx, &["getrandom", "statx"])?;
7168
}
7269
"freebsd" => {
73-
Self::null_ptr_extern_statics(this, &["__cxa_thread_atexit_impl"])?;
70+
Self::null_ptr_extern_statics(ecx, &["__cxa_thread_atexit_impl"])?;
7471
}
7572
"android" => {
76-
Self::null_ptr_extern_statics(this, &["bsd_signal"])?;
77-
Self::weak_symbol_extern_statics(this, &["signal", "getrandom"])?;
73+
Self::null_ptr_extern_statics(ecx, &["bsd_signal"])?;
74+
Self::weak_symbol_extern_statics(ecx, &["signal", "getrandom"])?;
7875
}
7976
"windows" => {
8077
// "_tls_used"
8178
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
82-
let val = ImmTy::from_int(0, this.machine.layouts.u8);
83-
Self::alloc_extern_static(this, "_tls_used", val)?;
79+
let val = ImmTy::from_int(0, ecx.machine.layouts.u8);
80+
Self::alloc_extern_static(ecx, "_tls_used", val)?;
8481
}
8582
"illumos" | "solaris" => {
86-
Self::weak_symbol_extern_statics(this, &["pthread_setname_np"])?;
83+
Self::weak_symbol_extern_statics(ecx, &["pthread_setname_np"])?;
8784
}
8885
_ => {} // No "extern statics" supported on this target
8986
}

0 commit comments

Comments
 (0)