Skip to content

Commit 0fc786f

Browse files
authored
Merge pull request #22 from icicle-emu/uninitialized-memory
Map memory as initialized unless `track_uninitialized` is enabled
2 parents aef686f + 583932d commit 0fc786f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::borrow::Cow;
22
use std::collections::HashMap;
33
use icicle_cpu::mem::{Mapping, MemError, perm};
4-
use icicle_cpu::{Cpu, ExceptionCode, ValueSource, VarSource, VmExit};
4+
use icicle_cpu::{Cpu, ExceptionCode, ValueSource, VmExit};
55
use pyo3::prelude::*;
66
use icicle_vm;
77
use pyo3::exceptions::*;
88
use target_lexicon;
99
use indexmap::IndexMap;
1010
use target_lexicon::Architecture;
11-
use icicle_cpu::lifter::InstructionSource;
1211
use sleigh_runtime::NamedRegister;
1312

1413
// References:
@@ -270,7 +269,7 @@ impl Icicle {
270269

271270
#[getter]
272271
pub fn get_icount(&mut self) -> u64 {
273-
return self.vm.cpu.icount;
272+
self.vm.cpu.icount
274273
}
275274

276275
#[setter]
@@ -352,7 +351,7 @@ impl Icicle {
352351
}
353352
}
354353

355-
// Setup the CPU state for the target triple
354+
// Set up the CPU state for the target triple
356355
let mut config = icicle_vm::cpu::Config::from_target_triple(
357356
format!("{architecture}-none").as_str()
358357
);
@@ -412,8 +411,9 @@ impl Icicle {
412411
}
413412

414413
pub fn mem_map(&mut self, address: u64, size: u64, protection: MemoryProtection) -> PyResult<()> {
414+
let init_perm = if self.vm.cpu.mem.track_uninitialized { perm::NONE } else { perm::INIT };
415415
let mapping = Mapping {
416-
perm: convert_protection(protection),
416+
perm: convert_protection(protection) | init_perm,
417417
value: 0,
418418
};
419419
if self.vm.cpu.mem.map_memory_len(address, size, mapping) {
@@ -465,7 +465,7 @@ impl Icicle {
465465
e,
466466
)
467467
})?;
468-
return Ok(Cow::Owned(buffer));
468+
Ok(Cow::Owned(buffer))
469469
}
470470

471471
pub fn mem_write(&mut self, address: u64, data: Vec<u8>) -> PyResult<()> {
@@ -486,7 +486,7 @@ impl Icicle {
486486
let name = sleigh.get_str(reg.name);
487487
result.insert(name.to_string(), (reg.offset, reg.var.size));
488488
}
489-
return Ok(result);
489+
Ok(result)
490490
}
491491

492492
pub fn reg_offset(&self, name: &str) -> PyResult<u32> {

0 commit comments

Comments
 (0)