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 e9cdc0f
Show file tree
Hide file tree
Showing 2 changed files with 17 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"
23 changes: 16 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,14 @@
pub mod nr;

const MACOS_SYSCALL_PREFIX: usize = 33554432;

#[inline(always)]
pub unsafe fn syscall0(n: usize) -> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n)
: "{rax}"(syscall)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -24,8 +27,9 @@ pub unsafe fn syscall0(n: usize) -> usize {
#[inline(always)]
pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1)
: "{rax}"(syscall), "{rdi}"(a1)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -34,8 +38,9 @@ pub unsafe fn syscall1(n: usize, a1: usize) -> usize {
#[inline(always)]
pub unsafe fn syscall2(n: usize, a1: usize, a2: usize) -> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2)
: "{rax}"(syscall), "{rdi}"(a1), "{rsi}"(a2)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -44,8 +49,9 @@ pub unsafe fn syscall2(n: usize, a1: usize, a2: usize) -> usize {
#[inline(always)]
pub unsafe fn syscall3(n: usize, a1: usize, a2: usize, a3: usize) -> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "{rax}"(syscall), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3)
: "rcx", "r11", "memory"
: "volatile");
ret
Expand All @@ -59,8 +65,9 @@ pub unsafe fn syscall4(n: usize,
a4: usize)
-> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -76,8 +83,9 @@ pub unsafe fn syscall5(n: usize,
a5: usize)
-> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5)
: "rcx", "r11", "memory"
: "volatile");
Expand All @@ -94,8 +102,9 @@ pub unsafe fn syscall6(n: usize,
a6: usize)
-> usize {
let ret: usize;
let syscall = n + MACOS_SYSCALL_PREFIX;
llvm_asm!("syscall" : "={rax}"(ret)
: "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
: "{rax}"(syscall), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3),
"{r10}"(a4), "{r8}"(a5), "{r9}"(a6)
: "rcx", "r11", "memory"
: "volatile");
Expand Down

0 comments on commit e9cdc0f

Please sign in to comment.