Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 1 | //===-- sanitizer_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. |
Alexey Samsonov | ef2e2cf | 2012-06-05 13:50:57 +0000 | [diff] [blame^] | 11 | // It contains macro used in run-time libraries code. |
Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef SANITIZER_DEFS_H |
| 14 | #define SANITIZER_DEFS_H |
| 15 | |
Alexey Samsonov | ef2e2cf | 2012-06-05 13:50:57 +0000 | [diff] [blame^] | 16 | #include "sanitizer_interface_defs.h" |
| 17 | using namespace __sanitizer; // NOLINT |
Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 18 | // ----------- ATTENTION ------------- |
| 19 | // This header should NOT include any other headers to avoid portability issues. |
| 20 | |
Alexey Samsonov | ef2e2cf | 2012-06-05 13:50:57 +0000 | [diff] [blame^] | 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. |
Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 27 | #if defined(_WIN32) |
Alexey Samsonov | ef2e2cf | 2012-06-05 13:50:57 +0000 | [diff] [blame^] | 28 | typedef 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)) |
Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Alexey Samsonov | ef2e2cf | 2012-06-05 13:50:57 +0000 | [diff] [blame^] | 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 |
Kostya Serebryany | 1b71207 | 2012-05-31 14:11:07 +0000 | [diff] [blame] | 61 | |
| 62 | #endif // SANITIZER_DEFS_H |