blob: ac220217ecf74ab50dd8326446af8400ec323847 [file] [log] [blame]
Kostya Serebryany1b712072012-05-31 14:11:07 +00001//===-- 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 Samsonovef2e2cf2012-06-05 13:50:57 +000011// It contains macro used in run-time libraries code.
Kostya Serebryany1b712072012-05-31 14:11:07 +000012//===----------------------------------------------------------------------===//
13#ifndef SANITIZER_DEFS_H
14#define SANITIZER_DEFS_H
15
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000016#include "sanitizer_interface_defs.h"
17using namespace __sanitizer; // NOLINT
Kostya Serebryany1b712072012-05-31 14:11:07 +000018// ----------- ATTENTION -------------
19// This header should NOT include any other headers to avoid portability issues.
20
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000021// 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 Serebryany1b712072012-05-31 14:11:07 +000027#if defined(_WIN32)
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000028typedef 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 Serebryany1b712072012-05-31 14:11:07 +000050#endif
51
Alexey Samsonovef2e2cf2012-06-05 13:50:57 +000052// 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 Serebryany1b712072012-05-31 14:11:07 +000061
62#endif // SANITIZER_DEFS_H