Skip to content

Commit

Permalink
Fix syscall for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinCB committed Jul 16, 2020
1 parent bf46a06 commit 7ff94a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ license = "MIT/Apache-2.0"
name = "sc"
readme = "README.md"
repository = "https://github.com/japaric/syscall.rs"
version = "0.2.2"
version = "0.2.3"
16 changes: 9 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,13 @@
pub mod nr;

const MACOS_SYSCALL_PREFIX: usize = 33554432;

#[inline(always)]
pub unsafe fn syscall0(n: usize) -> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n)
: "{rax}"(n + MACOS_SYSCALL_PREFIX)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -25,7 +27,7 @@ pub unsafe fn syscall0(n: usize) -> usize {
pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1)
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -35,7 +37,7 @@ pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
pub unsafe fn syscall2(n: usize, a1: usize, a2: usize) -> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2)
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1), "{rsi}"(a2)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -45,7 +47,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;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -60,7 +62,7 @@ pub unsafe fn syscall4(n: usize,
-> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -77,7 +79,7 @@ pub unsafe fn syscall5(n: usize,
-> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -95,7 +97,7 @@ pub unsafe fn syscall6(n: usize,
-> usize {
let ret: usize;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(n + MACOS_SYSCALL_PREFIX), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5), "{r9}"(a6)
: "rcx", "r11", "memory"
: "volatile");
Expand Down

0 comments on commit 7ff94a6

Please sign in to comment.