Skip to content

Commit

Permalink
Allow bypass of Sysno usage (#50)
Browse files Browse the repository at this point in the history
Fixes #46.
  • Loading branch information
sectordistrict authored Jul 25, 2024
1 parent c17d25b commit 723c446
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 208 deletions.
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub mod raw {
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall0(nr: Sysno) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall0(nr))
Errno::from_ret(raw::syscall0(nr as usize))
}

/// Issues a system call with 1 argument.
Expand All @@ -73,7 +73,7 @@ pub unsafe fn syscall0(nr: Sysno) -> Result<usize, Errno> {
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall1(nr: Sysno, a1: usize) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall1(nr, a1))
Errno::from_ret(raw::syscall1(nr as usize, a1))
}

/// Issues a system call with 2 arguments.
Expand All @@ -88,7 +88,7 @@ pub unsafe fn syscall2(
a1: usize,
a2: usize,
) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall2(nr, a1, a2))
Errno::from_ret(raw::syscall2(nr as usize, a1, a2))
}

/// Issues a system call with 3 arguments.
Expand All @@ -104,7 +104,7 @@ pub unsafe fn syscall3(
a2: usize,
a3: usize,
) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall3(nr, a1, a2, a3))
Errno::from_ret(raw::syscall3(nr as usize, a1, a2, a3))
}

/// Issues a system call with 4 arguments.
Expand All @@ -121,7 +121,7 @@ pub unsafe fn syscall4(
a3: usize,
a4: usize,
) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall4(nr, a1, a2, a3, a4))
Errno::from_ret(raw::syscall4(nr as usize, a1, a2, a3, a4))
}

/// Issues a system call with 5 arguments.
Expand All @@ -139,7 +139,7 @@ pub unsafe fn syscall5(
a4: usize,
a5: usize,
) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall5(nr, a1, a2, a3, a4, a5))
Errno::from_ret(raw::syscall5(nr as usize, a1, a2, a3, a4, a5))
}

/// Issues a system call with 6 arguments.
Expand All @@ -158,7 +158,7 @@ pub unsafe fn syscall6(
a5: usize,
a6: usize,
) -> Result<usize, Errno> {
Errno::from_ret(raw::syscall6(nr, a1, a2, a3, a4, a5, a6))
Errno::from_ret(raw::syscall6(nr as usize, a1, a2, a3, a4, a5, a6))
}

