sanitizer_internal_defs.h revision 94b5036ee6ba866e1702848855b6d687d1e70afa
1//===-- sanitizer_internal_defs.h -------------------------------*- 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// This file is shared between AddressSanitizer and ThreadSanitizer.
11// It contains macro used in run-time libraries code.
12//===----------------------------------------------------------------------===//
13#ifndef SANITIZER_DEFS_H
14#define SANITIZER_DEFS_H
15
16#include "sanitizer_interface_defs.h"
17using namespace __sanitizer;  // NOLINT
18// ----------- ATTENTION -------------
19// This header should NOT include any other headers to avoid portability issues.
20
21// Common defs.
22#define INLINE static inline
23#define INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
24#define WEAK SANITIZER_WEAK_ATTRIBUTE
25
26// Platform-specific defs.
27#if defined(_WIN32)
28typedef unsigned long    DWORD;  // NOLINT
29// FIXME(timurrrr): do we need this on Windows?
30# define ALIAS(x)
31# define ALIGNED(x) __declspec(align(x))
32# define NOINLINE __declspec(noinline)
33# define NORETURN __declspec(noreturn)
34# define THREADLOCAL   __declspec(thread)
35#else  // _WIN32
36# define ALIAS(x) __attribute__((alias(x)))
37# define ALIGNED(x) __attribute__((aligned(x)))
38# define NOINLINE __attribute__((noinline))
39# define NORETURN  __attribute__((noreturn))
40# define THREADLOCAL   __thread
41#endif  // _WIN32
42
43// We have no equivalent of these on Windows.
44#ifndef _WIN32
45# define ALWAYS_INLINE __attribute__((always_inline))
46# define LIKELY(x)     __builtin_expect(!!(x), 1)
47# define UNLIKELY(x)   __builtin_expect(!!(x), 0)
48# define FORMAT(f, a)  __attribute__((format(printf, f, a)))
49# define USED __attribute__((used))
50#endif
51
52// If __WORDSIZE was undefined by the platform, define it in terms of the
53// compiler built-ins __LP64__ and _WIN64.
54#ifndef __WORDSIZE
55# if __LP64__ || defined(_WIN64)
56#  define __WORDSIZE 64
57# else
58#  define __WORDSIZE 32
59#  endif
60#endif  // __WORDSIZE
61
62#endif  // SANITIZER_DEFS_H
63