From 04523fe0d34e586d6cce9bce689572bf2469a9f9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 10 Jan 2020 10:44:38 -0500 Subject: [PATCH] wip --- src/machine.rs | 7 +++++-- src/shims/env.rs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index f0cbe3f93a..ff4f8674ac 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -272,8 +272,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> { fn find_foreign_static( tcx: TyCtxt<'tcx>, def_id: DefId, - _memory_extra: &MemoryExtra, - ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> { + memory_extra: &MemoryExtra, + ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> { let attrs = tcx.get_attrs(def_id); let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) { Some(name) => name.as_str(), @@ -287,6 +287,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> { let data = vec![0; size.bytes() as usize]; Allocation::from_bytes(&data, tcx.data_layout.pointer_align.abi) } + "environ" => { + memory_extra.environ.as_ref().unwrap().clone() + } _ => throw_unsup_format!("can't access foreign static: {}", link_name), }; Ok(Cow::Owned(alloc)) diff --git a/src/shims/env.rs b/src/shims/env.rs index b68e000db2..bc0d66e439 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -44,7 +44,8 @@ impl EnvVars { } ecx.memory.mark_immutable(environ_place.ptr.assert_ptr().alloc_id).unwrap(); // A pointer to that place corresponds to the `environ` static. - let environ_alloc = ecx.memory.get_raw(environ_place.ptr.assert_ptr().alloc_id).unwrap().clone(); + let environ_ptr = ecx.force_ptr(environ_place.ptr).unwrap(); + let environ_alloc = ecx.memory.get_raw(environ_ptr.alloc_id).unwrap().clone(); ecx.memory.extra.environ = Some(environ_alloc); } }