feat(runtime): implement shared transactional memcard with async saves
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
This commit is contained in:
@@ -9,6 +9,7 @@ mod dynamic;
|
||||
mod gc;
|
||||
mod lifecycle;
|
||||
mod loader;
|
||||
mod native_arrays;
|
||||
mod random;
|
||||
mod reference;
|
||||
mod runtime;
|
||||
@@ -114,6 +115,9 @@ pub struct VirtualMachine {
|
||||
halted: bool,
|
||||
lifecycle: Option<lifecycle::LifecycleCall>,
|
||||
lifecycle_failure: Option<LogicalFrameEndingReason>,
|
||||
memcard_boot_started: bool,
|
||||
memcard_boot_result: Option<i32>,
|
||||
memcard_boot_required: bool,
|
||||
/// Set of ROM addresses used for software breakpoints in the debugger.
|
||||
breakpoints: std::collections::HashSet<usize>,
|
||||
/// GC: number of newly allocated live objects threshold to trigger a collection at safepoint.
|
||||
@@ -235,6 +239,9 @@ impl VirtualMachine {
|
||||
cycles: 0,
|
||||
halted: true,
|
||||
lifecycle: None,
|
||||
memcard_boot_started: false,
|
||||
memcard_boot_result: None,
|
||||
memcard_boot_required: false,
|
||||
lifecycle_failure: None,
|
||||
breakpoints: std::collections::HashSet::new(),
|
||||
gc_alloc_threshold: 1024, // conservative default; tests may override
|
||||
@@ -844,6 +851,11 @@ impl VirtualMachine {
|
||||
self.operand_stack
|
||||
.reserve(syscall.results_count())
|
||||
.map_err(|e| self.resource_trap(e, opcode, start_pc as u32))?;
|
||||
let mut arrays = native_arrays::SessionArrays {
|
||||
heap: &mut self.heap,
|
||||
registry: self.validated_image.as_ref().map(|image| image.registry().as_ref()),
|
||||
work: 0,
|
||||
};
|
||||
let mut strings = strings::SessionStringAllocator {
|
||||
ledger: &mut self.strings,
|
||||
budget: self.budget.clone(),
|
||||
@@ -852,10 +864,12 @@ impl VirtualMachine {
|
||||
self.operand_stack.native_result_buffer(),
|
||||
syscall.results_count(),
|
||||
&mut strings,
|
||||
);
|
||||
)
|
||||
.with_arrays(&mut arrays);
|
||||
let native_result = native.syscall(id, &args, &mut ret, ctx);
|
||||
let return_overflow = ret.overflowed();
|
||||
let return_failure = ret.failure().cloned();
|
||||
self.cycles += arrays.work;
|
||||
let native_result = return_failure.map(Err).unwrap_or(native_result);
|
||||
if native_result.is_err() {
|
||||
self.operand_stack.truncate(stack_height_before);
|
||||
@@ -885,6 +899,16 @@ impl VirtualMachine {
|
||||
return_overflow
|
||||
)));
|
||||
}
|
||||
if syscall == prometeu_hal::syscalls::Syscall::MemBootstrap {
|
||||
let context = self.pop_integer().map_err(LogicalFrameEndingReason::Panic)?;
|
||||
if !self.begin_memcard_boot(context).map_err(|e| {
|
||||
LogicalFrameEndingReason::Panic(format!("Invalid memcard bootstrap: {e:?}"))
|
||||
})? {
|
||||
return Err(LogicalFrameEndingReason::Panic(
|
||||
"Missing memcard boot binding".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
OpCode::Intrinsic => {
|
||||
let pc_at_intrinsic = start_pc as u32;
|
||||
@@ -1046,6 +1070,11 @@ impl VirtualMachine {
|
||||
return self.execute_collection(opcode, ty, field, start_pc as u32);
|
||||
}
|
||||
OpCode::FrameSync => {
|
||||
if self.memcard_boot_required && self.memcard_boot_result != Some(0) {
|
||||
return Err(LogicalFrameEndingReason::Panic(
|
||||
"Frame entered before memcard bootstrap admission".into(),
|
||||
));
|
||||
}
|
||||
if self.lifecycle.is_some() {
|
||||
return Err(self.trap(
|
||||
TRAP_TYPE,
|
||||
|
||||
Reference in New Issue
Block a user