Skip to content

Commit

Permalink
Add JS test for max instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Feb 24, 2023
1 parent d3c6ecf commit fc45d55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions js/test/js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ describe('Native syscall handlers', () => {
expect(called).toBe(false);
});
});

describe('Respect max instructions to execute', () => {
it('should stop execution when max instructions are reached', async () => {
let axecutor = new Axecutor(exitX86Code, 0x1000n, 0x1000n);
axecutor.set_max_instructions(1n);

axecutor.reg_write_64(Register.RDI, 0n);

await expect(axecutor.execute()).rejects.toThrow();

// The mov rdi, ... instruction must not be executed
expect(axecutor.reg_read_64(Register.RDI)).toBe(0n);
});
});
2 changes: 2 additions & 0 deletions src/state/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ impl Axecutor {

/// Sets an upper limit on the number of instructions that can be executed.
pub fn set_max_instructions(&mut self, max: u64) {
debug_log!("Setting max instructions to {}", max);

self.state.max_instructions = Some(max);
}
}
Expand Down

0 comments on commit fc45d55

Please sign in to comment.