Alexey Samsonov | bc3a7e3 | 2012-06-06 06:47:26 +0000 | [diff] [blame] | 1 | //===-- sanitizer_common.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 | // run-time libraries. |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 12 | // It declares common functions and classes that are used in both runtimes. |
Alexey Samsonov | bc3a7e3 | 2012-06-06 06:47:26 +0000 | [diff] [blame] | 13 | // Implementation of some functions are provided in sanitizer_common, while |
| 14 | // others must be defined by run-time library itself. |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | #ifndef SANITIZER_COMMON_H |
| 17 | #define SANITIZER_COMMON_H |
| 18 | |
| 19 | #include "sanitizer_internal_defs.h" |
| 20 | |
| 21 | namespace __sanitizer { |
| 22 | |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 23 | // NOTE: Functions below must be defined in each run-time. {{{ |
Alexey Samsonov | bc3a7e3 | 2012-06-06 06:47:26 +0000 | [diff] [blame] | 24 | void NORETURN Die(); |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 25 | // }}} |
| 26 | |
| 27 | // Constants. |
| 28 | const uptr kWordSize = __WORDSIZE / 8; |
| 29 | const uptr kWordSizeInBits = 8 * kWordSize; |
| 30 | const uptr kPageSizeBits = 12; |
| 31 | const uptr kPageSize = 1UL << kPageSizeBits; |
| 32 | |
| 33 | int GetPid(); |
| 34 | void RawWrite(const char *buffer); |
| 35 | void *MmapOrDie(uptr size); |
| 36 | void UnmapOrDie(void *addr, uptr size); |
| 37 | |
Alexey Samsonov | d323f4e | 2012-06-06 13:58:39 +0000 | [diff] [blame^] | 38 | void Printf(const char *format, ...); |
| 39 | int SNPrintf(char *buffer, uptr length, const char *format, ...); |
| 40 | void Report(const char *format, ...); |
Alexey Samsonov | 51ae983 | 2012-06-06 13:11:29 +0000 | [diff] [blame] | 41 | |
Alexey Samsonov | ee07290 | 2012-06-06 09:26:25 +0000 | [diff] [blame] | 42 | // Bit twiddling. |
| 43 | inline bool IsPowerOfTwo(uptr x) { |
| 44 | return (x & (x - 1)) == 0; |
| 45 | } |
| 46 | inline uptr RoundUpTo(uptr size, uptr boundary) { |
| 47 | // FIXME: Use CHECK here. |
| 48 | RAW_CHECK(IsPowerOfTwo(boundary)); |
| 49 | return (size + boundary - 1) & ~(boundary - 1); |
| 50 | } |
Alexey Samsonov | bc3a7e3 | 2012-06-06 06:47:26 +0000 | [diff] [blame] | 51 | |
| 52 | } // namespace __sanitizer |
| 53 | |
| 54 | #endif // SANITIZER_COMMON_H |