Skip to content

Fix_zero_offset_output_base_assumption #2068

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions vm/src/vm/runners/builtin_runner/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
#[derive(Debug, Clone, PartialEq)]
pub struct OutputBuiltinState {
pub base: usize,
pub base_offset: usize,
pub pages: Pages,
pub attributes: Attributes,
}

#[derive(Debug, Clone)]
pub struct OutputBuiltinRunner {
base: usize,
pub base_offset: usize,
pub(crate) pages: Pages,
pub(crate) attributes: Attributes,
pub(crate) stop_ptr: Option<usize>,
Expand All @@ -29,15 +31,17 @@ impl OutputBuiltinRunner {
pub fn new(included: bool) -> OutputBuiltinRunner {
OutputBuiltinRunner {
base: 0,
base_offset: 0,
pages: HashMap::default(),
attributes: HashMap::default(),
stop_ptr: None,
included,
}
}

pub fn new_state(&mut self, base: usize, included: bool) {
pub fn new_state(&mut self, base: usize, base_offset: usize, included: bool) {
self.base = base;
self.base_offset = base_offset;
self.pages = HashMap::default();
self.attributes = HashMap::default();
self.stop_ptr = None;
Expand Down Expand Up @@ -143,13 +147,15 @@ impl OutputBuiltinRunner {

pub fn set_state(&mut self, new_state: OutputBuiltinState) {
self.base = new_state.base;
self.base_offset = new_state.base_offset;
self.pages = new_state.pages;
self.attributes = new_state.attributes;
}

pub fn get_state(&mut self) -> OutputBuiltinState {
OutputBuiltinState {
base: self.base,
base_offset: self.base_offset,
pages: self.pages.clone(),
attributes: self.attributes.clone(),
}
Expand All @@ -168,7 +174,7 @@ impl OutputBuiltinRunner {
self.pages.insert(
page_id,
PublicMemoryPage {
start: page_start.offset,
start: page_start.offset - self.base_offset,
size: page_size,
},
);
Expand Down Expand Up @@ -493,6 +499,7 @@ mod tests {

let new_state = OutputBuiltinState {
base: 10,
base_offset: 0,
pages: HashMap::from([(1, PublicMemoryPage { start: 0, size: 3 })]),
attributes: HashMap::from([("gps_fact_topology".to_string(), vec![0, 2, 0])]),
};
Expand All @@ -510,6 +517,7 @@ mod tests {
fn new_state() {
let mut builtin = OutputBuiltinRunner {
base: 10,
base_offset: 0,
pages: HashMap::from([(1, PublicMemoryPage { start: 0, size: 3 })]),
attributes: HashMap::from([("gps_fact_topology".to_string(), vec![0, 2, 0])]),
stop_ptr: Some(10),
Expand All @@ -518,9 +526,10 @@ mod tests {

let new_base = 11;
let new_included = false;
builtin.new_state(new_base, new_included);
builtin.new_state(new_base, 2, new_included);

assert_eq!(builtin.base, new_base);
assert_eq!(builtin.base_offset, 2);
assert!(builtin.pages.is_empty());
assert!(builtin.attributes.is_empty());
assert_eq!(builtin.stop_ptr, None);
Expand Down Expand Up @@ -614,6 +623,7 @@ mod tests {
fn get_and_extend_additional_data() {
let builtin_a = OutputBuiltinRunner {
base: 0,
base_offset: 0,
pages: HashMap::from([(1, PublicMemoryPage { start: 0, size: 3 })]),
attributes: HashMap::from([("gps_fact_topology".to_string(), vec![0, 2, 0])]),
stop_ptr: None,
Expand All @@ -622,6 +632,7 @@ mod tests {
let additional_data = builtin_a.get_additional_data();
let mut builtin_b = OutputBuiltinRunner {
base: 0,
base_offset: 0,
pages: Default::default(),
attributes: Default::default(),
stop_ptr: None,
Expand Down
Loading