mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-05-01 12:30:58 +00:00
160 lines
3 KiB
Rust
160 lines
3 KiB
Rust
//! Syscall implementations for `s390x`.
|
|
|
|
use super::{StatfsBuf, SysInfo, UtsNameBuf};
|
|
|
|
pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 {
|
|
unsafe {
|
|
let fd: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 5i64, // SYS_open
|
|
in("r2") path,
|
|
in("r3") flags,
|
|
in("r4") 0i32, // mode
|
|
lateout("r2") fd,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
fd as i32
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 3i64, // SYS_read
|
|
in("r2") fd,
|
|
in("r3") buf,
|
|
in("r4") count,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as isize
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 4i64, // SYS_write
|
|
in("r2") fd,
|
|
in("r3") buf,
|
|
in("r4") count,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as isize
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_close(fd: i32) -> i32 {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 6i64, // SYS_close
|
|
in("r2") fd,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as i32
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 122i64, // SYS_uname
|
|
in("r2") buf,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as i32
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 99i64, // SYS_statfs
|
|
in("r2") path,
|
|
in("r3") buf,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as i32
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 116_i64, // __NR_sysinfo
|
|
in("r2") info,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
ret
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_sched_getaffinity(
|
|
pid: i32,
|
|
mask_size: usize,
|
|
mask: *mut u8,
|
|
) -> i32 {
|
|
unsafe {
|
|
let ret: i64;
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 240i64, // __NR_sched_getaffinity
|
|
in("r2") pid,
|
|
in("r3") mask_size,
|
|
in("r4") mask,
|
|
lateout("r2") ret,
|
|
options(nostack)
|
|
);
|
|
#[allow(clippy::cast_possible_truncation)]
|
|
{
|
|
ret as i32
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) unsafe fn sys_exit(code: i32) -> ! {
|
|
unsafe {
|
|
core::arch::asm!(
|
|
"svc 0",
|
|
in("r1") 1i64, // SYS_exit
|
|
in("r2") code,
|
|
options(noreturn, nostack)
|
|
);
|
|
}
|
|
}
|