|
1 | | -use rustc::ty::{layout::{Size, Align}, TyCtxt}; |
2 | | -use rustc_mir::interpret::Memory; |
| 1 | +use std::collections::HashMap; |
3 | 2 |
|
| 3 | +use rustc::ty::{layout::{Size, Align}, TyCtxt}; |
| 4 | +use rustc_mir::interpret::{Pointer, Memory}; |
| 5 | +use crate::stacked_borrows::Tag; |
4 | 6 | use crate::*; |
5 | 7 |
|
| 8 | +#[derive(Default)] |
| 9 | +pub struct EnvVars { |
| 10 | + map: HashMap<Vec<u8>, Pointer<Tag>>, |
| 11 | +} |
| 12 | + |
| 13 | +impl EnvVars { |
| 14 | + pub(crate) fn init<'mir, 'tcx>( |
| 15 | + ecx: &mut InterpCx<'mir, 'tcx, Evaluator<'tcx>>, |
| 16 | + tcx: &TyCtxt<'tcx>, |
| 17 | + ) { |
| 18 | + for (name, value) in std::env::vars() { |
| 19 | + let value = alloc_env_value(value.as_bytes(), ecx.memory_mut(), tcx); |
| 20 | + ecx.machine.env_vars.map.insert(name.into_bytes(), value); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + pub(crate) fn get(&self, name: &[u8]) -> Option<&Pointer<Tag>> { |
| 25 | + self.map.get(name) |
| 26 | + } |
| 27 | + |
| 28 | + pub(crate) fn unset(&mut self, name: &[u8]) -> Option<Pointer<Tag>> { |
| 29 | + self.map.remove(name) |
| 30 | + } |
| 31 | + |
| 32 | + pub(crate) fn set(&mut self, name: Vec<u8>, ptr: Pointer<Tag>) -> Option<Pointer<Tag>>{ |
| 33 | + self.map.insert(name, ptr) |
| 34 | + } |
| 35 | +} |
| 36 | + |
6 | 37 | pub(crate) fn alloc_env_value<'mir, 'tcx>( |
7 | 38 | bytes: &[u8], |
8 | 39 | memory: &mut Memory<'mir, 'tcx, Evaluator<'tcx>>, |
|
0 commit comments