extern crate alloc;
use super::sysno::*;
use crate::c_str::CString;
use crate::syscalls::*;
use crate::types::*;
use alloc::string::String;
use alloc::vec::Vec;
pub fn accept(sockfd: i32, addr: &mut sockaddr_in_t, addrlen: &mut socklen_t) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *mut sockaddr_in_t as usize;
let addrlen_ptr = addrlen as *mut socklen_t as usize;
syscall3(SYS_ACCEPT, sockfd, addr_ptr, addrlen_ptr).map(drop)
}
pub fn accept4(
sockfd: i32,
addr: &mut sockaddr_in_t,
addrlen: &mut socklen_t,
flags: i32,
) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *mut sockaddr_in_t as usize;
let addrlen_ptr = addrlen as *mut socklen_t as usize;
let flags = flags as usize;
syscall4(SYS_ACCEPT4, sockfd, addr_ptr, addrlen_ptr, flags).map(drop)
}
pub fn access(filename: &str, mode: i32) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall2(SYS_ACCESS, filename_ptr, mode).map(drop)
}
pub fn acct(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_ACCT, filename_ptr).map(drop)
}
pub fn add_key(
type_: &str,
description: &str,
payload: usize,
plen: size_t,
dest_keyring: key_serial_t,
) -> Result<key_serial_t, Errno> {
let type_ = CString::new(type_);
let type_ptr = type_.as_ptr() as usize;
let description = CString::new(description);
let description_ptr = description.as_ptr() as usize;
let plen = plen as usize;
let dest_keyring = dest_keyring as usize;
syscall5(
SYS_ADD_KEY,
type_ptr,
description_ptr,
payload,
plen,
dest_keyring,
)
.map(|ret| ret as key_serial_t)
}
pub fn adjtimex(buf: &mut timex_t) -> Result<i32, Errno> {
let buf_ptr = buf as *mut timex_t as usize;
syscall1(SYS_ADJTIMEX, buf_ptr).map(|ret| ret as i32)
}
pub fn afs_syscall() {
core::unimplemented!();
}
pub fn alarm(seconds: u32) -> u32 {
let seconds = seconds as usize;
syscall1(SYS_ALARM, seconds).expect("alarm() failed") as u32
}
pub fn arch_prctl(code: i32, arg2: usize) -> Result<(), Errno> {
let code = code as usize;
syscall2(SYS_ARCH_PRCTL, code, arg2).map(drop)
}
pub fn bind(sockfd: i32, addr: &sockaddr_in_t, addrlen: socklen_t) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *const sockaddr_in_t as usize;
let addrlen = addrlen as usize;
syscall3(SYS_BIND, sockfd, addr_ptr, addrlen).map(drop)
}
pub fn bpf(cmd: i32, attr: &mut bpf_attr_t, size: u32) -> Result<i32, Errno> {
let cmd = cmd as usize;
let attr_ptr = attr as *mut bpf_attr_t as usize;
let size = size as usize;
syscall3(SYS_BPF, cmd, attr_ptr, size).map(|ret| ret as i32)
}
pub fn brk(addr: usize) -> Result<(), Errno> {
syscall1(SYS_BRK, addr).map(drop)
}
pub fn capget(hdrp: &mut cap_user_header_t, data: &mut cap_user_data_t) -> Result<(), Errno> {
let hdrp_ptr = hdrp as *mut cap_user_header_t as usize;
let data_ptr = data as *mut cap_user_data_t as usize;
syscall2(SYS_CAPGET, hdrp_ptr, data_ptr).map(drop)
}
pub fn capset(hdrp: &mut cap_user_header_t, data: &cap_user_data_t) -> Result<(), Errno> {
let hdrp_ptr = hdrp as *mut cap_user_header_t as usize;
let data_ptr = data as *const cap_user_data_t as usize;
syscall2(SYS_CAPSET, hdrp_ptr, data_ptr).map(drop)
}
pub fn chdir(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_CHDIR, filename_ptr).map(drop)
}
pub fn chmod(filename: &str, mode: mode_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall2(SYS_CHMOD, filename_ptr, mode).map(drop)
}
pub fn chown(filename: &str, user: uid_t, group: gid_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let user = user as usize;
let group = group as usize;
syscall3(SYS_CHOWN, filename_ptr, user, group).map(drop)
}
pub fn chroot(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_CHROOT, filename_ptr).map(drop)
}
pub fn clock_adjtime(which_clock: clockid_t, tx: &mut timex_t) -> Result<(), Errno> {
let which_clock = which_clock as usize;
let tx_ptr = tx as *mut timex_t as usize;
syscall2(SYS_CLOCK_ADJTIME, which_clock, tx_ptr).map(drop)
}
pub fn clock_getres(which_clock: clockid_t, tp: &mut timespec_t) -> Result<(), Errno> {
let which_clock = which_clock as usize;
let tp_ptr = tp as *mut timespec_t as usize;
syscall2(SYS_CLOCK_GETRES, which_clock, tp_ptr).map(drop)
}
pub fn clock_gettime(which_clock: clockid_t, tp: &mut timespec_t) -> Result<(), Errno> {
let which_clock = which_clock as usize;
let tp_ptr = tp as *mut timespec_t as usize;
syscall2(SYS_CLOCK_GETTIME, which_clock, tp_ptr).map(drop)
}
pub fn clock_nanosleep(
which_clock: clockid_t,
flags: i32,
rqtp: ×pec_t,
rmtp: &mut timespec_t,
) -> Result<(), Errno> {
let which_clock = which_clock as usize;
let flags = flags as usize;
let rqtp_ptr = rqtp as *const timespec_t as usize;
let rmtp_ptr = rmtp as *mut timespec_t as usize;
syscall4(SYS_CLOCK_NANOSLEEP, which_clock, flags, rqtp_ptr, rmtp_ptr).map(drop)
}
pub fn clock_settime(which_clock: clockid_t, tp: ×pec_t) -> Result<(), Errno> {
let which_clock = which_clock as usize;
let tp_ptr = tp as *const timespec_t as usize;
syscall2(SYS_CLOCK_SETTIME, which_clock, tp_ptr).map(drop)
}
pub fn clone(
clone_flags: i32,
newsp: usize,
parent_tid: &mut i32,
child_tid: &mut i32,
tls: usize,
) -> Result<pid_t, Errno> {
let clone_flags = clone_flags as usize;
let parent_tid_ptr = parent_tid as *mut i32 as usize;
let child_tid_ptr = child_tid as *mut i32 as usize;
syscall5(
SYS_CLONE,
clone_flags,
newsp,
parent_tid_ptr,
child_tid_ptr,
tls,
)
.map(|ret| ret as pid_t)
}
pub fn clone3() {
core::unimplemented!();
}
pub fn close(fd: i32) -> Result<(), Errno> {
let fd = fd as usize;
syscall1(SYS_CLOSE, fd).map(drop)
}
pub fn connect(sockfd: i32, addr: &sockaddr_in_t, addrlen: socklen_t) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *const sockaddr_in_t as usize;
let addrlen = addrlen as usize;
syscall3(SYS_CONNECT, sockfd, addr_ptr, addrlen).map(drop)
}
pub fn copy_file_range(
fd_in: i32,
off_in: &mut loff_t,
fd_out: i32,
off_out: &mut loff_t,
len: size_t,
flags: u32,
) -> Result<ssize_t, Errno> {
let fd_in = fd_in as usize;
let off_in_ptr = off_in as *mut loff_t as usize;
let fd_out = fd_out as usize;
let off_out_ptr = off_out as *mut loff_t as usize;
let len = len as usize;
let flags = flags as usize;
syscall6(
SYS_COPY_FILE_RANGE,
fd_in,
off_in_ptr,
fd_out,
off_out_ptr,
len,
flags,
)
.map(|ret| ret as ssize_t)
}
pub fn creat(filename: &str, mode: mode_t) -> Result<i32, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall2(SYS_CREAT, filename_ptr, mode).map(|ret| ret as i32)
}
pub fn create_module() {
core::unimplemented!();
}
pub fn delete_module(name: &str, flags: i32) -> Result<(), Errno> {
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_DELETE_MODULE, name_ptr, flags).map(drop)
}
pub fn dup(oldfd: i32) -> Result<isize, Errno> {
let oldfd = oldfd as usize;
syscall1(SYS_DUP, oldfd).map(|ret| ret as isize)
}
pub fn dup2(oldfd: i32, newfd: i32) -> Result<(), Errno> {
let oldfd = oldfd as usize;
let newfd = newfd as usize;
syscall2(SYS_DUP2, oldfd, newfd).map(drop)
}
pub fn dup3(oldfd: i32, newfd: i32, flags: i32) -> Result<(), Errno> {
let oldfd = oldfd as usize;
let newfd = newfd as usize;
let flags = flags as usize;
syscall3(SYS_DUP3, oldfd, newfd, flags).map(drop)
}
pub fn epoll_create(size: i32) -> Result<i32, Errno> {
let size = size as usize;
syscall1(SYS_EPOLL_CREATE, size).map(|ret| ret as i32)
}
pub fn epoll_create1(flags: i32) -> Result<i32, Errno> {
let flags = flags as usize;
syscall1(SYS_EPOLL_CREATE1, flags).map(|ret| ret as i32)
}
pub fn epoll_ctl(epfd: i32, op: i32, fd: i32, event: &mut epoll_event_t) -> Result<(), Errno> {
let epfd = epfd as usize;
let op = op as usize;
let fd = fd as usize;
let event_ptr = event as *mut epoll_event_t as usize;
syscall4(SYS_EPOLL_CTL, epfd, op, fd, event_ptr).map(drop)
}
pub fn epoll_ctl_old() {
core::unimplemented!();
}
pub fn epoll_pwait(epfd: i32, op: i32, fd: i32, events: &mut epoll_event_t) -> Result<i32, Errno> {
let epfd = epfd as usize;
let op = op as usize;
let fd = fd as usize;
let events_ptr = events as *mut epoll_event_t as usize;
syscall4(SYS_EPOLL_PWAIT, epfd, op, fd, events_ptr).map(|ret| ret as i32)
}
pub fn epoll_wait(
epfd: i32,
events: &mut epoll_event_t,
maxevents: i32,
timeout: i32,
) -> Result<i32, Errno> {
let epfd = epfd as usize;
let events_ptr = events as *mut epoll_event_t as usize;
let maxevents = maxevents as usize;
let timeout = timeout as usize;
syscall4(SYS_EPOLL_WAIT, epfd, events_ptr, maxevents, timeout).map(|ret| ret as i32)
}
pub fn epoll_wait_old() {
core::unimplemented!();
}
pub fn eventfd(count: u32) -> Result<i32, Errno> {
let count = count as usize;
syscall1(SYS_EVENTFD, count).map(|ret| ret as i32)
}
pub fn eventfd2(count: u32, flags: i32) -> Result<i32, Errno> {
let count = count as usize;
let flags = flags as usize;
syscall2(SYS_EVENTFD2, count, flags).map(|ret| ret as i32)
}
pub fn execve(filename: &str, argv: &[&str], env: &[&str]) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let argv_ptr = argv.as_ptr() as usize;
let env_ptr = env.as_ptr() as usize;
syscall3(SYS_EXECVE, filename_ptr, argv_ptr, env_ptr).map(drop)
}
pub fn execveat(
fd: i32,
filename: &str,
argv: &[&str],
env: &[&str],
flags: i32,
) -> Result<(), Errno> {
let fd = fd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let argv_ptr = argv.as_ptr() as usize;
let env_ptr = env.as_ptr() as usize;
let flags = flags as usize;
syscall5(SYS_EXECVEAT, fd, filename_ptr, argv_ptr, env_ptr, flags).map(drop)
}
pub fn exit(status: u8) {
let status = status as usize;
let _ret = syscall1(SYS_EXIT, status);
}
pub fn exit_group(status: i32) {
let status = status as usize;
let _ret = syscall1(SYS_EXIT_GROUP, status);
}
pub fn faccessat(dfd: i32, filename: &str, mode: i32) -> Result<(), Errno> {
let dfd = dfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall3(SYS_FACCESSAT, dfd, filename_ptr, mode).map(drop)
}
pub fn fadvise64(fd: i32, offset: loff_t, len: size_t, advice: i32) -> Result<(), Errno> {
let fd = fd as usize;
let offset = offset as usize;
let len = len as usize;
let advice = advice as usize;
syscall4(SYS_FADVISE64, fd, offset, len, advice).map(drop)
}
pub fn fallocate(fd: i32, mode: i32, offset: loff_t, len: loff_t) -> Result<(), Errno> {
let fd = fd as usize;
let mode = mode as usize;
let offset = offset as usize;
let len = len as usize;
syscall4(SYS_FALLOCATE, fd, mode, offset, len).map(drop)
}
pub fn fanotify_init(flags: u32, event_f_flags: u32) -> Result<i32, Errno> {
let flags = flags as usize;
let event_f_flags = event_f_flags as usize;
syscall2(SYS_FANOTIFY_INIT, flags, event_f_flags).map(|ret| ret as i32)
}
pub fn fanotify_mark(
fanotify_fd: i32,
flags: u32,
mask: u64,
fd: i32,
filename: &str,
) -> Result<(), Errno> {
let fanotify_fd = fanotify_fd as usize;
let flags = flags as usize;
let mask = mask as usize;
let fd = fd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall5(
SYS_FANOTIFY_MARK,
fanotify_fd,
flags,
mask,
fd,
filename_ptr,
)
.map(drop)
}
pub fn fchdir(fd: i32) -> Result<(), Errno> {
let fd = fd as usize;
syscall1(SYS_FCHDIR, fd).map(drop)
}
pub fn fchmod(fd: i32, mode: mode_t) -> Result<(), Errno> {
let fd = fd as usize;
let mode = mode as usize;
syscall2(SYS_FCHMOD, fd, mode).map(drop)
}
pub fn fchmodat(dirfd: i32, filename: &str, mode: mode_t) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall3(SYS_FCHMODAT, dirfd, filename_ptr, mode).map(drop)
}
pub fn fchown(fd: i32, user: uid_t, group: gid_t) -> Result<(), Errno> {
let fd = fd as usize;
let user = user as usize;
let group = group as usize;
syscall3(SYS_FCHOWN, fd, user, group).map(drop)
}
pub fn fchownat(
dirfd: i32,
filename: &str,
user: uid_t,
group: gid_t,
flag: i32,
) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let user = user as usize;
let group = group as usize;
let flag = flag as usize;
syscall5(SYS_FCHOWNAT, dirfd, filename_ptr, user, group, flag).map(drop)
}
pub fn fcntl(fd: i32, cmd: i32, arg: usize) -> Result<i32, Errno> {
let fd = fd as usize;
let cmd = cmd as usize;
syscall3(SYS_FCNTL, fd, cmd, arg).map(|ret| ret as i32)
}
pub fn fdatasync(fd: i32) -> Result<(), Errno> {
let fd = fd as usize;
syscall1(SYS_FDATASYNC, fd).map(drop)
}
pub fn fgetxattr(fd: i32, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_FGETXATTR, fd, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn finit_module(fd: i32, param_values: &str, flags: i32) -> Result<(), Errno> {
let fd = fd as usize;
let param_values = CString::new(param_values);
let param_values_ptr = param_values.as_ptr() as usize;
let flags = flags as usize;
syscall3(SYS_FINIT_MODULE, fd, param_values_ptr, flags).map(drop)
}
pub fn flistxattr(fd: i32, list: &mut [u8]) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let list_ptr = list.as_mut_ptr() as usize;
let len = list.len();
syscall3(SYS_FLISTXATTR, fd, list_ptr, len).map(|ret| ret as ssize_t)
}
pub fn flock(fd: i32, operation: i32) -> Result<(), Errno> {
let fd = fd as usize;
let operation = operation as usize;
syscall2(SYS_FLOCK, fd, operation).map(drop)
}
pub fn fork() -> Result<pid_t, Errno> {
syscall0(SYS_FORK).map(|ret| ret as pid_t)
}
pub fn fremovexattr(fd: i32, name: &str) -> Result<(), Errno> {
let fd = fd as usize;
let name_ptr = name.as_ptr() as usize;
syscall2(SYS_FREMOVEXATTR, fd, name_ptr).map(drop)
}
pub fn fsconfig(fd: i32, cmd: u32, key: &str, value: &str, aux: i32) -> Result<(), Errno> {
let fd = fd as usize;
let cmd = cmd as usize;
let key = CString::new(key);
let key_ptr = key.as_ptr() as usize;
let value = CString::new(value);
let value_ptr = value.as_ptr() as usize;
let aux = aux as usize;
syscall5(SYS_FSCONFIG, fd, cmd, key_ptr, value_ptr, aux).map(drop)
}
pub fn fsetxattr(fd: i32, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_FSETXATTR, fd, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn fsmount(fs_fd: i32, flags: u32, attr_flags: u32) -> Result<i32, Errno> {
let fs_fd = fs_fd as usize;
let flags = flags as usize;
let attr_flags = attr_flags as usize;
syscall3(SYS_FSMOUNT, fs_fd, flags, attr_flags).map(|ret| ret as i32)
}
pub fn fsopen(fs_name: &str, flags: u32) -> Result<(), Errno> {
let fs_name = CString::new(fs_name);
let fs_name_ptr = fs_name.as_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_FSOPEN, fs_name_ptr, flags).map(drop)
}
pub fn fspick(dfd: i32, path: &str, flags: i32) -> Result<i32, Errno> {
let dfd = dfd as usize;
let path = CString::new(path);
let path_ptr = path.as_ptr() as usize;
let flags = flags as usize;
syscall3(SYS_FSPICK, dfd, path_ptr, flags).map(|ret| ret as i32)
}
pub fn fstat(fd: i32, statbuf: &mut stat_t) -> Result<(), Errno> {
let fd = fd as usize;
let statbuf_ptr = statbuf as *mut stat_t as usize;
syscall2(SYS_FSTAT, fd, statbuf_ptr).map(drop)
}
pub fn fstatfs(fd: i32, buf: &mut statfs_t) -> Result<(), Errno> {
let fd = fd as usize;
let buf_ptr = buf as *mut statfs_t as usize;
syscall2(SYS_FSTATFS, fd, buf_ptr).map(drop)
}
pub fn fsync(fd: i32) -> Result<(), Errno> {
let fd = fd as usize;
syscall1(SYS_FSYNC, fd).map(drop)
}
pub fn ftruncate(fd: i32, length: off_t) -> Result<(), Errno> {
let fd = fd as usize;
let length = length as usize;
syscall2(SYS_FTRUNCATE, fd, length).map(drop)
}
pub fn futex(
uaddr: &mut i32,
futex_op: i32,
val: u32,
timeout: &mut timespec_t,
uaddr2: &mut i32,
val3: i32,
) -> Result<i32, Errno> {
let uaddr_ptr = uaddr as *mut i32 as usize;
let futex_op = futex_op as usize;
let val = val as usize;
let timeout_ptr = timeout as *mut timespec_t as usize;
let uaddr2_ptr = uaddr2 as *mut i32 as usize;
let val3 = val3 as usize;
syscall6(
SYS_FUTEX,
uaddr_ptr,
futex_op,
val,
timeout_ptr,
uaddr2_ptr,
val3,
)
.map(|ret| ret as i32)
}
pub fn futimesat(dirfd: i32, filename: &str, times: &[timeval_t; 2]) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let times_ptr = times.as_ptr() as usize;
syscall3(SYS_FUTIMESAT, dirfd, filename_ptr, times_ptr).map(drop)
}
pub fn getcpu(cpu: &mut u32, node: &mut u32, cache: &mut getcpu_cache_t) -> Result<(), Errno> {
let cpu_ptr = cpu as *mut u32 as usize;
let node_ptr = node as *mut u32 as usize;
let cache_ptr = cache as *mut getcpu_cache_t as usize;
syscall3(SYS_GETCPU, cpu_ptr, node_ptr, cache_ptr).map(drop)
}
pub fn getcwd() -> Result<Vec<u8>, Errno> {
let buf_len = (PATH_MAX + 1) as usize;
let buf = CString::with_capacity(buf_len);
let buf_ptr = buf.as_ptr() as usize;
syscall2(SYS_GETCWD, buf_ptr, buf_len).map(|_ret| buf.strim_into_bytes())
}
pub fn getdents() {
core::unimplemented!();
}
pub fn getdents64(fd: i32) -> Result<Vec<linux_dirent64_extern_t>, Errno> {
const BUF_SIZE: usize = 4096;
let buf: Vec<u8> = vec![0; BUF_SIZE];
let buf_box = buf.into_boxed_slice();
let buf_box_ptr = alloc::boxed::Box::into_raw(buf_box) as *mut u8 as usize;
let fd = fd as usize;
let nread = syscall3(SYS_GETDENTS64, fd, buf_box_ptr, BUF_SIZE)?;
let mut result: Vec<linux_dirent64_extern_t> = Vec::new();
if nread == 0 {
return Ok(result);
}
let mut bpos = 0;
while bpos < nread {
let d = (buf_box_ptr + bpos) as *mut linux_dirent64_t;
let mut name_vec: Vec<u8> = vec![];
for i in 0..PATH_MAX {
unsafe {
let c = (*d).d_name[i as usize];
if c == 0 {
break;
}
name_vec.push(c);
}
}
let name = String::from_utf8(name_vec).unwrap();
unsafe {
result.push(linux_dirent64_extern_t {
d_ino: (*d).d_ino,
d_off: (*d).d_off,
d_type: (*d).d_type,
d_name: name,
});
bpos = bpos + (*d).d_reclen as usize;
}
}
return Ok(result);
}
pub fn getegid() -> gid_t {
syscall0(SYS_GETEGID).expect("getegid() failed") as gid_t
}
pub fn geteuid() -> uid_t {
syscall0(SYS_GETEUID).expect("geteuid() failed") as uid_t
}
pub fn getgid() -> gid_t {
syscall0(SYS_GETGID).expect("getgid() failed") as gid_t
}
pub fn getgroups(size: i32, group_list: &mut [gid_t]) -> Result<i32, Errno> {
let size = size as usize;
let group_ptr = group_list.as_mut_ptr() as usize;
syscall2(SYS_GETGROUPS, size, group_ptr).map(|ret| ret as i32)
}
pub fn getitimer(which: i32, curr_val: &mut itimerval_t) -> Result<(), Errno> {
let which = which as usize;
let curr_val_ptr = curr_val as *mut itimerval_t as usize;
syscall2(SYS_GETITIMER, which, curr_val_ptr).map(drop)
}
pub fn getpeername(
sockfd: i32,
addr: &mut sockaddr_in_t,
addrlen: &mut socklen_t,
) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *mut sockaddr_in_t as usize;
let addrlen_ptr = addrlen as *mut socklen_t as usize;
syscall3(SYS_GETPEERNAME, sockfd, addr_ptr, addrlen_ptr).map(drop)
}
pub fn getpgid(pid: pid_t) -> Result<pid_t, Errno> {
let pid = pid as usize;
syscall1(SYS_GETPGID, pid).map(|ret| ret as pid_t)
}
pub fn getpgrp() -> pid_t {
syscall0(SYS_GETPGRP).expect("getpgrp() failed") as pid_t
}
pub fn getpid() -> pid_t {
syscall0(SYS_GETPID).expect("getpid() failed") as pid_t
}
pub fn getpmsg() {
core::unimplemented!();
}
pub fn getppid() -> pid_t {
syscall0(SYS_GETPPID).expect("getppid() failed") as pid_t
}
pub fn getpriority(which: i32, who: i32) -> Result<i32, Errno> {
let which = which as usize;
let who = who as usize;
syscall2(SYS_GETPRIORITY, which, who).map(|ret| {
let ret = ret as i32;
if ret > PRIO_MAX {
return PRIO_MAX - ret;
}
ret
})
}
pub fn getrandom(buf: &mut [u8], flags: u32) -> Result<ssize_t, Errno> {
let buf_ptr = buf.as_mut_ptr() as usize;
let buf_len = buf.len();
let flags = flags as usize;
syscall3(SYS_GETRANDOM, buf_ptr, buf_len, flags).map(|ret| ret as ssize_t)
}
pub fn getresgid(rgid: &mut gid_t, egid: &mut gid_t, sgid: &mut gid_t) -> Result<(), Errno> {
let rgid_ptr = rgid as *mut gid_t as usize;
let egid_ptr = egid as *mut gid_t as usize;
let sgid_ptr = sgid as *mut gid_t as usize;
syscall3(SYS_GETRESGID, rgid_ptr, egid_ptr, sgid_ptr).map(drop)
}
pub fn getresuid(ruid: &mut uid_t, euid: &mut uid_t, suid: &mut uid_t) -> Result<(), Errno> {
let ruid_ptr = ruid as *mut uid_t as usize;
let euid_ptr = euid as *mut uid_t as usize;
let suid_ptr = suid as *mut uid_t as usize;
syscall3(SYS_GETRESUID, ruid_ptr, euid_ptr, suid_ptr).map(drop)
}
pub fn getrlimit(resource: i32, rlim: &mut rlimit_t) -> Result<(), Errno> {
let resource = resource as usize;
let rlim_ptr = rlim as *mut rlimit_t as usize;
syscall2(SYS_GETRLIMIT, resource, rlim_ptr).map(drop)
}
pub fn getrusage(who: i32, usage: &mut rusage_t) -> Result<(), Errno> {
let who = who as usize;
let usage_ptr = usage as *mut rusage_t as usize;
syscall2(SYS_GETRUSAGE, who, usage_ptr).map(drop)
}
pub fn getsid(pid: pid_t) -> pid_t {
let pid = pid as usize;
syscall1(SYS_GETSID, pid).expect("getsid() failed") as pid_t
}
pub fn getsockname(
sockfd: i32,
addr: &mut sockaddr_in_t,
addrlen: &mut socklen_t,
) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let addr_ptr = addr as *mut sockaddr_in_t as usize;
let addrlen_ptr = addrlen as *mut socklen_t as usize;
syscall3(SYS_GETSOCKNAME, sockfd, addr_ptr, addrlen_ptr).map(drop)
}
pub fn getsockopt(
sockfd: i32,
level: i32,
optname: i32,
optval: &mut usize,
optlen: &mut socklen_t,
) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let level = level as usize;
let optname = optname as usize;
let optval_ptr = optval as *mut usize as usize;
let optlen_ptr = optlen as *mut socklen_t as usize;
syscall5(
SYS_GETSOCKOPT,
sockfd,
level,
optname,
optval_ptr,
optlen_ptr,
)
.map(drop)
}
pub fn gettid() -> pid_t {
syscall0(SYS_GETTID).expect("getpid() failed") as pid_t
}
pub fn gettimeofday(timeval: &mut timeval_t, tz: &mut timezone_t) -> Result<(), Errno> {
let timeval_ptr = timeval as *mut timeval_t as usize;
let tz_ptr = tz as *mut timezone_t as usize;
syscall2(SYS_GETTIMEOFDAY, timeval_ptr, tz_ptr).map(drop)
}
pub fn getuid() -> uid_t {
syscall0(SYS_GETUID).expect("getuid() failed") as uid_t
}
pub fn getxattr(filename: &str, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_GETXATTR, filename_ptr, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn get_kernel_syms() {
core::unimplemented!();
}
pub fn get_mempolicy(
mode: &mut i32,
nmask: &mut usize,
maxnode: usize,
addr: usize,
flags: usize,
) -> Result<(), Errno> {
let mode_ptr = mode as *mut i32 as usize;
let nmask_ptr = nmask as *mut usize as usize;
syscall5(SYS_GET_MEMPOLICY, mode_ptr, nmask_ptr, maxnode, addr, flags).map(drop)
}
pub fn get_robust_list(
pid: pid_t,
head_ptr: &mut usize,
len_ptr: &mut size_t,
) -> Result<(), Errno> {
let pid = pid as usize;
let head_ptr = head_ptr as *mut usize as usize;
let len_ptr = len_ptr as *mut size_t as usize;
syscall3(SYS_GET_ROBUST_LIST, pid, head_ptr, len_ptr).map(drop)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn get_thread_area(user_desc: &mut user_desc_t) -> Result<(), Errno> {
let user_desc_ptr = user_desc as *mut user_desc_t as usize;
syscall1(SYS_GET_THREAD_AREA, user_desc_ptr).map(drop)
}
pub fn init_module(module_image: usize, len: usize, param_values: &str) -> Result<(), Errno> {
let param_values = CString::new(param_values);
let param_values_ptr = param_values.as_ptr() as usize;
syscall3(SYS_INIT_MODULE, module_image, len, param_values_ptr).map(drop)
}
pub fn inotify_add_watch(fd: i32, filename: &str, mask: u32) -> Result<i32, Errno> {
let fd = fd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mask = mask as usize;
syscall3(SYS_INOTIFY_ADD_WATCH, fd, filename_ptr, mask).map(|ret| ret as i32)
}
pub fn inotify_init() -> Result<i32, Errno> {
syscall0(SYS_INOTIFY_INIT).map(|ret| ret as i32)
}
pub fn inotify_init1(flags: i32) -> Result<i32, Errno> {
let flags = flags as usize;
syscall1(SYS_INOTIFY_INIT1, flags).map(|ret| ret as i32)
}
pub fn inotify_rm_watch(fd: i32, wd: i32) -> Result<(), Errno> {
let fd = fd as usize;
let wd = wd as usize;
syscall2(SYS_INOTIFY_RM_WATCH, fd, wd).map(drop)
}
pub fn ioctl(fd: i32, cmd: i32, arg: usize) -> Result<(), Errno> {
let fd = fd as usize;
let cmd = cmd as usize;
syscall3(SYS_IOCTL, fd, cmd, arg).map(drop)
}
pub fn ioperm(from: usize, num: usize, turn_on: i32) -> Result<(), Errno> {
let turn_on = turn_on as usize;
syscall3(SYS_IOPERM, from, num, turn_on).map(drop)
}
pub fn iopl(level: i32) -> Result<(), Errno> {
let level = level as usize;
syscall1(SYS_IOPL, level).map(drop)
}
pub fn ioprio_get(which: i32, who: i32) -> Result<i32, Errno> {
let which = which as usize;
let who = who as usize;
syscall2(SYS_IOPRIO_GET, which, who).map(|ret| ret as i32)
}
pub fn ioprio_set(which: i32, who: i32, ioprio: i32) -> Result<(), Errno> {
let which = which as usize;
let who = who as usize;
let ioprio = ioprio as usize;
syscall3(SYS_IOPRIO_SET, which, who, ioprio).map(drop)
}
pub fn io_cancel(
ctx_id: aio_context_t,
iocb: &mut iocb_t,
result: &mut io_event_t,
) -> Result<(), Errno> {
let ctx_id = ctx_id as usize;
let iocb_ptr = iocb as *mut iocb_t as usize;
let result_ptr = result as *mut io_event_t as usize;
syscall3(SYS_IO_CANCEL, ctx_id, iocb_ptr, result_ptr).map(drop)
}
pub fn io_destroy(ctx_id: aio_context_t) -> Result<(), Errno> {
let ctx_id = ctx_id as usize;
syscall1(SYS_IO_DESTROY, ctx_id).map(drop)
}
pub fn io_getevents(
ctx_id: aio_context_t,
min_nr: isize,
nr: isize,
events: &mut io_event_t,
timeout: &mut timespec_t,
) -> Result<i32, Errno> {
let ctx_id = ctx_id as usize;
let min_nr = min_nr as usize;
let nr = nr as usize;
let events_ptr = events as *mut io_event_t as usize;
let timeout_ptr = timeout as *mut timespec_t as usize;
syscall5(
SYS_IO_GETEVENTS,
ctx_id,
min_nr,
nr,
events_ptr,
timeout_ptr,
)
.map(|ret| ret as i32)
}
pub fn io_pgetevents(
ctx_id: aio_context_t,
min_nr: isize,
nr: isize,
events: &mut io_event_t,
timeout: &mut timespec_t,
usig: &aio_sigset_t,
) -> Result<i32, Errno> {
let ctx_id = ctx_id as usize;
let min_nr = min_nr as usize;
let nr = nr as usize;
let events_ptr = events as *mut io_event_t as usize;
let timeout_ptr = timeout as *mut timespec_t as usize;
let usig_ptr = usig as *const aio_sigset_t as usize;
syscall6(
SYS_IO_PGETEVENTS,
ctx_id,
min_nr,
nr,
events_ptr,
timeout_ptr,
usig_ptr,
)
.map(|ret| ret as i32)
}
pub fn io_setup(nr_events: u32, ctx_id: &mut aio_context_t) -> Result<(), Errno> {
let nr_events = nr_events as usize;
let ctx_id_ptr = ctx_id as *mut aio_context_t as usize;
syscall2(SYS_IO_SETUP, nr_events, ctx_id_ptr).map(drop)
}
pub fn io_submit(ctx_id: aio_context_t, nr: isize, iocb: &mut iocb_t) -> Result<i32, Errno> {
let ctx_id = ctx_id as usize;
let nr = nr as usize;
let iocb_ptr = iocb as *mut iocb_t as usize;
syscall3(SYS_IO_SUBMIT, ctx_id, nr, iocb_ptr).map(|ret| ret as i32)
}
pub fn io_uring_enter(
fd: i32,
to_submit: u32,
min_complete: u32,
flags: u32,
sig: &sigset_t,
sigsetsize: size_t,
) -> Result<i32, Errno> {
let fd = fd as usize;
let to_submit = to_submit as usize;
let min_complete = min_complete as usize;
let flags = flags as usize;
let sig_ptr = sig as *const sigset_t as usize;
let sigsetsize = sigsetsize as usize;
syscall6(
SYS_IO_URING_ENTER,
fd,
to_submit,
min_complete,
flags,
sig_ptr,
sigsetsize,
)
.map(|ret| ret as i32)
}
pub fn io_uring_register(fd: i32, opcode: u32, arg: usize, nr_args: u32) -> Result<i32, Errno> {
let fd = fd as usize;
let opcode = opcode as usize;
let nr_args = nr_args as usize;
syscall4(SYS_IO_URING_REGISTER, fd, opcode, arg, nr_args).map(|ret| ret as i32)
}
pub fn io_uring_setup(entries: u32, params: &mut io_uring_params_t) -> Result<i32, Errno> {
let entries = entries as usize;
let params_ptr = params as *mut io_uring_params_t as usize;
syscall2(SYS_IO_URING_SETUP, entries, params_ptr).map(|ret| ret as i32)
}
pub fn kcmp(pid1: pid_t, pid2: pid_t, type_: i32, idx1: usize, idx2: usize) -> Result<i32, Errno> {
let pid1 = pid1 as usize;
let pid2 = pid2 as usize;
let type_ = type_ as usize;
syscall5(SYS_KCMP, pid1, pid2, type_, idx1, idx2).map(|ret| ret as i32)
}
pub fn kexec_file_load(
kernel_fd: i32,
initrd_fd: i32,
cmdline: &str,
flags: usize,
) -> Result<(), Errno> {
let kernel_fd = kernel_fd as usize;
let initrd_fd = initrd_fd as usize;
let cmdline_len = cmdline.len();
let cmdline = CString::new(cmdline);
let cmdline_ptr = cmdline.as_ptr() as usize;
syscall5(
SYS_KEXEC_FILE_LOAD,
kernel_fd,
initrd_fd,
cmdline_ptr,
cmdline_len,
flags,
)
.map(drop)
}
pub fn kexec_load(
entry: usize,
nr_segments: usize,
segments: &mut kexec_segment_t,
flags: usize,
) -> Result<(), Errno> {
let segments_ptr = segments as *mut kexec_segment_t as usize;
syscall4(SYS_KEXEC_LOAD, entry, nr_segments, segments_ptr, flags).map(drop)
}
pub fn keyctl(
operation: i32,
arg2: usize,
arg3: usize,
arg4: usize,
arg5: usize,
) -> Result<usize, Errno> {
let operation = operation as usize;
syscall5(SYS_KEYCTL, operation, arg2, arg3, arg4, arg5)
}
pub fn kill(pid: pid_t, signal: i32) -> Result<(), Errno> {
let pid = pid as usize;
let signal = signal as usize;
syscall2(SYS_KILL, pid, signal).map(drop)
}
pub fn lchown(filename: &str, user: uid_t, group: gid_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let user = user as usize;
let group = group as usize;
syscall3(SYS_LCHOWN, filename_ptr, user, group).map(drop)
}
pub fn lgetxattr(filename: &str, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_LGETXATTR, filename_ptr, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn link(oldfilename: &str, newfilename: &str) -> Result<(), Errno> {
let oldfilename = CString::new(oldfilename);
let oldfilename_ptr = oldfilename.as_ptr() as usize;
let newfilename = CString::new(newfilename);
let newfilename_ptr = newfilename.as_ptr() as usize;
syscall2(SYS_LINK, oldfilename_ptr, newfilename_ptr).map(drop)
}
pub fn linkat(olddfd: i32, oldfilename: &str, newdfd: i32, newfilename: &str) -> Result<(), Errno> {
let olddfd = olddfd as usize;
let oldfilename = CString::new(oldfilename);
let oldfilename_ptr = oldfilename.as_ptr() as usize;
let newdfd = newdfd as usize;
let newfilename = CString::new(newfilename);
let newfilename_ptr = newfilename.as_ptr() as usize;
syscall4(SYS_LINKAT, olddfd, oldfilename_ptr, newdfd, newfilename_ptr).map(drop)
}
pub fn listen(sockfd: i32, backlog: i32) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let backlog = backlog as usize;
syscall2(SYS_LISTEN, sockfd, backlog).map(drop)
}
pub fn listxattr(filename: &str, list: &mut [u8]) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let list_ptr = list.as_mut_ptr() as usize;
let len = list.len();
syscall3(SYS_LISTXATTR, filename_ptr, list_ptr, len).map(|ret| ret as ssize_t)
}
pub fn llistxattr(filename: &str, list: &mut [u8]) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let list_ptr = list.as_mut_ptr() as usize;
let len = list.len();
syscall3(SYS_LLISTXATTR, filename_ptr, list_ptr, len).map(|ret| ret as ssize_t)
}
pub fn lookup_dcookie(cookie: u64, buf: &mut [u8]) -> Result<i32, Errno> {
let cookie = cookie as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let buf_len = buf.len();
syscall3(SYS_LOOKUP_DCOOKIE, cookie, buf_ptr, buf_len).map(|ret| ret as i32)
}
pub fn lremovexattr(filename: &str, name: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
syscall2(SYS_LREMOVEXATTR, filename_ptr, name_ptr).map(drop)
}
pub fn lseek(fd: i32, offset: off_t, whence: i32) -> Result<(), Errno> {
let fd = fd as usize;
let offset = offset as usize;
let whence = whence as usize;
syscall3(SYS_LSEEK, fd, offset, whence).map(drop)
}
pub fn lsetxattr(filename: &str, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_LSETXATTR, filename_ptr, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn lstat(filename: &str, statbuf: &mut stat_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let statbuf_ptr = statbuf as *mut stat_t as usize;
syscall2(SYS_LSTAT, filename_ptr, statbuf_ptr).map(drop)
}
pub fn madvise(addr: usize, len: size_t, advice: i32) -> Result<(), Errno> {
let len = len as usize;
let advice = advice as usize;
syscall3(SYS_MADVISE, addr, len, advice).map(drop)
}
pub fn mbind(
start: usize,
len: usize,
mode: i32,
nmask: *const usize,
maxnode: usize,
flags: i32,
) -> Result<(), Errno> {
let mode = mode as usize;
let nmask = nmask as usize;
let flags = flags as usize;
syscall6(SYS_MBIND, start, len, mode, nmask, maxnode, flags).map(drop)
}
pub fn membarrier(cmd: i32, flags: i32) -> Result<i32, Errno> {
let cmd = cmd as usize;
let flags = flags as usize;
syscall2(SYS_MEMBARRIER, cmd, flags).map(|ret| ret as i32)
}
pub fn memfd_create(name: &str, flags: u32) -> Result<i32, Errno> {
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_MEMFD_CREATE, name_ptr, flags).map(|ret| ret as i32)
}
pub fn migrate_pages(
pid: pid_t,
maxnode: usize,
old_nodes: *const usize,
new_nodes: *const usize,
) -> Result<isize, Errno> {
let pid = pid as usize;
let old_nodes = old_nodes as usize;
let new_nodes = new_nodes as usize;
syscall4(SYS_MIGRATE_PAGES, pid, maxnode, old_nodes, new_nodes).map(|ret| ret as isize)
}
pub fn mincore(start: usize, len: size_t, vec: *const u8) -> Result<(), Errno> {
let len = len as usize;
let vec_ptr = vec as usize;
syscall3(SYS_MINCORE, start, len, vec_ptr).map(drop)
}
pub fn mkdir(filename: &str, mode: mode_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall2(SYS_MKDIR, filename_ptr, mode).map(drop)
}
pub fn mkdirat(dirfd: i32, filename: &str, mode: mode_t) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
syscall3(SYS_MKDIRAT, dirfd, filename_ptr, mode).map(drop)
}
pub fn mknod(filename: &str, mode: mode_t, dev: dev_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
let dev = dev as usize;
syscall3(SYS_MKNOD, filename_ptr, mode, dev).map(drop)
}
pub fn mknodat(dirfd: i32, filename: &str, mode: mode_t, dev: dev_t) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let mode = mode as usize;
let dev = dev as usize;
syscall4(SYS_MKNODAT, dirfd, filename_ptr, mode, dev).map(drop)
}
pub fn mlock(addr: usize, len: size_t) -> Result<(), Errno> {
let len = len as usize;
syscall2(SYS_MLOCK, addr, len).map(drop)
}
pub fn mlock2(addr: usize, len: size_t, flags: i32) -> Result<(), Errno> {
let len = len as usize;
let flags = flags as usize;
syscall3(SYS_MLOCK2, addr, len, flags).map(drop)
}
pub fn mlockall(flags: i32) -> Result<(), Errno> {
let flags = flags as usize;
syscall1(SYS_MLOCKALL, flags).map(drop)
}
pub fn mmap(
start: usize,
len: size_t,
prot: i32,
flags: i32,
fd: i32,
offset: off_t,
) -> Result<usize, Errno> {
let len = len as usize;
let prot = prot as usize;
let flags = flags as usize;
let fd = fd as usize;
let offset = offset as usize;
syscall6(SYS_MMAP, start, len, prot, flags, fd, offset)
}
pub fn modify_ldt() {
core::unimplemented!();
}
pub fn mount(
dev_name: &str,
dir_name: &str,
fs_type: &str,
flags: usize,
data: usize,
) -> Result<(), Errno> {
let dev_name_ptr = dev_name.as_ptr() as usize;
let dir_name_ptr = dir_name.as_ptr() as usize;
let fs_type_ptr = fs_type.as_ptr() as usize;
syscall5(
SYS_MOUNT,
dev_name_ptr,
dir_name_ptr,
fs_type_ptr,
flags,
data,
)
.map(drop)
}
pub fn move_mount(
from_dfd: i32,
from_pathname: &str,
to_dfd: i32,
to_pathname: &str,
flags: u32,
) -> Result<i32, Errno> {
let from_dfd = from_dfd as usize;
let from_pathname = CString::new(from_pathname);
let from_pathname_ptr = from_pathname.as_ptr() as usize;
let to_dfd = to_dfd as usize;
let to_pathname = CString::new(to_pathname);
let to_pathname_ptr = to_pathname.as_ptr() as usize;
let flags = flags as usize;
syscall5(
SYS_MOVE_MOUNT,
from_dfd,
from_pathname_ptr,
to_dfd,
to_pathname_ptr,
flags,
)
.map(|ret| ret as i32)
}
pub fn move_pages(
pid: pid_t,
nr_pages: usize,
pages: usize,
nodes: *const i32,
status: &mut i32,
flags: i32,
) -> Result<(), Errno> {
let pid = pid as usize;
let nodes_ptr = nodes as usize;
let status = status as *mut i32 as usize;
let flags = flags as usize;
syscall6(
SYS_MOVE_PAGES,
pid,
nr_pages,
pages,
nodes_ptr,
status,
flags,
)
.map(drop)
}
pub fn mprotect(addr: usize, len: size_t, prot: i32) -> Result<(), Errno> {
let len = len as usize;
let prot = prot as usize;
syscall3(SYS_MPROTECT, addr, len, prot).map(drop)
}
pub fn mq_getsetattr(
mqdes: mqd_t,
new_attr: &mut mq_attr_t,
old_attr: &mut mq_attr_t,
) -> Result<mqd_t, Errno> {
let mqdes = mqdes as usize;
let new_attr_ptr = new_attr as *mut mq_attr_t as usize;
let old_attr_ptr = old_attr as *mut mq_attr_t as usize;
syscall3(SYS_MQ_GETSETATTR, mqdes, new_attr_ptr, old_attr_ptr).map(|ret| ret as mqd_t)
}
pub fn mq_notify(mqdes: mqd_t, notification: &sigevent_t) -> Result<(), Errno> {
let mqdes = mqdes as usize;
let notification_ptr = notification as *const sigevent_t as usize;
syscall2(SYS_MQ_NOTIFY, mqdes, notification_ptr).map(drop)
}
pub fn mq_open(
name: &str,
oflag: i32,
mode: umode_t,
attr: &mut mq_attr_t,
) -> Result<mqd_t, Errno> {
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let oflag = oflag as usize;
let mode = mode as usize;
let attr_ptr = attr as *mut mq_attr_t as usize;
syscall4(SYS_MQ_OPEN, name_ptr, oflag, mode, attr_ptr).map(|ret| ret as mqd_t)
}
pub fn mq_timedreceive(
mqdes: mqd_t,
msg: &str,
msg_prio: u32,
abs_timeout: ×pec_t,
) -> Result<ssize_t, Errno> {
let mqdes = mqdes as usize;
let msg = CString::new(msg);
let msg_ptr = msg.as_ptr() as usize;
let msg_len = msg.len();
let msg_prio = msg_prio as usize;
let abs_timeout_ptr = abs_timeout as *const timespec_t as usize;
syscall5(
SYS_MQ_TIMEDRECEIVE,
mqdes,
msg_ptr,
msg_len,
msg_prio,
abs_timeout_ptr,
)
.map(|ret| ret as ssize_t)
}
pub fn mq_timedsend(
mqdes: mqd_t,
msg: &str,
msg_prio: u32,
abs_timeout: ×pec_t,
) -> Result<(), Errno> {
let mqdes = mqdes as usize;
let msg = CString::new(msg);
let msg_ptr = msg.as_ptr() as usize;
let msg_len = msg.len();
let msg_prio = msg_prio as usize;
let abs_timeout_ptr = abs_timeout as *const timespec_t as usize;
syscall5(
SYS_MQ_TIMEDSEND,
mqdes,
msg_ptr,
msg_len,
msg_prio,
abs_timeout_ptr,
)
.map(drop)
}
pub fn mq_unlink(name: &str) -> Result<(), Errno> {
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
syscall1(SYS_MQ_UNLINK, name_ptr).map(drop)
}
pub fn mremap(
addr: usize,
old_len: size_t,
new_len: size_t,
flags: usize,
new_addr: usize,
) -> Result<usize, Errno> {
let old_len = old_len as usize;
let new_len = new_len as usize;
syscall5(SYS_MREMAP, addr, old_len, new_len, flags, new_addr)
}
pub fn msgctl(msqid: i32, cmd: i32, buf: &mut msqid_ds_t) -> Result<i32, Errno> {
let msqid = msqid as usize;
let cmd = cmd as usize;
let buf_ptr = buf as *mut msqid_ds_t as usize;
syscall3(SYS_MSGCTL, msqid, cmd, buf_ptr).map(|ret| ret as i32)
}
pub fn msgget(key: key_t, msgflg: i32) -> Result<i32, Errno> {
let key = key as usize;
let msgflg = msgflg as usize;
syscall2(SYS_MSGGET, key, msgflg).map(|ret| ret as i32)
}
pub fn msgrcv(msqid: i32, msgq: usize, msgsz: size_t, msgtyp: isize) -> Result<ssize_t, Errno> {
let msqid = msqid as usize;
let msgsz = msgsz as usize;
let msgtyp = msgtyp as usize;
syscall4(SYS_MSGRCV, msqid, msgq, msgsz, msgtyp).map(|ret| ret as ssize_t)
}
pub fn msgsnd(msqid: i32, msgq: usize, msgsz: size_t, msgflg: i32) -> Result<(), Errno> {
let msqid = msqid as usize;
let msgsz = msgsz as usize;
let msgflg = msgflg as usize;
syscall4(SYS_MSGSND, msqid, msgq, msgsz, msgflg).map(drop)
}
pub fn msync(addr: usize, len: size_t, flags: i32) -> Result<(), Errno> {
let len = len as usize;
let flags = flags as usize;
syscall3(SYS_MSYNC, addr, len, flags).map(drop)
}
pub fn munlock(addr: usize, len: size_t) -> Result<(), Errno> {
let len = len as usize;
syscall2(SYS_MUNLOCK, addr, len).map(drop)
}
pub fn munlockall() -> Result<(), Errno> {
syscall0(SYS_MUNLOCKALL).map(drop)
}
pub fn munmap(addr: usize, len: size_t) -> Result<(), Errno> {
let len = len as usize;
syscall2(SYS_MUNMAP, addr, len).map(drop)
}
pub fn name_to_handle_at(
dfd: i32,
filename: &str,
handle: &mut file_handle_t,
mount_id: &mut i32,
flags: i32,
) -> Result<(), Errno> {
let dfd = dfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let handle_ptr = handle as *mut file_handle_t as usize;
let mount_id_ptr = mount_id as *mut i32 as usize;
let flags = flags as usize;
syscall5(
SYS_NAME_TO_HANDLE_AT,
dfd,
filename_ptr,
handle_ptr,
mount_id_ptr,
flags,
)
.map(drop)
}
pub fn nanosleep(req: ×pec_t, rem: &mut timespec_t) -> Result<(), Errno> {
let req_ptr = req as *const timespec_t as usize;
let rem_ptr = rem as *mut timespec_t as usize;
syscall2(SYS_NANOSLEEP, req_ptr, rem_ptr).map(drop)
}
pub fn newfstatat(dfd: i32, filename: &str, statbuf: &mut stat_t, flag: i32) -> Result<(), Errno> {
let dfd = dfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let statbuf_ptr = statbuf as *mut stat_t as usize;
let flag = flag as usize;
syscall4(SYS_NEWFSTATAT, dfd, filename_ptr, statbuf_ptr, flag).map(drop)
}
pub fn nfsservctl() {
core::unimplemented!();
}
pub fn open(filename: &str, flags: i32, mode: mode_t) -> Result<i32, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flags = flags as usize;
let mode = mode as usize;
syscall3(SYS_OPEN, filename_ptr, flags, mode).map(|ret| ret as i32)
}
pub fn openat(dirfd: i32, filename: &str, flags: i32, mode: mode_t) -> Result<i32, Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flags = flags as usize;
let mode = mode as usize;
syscall4(SYS_OPENAT, dirfd, filename_ptr, flags, mode).map(|ret| ret as i32)
}
pub fn open_by_handle_at(
mount_fd: i32,
handle: &mut file_handle_t,
flags: i32,
) -> Result<(), Errno> {
let mount_fd = mount_fd as usize;
let handle_ptr = handle as *mut file_handle_t as usize;
let flags = flags as usize;
syscall3(SYS_OPEN_BY_HANDLE_AT, mount_fd, handle_ptr, flags).map(drop)
}
pub fn open_tree(dfd: i32, filename: &str, flags: u32) -> Result<i32, Errno> {
let dfd = dfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flags = flags as usize;
syscall3(SYS_OPEN_TREE, dfd, filename_ptr, flags).map(|ret| ret as i32)
}
pub fn pause() -> Result<(), Errno> {
syscall0(SYS_PAUSE).map(drop)
}
pub fn perf_event_open(
attr: &mut perf_event_attr_t,
pid: pid_t,
cpu: i32,
group_fd: i32,
flags: usize,
) -> Result<i32, Errno> {
let attr_ptr = attr as *mut perf_event_attr_t as usize;
let pid = pid as usize;
let cpu = cpu as usize;
let group_fd = group_fd as usize;
syscall5(SYS_PERF_EVENT_OPEN, attr_ptr, pid, cpu, group_fd, flags).map(|ret| ret as i32)
}
pub fn personality(persona: u32) -> Result<u32, Errno> {
let persona = persona as usize;
syscall1(SYS_PERSONALITY, persona).map(|ret| ret as u32)
}
pub fn pidfd_open() {
core::unimplemented!();
}
pub fn pidfd_send_signal(
pidfd: i32,
sig: i32,
info: &mut siginfo_t,
flags: u32,
) -> Result<(), Errno> {
let pidfd = pidfd as usize;
let sig = sig as usize;
let info_ptr = info as *mut siginfo_t as usize;
let flags = flags as usize;
syscall4(SYS_PIDFD_SEND_SIGNAL, pidfd, sig, info_ptr, flags).map(drop)
}
pub fn pipe(pipefd: &mut [i32; 2]) -> Result<(), Errno> {
let pipefd_ptr = pipefd.as_mut_ptr() as usize;
syscall1(SYS_PIPE, pipefd_ptr).map(drop)
}
pub fn pipe2(pipefd: &mut [i32; 2], flags: i32) -> Result<(), Errno> {
let pipefd_ptr = pipefd.as_mut_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_PIPE2, pipefd_ptr, flags).map(drop)
}
pub fn pivot_root(new_root: &str, put_old: &str) -> Result<(), Errno> {
let new_root_ptr = new_root.as_ptr() as usize;
let put_old_ptr = put_old.as_ptr() as usize;
syscall2(SYS_PIVOT_ROOT, new_root_ptr, put_old_ptr).map(drop)
}
pub fn pkey_alloc(flags: usize, init_val: usize) -> Result<i32, Errno> {
syscall2(SYS_PKEY_ALLOC, flags, init_val).map(|ret| ret as i32)
}
pub fn pkey_free(pkey: i32) -> Result<(), Errno> {
let pkey = pkey as usize;
syscall1(SYS_PKEY_FREE, pkey).map(drop)
}
pub fn pkey_mprotect(start: usize, len: size_t, prot: usize, pkey: i32) -> Result<(), Errno> {
let len = len as usize;
let pkey = pkey as usize;
syscall4(SYS_PKEY_MPROTECT, start, len, prot, pkey).map(drop)
}
pub fn poll(fds: &mut [pollfd_t], timeout: i32) -> Result<(), Errno> {
let fds_ptr = fds.as_mut_ptr() as usize;
let nfds = fds.len() as usize;
let timeout = timeout as usize;
syscall3(SYS_POLL, fds_ptr, nfds, timeout).map(drop)
}
pub fn ppoll(
fds: &mut pollfd_t,
nfds: i32,
timeout: ×pec_t,
sigmask: &sigset_t,
sigsetsize: size_t,
) -> Result<i32, Errno> {
let fds_ptr = fds as *mut pollfd_t as usize;
let nfds = nfds as usize;
let timeout_ptr = timeout as *const timespec_t as usize;
let sigmask_ptr = sigmask as *const sigset_t as usize;
let sigsetsize = sigsetsize as usize;
syscall5(
SYS_PPOLL,
fds_ptr,
nfds,
timeout_ptr,
sigmask_ptr,
sigsetsize,
)
.map(|ret| ret as i32)
}
pub fn prctl(
option: i32,
arg2: usize,
arg3: usize,
arg4: usize,
arg5: usize,
) -> Result<i32, Errno> {
let option = option as usize;
let arg2 = arg2 as usize;
let arg3 = arg3 as usize;
let arg4 = arg4 as usize;
let arg5 = arg5 as usize;
syscall5(SYS_PRCTL, option, arg2, arg3, arg4, arg5).map(|ret| ret as i32)
}
pub fn pread64(fd: i32, buf: &mut [u8], offset: off_t) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let buf_ptr = buf.as_ptr() as usize;
let len = buf.len() as usize;
let offset = offset as usize;
syscall4(SYS_PREAD64, fd, buf_ptr, len, offset).map(|ret| ret as ssize_t)
}
pub fn preadv(fd: i32, vec: &[iovec_t], pos_l: usize, pos_h: usize) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let vec_ptr = vec.as_ptr() as usize;
let vec_len = vec.len();
syscall5(SYS_PREADV, fd, vec_ptr, vec_len, pos_l, pos_h).map(|ret| ret as ssize_t)
}
pub fn preadv2(
fd: i32,
vec: &[iovec_t],
pos_l: usize,
pos_h: usize,
flags: rwf_t,
) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let vec_ptr = vec.as_ptr() as usize;
let vec_len = vec.len();
let flags = flags as usize;
syscall6(SYS_PREADV2, fd, vec_ptr, vec_len, pos_l, pos_h, flags).map(|ret| ret as ssize_t)
}
pub fn prlimit64(
pid: pid_t,
resource: i32,
new_limit: &rlimit_t,
old_limit: &mut rlimit_t,
) -> Result<(), Errno> {
let pid = pid as usize;
let resource = resource as usize;
let new_limit_ptr = new_limit as *const rlimit_t as usize;
let old_limit_ptr = old_limit as *mut rlimit_t as usize;
syscall4(SYS_PRLIMIT64, pid, resource, new_limit_ptr, old_limit_ptr).map(drop)
}
pub fn process_vm_readv(
pid: pid_t,
lvec: &[iovec_t],
rvec: &[iovec_t],
flags: i32,
) -> Result<ssize_t, Errno> {
let pid = pid as usize;
let lvec_ptr = lvec.as_ptr() as usize;
let lvec_len = lvec.len();
let rvec_ptr = rvec.as_ptr() as usize;
let rvec_len = rvec.len();
let flags = flags as usize;
syscall6(
SYS_PROCESS_VM_READV,
pid,
lvec_ptr,
lvec_len,
rvec_ptr,
rvec_len,
flags,
)
.map(|ret| ret as ssize_t)
}
pub fn process_vm_writev(
pid: pid_t,
lvec: &[iovec_t],
rvec: &[iovec_t],
flags: i32,
) -> Result<ssize_t, Errno> {
let pid = pid as usize;
let lvec_ptr = lvec.as_ptr() as usize;
let lvec_len = lvec.len();
let rvec_ptr = rvec.as_ptr() as usize;
let rvec_len = rvec.len();
let flags = flags as usize;
syscall6(
SYS_PROCESS_VM_WRITEV,
pid,
lvec_ptr,
lvec_len,
rvec_ptr,
rvec_len,
flags,
)
.map(|ret| ret as ssize_t)
}
pub fn pselect6(
nfds: i32,
readfds: &mut fd_set_t,
writefds: &mut fd_set_t,
exceptfds: &mut fd_set_t,
timeout: ×pec_t,
sigmask: &sigset_t,
) -> Result<i32, Errno> {
let nfds = nfds as usize;
let readfds_ptr = readfds as *mut fd_set_t as usize;
let writefds_ptr = writefds as *mut fd_set_t as usize;
let exceptfds_ptr = exceptfds as *mut fd_set_t as usize;
let timeout_ptr = timeout as *const timespec_t as usize;
let sigmask_ptr = sigmask as *const sigset_t as usize;
syscall6(
SYS_PSELECT6,
nfds,
readfds_ptr,
writefds_ptr,
exceptfds_ptr,
timeout_ptr,
sigmask_ptr,
)
.map(|ret| ret as i32)
}
pub fn ptrace(request: i32, pid: pid_t, addr: usize, data: usize) -> Result<isize, Errno> {
let request = request as usize;
let pid = pid as usize;
syscall4(SYS_PTRACE, request, pid, addr, data).map(|ret| ret as isize)
}
pub fn putpmsg() {
core::unimplemented!();
}
pub fn pwrite64(fd: i32, buf: &[u8], offset: off_t) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let buf_ptr = buf.as_ptr() as usize;
let len = buf.len() as usize;
let offset = offset as usize;
syscall4(SYS_PWRITE64, fd, buf_ptr, len, offset).map(|ret| ret as ssize_t)
}
pub fn pwritev(
fd: i32,
vec: &iovec_t,
vlen: usize,
pos_l: usize,
pos_h: usize,
) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let vec_ptr = vec as *const iovec_t as usize;
syscall5(SYS_PWRITEV, fd, vec_ptr, vlen, pos_l, pos_h).map(|ret| ret as ssize_t)
}
pub fn pwritev2(
fd: i32,
vec: &iovec_t,
vlen: usize,
pos_l: usize,
pos_h: usize,
flags: rwf_t,
) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let vec_ptr = vec as *const iovec_t as usize;
let flags = flags as usize;
syscall6(SYS_PWRITEV2, fd, vec_ptr, vlen, pos_l, pos_h, flags).map(|ret| ret as ssize_t)
}
pub fn query_module() {
core::unimplemented!();
}
pub fn quotactl(cmd: i32, special: &str, id: qid_t, addr: usize) -> Result<(), Errno> {
let cmd = cmd as usize;
let special = CString::new(special);
let special_ptr = special.as_ptr() as usize;
let id = id as usize;
syscall4(SYS_QUOTACTL, cmd, special_ptr, id, addr).map(drop)
}
pub fn read(fd: i32, buf: &mut [u8]) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let len = buf.len() as usize;
syscall3(SYS_READ, fd, buf_ptr, len).map(|ret| ret as ssize_t)
}
pub fn readahead(fd: i32, offset: off_t, count: size_t) -> Result<(), Errno> {
let fd = fd as usize;
let offset = offset as usize;
let count = count as usize;
syscall3(SYS_READAHEAD, fd, offset, count).map(drop)
}
pub fn readlink(filename: &str, buf: &mut [u8]) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let buf_len = buf.len();
syscall3(SYS_READLINK, filename_ptr, buf_ptr, buf_len).map(|ret| ret as ssize_t)
}
pub fn readlinkat(dirfd: i32, filename: &str, buf: &mut [u8]) -> Result<ssize_t, Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let buf_len = buf.len();
syscall4(SYS_READLINKAT, dirfd, filename_ptr, buf_ptr, buf_len).map(|ret| ret as ssize_t)
}
pub fn readv(fd: i32, iov: &mut [iovec_t]) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let iov_ptr = iov.as_mut_ptr() as usize;
let len = iov.len() as usize;
syscall3(SYS_READV, fd, iov_ptr, len).map(|ret| ret as ssize_t)
}
pub fn reboot(magic: i32, magci2: i32, cmd: u32, arg: usize) -> Result<(), Errno> {
let magic = magic as usize;
let magic2 = magci2 as usize;
let cmd = cmd as usize;
syscall4(SYS_REBOOT, magic, magic2, cmd, arg).map(drop)
}
pub fn recvfrom(
sockfd: i32,
buf: &mut [u8],
flags: i32,
src_addr: &mut sockaddr_in_t,
addrlen: &mut socklen_t,
) -> Result<ssize_t, Errno> {
let sockfd = sockfd as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let buflen = buf.len();
let flags = flags as usize;
let src_addr_ptr = src_addr as *mut sockaddr_in_t as usize;
let addrlen_ptr = addrlen as *mut socklen_t as usize;
syscall6(
SYS_RECVFROM,
sockfd,
buf_ptr,
buflen,
flags,
src_addr_ptr,
addrlen_ptr,
)
.map(|ret| ret as ssize_t)
}
pub fn recvmmsg(
sockfd: i32,
msgvec: &mut [mmsghdr_t],
flags: i32,
timeout: &mut timespec_t,
) -> Result<i32, Errno> {
let sockfd = sockfd as usize;
let msgvec_ptr = msgvec as *mut [mmsghdr_t] as *mut mmsghdr_t as usize;
let vlen = msgvec.len() as usize;
let flags = flags as usize;
let timeout_ptr = timeout as *mut timespec_t as usize;
syscall5(SYS_RECVMMSG, sockfd, msgvec_ptr, vlen, flags, timeout_ptr).map(|ret| ret as i32)
}
pub fn recvmsg(sockfd: i32, msg: &mut msghdr_t, flags: i32) -> Result<ssize_t, Errno> {
let sockfd = sockfd as usize;
let msg_ptr = msg as *mut msghdr_t as usize;
let flags = flags as usize;
syscall3(SYS_RECVMSG, sockfd, msg_ptr, flags).map(|ret| ret as ssize_t)
}
pub fn remap_file_pages(
start: usize,
size: size_t,
prot: i32,
pgoff: off_t,
flags: i32,
) -> Result<(), Errno> {
let size = size as usize;
let prot = prot as usize;
let pgoff = pgoff as usize;
let flags = flags as usize;
syscall5(SYS_REMAP_FILE_PAGES, start, size, prot, pgoff, flags).map(drop)
}
pub fn removexattr(filename: &str, name: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name_ptr = name.as_ptr() as usize;
syscall2(SYS_REMOVEXATTR, filename_ptr, name_ptr).map(drop)
}
pub fn rename(oldfilename: &str, newfilename: &str) -> Result<(), Errno> {
let oldfilename = CString::new(oldfilename);
let oldfilename_ptr = oldfilename.as_ptr() as usize;
let newfilename = CString::new(newfilename);
let newfilename_ptr = newfilename.as_ptr() as usize;
syscall2(SYS_RENAME, oldfilename_ptr, newfilename_ptr).map(drop)
}
pub fn renameat(
olddfd: i32,
oldfilename: &str,
newdfd: i32,
newfilename: &str,
) -> Result<(), Errno> {
let olddfd = olddfd as usize;
let oldfilename = CString::new(oldfilename);
let oldfilename_ptr = oldfilename.as_ptr() as usize;
let newdfd = newdfd as usize;
let newfilename = CString::new(newfilename);
let newfilename_ptr = newfilename.as_ptr() as usize;
syscall4(
SYS_RENAMEAT,
olddfd,
oldfilename_ptr,
newdfd,
newfilename_ptr,
)
.map(drop)
}
pub fn renameat2(
olddfd: i32,
oldfilename: &str,
newdfd: i32,
newfilename: &str,
flags: i32,
) -> Result<(), Errno> {
let olddfd = olddfd as usize;
let oldfilename = CString::new(oldfilename);
let oldfilename_ptr = oldfilename.as_ptr() as usize;
let newdfd = newdfd as usize;
let newfilename = CString::new(newfilename);
let newfilename_ptr = newfilename.as_ptr() as usize;
let flags = flags as usize;
syscall5(
SYS_RENAMEAT2,
olddfd,
oldfilename_ptr,
newdfd,
newfilename_ptr,
flags,
)
.map(drop)
}
pub fn request_key(
type_: &str,
description: &str,
callout_info: &str,
dest_keyring: key_serial_t,
) -> Result<key_serial_t, Errno> {
let type_ = CString::new(type_);
let type_ptr = type_.as_ptr() as usize;
let description = CString::new(description);
let description_ptr = description.as_ptr() as usize;
let callout_info = CString::new(callout_info);
let callout_info_ptr = callout_info.as_ptr() as usize;
let dest_keyring = dest_keyring as usize;
syscall4(
SYS_REQUEST_KEY,
type_ptr,
description_ptr,
callout_info_ptr,
dest_keyring,
)
.map(|ret| ret as key_serial_t)
}
pub fn restart_syscall() -> Result<i32, Errno> {
syscall0(SYS_RESTART_SYSCALL).map(|ret| ret as i32)
}
pub fn rmdir(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_RMDIR, filename_ptr).map(drop)
}
pub fn rseq(rseq: &mut [rseq_t], flags: i32, sig: u32) -> Result<i32, Errno> {
let rseq_ptr = rseq.as_mut_ptr() as usize;
let rseq_len = rseq.len();
let flags = flags as usize;
let sig = sig as usize;
syscall4(SYS_RSEQ, rseq_ptr, rseq_len, flags, sig).map(|ret| ret as i32)
}
pub fn rt_sigaction(
sig: i32,
act: &sigaction_t,
old_act: &mut sigaction_t,
sigsetsize: size_t,
) -> Result<(), Errno> {
let sig = sig as usize;
let act_ptr = act as *const sigaction_t as usize;
let old_act_ptr = old_act as *mut sigaction_t as usize;
let sigsetsize = sigsetsize as usize;
syscall4(SYS_RT_SIGACTION, sig, act_ptr, old_act_ptr, sigsetsize).map(drop)
}
pub fn rt_sigpending(set: &mut [sigset_t]) -> Result<(), Errno> {
let set_ptr = set.as_mut_ptr() as usize;
syscall1(SYS_RT_SIGPENDING, set_ptr).map(drop)
}
pub fn rt_sigprocmask(how: i32, set: &sigset_t, oldset: &mut sigset_t) -> Result<(), Errno> {
let how = how as usize;
let set_ptr = set as *const sigset_t as usize;
let oldset_ptr = oldset as *mut sigset_t as usize;
syscall3(SYS_RT_SIGPROCMASK, how, set_ptr, oldset_ptr).map(drop)
}
pub fn rt_sigqueueinfo(pid: pid_t, sig: i32, uinfo: &mut siginfo_t) -> Result<(), Errno> {
let pid = pid as usize;
let sig = sig as usize;
let uinfo_ptr = uinfo as *mut siginfo_t as usize;
syscall3(SYS_RT_SIGQUEUEINFO, pid, sig, uinfo_ptr).map(drop)
}
pub fn rt_sigreturn() {
let _ = syscall0(SYS_RT_SIGRETURN);
}
pub fn rt_sigsuspend(set: &mut sigset_t, sigsetsize: size_t) -> Result<(), Errno> {
let set_ptr = set as *mut sigset_t as usize;
let sigsetsize = sigsetsize as usize;
syscall2(SYS_RT_SIGSUSPEND, set_ptr, sigsetsize).map(drop)
}
pub fn rt_sigtimedwait(
uthese: &sigset_t,
uinfo: &mut siginfo_t,
uts: ×pec_t,
sigsetsize: size_t,
) -> Result<i32, Errno> {
let uthese_ptr = uthese as *const sigset_t as usize;
let uinfo_ptr = uinfo as *mut siginfo_t as usize;
let uts_ptr = uts as *const timespec_t as usize;
let sigsetsize = sigsetsize as usize;
syscall4(
SYS_RT_SIGTIMEDWAIT,
uthese_ptr,
uinfo_ptr,
uts_ptr,
sigsetsize,
)
.map(|ret| ret as i32)
}
pub fn rt_tgsigqueueinfo(
tgid: pid_t,
tid: pid_t,
sig: i32,
uinfo: &mut siginfo_t,
) -> Result<(), Errno> {
let tgid = tgid as usize;
let tid = tid as usize;
let sig = sig as usize;
let uinfo_ptr = uinfo as *mut siginfo_t as usize;
syscall4(SYS_RT_TGSIGQUEUEINFO, tgid, tid, sig, uinfo_ptr).map(drop)
}
pub fn sched_getaffinity(pid: pid_t, len: u32, user_mask: &mut usize) -> Result<(), Errno> {
let pid = pid as usize;
let len = len as usize;
let user_mask_ptr = user_mask as *mut usize as usize;
syscall3(SYS_SCHED_GETAFFINITY, pid, len, user_mask_ptr).map(drop)
}
pub fn sched_getattr(
pid: pid_t,
attr: &mut sched_attr_t,
size: u32,
flags: u32,
) -> Result<(), Errno> {
let pid = pid as usize;
let attr_ptr = attr as *mut sched_attr_t as usize;
let size = size as usize;
let flags = flags as usize;
syscall4(SYS_SCHED_GETATTR, pid, attr_ptr, size, flags).map(drop)
}
pub fn sched_getparam(pid: pid_t, param: &mut sched_param_t) -> Result<(), Errno> {
let pid = pid as usize;
let param_ptr = param as *mut sched_param_t as usize;
syscall2(SYS_SCHED_GETPARAM, pid, param_ptr).map(drop)
}
pub fn sched_getscheduler(pid: pid_t) -> Result<i32, Errno> {
let pid = pid as usize;
syscall1(SYS_SCHED_GETSCHEDULER, pid).map(|ret| ret as i32)
}
pub fn sched_get_priority_max(policy: i32) -> Result<i32, Errno> {
let policy = policy as usize;
syscall1(SYS_SCHED_GET_PRIORITY_MAX, policy).map(|ret| ret as i32)
}
pub fn sched_get_priority_min(policy: i32) -> Result<i32, Errno> {
let policy = policy as usize;
syscall1(SYS_SCHED_GET_PRIORITY_MIN, policy).map(|ret| ret as i32)
}
pub fn sched_rr_get_interval(pid: pid_t, interval: &mut timespec_t) -> Result<(), Errno> {
let pid = pid as usize;
let interval_ptr = interval as *mut timespec_t as usize;
syscall2(SYS_SCHED_RR_GET_INTERVAL, pid, interval_ptr).map(drop)
}
pub fn sched_setaffinity(pid: pid_t, len: u32, user_mask: &mut usize) -> Result<(), Errno> {
let pid = pid as usize;
let len = len as usize;
let user_mask_ptr = user_mask as *mut usize as usize;
syscall3(SYS_SCHED_SETAFFINITY, pid, len, user_mask_ptr).map(drop)
}
pub fn sched_setattr(pid: pid_t, attr: &mut sched_attr_t, flags: u32) -> Result<(), Errno> {
let pid = pid as usize;
let attr_ptr = attr as *mut sched_attr_t as usize;
let flags = flags as usize;
syscall3(SYS_SCHED_SETATTR, pid, attr_ptr, flags).map(drop)
}
pub fn sched_setparam(pid: pid_t, param: &sched_param_t) -> Result<(), Errno> {
let pid = pid as usize;
let param_ptr = param as *const sched_param_t as usize;
syscall2(SYS_SCHED_SETPARAM, pid, param_ptr).map(drop)
}
pub fn sched_setscheduler(pid: pid_t, policy: i32, param: &sched_param_t) -> Result<(), Errno> {
let pid = pid as usize;
let policy = policy as usize;
let param_ptr = param as *const sched_param_t as usize;
syscall3(SYS_SCHED_SETSCHEDULER, pid, policy, param_ptr).map(drop)
}
pub fn sched_yield() -> Result<(), Errno> {
syscall0(SYS_SCHED_YIELD).map(drop)
}
pub fn seccomp(operation: u32, flags: u32, args: usize) -> Result<(), Errno> {
let operation = operation as usize;
let flags = flags as usize;
syscall3(SYS_SECCOMP, operation, flags, args).map(drop)
}
pub fn security() {
core::unimplemented!();
}
pub fn select(
nfds: i32,
readfds: &mut fd_set_t,
writefds: &mut fd_set_t,
exceptfds: &mut fd_set_t,
timeout: &mut timeval_t,
) -> Result<i32, Errno> {
let nfds = nfds as usize;
let readfds_ptr = readfds as *mut fd_set_t as usize;
let writefds_ptr = writefds as *mut fd_set_t as usize;
let exceptfds_ptr = exceptfds as *mut fd_set_t as usize;
let timeout_ptr = timeout as *mut timeval_t as usize;
syscall5(
SYS_SELECT,
nfds,
readfds_ptr,
writefds_ptr,
exceptfds_ptr,
timeout_ptr,
)
.map(|ret| ret as i32)
}
pub fn semctl(semid: i32, semnum: i32, cmd: i32, arg: usize) -> Result<i32, Errno> {
let semid = semid as usize;
let semnum = semnum as usize;
let cmd = cmd as usize;
syscall4(SYS_SEMCTL, semid, semnum, cmd, arg).map(|ret| ret as i32)
}
pub fn semget(key: key_t, nsems: i32, semflg: i32) -> Result<i32, Errno> {
let key = key as usize;
let nsems = nsems as usize;
let semflg = semflg as usize;
syscall3(SYS_SEMGET, key, nsems, semflg).map(|ret| ret as i32)
}
pub fn semop(semid: i32, sops: &mut [sembuf_t]) -> Result<(), Errno> {
let semid = semid as usize;
let sops_ptr = sops.as_ptr() as usize;
let nops = sops.len();
syscall3(SYS_SEMOP, semid, sops_ptr, nops).map(drop)
}
pub fn semtimedop(semid: i32, sops: &mut [sembuf_t], timeout: ×pec_t) -> Result<(), Errno> {
let semid = semid as usize;
let sops_ptr = sops.as_ptr() as usize;
let nops = sops.len();
let timeout_ptr = timeout as *const timespec_t as usize;
syscall4(SYS_SEMTIMEDOP, semid, sops_ptr, nops, timeout_ptr).map(drop)
}
pub fn sendfile(
out_fd: i32,
in_fd: i32,
offset: &mut off_t,
count: size_t,
) -> Result<ssize_t, Errno> {
let out_fd = out_fd as usize;
let in_fd = in_fd as usize;
let offset_ptr = offset as *mut off_t as usize;
let count = count as usize;
syscall4(SYS_SENDFILE, out_fd, in_fd, offset_ptr, count).map(|ret| ret as ssize_t)
}
pub fn sendmmsg(sockfd: i32, msgvec: &mut [mmsghdr_t], flags: i32) -> Result<i32, Errno> {
let sockfd = sockfd as usize;
let msgvec_ptr = msgvec as *mut [mmsghdr_t] as *mut mmsghdr_t as usize;
let vlen = msgvec.len() as usize;
let flags = flags as usize;
syscall4(SYS_SENDMMSG, sockfd, msgvec_ptr, vlen, flags).map(|ret| ret as i32)
}
pub fn sendmsg(sockfd: i32, msg: &msghdr_t, flags: i32) -> Result<ssize_t, Errno> {
let sockfd = sockfd as usize;
let msg_ptr = msg as *const msghdr_t as usize;
let flags = flags as usize;
syscall3(SYS_SENDMSG, sockfd, msg_ptr, flags).map(|ret| ret as ssize_t)
}
pub fn sendto(
sockfd: i32,
buf: &[u8],
len: size_t,
flags: i32,
dest_addr: &sockaddr_in_t,
addrlen: socklen_t,
) -> Result<ssize_t, Errno> {
let sockfd = sockfd as usize;
let buf_ptr = buf.as_ptr() as usize;
let len = len as usize;
let flags = flags as usize;
let dest_addr_ptr = dest_addr as *const sockaddr_in_t as usize;
let addrlen = addrlen as usize;
syscall6(
SYS_SENDTO,
sockfd,
buf_ptr,
len,
flags,
dest_addr_ptr,
addrlen,
)
.map(|ret| ret as ssize_t)
}
pub fn setdomainname(name: &str) -> Result<(), Errno> {
let name = CString::new(name);
let name_ptr = name.as_ptr() as usize;
let name_len = name.len() as usize;
syscall2(SYS_SETDOMAINNAME, name_ptr, name_len).map(drop)
}
pub fn setfsgid(fsgid: gid_t) -> Result<gid_t, Errno> {
let fsgid = fsgid as usize;
syscall1(SYS_SETFSGID, fsgid).map(|ret| ret as gid_t)
}
pub fn setfsuid(fsuid: uid_t) -> Result<uid_t, Errno> {
let fsuid = fsuid as usize;
syscall1(SYS_SETFSUID, fsuid).map(|ret| ret as uid_t)
}
pub fn setgid(gid: gid_t) -> Result<(), Errno> {
let gid = gid as usize;
syscall1(SYS_SETGID, gid).map(drop)
}
pub fn setgroups(group_list: &[gid_t]) -> Result<(), Errno> {
let group_ptr = group_list.as_ptr() as usize;
let group_len = group_list.len();
syscall2(SYS_SETGROUPS, group_ptr, group_len).map(drop)
}
pub fn sethostname(name: &str) -> Result<(), Errno> {
let name_ptr = name.as_ptr() as usize;
let name_len = name.len();
syscall2(SYS_SETHOSTNAME, name_ptr, name_len).map(drop)
}
pub fn setitimer(
which: i32,
new_val: &itimerval_t,
old_val: &mut itimerval_t,
) -> Result<(), Errno> {
let which = which as usize;
let new_val_ptr = new_val as *const itimerval_t as usize;
let old_val_ptr = old_val as *mut itimerval_t as usize;
syscall3(SYS_SETITIMER, which, new_val_ptr, old_val_ptr).map(drop)
}
pub fn setns(fd: i32, nstype: i32) -> Result<(), Errno> {
let fd = fd as usize;
let nstype = nstype as usize;
syscall2(SYS_SETNS, fd, nstype).map(drop)
}
pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<(), Errno> {
let pid = pid as usize;
let pgid = pgid as usize;
syscall2(SYS_SETPGID, pid, pgid).map(drop)
}
pub fn setpriority(which: i32, who: i32, prio: i32) -> Result<(), Errno> {
let which = which as usize;
let who = who as usize;
let prio = prio as usize;
syscall3(SYS_SETPRIORITY, which, who, prio).map(drop)
}
pub fn setregid(rgid: gid_t, egid: gid_t) -> Result<(), Errno> {
let rgid = rgid as usize;
let egid = egid as usize;
syscall2(SYS_SETREGID, rgid, egid).map(drop)
}
pub fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> Result<(), Errno> {
let rgid = rgid as usize;
let egid = egid as usize;
let sgid = sgid as usize;
syscall3(SYS_SETRESGID, rgid, egid, sgid).map(drop)
}
pub fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> Result<(), Errno> {
let ruid = ruid as usize;
let euid = euid as usize;
let suid = suid as usize;
syscall3(SYS_SETRESUID, ruid, euid, suid).map(drop)
}
pub fn setreuid(ruid: uid_t, euid: uid_t) -> Result<(), Errno> {
let ruid = ruid as usize;
let euid = euid as usize;
syscall2(SYS_SETREUID, ruid, euid).map(drop)
}
pub fn setrlimit(resource: u32, rlimit: &rlimit_t) -> Result<(), Errno> {
let resource = resource as usize;
let rlimit_ptr = rlimit as *const rlimit_t as usize;
syscall2(SYS_SETRLIMIT, resource, rlimit_ptr).map(drop)
}
pub fn setsid() -> Result<pid_t, Errno> {
syscall0(SYS_SETSID).map(|ret| ret as pid_t)
}
pub fn setsockopt(
sockfd: i32,
level: i32,
optname: i32,
optval: usize,
optlen: socklen_t,
) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let level = level as usize;
let optname = optname as usize;
let optlen = optlen as usize;
syscall5(SYS_SETSOCKOPT, sockfd, level, optname, optval, optlen).map(drop)
}
pub fn settimeofday(timeval: &timeval_t, tz: &timezone_t) -> Result<(), Errno> {
let timeval_ptr = timeval as *const timeval_t as usize;
let tz_ptr = tz as *const timezone_t as usize;
syscall2(SYS_SETTIMEOFDAY, timeval_ptr, tz_ptr).map(drop)
}
pub fn setuid(uid: uid_t) -> Result<(), Errno> {
let uid = uid as usize;
syscall1(SYS_SETUID, uid).map(drop)
}
pub fn setxattr(filename: &str, name: &str, value: usize, size: size_t) -> Result<ssize_t, Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let name_ptr = name.as_ptr() as usize;
let size = size as usize;
syscall4(SYS_SETXATTR, filename_ptr, name_ptr, value, size).map(|ret| ret as ssize_t)
}
pub fn set_mempolicy(mode: i32, nmask: *const usize, maxnode: usize) -> Result<(), Errno> {
let mode = mode as usize;
let nmask = nmask as usize;
syscall3(SYS_SET_MEMPOLICY, mode, nmask, maxnode).map(drop)
}
pub fn set_robust_list(heads: &mut [robust_list_head_t]) -> Result<(), Errno> {
let heads_ptr = heads.as_mut_ptr() as usize;
let len = heads.len();
syscall2(SYS_SET_ROBUST_LIST, heads_ptr, len).map(drop)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn set_thread_area(user_desc: &mut user_desc_t) -> Result<(), Errno> {
let user_desc_ptr = user_desc as *mut user_desc_t as usize;
syscall1(SYS_SET_THREAD_AREA, user_desc_ptr).map(drop)
}
#[cfg(any(target_arch = "mips", target_arch = "mips64"))]
pub fn set_thread_area(addr: usize) -> Result<(), Errno> {
syscall1(SYS_SET_THREAD_AREA, addr).map(drop)
}
pub fn set_tid_address(tid: &mut i32) -> Result<isize, Errno> {
let tid_ptr = tid as *mut i32 as usize;
syscall1(SYS_SET_TID_ADDRESS, tid_ptr).map(|ret| ret as isize)
}
pub fn shmat(shmid: i32, shmaddr: usize, shmflg: i32) -> Result<usize, Errno> {
let shmid = shmid as usize;
let shmflg = shmflg as usize;
syscall3(SYS_SHMAT, shmid, shmaddr, shmflg)
}
pub fn shmctl(shmid: i32, cmd: i32, buf: &mut shmid_ds_t) -> Result<i32, Errno> {
let shmid = shmid as usize;
let cmd = cmd as usize;
let buf_ptr = buf as *mut shmid_ds_t as usize;
syscall3(SYS_SHMCTL, shmid, cmd, buf_ptr).map(|ret| ret as i32)
}
pub fn shmdt(shmaddr: usize) -> Result<(), Errno> {
syscall1(SYS_SHMDT, shmaddr).map(drop)
}
pub fn shmget(key: key_t, size: size_t, shmflg: i32) -> Result<(), Errno> {
let key = key as usize;
let size = size as usize;
let shmflg = shmflg as usize;
syscall3(SYS_SHMGET, key, size, shmflg).map(drop)
}
pub fn shutdown(sockfd: i32, how: i32) -> Result<(), Errno> {
let sockfd = sockfd as usize;
let how = how as usize;
syscall2(SYS_SHUTDOWN, sockfd, how).map(drop)
}
pub fn sigaltstack(uss: &sigaltstack_t, uoss: &mut sigaltstack_t) -> Result<(), Errno> {
let uss_ptr = uss as *const sigaltstack_t as usize;
let uoss_ptr = uoss as *mut sigaltstack_t as usize;
syscall2(SYS_SIGALTSTACK, uss_ptr, uoss_ptr).map(drop)
}
pub fn signalfd(fd: i32, mask: &[sigset_t]) -> Result<i32, Errno> {
let fd = fd as usize;
let mask_ptr = mask.as_ptr() as usize;
let mask_len = mask.len() as usize;
syscall3(SYS_SIGNALFD, fd, mask_ptr, mask_len).map(|ret| ret as i32)
}
pub fn signalfd4(fd: i32, mask: &[sigset_t], flags: i32) -> Result<i32, Errno> {
let fd = fd as usize;
let mask_ptr = mask.as_ptr() as usize;
let mask_len = mask.len() as usize;
let flags = flags as usize;
syscall4(SYS_SIGNALFD4, fd, mask_ptr, mask_len, flags).map(|ret| ret as i32)
}
pub fn socket(domain: i32, sock_type: i32, protocol: i32) -> Result<i32, Errno> {
let domain = domain as usize;
let sock_type = sock_type as usize;
let protocol = protocol as usize;
syscall3(SYS_SOCKET, domain, sock_type, protocol).map(|ret| ret as i32)
}
pub fn socketpair(domain: i32, type_: i32, protocol: i32, sv: [i32; 2]) -> Result<(), Errno> {
let domain = domain as usize;
let type_ = type_ as usize;
let protocol = protocol as usize;
let sv_ptr = sv.as_ptr() as usize;
syscall4(SYS_SOCKETPAIR, domain, type_, protocol, sv_ptr).map(drop)
}
pub fn splice(
fd_in: i32,
off_in: &mut loff_t,
fd_out: i32,
off_out: &mut loff_t,
len: size_t,
flags: u32,
) -> Result<ssize_t, Errno> {
let fd_in = fd_in as usize;
let off_in_ptr = off_in as *mut loff_t as usize;
let fd_out = fd_out as usize;
let off_out_ptr = off_out as *mut loff_t as usize;
let len = len as usize;
let flags = flags as usize;
syscall6(
SYS_SPLICE,
fd_in,
off_in_ptr,
fd_out,
off_out_ptr,
len,
flags,
)
.map(|ret| ret as ssize_t)
}
pub fn stat(filename: &str, statbuf: &mut stat_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let statbuf_ptr = statbuf as *mut stat_t as usize;
syscall2(SYS_STAT, filename_ptr, statbuf_ptr).map(drop)
}
pub fn statfs(filename: &str, buf: &mut statfs_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let buf_ptr = buf as *mut statfs_t as usize;
syscall2(SYS_STATFS, filename_ptr, buf_ptr).map(drop)
}
pub fn statx(
dirfd: i32,
filename: &str,
flags: i32,
mask: u32,
buf: &mut statx_t,
) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flags = flags as usize;
let mask = mask as usize;
let buf_ptr = buf as *mut statx_t as usize;
syscall5(SYS_STATX, dirfd, filename_ptr, flags, mask, buf_ptr).map(drop)
}
pub fn swapoff(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_SWAPOFF, filename_ptr).map(drop)
}
pub fn swapon(filename: &str, flags: i32) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_SWAPON, filename_ptr, flags).map(drop)
}
pub fn symlink(oldname: &str, newname: &str) -> Result<(), Errno> {
let oldname_ptr = oldname.as_ptr() as usize;
let newname_ptr = newname.as_ptr() as usize;
syscall2(SYS_SYMLINK, oldname_ptr, newname_ptr).map(drop)
}
pub fn symlinkat(oldname: &str, newfd: i32, newname: &str) -> Result<(), Errno> {
let oldname_ptr = oldname.as_ptr() as usize;
let newfd = newfd as usize;
let newname_ptr = newname.as_ptr() as usize;
syscall3(SYS_SYMLINKAT, oldname_ptr, newfd, newname_ptr).map(drop)
}
pub fn sync() {
let _ret = syscall0(SYS_SYNC);
}
pub fn syncfs(fd: i32) -> Result<(), Errno> {
let fd = fd as usize;
syscall1(SYS_SYNCFS, fd).map(drop)
}
pub fn sync_file_range(fd: i32, offset: off_t, nbytes: off_t, flags: i32) -> Result<(), Errno> {
let fd = fd as usize;
let offset = offset as usize;
let nbytes = nbytes as usize;
let flags = flags as usize;
syscall4(SYS_SYNC_FILE_RANGE, fd, offset, nbytes, flags).map(drop)
}
pub fn sysfs(option: i32, arg1: usize, arg2: usize) -> Result<i32, Errno> {
let option = option as usize;
let arg1 = arg1 as usize;
let arg2 = arg2 as usize;
syscall3(SYS_SYSFS, option, arg1, arg2).map(|ret| ret as i32)
}
pub fn sysinfo(info: &mut sysinfo_t) -> Result<(), Errno> {
let info_ptr = info as *mut sysinfo_t as usize;
syscall1(SYS_SYSINFO, info_ptr).map(drop)
}
pub fn syslog(action: i32, buf: &mut [u8]) -> Result<i32, Errno> {
let action = action as usize;
let buf_ptr = buf.as_mut_ptr() as usize;
let buf_len = buf.len();
syscall3(SYS_SYSLOG, action, buf_ptr, buf_len).map(|ret| ret as i32)
}
pub fn tee(fd_in: i32, fd_out: i32, len: size_t, flags: u32) -> Result<ssize_t, Errno> {
let fd_in = fd_in as usize;
let fd_out = fd_out as usize;
let len = len as usize;
let flags = flags as usize;
syscall4(SYS_TEE, fd_in, fd_out, len, flags).map(|ret| ret as ssize_t)
}
pub fn tgkill(tgid: i32, tid: i32, sig: i32) -> Result<(), Errno> {
let tgid = tgid as usize;
let tid = tid as usize;
let sig = sig as usize;
syscall3(SYS_TGKILL, tgid, tid, sig).map(drop)
}
pub fn time() -> Result<time_t, Errno> {
syscall0(SYS_TIME).map(|ret| ret as time_t)
}
pub fn timerfd_create(clockid: i32, flags: i32) -> Result<i32, Errno> {
let clockid = clockid as usize;
let flags = flags as usize;
syscall2(SYS_TIMERFD_CREATE, clockid, flags).map(|ret| ret as i32)
}
pub fn timerfd_gettime(ufd: i32, otmr: &mut itimerval_t) -> Result<(), Errno> {
let ufd = ufd as usize;
let otmr_ptr = otmr as *mut itimerval_t as usize;
syscall2(SYS_TIMERFD_GETTIME, ufd, otmr_ptr).map(drop)
}
pub fn timerfd_settime(
ufd: i32,
flags: i32,
utmr: &itimerval_t,
otmr: &mut itimerval_t,
) -> Result<(), Errno> {
let ufd = ufd as usize;
let flags = flags as usize;
let utmr_ptr = utmr as *const itimerval_t as usize;
let otmr_ptr = otmr as *mut itimerval_t as usize;
syscall4(SYS_TIMERFD_SETTIME, ufd, flags, utmr_ptr, otmr_ptr).map(drop)
}
pub fn timer_create(
clock: clockid_t,
event: &mut sigevent_t,
timer_id: &mut timer_t,
) -> Result<(), Errno> {
let clock = clock as usize;
let event_ptr = event as *mut sigevent_t as usize;
let timer_id_ptr = timer_id as *mut timer_t as usize;
syscall3(SYS_TIMER_CREATE, clock, event_ptr, timer_id_ptr).map(drop)
}
pub fn timer_delete(timer_id: timer_t) -> Result<(), Errno> {
let timer_id = timer_id as usize;
syscall1(SYS_TIMER_DELETE, timer_id).map(drop)
}
pub fn timer_getoverrun(timer_id: timer_t) -> Result<(), Errno> {
let timer_id = timer_id as usize;
syscall1(SYS_TIMER_GETOVERRUN, timer_id).map(drop)
}
pub fn timer_gettime(timer_id: timer_t, curr: &mut itimerspec_t) -> Result<(), Errno> {
let timer_id = timer_id as usize;
let curr_ptr = curr as *mut itimerspec_t as usize;
syscall2(SYS_TIMER_GETTIME, timer_id, curr_ptr).map(drop)
}
pub fn timer_settime(
timer_id: timer_t,
flags: i32,
new_value: &itimerspec_t,
old_value: &mut itimerspec_t,
) -> Result<(), Errno> {
let timer_id = timer_id as usize;
let flags = flags as usize;
let new_value_ptr = new_value as *const itimerspec_t as usize;
let old_value_ptr = old_value as *mut itimerspec_t as usize;
syscall4(
SYS_TIMER_SETTIME,
timer_id,
flags,
new_value_ptr,
old_value_ptr,
)
.map(drop)
}
pub fn times(buf: &mut tms_t) -> Result<clock_t, Errno> {
let buf_ptr = buf as *mut tms_t as usize;
syscall1(SYS_TIMES, buf_ptr).map(|ret| ret as clock_t)
}
pub fn tkill(tid: i32, sig: i32) -> Result<(), Errno> {
let tid = tid as usize;
let sig = sig as usize;
syscall2(SYS_TKILL, tid, sig).map(drop)
}
pub fn truncate(filename: &str, length: off_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let length = length as usize;
syscall2(SYS_TRUNCATE, filename_ptr, length).map(drop)
}
pub fn tuxcall() {
core::unimplemented!();
}
pub fn umask(mode: mode_t) -> Result<mode_t, Errno> {
let mode = mode as usize;
syscall1(SYS_UMASK, mode).map(|ret| ret as mode_t)
}
pub fn umount2(name: &str, flags: i32) -> Result<(), Errno> {
let name_ptr = name.as_ptr() as usize;
let flags = flags as usize;
syscall2(SYS_UMOUNT2, name_ptr, flags).map(drop)
}
pub fn uname(buf: &mut utsname_t) -> Result<(), Errno> {
let buf_ptr = buf as *mut utsname_t as usize;
syscall1(SYS_UNAME, buf_ptr).map(drop)
}
pub fn unlink(filename: &str) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
syscall1(SYS_UNLINK, filename_ptr).map(drop)
}
pub fn unlinkat(dfd: i32, filename: &str, flag: i32) -> Result<(), Errno> {
let dfd = dfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let flag = flag as usize;
syscall3(SYS_UNLINKAT, dfd, filename_ptr, flag).map(drop)
}
pub fn unshare(flags: i32) -> Result<(), Errno> {
let flags = flags as usize;
syscall1(SYS_UNSHARE, flags).map(drop)
}
pub fn uselib(library: &str) -> Result<(), Errno> {
let library_ptr = library.as_ptr() as usize;
syscall1(SYS_USELIB, library_ptr).map(drop)
}
pub fn userfaultfd(flags: i32) -> Result<i32, Errno> {
let flags = flags as usize;
syscall1(SYS_USERFAULTFD, flags).map(|ret| ret as i32)
}
pub fn ustat(dev: dev_t, ubuf: &mut ustat_t) -> Result<(), Errno> {
let dev = dev as usize;
let ubuf_ptr = ubuf as *mut ustat_t as usize;
syscall2(SYS_USTAT, dev, ubuf_ptr).map(drop)
}
pub fn utime(filename: &str, times: &utimbuf_t) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let times_ptr = times as *const utimbuf_t as usize;
syscall2(SYS_UTIME, filename_ptr, times_ptr).map(drop)
}
pub fn utimensat(
dirfd: i32,
filename: &str,
times: &[timespec_t; 2],
flags: i32,
) -> Result<(), Errno> {
let dirfd = dirfd as usize;
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let times_ptr = times.as_ptr() as usize;
let flags = flags as usize;
syscall4(SYS_UTIMENSAT, dirfd, filename_ptr, times_ptr, flags).map(drop)
}
pub fn utimes(filename: &str, times: &[timeval_t; 2]) -> Result<(), Errno> {
let filename = CString::new(filename);
let filename_ptr = filename.as_ptr() as usize;
let times_ptr = times.as_ptr() as usize;
syscall2(SYS_UTIMES, filename_ptr, times_ptr).map(drop)
}
pub fn vfork() -> Result<pid_t, Errno> {
syscall0(SYS_VFORK).map(|ret| ret as pid_t)
}
pub fn vhangup() -> Result<(), Errno> {
syscall0(SYS_VHANGUP).map(drop)
}
pub fn vmsplice(fd: i32, iov: &iovec_t, nr_segs: usize, flags: u32) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let iov_ptr = iov as *const iovec_t as usize;
let flags = flags as usize;
syscall4(SYS_VMSPLICE, fd, iov_ptr, nr_segs, flags).map(|ret| ret as ssize_t)
}
pub fn vserver() {
core::unimplemented!();
}
pub fn wait4(
pid: pid_t,
wstatus: &mut i32,
options: i32,
rusage: &mut rusage_t,
) -> Result<(), Errno> {
let pid = pid as usize;
let wstatus_ptr = wstatus as *mut i32 as usize;
let options = options as usize;
let rusage_ptr = rusage as *mut rusage_t as usize;
syscall4(SYS_WAIT4, pid, wstatus_ptr, options, rusage_ptr).map(drop)
}
pub fn waitid(
which: i32,
pid: pid_t,
info: &mut siginfo_t,
options: i32,
ru: &mut rusage_t,
) -> Result<(), Errno> {
let which = which as usize;
let pid = pid as usize;
let info_ptr = info as *mut siginfo_t as usize;
let options = options as usize;
let ru_ptr = ru as *mut rusage_t as usize;
syscall5(SYS_WAITID, which, pid, info_ptr, options, ru_ptr).map(drop)
}
pub fn write(fd: i32, buf_ptr: usize, count: size_t) -> Result<ssize_t, Errno> {
let fd = fd as usize;
syscall3(SYS_WRITE, fd, buf_ptr, count).map(|ret| ret as ssize_t)
}
pub fn writev(fd: i32, iov: &[iovec_t]) -> Result<ssize_t, Errno> {
let fd = fd as usize;
let iov_ptr = iov.as_ptr() as usize;
let len = iov.len() as usize;
syscall3(SYS_WRITEV, fd, iov_ptr, len).map(|ret| ret as ssize_t)
}
pub fn _sysctl(args: &mut sysctl_args_t) -> Result<(), Errno> {
let args_ptr = args as *mut sysctl_args_t as usize;
syscall1(SYS__SYSCTL, args_ptr).map(drop)
}