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:
@@ -70,12 +70,22 @@ impl VirtualMachineRuntime {
|
||||
(glyph, sounds, scenes)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn debug_step_instruction(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
fs: &mut VirtualFS,
|
||||
fs_state: &mut FsState,
|
||||
memcard: &mut MemcardService,
|
||||
open_files: &mut HashMap<u32, String>,
|
||||
next_handle: &mut u32,
|
||||
vm: &mut VirtualMachine,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<CrashReport> {
|
||||
if vm.memcard_boot_result() == Some(0) && memcard.session.boot_pending() {
|
||||
return None;
|
||||
}
|
||||
let was_memcard_boot = vm.memcard_boot_active();
|
||||
if vm.call_stack_is_empty()
|
||||
&& let Err(error) = vm.prepare_boot_call()
|
||||
{
|
||||
@@ -85,23 +95,33 @@ impl VirtualMachineRuntime {
|
||||
}
|
||||
let step_result = {
|
||||
let mut ctx = HostContext::new_platform(Some(platform));
|
||||
let mut fs = VirtualFS::new();
|
||||
let mut fs_state = FsState::Unmounted;
|
||||
let mut memcard = MemcardService::new();
|
||||
let mut open_files = HashMap::new();
|
||||
let mut next_handle = 1;
|
||||
let mut host = VmRuntimeHost {
|
||||
runtime: self,
|
||||
log_service,
|
||||
fs: &mut fs,
|
||||
fs_state: &mut fs_state,
|
||||
memcard: &mut memcard,
|
||||
open_files: &mut open_files,
|
||||
next_handle: &mut next_handle,
|
||||
fs,
|
||||
fs_state,
|
||||
memcard,
|
||||
open_files,
|
||||
next_handle,
|
||||
};
|
||||
vm.step(&mut host, &mut ctx)
|
||||
};
|
||||
|
||||
if was_memcard_boot
|
||||
&& step_result == Err(LogicalFrameEndingReason::LifecycleComplete)
|
||||
&& let Err(error) = memcard.session.finish_boot(
|
||||
vm.memcard_boot_result() == Some(0),
|
||||
&memcard.lane,
|
||||
Instant::now(),
|
||||
)
|
||||
{
|
||||
let report = CrashReport::VmPanic {
|
||||
message: format!("Memcard bootstrap failed: {error:?}: {}", memcard.diagnostic),
|
||||
pc: Some(vm.pc() as u32),
|
||||
};
|
||||
self.last_crash_report = Some(report.clone());
|
||||
return Some(report);
|
||||
}
|
||||
match step_result {
|
||||
Ok(())
|
||||
| Err(
|
||||
@@ -201,6 +221,55 @@ impl VirtualMachineRuntime {
|
||||
signals: &InputSignals,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<CrashReport> {
|
||||
if vm.memcard_boot_active() {
|
||||
let reason = self.tick_lifecycle(
|
||||
log_service,
|
||||
fs,
|
||||
fs_state,
|
||||
mem_card,
|
||||
open_files,
|
||||
next_handle,
|
||||
vm,
|
||||
platform,
|
||||
false,
|
||||
);
|
||||
let failure = match reason {
|
||||
LogicalFrameEndingReason::LifecycleComplete => {
|
||||
let ready = vm.memcard_boot_result() == Some(0);
|
||||
mem_card.session.finish_boot(ready, &mem_card.lane, Instant::now()).err().map(
|
||||
|error| CrashReport::VmPanic {
|
||||
message: format!(
|
||||
"Memcard bootstrap failed: {error:?}: {}",
|
||||
mem_card.diagnostic
|
||||
),
|
||||
pc: Some(vm.pc() as u32),
|
||||
},
|
||||
)
|
||||
}
|
||||
LogicalFrameEndingReason::BudgetExhausted
|
||||
| LogicalFrameEndingReason::Breakpoint => None,
|
||||
LogicalFrameEndingReason::Trap(trap) => Some(CrashReport::VmTrap { trap }),
|
||||
other => Some(CrashReport::VmPanic {
|
||||
message: format!("Memcard bootstrap stopped: {other:?}"),
|
||||
pc: Some(vm.pc() as u32),
|
||||
}),
|
||||
};
|
||||
if let Some(report) = &failure {
|
||||
self.last_crash_report = Some(report.clone());
|
||||
}
|
||||
return failure;
|
||||
}
|
||||
if vm.memcard_boot_result() == Some(0) {
|
||||
if let Some(error) = mem_card.session.boot_error() {
|
||||
return Some(CrashReport::VmPanic {
|
||||
message: format!("Memcard registration failed: {error:?}"),
|
||||
pc: Some(vm.pc() as u32),
|
||||
});
|
||||
}
|
||||
if mem_card.session.boot_pending() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
let start = Instant::now();
|
||||
self.tick_index += 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user