brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 7501980 Raw
52 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 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>14 15#ifdef __BIONIC__16#include "gwp_asan/definitions.h"17#include <stdlib.h>18extern "C" GWP_ASAN_WEAK void android_set_abort_message(const char *);19#else // __BIONIC__20#include <stdio.h>21#endif22 23namespace gwp_asan {24void 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__33}34 35void dieWithErrorCode(const char *Message, int64_t ErrorCode) {36#ifdef __BIONIC__37  if (&android_set_abort_message == nullptr)38    abort();39 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__50}51} // namespace gwp_asan52