1 | //===-- utilities_fuchsia.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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "gwp_asan/utilities.h" |
10 | |
11 | #include <alloca.h> |
12 | #include <stdio.h> |
13 | #include <string.h> |
14 | #include <zircon/sanitizer.h> |
15 | #include <zircon/status.h> |
16 | |
17 | namespace gwp_asan { |
18 | void die(const char *Message) { |
19 | __sanitizer_log_write(Message, strlen(s: Message)); |
20 | __builtin_trap(); |
21 | } |
22 | |
23 | void dieWithErrorCode(const char *Message, int64_t ErrorCode) { |
24 | const char *error_str = |
25 | _zx_status_get_string(static_cast<zx_status_t>(ErrorCode)); |
26 | size_t buffer_size = strlen(s: Message) + 32 + strlen(s: error_str); |
27 | char *buffer = static_cast<char *>(alloca(buffer_size)); |
28 | snprintf(s: buffer, maxlen: buffer_size, format: "%s (Error Code: %s)", Message, error_str); |
29 | __sanitizer_log_write(buffer, strlen(s: buffer)); |
30 | __builtin_trap(); |
31 | } |
32 | } // namespace gwp_asan |
33 |