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 | #include <stdint.h> |
16 | |
17 | namespace gwp_asan { |
18 | // Terminates in a platform-specific way with `Message`. |
19 | void die(const char *Message); |
20 | void dieWithErrorCode(const char *Message, int64_t ErrorCode); |
21 | |
22 | // Checks that `Condition` is true, otherwise dies with `Message`. |
23 | GWP_ASAN_ALWAYS_INLINE void check(bool Condition, const char *Message) { |
24 | if (GWP_ASAN_LIKELY(Condition)) |
25 | return; |
26 | die(Message); |
27 | } |
28 | |
29 | // Checks that `Condition` is true, otherwise dies with `Message` (including |
30 | // errno at the end). |
31 | GWP_ASAN_ALWAYS_INLINE void |
32 | checkWithErrorCode(bool Condition, const char *Message, int64_t ErrorCode) { |
33 | if (GWP_ASAN_LIKELY(Condition)) |
34 | return; |
35 | dieWithErrorCode(Message, ErrorCode); |
36 | } |
37 | } // namespace gwp_asan |
38 | |
39 | #endif // GWP_ASAN_UTILITIES_H_ |
40 |