Last active
December 19, 2017 13:14
-
-
Save Aatch/5894562 to your computer and use it in GitHub Desktop.
x86-64 syscalls in rust, using asm!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[inline(always)] | |
unsafe fn syscall0(n: int) -> int { | |
let mut ret : int = 0; | |
asm!("syscall" : "={rax}"(ret) : "{rax}"(n) : "rcx", "r11", "memory" : "volatile"); | |
return ret; | |
} | |
#[inline(always)] | |
unsafe fn syscall1(n: int, a1: int) -> int { | |
let mut ret : int = 0; | |
asm!("syscall" : "={rax}"(ret) : "{rax}"(n), "{rdi}"(a1) : "rcx", "r11", "memory" : "volatile"); | |
return ret; | |
} | |
#[inline(always)] | |
unsafe fn syscall2(n: int, a1: int, a2: int) -> int { | |
let mut ret : int = 0; | |
asm!("syscall" : "={rax}"(ret) : "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2) : "rcx", "r11", "memory" : "volatile"); | |
return ret; | |
} | |
#[inline(always)] | |
unsafe fn syscall3(n: int, a1: int, a2: int, a3: int) -> int { | |
let mut ret : int = 0; | |
asm!("syscall" : "={rax}"(ret) : "{rax}"(n), "{rdi}"(a1), "{rsi}"(a2), "{rdx}"(a3) : "rcx", "r11", "memory" : "volatile"); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment