Skip to content

Commit e9c03d5

Browse files
committed
Add support for dynamically updating the memory capacity
1 parent 8acc071 commit e9c03d5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

python/icicle/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ def exception_value(self) -> int: ...
104104

105105
sp: int
106106

107+
"""
108+
Physical memory capacity in pages (adjust when seeing OutOfMemory)
109+
The default limit is set so that the maximum corresponds to ~400 MB of host memory.
110+
"""
111+
mem_capacity: int
112+
107113
# TODO: API to get memory information?
108114

109115
def mem_map(self, address: int, size: int, protection: MemoryProtection): ...
@@ -146,7 +152,7 @@ def __init__(self, message: str, code: MemoryExceptionCode):
146152
self.code = code
147153

148154
def __str__(self):
149-
return f"{super().__str__()}: {self.code}"
155+
return f"{super().__str__()} ({self.code})"
150156

151157
def __ghidra_init():
152158
import os

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ impl Icicle {
312312
self.vm.cpu.write_reg(self.vm.cpu.arch.reg_sp, address)
313313
}
314314

315+
#[getter]
316+
pub fn get_mem_capacity(&self) -> usize {
317+
self.vm.cpu.mem.capacity()
318+
}
319+
320+
#[setter]
321+
pub fn set_mem_capacity(&mut self, capacity: usize) -> PyResult<()> {
322+
if self.vm.cpu.mem.set_capacity(capacity) {
323+
return Ok(());
324+
}
325+
Err(
326+
raise_MemoryException(
327+
format!("Reducing memory capacity is not supported"),
328+
MemError::Unknown,
329+
)
330+
)
331+
}
332+
315333
#[new]
316334
#[pyo3(signature = (
317335
architecture,

0 commit comments

Comments
 (0)