| 1 | /* Copyright (C) 2012-2024 Free Software Foundation, Inc. |
| 2 | Written by Ian Lance Taylor, Google. |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, are permitted provided that the following conditions are |
| 6 | met: |
| 7 | |
| 8 | (1) Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | |
| 11 | (2) Redistributions in binary form must reproduce the above copyright |
| 12 | notice, this list of conditions and the following disclaimer in |
| 13 | the documentation and/or other materials provided with the |
| 14 | distribution. |
| 15 | |
| 16 | (3) The name of the author may not be used to |
| 17 | endorse or promote products derived from this software without |
| 18 | specific prior written permission. |
| 19 | |
| 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 24 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 29 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | POSSIBILITY OF SUCH DAMAGE. */ |
| 31 | |
| 32 | #ifndef _ALL_SOURCE |
| 33 | #define _ALL_SOURCE 1 |
| 34 | #endif |
| 35 | #ifndef _GNU_SOURCE |
| 36 | #define _GNU_SOURCE 1 |
| 37 | #endif |
| 38 | #ifndef _POSIX_PTHREAD_SEMANTICS |
| 39 | #define _POSIX_PTHREAD_SEMANTICS 1 |
| 40 | #endif |
| 41 | #ifndef _TANDEM_SOURCE |
| 42 | #define _TANDEM_SOURCE 1 |
| 43 | #endif |
| 44 | #ifndef __EXTENSIONS__ |
| 45 | #define __EXTENSIONS__ 1 |
| 46 | #endif |
| 47 | #ifndef _DARWIN_USE_64_BIT_INODE |
| 48 | #define _DARWIN_USE_64_BIT_INODE 1 |
| 49 | #endif |
| 50 | |
| 51 | #define HAVE_ATOMIC_FUNCTIONS 1 |
| 52 | #define HAVE_CLOCK_GETTIME 1 |
| 53 | #define HAVE_DECL_GETPAGESIZE 0 |
| 54 | #define HAVE_DECL_STRNLEN 1 |
| 55 | #define HAVE_GETIPINFO 1 |
| 56 | #define HAVE_LSTAT 1 |
| 57 | #define HAVE_READLINK 1 |
| 58 | #define HAVE_SYNC_FUNCTIONS 1 |
| 59 | |
| 60 | #define HAVE_DLFCN_H 1 |
| 61 | #define HAVE_INTTYPES_H 1 |
| 62 | #define HAVE_MEMORY_H 1 |
| 63 | #define HAVE_STDINT_H 1 |
| 64 | #define HAVE_STDLIB_H 1 |
| 65 | #define HAVE_STRINGS_H 1 |
| 66 | #define HAVE_STRING_H 1 |
| 67 | #define HAVE_UNISTD_H 1 |
| 68 | #define STDC_HEADERS 1 |
| 69 | |
| 70 | #include <stdint.h> |
| 71 | |
| 72 | #if UINTPTR_MAX == 0xFFFFFFFF |
| 73 | #define BACKTRACE_ELF_SIZE 32 |
| 74 | #define BACKTRACE_XCOFF_SIZE 32 |
| 75 | #elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu |
| 76 | #define BACKTRACE_ELF_SIZE 64 |
| 77 | #define BACKTRACE_XCOFF_SIZE 64 |
| 78 | #endif |
| 79 | |
| 80 | #ifndef _WIN32 |
| 81 | #define HAVE_FCNTL 1 |
| 82 | #endif |
| 83 | |
| 84 | #if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) |
| 85 | #define HAVE_DL_ITERATE_PHDR 1 |
| 86 | #endif |
| 87 | |
| 88 | #ifdef HAVE_DL_ITERATE_PHDR |
| 89 | #if defined(__has_include) |
| 90 | #if __has_include(<link.h>) |
| 91 | #define HAVE_LINK_H 1 |
| 92 | #elif __has_include(<sys/link.h>) |
| 93 | #define HAVE_SYS_LINK_H 1 |
| 94 | #else |
| 95 | #undef HAVE_DL_ITERATE_PHDR |
| 96 | #endif |
| 97 | #else |
| 98 | #define HAVE_LINK_H 1 |
| 99 | #endif |
| 100 | #endif |
| 101 | |
| 102 | #if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) |
| 103 | #define HAVE_KERN_PROC 1 |
| 104 | #define HAVE_KERN_PROC_ARGS 1 |
| 105 | #endif |
| 106 | |
| 107 | #ifdef __APPLE__ |
| 108 | #define HAVE_MACH_O_DYLD_H 1 |
| 109 | #endif |
| 110 | |
| 111 | #ifdef _WIN32 |
| 112 | #define HAVE_WINDOWS_H 1 |
| 113 | #define HAVE_TLHELP32_H 1 |
| 114 | #define HAVE_DECL__PGMPTR 0 |
| 115 | #endif |
| 116 | |
| 117 | #if defined(_WIN32) |
| 118 | #define BACKTRACE_SUPPORTED 1 |
| 119 | #define BACKTRACE_USES_MALLOC 1 |
| 120 | #define BACKTRACE_SUPPORTS_DATA 0 |
| 121 | #elif defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) |
| 122 | #define BACKTRACE_SUPPORTED 1 |
| 123 | #define BACKTRACE_USES_MALLOC 0 |
| 124 | #define BACKTRACE_SUPPORTS_DATA 1 |
| 125 | #else |
| 126 | #define BACKTRACE_SUPPORTED 0 |
| 127 | #define BACKTRACE_USES_MALLOC 0 |
| 128 | #define BACKTRACE_SUPPORTS_DATA 0 |
| 129 | #endif |
| 130 | |
| 131 | #define BACKTRACE_SUPPORTS_THREADS 1 |
| 132 | |
| 133 | #if __TINYC__ |
| 134 | #undef HAVE_ATOMIC_FUNCTIONS |
| 135 | #undef HAVE_SYNC_FUNCTIONS |
| 136 | #undef BACKTRACE_SUPPORTED |
| 137 | #define BACKTRACE_SUPPORTED 0 |
| 138 | #undef BACKTRACE_SUPPORTS_THREADS |
| 139 | #define BACKTRACE_SUPPORTS_THREADS 0 |
| 140 | #endif |
| 141 | |
| 142 | #include "base.c" |
| 143 | |
| 144 | #if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) |
| 145 | #include "linux.c" |
| 146 | #elif defined(__APPLE__) |
| 147 | #include "darwin.c" |
| 148 | #elif defined(_WIN32) |
| 149 | #include "windows.c" |
| 150 | #endif |
| 151 | |