-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environ shim #1147
Environ shim #1147
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ use std::ffi::{OsString, OsStr}; | |||||
use std::env; | ||||||
|
||||||
use crate::stacked_borrows::Tag; | ||||||
use crate::rustc_target::abi::LayoutOf; | ||||||
use crate::*; | ||||||
|
||||||
use rustc::ty::layout::Size; | ||||||
|
@@ -20,15 +21,34 @@ impl EnvVars { | |||||
ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>, | ||||||
excluded_env_vars: Vec<String>, | ||||||
) { | ||||||
let mut vars = Vec::new(); | ||||||
if ecx.machine.communicate { | ||||||
// Put each environment variable pointer in `EnvVars`, collect pointers. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for (name, value) in env::vars() { | ||||||
if !excluded_env_vars.contains(&name) { | ||||||
let var_ptr = | ||||||
alloc_env_var_as_c_str(name.as_ref(), value.as_ref(), ecx); | ||||||
ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr); | ||||||
vars.push(var_ptr.into()); | ||||||
} | ||||||
} | ||||||
} | ||||||
// add trailing null pointer | ||||||
vars.push(Scalar::from_int(0, ecx.pointer_size())); | ||||||
// Make an array with all these pointers, in the Miri memory. | ||||||
let tcx = ecx.tcx; | ||||||
let environ_layout = | ||||||
ecx.layout_of(tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), vars.len() as u64)).unwrap(); | ||||||
let environ_place = ecx.allocate(environ_layout, MiriMemoryKind::Env.into()); | ||||||
for (idx, var) in vars.into_iter().enumerate() { | ||||||
pvdrz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
let place = ecx.mplace_field(environ_place, idx as u64).unwrap(); | ||||||
ecx.write_scalar(var, place.into()).unwrap(); | ||||||
} | ||||||
ecx.memory.mark_immutable(environ_place.ptr.assert_ptr().alloc_id).unwrap(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this prevent later uses of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the question is, do we try to be smart and recycle those lists, or do we just allocate a new one on each change? But either way, we'll have to construct such a list multiple times -- so it probably should have its own function. |
||||||
// A pointer to that place corresponds to the `environ` static. | ||||||
let environ_ptr = ecx.force_ptr(environ_place.ptr).unwrap(); | ||||||
let environ_alloc = ecx.memory.get_raw(environ_ptr.alloc_id).unwrap().clone(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is suboptimal as the allocation will be left in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having the allocation last forever makes sense to me, it's a static after all. We'll also need to update this allocation when the environment changes (whenever |
||||||
ecx.memory.extra.environ = Some(environ_alloc); | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's some odd formatting... either all arguments should be on one line, or they should all have their own line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I have rustfmt disabled to avoid huge diffs. I'll do the formatting when I have a more concise PR