ckb_debugger/
syscall_random.rs

1use ckb_vm::{
2    Error, Register, SupportMachine, Syscalls,
3    registers::{A0, A7},
4};
5
6pub struct Random {}
7
8impl Random {
9    pub fn new() -> Self {
10        Self {}
11    }
12}
13
14impl<Mac: SupportMachine> Syscalls<Mac> for Random {
15    fn initialize(&mut self, _machine: &mut Mac) -> Result<(), Error> {
16        Ok(())
17    }
18
19    fn ecall(&mut self, machine: &mut Mac) -> Result<bool, Error> {
20        let id = machine.registers()[A7].to_u64();
21        if id != 9002 {
22            return Ok(false);
23        }
24        let r = crate::arch::random();
25        machine.set_register(A0, Mac::REG::from_u64(r));
26        return Ok(true);
27    }
28}