1 //===-- sanitizer_syscall_linux_x86_64.inc ----------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Implementations of internal_syscall and internal_iserror for Linux/x86_64.
10 //===----------------------------------------------------------------------===//
12 #define SYSCALL(name) __NR_ ## name
14 static uptr internal_syscall(u64 nr) {
16 asm volatile("syscall" : "=a"(retval) : "a"(nr) : "rcx", "r11",
21 template <typename T1>
22 static uptr internal_syscall(u64 nr, T1 arg1) {
24 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1) :
25 "rcx", "r11", "memory", "cc");
29 template <typename T1, typename T2>
30 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2) {
32 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
33 "S"((u64)arg2) : "rcx", "r11", "memory", "cc");
37 template <typename T1, typename T2, typename T3>
38 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3) {
40 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
41 "S"((u64)arg2), "d"((u64)arg3) : "rcx", "r11", "memory", "cc");
45 template <typename T1, typename T2, typename T3, typename T4>
46 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
48 asm volatile("mov %5, %%r10;"
49 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
50 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4) :
51 "rcx", "r11", "r10", "memory", "cc");
55 template <typename T1, typename T2, typename T3, typename T4, typename T5>
56 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
59 asm volatile("mov %5, %%r10;"
61 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
62 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5) :
63 "rcx", "r11", "r10", "r8", "memory", "cc");
67 template <typename T1, typename T2, typename T3, typename T4, typename T5,
69 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
72 asm volatile("mov %5, %%r10;"
75 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
76 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5),
77 "r"((u64)arg6) : "rcx", "r11", "r10", "r8", "r9",
82 bool internal_iserror(uptr retval, int *rverrno) {
83 if (retval >= (uptr)-4095) {