From 37c9824cd7674aa9b8b9f094cf3a93e6da2c1f99 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 8 Sep 2026 17:31:44 +0200 Subject: vnf: refuse to proceed if the machine is inactive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/vnf/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 729bd58..0b15d6a 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -659,8 +659,20 @@ impl Machine { Ok(()) } - /// Step the execution of the machine by one instruction. + /// Step the execution of the machine by one instruction. It will return an + /// error if the execution fails for whatever reason, but also if this + /// machine is no longer active. Hence, if the machine has been deactivated + /// for some reason (e.g. an unexpected 'brk' with 'Machine.halt_on_brk' set + /// to true), then it's up to the caller to create a new [`Machine`] + /// instance. pub fn next_iteration(&mut self) -> Result<(), String> { + // This is a public function, and so it can be called even if it doesn't + // make sense to do so. Let's make a sanity check and return an error + // whenever the machine is set to be inactive. + if !self.active { + return Err("the machine is no longer active, cannot iterate over it".to_string()); + } + // Perform a new iteration of the PPU and the CPU. self.next_ppu()?; self.execute()?; -- cgit v1.2.3