]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_syscall_generic.inc
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_syscall_generic.inc
1 //===-- sanitizer_syscall_generic.inc ---------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Generic implementations of internal_syscall* and internal_iserror.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD || \
15   SANITIZER_OPENBSD || SANITIZER_SOLARIS
16 # define SYSCALL(name) SYS_ ## name
17 #else
18 # define SYSCALL(name) __NR_ ## name
19 #endif
20
21 #if SANITIZER_NETBSD
22 // We use 3 kinds of internal_syscall's for different types of retval in order
23 // to address differences in calling conventions (e.g. registers to place the
24 // return value in).
25 //   - internal_syscall     for 32-bit length (int, pid_t)
26 //   - internal_syscall64   for 64-bit length (off_t)
27 //   - internal_syscall_ptr for pointer and (s)size_t
28 # define  internal_syscall      syscall
29 # define  internal_syscall64    __syscall
30 // Handle syscall renames manually
31 # define SYS_stat SYS___stat50
32 # define SYS_lstat SYS___lstat50
33 # define SYS_fstat SYS___fstat50
34 # define SYS_gettimeofday SYS___gettimeofday50
35 # define SYS_wait4 SYS___wait450
36 # define SYS_getdents SYS___getdents30
37 # define SYS_sigaltstack SYS___sigaltstack14
38 # define SYS_sigprocmask SYS___sigprocmask14
39 # define SYS_nanosleep SYS___nanosleep50
40 # define SYS_clock_gettime SYS___clock_gettime50
41 # if SANITIZER_WORDSIZE == 64
42 #  define internal_syscall_ptr  __syscall
43 # else
44 #  define internal_syscall_ptr  syscall
45 # endif
46 #elif defined(__x86_64__) && (SANITIZER_FREEBSD || SANITIZER_MAC)
47 # define internal_syscall __syscall
48 # define internal_syscall64 __syscall
49 # define internal_syscall_ptr __syscall
50 # else
51 # define internal_syscall syscall
52 # define internal_syscall64 syscall
53 # define internal_syscall_ptr syscall
54 #endif
55
56 bool internal_iserror(uptr retval, int *rverrno) {
57   if (retval == (uptr)-1) {
58     if (rverrno)
59       *rverrno = errno;
60     return true;
61   } else {
62     return false;
63   }
64 }