• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- utilities.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef GWP_ASAN_UTILITIES_H_
10 #define GWP_ASAN_UTILITIES_H_
11 
12 #include "gwp_asan/definitions.h"
13 
14 #include <stddef.h>
15 
16 namespace gwp_asan {
17 // Terminates in a platform-specific way with `Message`.
18 void die(const char *Message);
19 
20 // Checks that `Condition` is true, otherwise dies with `Message`.
Check(bool Condition,const char * Message)21 GWP_ASAN_ALWAYS_INLINE void Check(bool Condition, const char *Message) {
22   if (Condition)
23     return;
24   die(Message);
25 }
26 
27 enum class AlignmentStrategy {
28   // Default => POWER_OF_TWO on most platforms, BIONIC for Android Bionic.
29   DEFAULT,
30   POWER_OF_TWO,
31   BIONIC,
32   PERFECT,
33 };
34 
35 // Returns the real size of a right-aligned allocation.
36 size_t rightAlignedAllocationSize(
37     size_t RealAllocationSize,
38     AlignmentStrategy Align = AlignmentStrategy::DEFAULT);
39 } // namespace gwp_asan
40 
41 #endif // GWP_ASAN_UTILITIES_H_
42