/// Does a raw syscall.
Expand Down
19 changes: 12 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,29 @@ macro_rules! syscall {
#[macro_export]
macro_rules! raw_syscall {
($nr:expr) => {
$crate::raw::syscall0($nr)
$crate::raw::syscall0($nr as usize)
};

($nr:expr, $a1:expr) => {
$crate::raw::syscall1($nr, $a1 as usize)
$crate::raw::syscall1($nr as usize, $a1 as usize)
};

($nr:expr, $a1:expr, $a2:expr) => {
$crate::raw::syscall2($nr, $a1 as usize, $a2 as usize)
$crate::raw::syscall2($nr as usize, $a1 as usize, $a2 as usize)
};

($nr:expr, $a1:expr, $a2:expr, $a3:expr) => {
$crate::raw::syscall3($nr, $a1 as usize, $a2 as usize, $a3 as usize)
$crate::raw::syscall3(
$nr as usize,
$a1 as usize,
$a2 as usize,
$a3 as usize,
)
};

($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr) => {
$crate::raw::syscall4(
$nr,
$nr as usize,
$a1 as usize,
$a2 as usize,
$a3 as usize,
Expand All @@ -118,7 +123,7 @@ macro_rules! raw_syscall {

($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr) => {
$crate::raw::syscall5(
$nr,
$nr as usize,
$a1 as usize,
$a2 as usize,
$a3 as usize,
Expand All @@ -129,7 +134,7 @@ macro_rules! raw_syscall {

($nr:expr, $a1:expr, $a2:expr, $a3:expr, $a4:expr, $a5:expr, $a6:expr) => {
$crate::raw::syscall6(
$nr,
$nr as usize,
$a1 as usize,
$a2 as usize,
$a3 as usize,
Expand Down
30 changes: 14 additions & 16 deletions src/syscall/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
// No other registers are clobbered.
use core::arch::asm;

use crate::arch::aarch64::Sysno;

/// Issues a raw system call with 0 arguments.
///
/// # Safety
///
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall0(n: Sysno) -> usize {
pub unsafe fn syscall0(n: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
lateout("x0") ret,
options(nostack, preserves_flags)
);
Expand All @@ -40,11 +38,11 @@ pub unsafe fn syscall0(n: Sysno) -> usize {
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall1(n: Sysno, arg1: usize) -> usize {
pub unsafe fn syscall1(n: usize, arg1: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
options(nostack, preserves_flags)
);
Expand All @@ -58,11 +56,11 @@ pub unsafe fn syscall1(n: Sysno, arg1: usize) -> usize {
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall2(n: Sysno, arg1: usize, arg2: usize) -> usize {
pub unsafe fn syscall2(n: usize, arg1: usize, arg2: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
in("x1") arg2,
options(nostack, preserves_flags)
Expand All @@ -78,15 +76,15 @@ pub unsafe fn syscall2(n: Sysno, arg1: usize, arg2: usize) -> usize {
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall3(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
in("x1") arg2,
in("x2") arg3,
Expand All @@ -103,7 +101,7 @@ pub unsafe fn syscall3(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall4(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -112,7 +110,7 @@ pub unsafe fn syscall4(
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
in("x1") arg2,
in("x2") arg3,
Expand All @@ -130,7 +128,7 @@ pub unsafe fn syscall4(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall5(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -140,7 +138,7 @@ pub unsafe fn syscall5(
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
in("x1") arg2,
in("x2") arg3,
Expand All @@ -159,7 +157,7 @@ pub unsafe fn syscall5(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall6(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -170,7 +168,7 @@ pub unsafe fn syscall6(
let mut ret: usize;
asm!(
"svc 0",
in("x8") n as usize,
in("x8") n,
inlateout("x0") arg1 => ret,
in("x1") arg2,
in("x2") arg3,
Expand Down
30 changes: 14 additions & 16 deletions src/syscall/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
// No other registers are clobbered.
use core::arch::asm;

use crate::arch::arm::Sysno;

/// Issues a raw system call with 0 arguments.
///
/// # Safety
///
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall0(n: Sysno) -> usize {
pub unsafe fn syscall0(n: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
lateout("r0") ret,
options(nostack, preserves_flags)
);
Expand All @@ -40,11 +38,11 @@ pub unsafe fn syscall0(n: Sysno) -> usize {
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall1(n: Sysno, arg1: usize) -> usize {
pub unsafe fn syscall1(n: usize, arg1: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
options(nostack, preserves_flags)
);
Expand All @@ -58,11 +56,11 @@ pub unsafe fn syscall1(n: Sysno, arg1: usize) -> usize {
/// Running a system call is inherently unsafe. It is the caller's
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall2(n: Sysno, arg1: usize, arg2: usize) -> usize {
pub unsafe fn syscall2(n: usize, arg1: usize, arg2: usize) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
in("r1") arg2,
options(nostack, preserves_flags)
Expand All @@ -78,15 +76,15 @@ pub unsafe fn syscall2(n: Sysno, arg1: usize, arg2: usize) -> usize {
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall3(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
) -> usize {
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
in("r1") arg2,
in("r2") arg3,
Expand All @@ -103,7 +101,7 @@ pub unsafe fn syscall3(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall4(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -112,7 +110,7 @@ pub unsafe fn syscall4(
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
in("r1") arg2,
in("r2") arg3,
Expand All @@ -130,7 +128,7 @@ pub unsafe fn syscall4(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall5(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -140,7 +138,7 @@ pub unsafe fn syscall5(
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
in("r1") arg2,
in("r2") arg3,
Expand All @@ -159,7 +157,7 @@ pub unsafe fn syscall5(
/// responsibility to ensure safety.
#[inline]
pub unsafe fn syscall6(
n: Sysno,
n: usize,
arg1: usize,
arg2: usize,
arg3: usize,
Expand All @@ -170,7 +168,7 @@ pub unsafe fn syscall6(
let mut ret: usize;
asm!(
"svc 0",
in("r7") n as usize,
in("r7") n,
inlateout("r0") arg1 => ret,
in("r1") arg2,
in("r2") arg3,
Expand Down
Loading

0 comments on commit 723c446

Please sign in to comment.