Auto merge of #938 - christianpoveda:clean-env-alloc, r=RalfJung
Rewrite alloc_env_var Just to simplify the logic behind `shims::env`
This commit is contained in:
commit
2bf8c3a494
@ -1,6 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use rustc::ty::layout::{Size, Align};
|
use rustc::ty::layout::{Size};
|
||||||
use rustc_mir::interpret::{Pointer, Memory};
|
use rustc_mir::interpret::{Pointer, Memory};
|
||||||
use crate::stacked_borrows::Tag;
|
use crate::stacked_borrows::Tag;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
@ -36,24 +36,11 @@ fn alloc_env_var<'mir, 'tcx>(
|
|||||||
value: &[u8],
|
value: &[u8],
|
||||||
memory: &mut Memory<'mir, 'tcx, Evaluator<'tcx>>,
|
memory: &mut Memory<'mir, 'tcx, Evaluator<'tcx>>,
|
||||||
) -> Pointer<Tag> {
|
) -> Pointer<Tag> {
|
||||||
let bytes = [name, b"=", value].concat();
|
let mut bytes = name.to_vec();
|
||||||
let tcx = {memory.tcx.tcx};
|
bytes.push(b'=');
|
||||||
let length = bytes.len() as u64;
|
bytes.extend_from_slice(value);
|
||||||
// `+1` for the null terminator.
|
bytes.push(0);
|
||||||
let ptr = memory.allocate(
|
memory.allocate_static_bytes(bytes.as_slice(), MiriMemoryKind::Env.into())
|
||||||
Size::from_bytes(length + 1),
|
|
||||||
Align::from_bytes(1).unwrap(),
|
|
||||||
MiriMemoryKind::Env.into(),
|
|
||||||
);
|
|
||||||
// We just allocated these, so the write cannot fail.
|
|
||||||
let alloc = memory.get_mut(ptr.alloc_id).unwrap();
|
|
||||||
alloc.write_bytes(&tcx, ptr, &bytes).unwrap();
|
|
||||||
let trailing_zero_ptr = ptr.offset(
|
|
||||||
Size::from_bytes(length),
|
|
||||||
&tcx,
|
|
||||||
).unwrap();
|
|
||||||
alloc.write_bytes(&tcx, trailing_zero_ptr, &[0]).unwrap();
|
|
||||||
ptr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
|
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user