33 lines · cpp
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-exception6//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 17namespace gwp_asan {18void die(const char *Message) {19 __sanitizer_log_write(Message, strlen(Message));20 __builtin_trap();21}22 23void 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(Message) + 32 + strlen(error_str);27 char *buffer = static_cast<char *>(alloca(buffer_size));28 snprintf(buffer, buffer_size, "%s (Error Code: %s)", Message, error_str);29 __sanitizer_log_write(buffer, strlen(buffer));30 __builtin_trap();31}32} // namespace gwp_asan33