xref: /llvm-project/compiler-rt/lib/gwp_asan/platform_specific/utilities_fuchsia.cpp (revision 0a94511aec7a41194c0e61d88801312542ff70ce)
163ad0876SKostya Kortchinsky //===-- utilities_fuchsia.cpp -----------------------------------*- C++ -*-===//
263ad0876SKostya Kortchinsky //
363ad0876SKostya Kortchinsky // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
463ad0876SKostya Kortchinsky // See https://llvm.org/LICENSE.txt for license information.
563ad0876SKostya Kortchinsky // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
663ad0876SKostya Kortchinsky //
763ad0876SKostya Kortchinsky //===----------------------------------------------------------------------===//
863ad0876SKostya Kortchinsky 
963ad0876SKostya Kortchinsky #include "gwp_asan/utilities.h"
1063ad0876SKostya Kortchinsky 
11*0a94511aSMitch Phillips #include <alloca.h>
12*0a94511aSMitch Phillips #include <stdio.h>
1363ad0876SKostya Kortchinsky #include <string.h>
1463ad0876SKostya Kortchinsky #include <zircon/sanitizer.h>
15*0a94511aSMitch Phillips #include <zircon/status.h>
1663ad0876SKostya Kortchinsky 
1763ad0876SKostya Kortchinsky namespace gwp_asan {
1863ad0876SKostya Kortchinsky void die(const char *Message) {
1963ad0876SKostya Kortchinsky   __sanitizer_log_write(Message, strlen(Message));
2063ad0876SKostya Kortchinsky   __builtin_trap();
2163ad0876SKostya Kortchinsky }
22*0a94511aSMitch Phillips 
23*0a94511aSMitch Phillips void dieWithErrorCode(const char *Message, int64_t ErrorCode) {
24*0a94511aSMitch Phillips   const char *error_str =
25*0a94511aSMitch Phillips       _zx_status_get_string(static_cast<zx_status_t>(ErrorCode));
26*0a94511aSMitch Phillips   size_t buffer_size = strlen(Message) + 32 + strlen(error_str);
27*0a94511aSMitch Phillips   char *buffer = static_cast<char *>(alloca(buffer_size));
28*0a94511aSMitch Phillips   snprintf(buffer, buffer_size, "%s (Error Code: %s)", Message, error_str);
29*0a94511aSMitch Phillips   __sanitizer_log_write(buffer, strlen(buffer));
30*0a94511aSMitch Phillips   __builtin_trap();
31*0a94511aSMitch Phillips }
3263ad0876SKostya Kortchinsky } // namespace gwp_asan
33