1 //===-- sanitizer_syscall_linux_x86_64.inc ----------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementations of internal_syscall and internal_iserror for Linux/x86_64.
11 //===----------------------------------------------------------------------===//
13 #define SYSCALL(name) __NR_ ## name
15 static uptr internal_syscall(u64 nr) {
17 asm volatile("syscall" : "=a"(retval) : "a"(nr) : "rcx", "r11",
22 template <typename T1>
23 static uptr internal_syscall(u64 nr, T1 arg1) {
25 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1) :
26 "rcx", "r11", "memory", "cc");
30 template <typename T1, typename T2>
31 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2) {
33 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
34 "S"((u64)arg2) : "rcx", "r11", "memory", "cc");
38 template <typename T1, typename T2, typename T3>
39 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3) {
41 asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
42 "S"((u64)arg2), "d"((u64)arg3) : "rcx", "r11", "memory", "cc");
46 template <typename T1, typename T2, typename T3, typename T4>
47 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
49 asm volatile("mov %5, %%r10;"
50 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
51 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4) :
52 "rcx", "r11", "r10", "memory", "cc");
56 template <typename T1, typename T2, typename T3, typename T4, typename T5>
57 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
60 asm volatile("mov %5, %%r10;"
62 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
63 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5) :
64 "rcx", "r11", "r10", "r8", "memory", "cc");
68 template <typename T1, typename T2, typename T3, typename T4, typename T5,
70 static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
73 asm volatile("mov %5, %%r10;"
76 "syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
77 "S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5),
78 "r"((u64)arg6) : "rcx", "r11", "r10", "r8", "r9",
83 bool internal_iserror(uptr retval, int *rverrno) {
84 if (retval >= (uptr)-4095) {