1251034Sed//===-- sanitizer_syscall_generic.inc ---------------------------*- C++ -*-===//
2251034Sed//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6251034Sed//
7251034Sed//===----------------------------------------------------------------------===//
8251034Sed//
9327952Sdim// Generic implementations of internal_syscall* and internal_iserror.
10251034Sed//
11251034Sed//===----------------------------------------------------------------------===//
12251034Sed
13344779Sdim// NetBSD uses libc calls directly
14344779Sdim#if !SANITIZER_NETBSD
15344779Sdim
16344779Sdim#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_OPENBSD || SANITIZER_SOLARIS
17276789Sdim# define SYSCALL(name) SYS_ ## name
18276789Sdim#else
19276789Sdim# define SYSCALL(name) __NR_ ## name
20276789Sdim#endif
21251034Sed
22344779Sdim#if defined(__x86_64__) && (SANITIZER_FREEBSD || SANITIZER_MAC)
23276789Sdim# define internal_syscall __syscall
24276789Sdim# else
25276789Sdim# define internal_syscall syscall
26276789Sdim#endif
27276789Sdim
28344779Sdim#endif
29344779Sdim
30251034Sedbool internal_iserror(uptr retval, int *rverrno) {
31251034Sed  if (retval == (uptr)-1) {
32251034Sed    if (rverrno)
33251034Sed      *rverrno = errno;
34251034Sed    return true;
35251034Sed  } else {
36251034Sed    return false;
37251034Sed  }
38251034Sed}
39