Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions crates/celox/src/backend/native/runtime_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ impl NativeProgramInstance {
///
/// The image's machine code must come from a trusted source. Image
/// validation is structural and does not authenticate executable code.
///
/// An image with process kernels, which only a timed
/// [`crate::Simulation`] runs, fails to attach.
pub unsafe fn from_image(image: NativeProgramImage) -> Result<Self, NativeProgramLoadError> {
let schema = image.runtime_schema();
if !schema.processes.is_empty() {
let origin = schema.process_origins.first().cloned().unwrap_or_default();
return Err(NativeProgramLoadError::Attach(SimulatorError::new(
crate::SimulatorErrorKind::ProcessRequiresSimulation(origin),
)));
}
// Safety: upheld by this constructor's caller.
let shared = Arc::new(
unsafe { SharedNativeCode::from_image(image) }
Expand Down
22 changes: 22 additions & 0 deletions crates/celox/src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,28 @@ impl<B: SimBackend> Simulation<B> {
Ok(())
}

/// Run every time slot before `time`, then move to `time` without
/// running its slot: the next [`Self::step`] or [`Self::run_until`]
/// runs it, together with the host writes made in between. A target not
/// after the current time changes nothing. Like [`Self::run_until`], it
/// returns early, before `time`, at a `$stop` or `$finish`.
pub fn advance_to(&mut self, time: u64) -> Result<(), RuntimeErrorCode> {
let Some(last) = time.checked_sub(1).filter(|&last| last >= self.time()) else {
return Ok(());
};
self.run_until(last)?;
if self.time() != last || self.is_finished() || self.is_stopped() {
return Ok(());
}
self.state.advance_time(&mut self.simulator.backend, time);
if let Some(shadow) = &mut self.shadow {
shadow
.state
.advance_time(&mut shadow.simulator.backend, time);
}
Ok(())
}

/// Like [`Self::run_until`], but takes at most `max_steps` steps.
/// Returns `false`, with the simulation at the time of its last step,
/// when another step would be needed to reach `end_time`, including when
Expand Down
Loading
Loading