Skip to content

Add unix syscall class to syscall nums for macos #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/platform/macos-x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@

pub mod nr;

/// Add the unix syscall class to the syscall number
///
/// https://opensource.apple.com/source/xnu/xnu-4570.41.2/osfmk/mach/i386/syscall_sw.h.auto.html
#[inline(always)]
pub fn syscall_construct_unix(n: usize) -> usize {
(2usize << 24) | (n & !(0xFFusize << 24))
}

#[inline(always)]
pub unsafe fn syscall0(n: usize) -> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n)
: "{rax}"(syscall_construct_unix(n))
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -25,7 +33,7 @@ pub unsafe fn syscall0(n: usize) -> usize {
pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1)
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -35,7 +43,7 @@ pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
pub unsafe fn syscall2(n: usize, a1: usize, a2: usize) -> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2)
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1), "{rsi}"(a2)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -45,7 +53,7 @@ pub unsafe fn syscall2(n: usize, a1: usize, a2: usize) -> usize {
pub unsafe fn syscall3(n: usize, a1: usize, a2: usize, a3: usize) -> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -60,7 +68,7 @@ pub unsafe fn syscall4(n: usize,
-> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -77,7 +85,7 @@ pub unsafe fn syscall5(n: usize,
-> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -95,7 +103,7 @@ pub unsafe fn syscall6(n: usize,
-> usize {
let ret: usize;
asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall_construct_unix(n)), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5), "{r9}"(a6)
: "rcx", "r11", "memory"
: "volatile");
Expand Down