[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / lib / gwp_asan / platform_specific / utilities_posix.cpp
blob750198062ce4f54f29a7e08fec11c8110354c7b8
1 //===-- utilities_posix.cpp -------------------------------------*- 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 //===----------------------------------------------------------------------===//
9 #include <alloca.h>
10 #include <features.h> // IWYU pragma: keep (for __BIONIC__ macro)
11 #include <inttypes.h>
12 #include <stdint.h>
13 #include <string.h>
15 #ifdef __BIONIC__
16 #include "gwp_asan/definitions.h"
17 #include <stdlib.h>
18 extern "C" GWP_ASAN_WEAK void android_set_abort_message(const char *);
19 #else // __BIONIC__
20 #include <stdio.h>
21 #endif
23 namespace gwp_asan {
24 void die(const char *Message) {
25 #ifdef __BIONIC__
26 if (&android_set_abort_message != nullptr)
27 android_set_abort_message(Message);
28 abort();
29 #else // __BIONIC__
30 fprintf(stderr, "%s", Message);
31 __builtin_trap();
32 #endif // __BIONIC__
35 void dieWithErrorCode(const char *Message, int64_t ErrorCode) {
36 #ifdef __BIONIC__
37 if (&android_set_abort_message == nullptr)
38 abort();
40 size_t buffer_size = strlen(Message) + 48;
41 char *buffer = static_cast<char *>(alloca(buffer_size));
42 snprintf(buffer, buffer_size, "%s (Error Code: %" PRId64 ")", Message,
43 ErrorCode);
44 android_set_abort_message(buffer);
45 abort();
46 #else // __BIONIC__
47 fprintf(stderr, "%s (Error Code: %" PRId64 ")", Message, ErrorCode);
48 __builtin_trap();
49 #endif // __BIONIC__
51 } // namespace gwp_asan