abort.h
Go to the documentation of this file.
1 //
2 // Bareflank Unwind Library
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef ABORT_H
23 #define ABORT_H
24 
25 #ifdef CROSS_COMPILED
26 extern "C" void abort(void);
27 extern "C" int printf(const char *format, ...);
28 extern "C" unsigned int write(int fd, const void *buf, unsigned int count);
29 #else
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #endif
34 
35 inline void
36 private_abort(const char *msg, const char *func, int line)
37 {
38  (void) msg;
39  (void) func;
40  (void) line;
41 
42 #ifdef DISABLE_LOGGING
43  auto ignored = write(1, "abort called in the unwinder", 28);
44  (void) ignored;
45 #else
46  printf("%s FATAL ERROR [%d]: %s\n", func, line, msg);
47 #endif
48 
49  abort();
50 }
51 #define ABORT(a) { private_abort(a,__func__,__LINE__); __builtin_unreachable(); }
52 
53 #endif
void write(field_type field, value_type value, name_type name="")
void private_abort(const char *msg, const char *func, int line)
Definition: abort.h:36