Skip to content

Instantly share code, notes, and snippets.

@Aatch
Last active December 19, 2017 13:14
Show Gist options
  • Save Aatch/5894562 to your computer and use it in GitHub Desktop.
Save Aatch/5894562 to your computer and use it in GitHub Desktop.
x86-64 syscalls in rust, using asm!
#[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