1b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//===----------------------------- config.h -------------------------------===//
2b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//
3b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//                     The LLVM Compiler Infrastructure
4b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//
5b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik// This file is dual licensed under the MIT and the University of Illinois Open
6b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik// Source Licenses. See LICENSE.TXT for details.
7b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//
8b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//
9b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//  Defines macros used within libuwind project.
10b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//
11b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik//===----------------------------------------------------------------------===//
12b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
13b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
14b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#ifndef LIBUNWIND_CONFIG_H
15b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#define LIBUNWIND_CONFIG_H
16b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
17b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#include <assert.h>
18e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert#include <stdio.h>
19b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
20b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik// Define static_assert() unless already defined by compiler.
21b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#ifndef __has_feature
22b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define __has_feature(__x) 0
23b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#endif
248cb8b2086426108c6ea737d83cfd739ae5e5d8d9Nick Kledzik#if !(__has_feature(cxx_static_assert)) && !defined(static_assert)
25b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define static_assert(__b, __m) \
26b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik      extern int compile_time_assert_failed[ ( __b ) ? 1 : -1 ]  \
27b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik                                                  __attribute__( ( unused ) );
28b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#endif
29b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
30b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik// Platform specific configuration defines.
31b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#if __APPLE__
32b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #include <Availability.h>
33b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #ifdef __cplusplus
34b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    extern "C" {
35b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #endif
36b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    void __assert_rtn(const char *, const char *, int, const char *)
37b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik                                                      __attribute__((noreturn));
38b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #ifdef __cplusplus
39b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    }
40b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #endif
41b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
42b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__)
43b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_BUILD_SJLJ_APIS      (__arm__)
44b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
45b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
46b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
47e085735cbedc82b1064f05ff796e32e906a95036Dan Albert  #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libunwind: " msg, __VA_ARGS__)
48b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_ABORT(msg) __assert_rtn(__func__, __FILE__, __LINE__, msg)
49b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
50b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #if FOR_DYLD
51b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
52b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   0
53b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
54b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #else
55b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 1
56b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   1
57b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
58b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #endif
59b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
60b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#else
61e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #include <stdlib.h>
62e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert
63e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  static inline void assert_rtn(const char* func, const char* file, int line, const char* msg)  __attribute__ ((noreturn));
64e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  static inline void assert_rtn(const char* func, const char* file, int line, const char* msg) {
65e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert    fprintf(stderr, "libunwind: %s %s:%d - %s\n",  func, file, line, msg);
66e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert    assert(false);
67e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert    abort();
68e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  }
69e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert
70e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_BUILD_ZERO_COST_APIS (__i386__ || __x86_64__ || __arm64__ || __arm__)
71e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_BUILD_SJLJ_APIS      0
72e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_SUPPORT_FRAME_APIS   (__i386__ || __x86_64__)
73e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_EXPORT               __attribute__((visibility("default")))
74e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_HIDDEN               __attribute__((visibility("hidden")))
75e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_LOG(msg, ...) fprintf(stderr, "libuwind: " msg, __VA_ARGS__)
76e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_ABORT(msg) assert_rtn(__func__, __FILE__, __LINE__, msg)
77e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert
78e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_SUPPORT_COMPACT_UNWIND 0
79e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_SUPPORT_DWARF_UNWIND   0
80e45805f0d3f8dafef1297cc7dc49e610713f023bDan Albert  #define _LIBUNWIND_SUPPORT_DWARF_INDEX    0
81b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#endif
82b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
83b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
84b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik// Macros that define away in non-Debug builds
85b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#ifdef NDEBUG
86b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_DEBUG_LOG(msg, ...)
87b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACE_API(msg, ...)
88b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACING_UNWINDING 0
89b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACE_UNWINDING(msg, ...)
90b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_LOG_NON_ZERO(x) x
91b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#else
92b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #ifdef __cplusplus
93b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    extern "C" {
94b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #endif
95b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    extern  bool logAPIs();
96b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    extern  bool logUnwinding();
97b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #ifdef __cplusplus
98b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik    }
99b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #endif
100b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_DEBUG_LOG(msg, ...)  _LIBUNWIND_LOG(msg, __VA_ARGS__)
101b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_LOG_NON_ZERO(x) \
102b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik            do { \
103b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik              int _err = x; \
104b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik              if ( _err != 0 ) \
105b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik                _LIBUNWIND_LOG("" #x "=%d in %s", _err, __FUNCTION__); \
106b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik             } while (0)
107b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACE_API(msg, ...) \
108b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik            do { \
109b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik              if ( logAPIs() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
110b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik            } while(0)
111b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACE_UNWINDING(msg, ...) \
112b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik            do { \
113b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik              if ( logUnwinding() ) _LIBUNWIND_LOG(msg, __VA_ARGS__); \
114b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik            } while(0)
115b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik  #define _LIBUNWIND_TRACING_UNWINDING logUnwinding()
116b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#endif
117b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
118b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik
119b78da9875b6e35187b5d584746c78faaf3230a3dNick Kledzik#endif // LIBUNWIND_CONFIG_H
120