Skip to main content

sbpf_vm/
syscalls.rs

1use crate::{compute::ComputeMeter, errors::SbpfVmResult, memory::Memory};
2
3/// Trait for handling syscalls
4pub trait SyscallHandler {
5    fn handle(
6        &mut self,
7        name: &str,
8        registers: [u64; 5],
9        memory: &mut Memory,
10        compute: ComputeMeter,
11    ) -> SbpfVmResult<u64>;
12}
13
14/// Mock syscall handler for testing
15#[derive(Debug, Default)]
16pub struct MockSyscallHandler {
17    pub logs: Vec<String>,
18}
19
20impl SyscallHandler for MockSyscallHandler {
21    fn handle(
22        &mut self,
23        name: &str,
24        _registers: [u64; 5],
25        _memory: &mut Memory,
26        _compute: ComputeMeter,
27    ) -> SbpfVmResult<u64> {
28        self.logs.push(format!("syscall: {}", name));
29        Ok(0)
30    }
31}