mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
679 B
Rust
24 lines
679 B
Rust
use std::{cell::RefCell, ffi::c_long, io, ptr};
|
|
|
|
use libc::c_void;
|
|
|
|
use super::{SysResult, Syscall};
|
|
|
|
type SyscallFn = unsafe fn(Syscall<'_>) -> SysResult<c_long>;
|
|
|
|
#[cfg(test)]
|
|
thread_local! {
|
|
pub(crate) static TEST_SYSCALL: RefCell<SyscallFn> = RefCell::new(test_syscall);
|
|
pub(crate) static TEST_MMAP_RET: RefCell<*mut c_void> = RefCell::new(ptr::null_mut());
|
|
}
|
|
|
|
#[cfg(test)]
|
|
unsafe fn test_syscall(_call: Syscall<'_>) -> SysResult<c_long> {
|
|
Err((-1, io::Error::from_raw_os_error(libc::EINVAL)))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub(crate) fn override_syscall(call: unsafe fn(Syscall<'_>) -> SysResult<c_long>) {
|
|
TEST_SYSCALL.with(|test_impl| *test_impl.borrow_mut() = call);
|
|
}
|