infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
infix_config.h
Go to the documentation of this file.
1
32
#pragma once
33
// System Feature Test Macros
42
#if !defined(_POSIX_C_SOURCE)
43
#define _POSIX_C_SOURCE 200809L
44
#endif
45
#if (defined(__linux__) || defined(__gnu_linux__)) && !defined(_GNU_SOURCE)
46
#define _GNU_SOURCE
47
#endif
48
// Operating System Detection
54
#if defined(_WIN32)
55
#define INFIX_OS_WINDOWS
56
#include <windows.h>
// Included early for common types like SYSTEM_INFO, HANDLE, etc.
57
// Compatibility shim for POSIX types not present in Clang/MSVC headers.
58
#if !defined(__CYGWIN__)
// Cygwin provides its own full POSIX environment
59
#include <stddef.h>
// For ptrdiff_t
60
#ifndef ssize_t
61
// Define ssize_t as ptrdiff_t, the standard signed counterpart to size_t.
62
typedef
ptrdiff_t ssize_t;
63
#endif
64
#endif
65
#if defined(__MSYS__)
66
#define INFIX_ENV_MSYS 1
67
#elif defined(__CYGWIN__)
68
#define INFIX_ENV_CYGWIN 1
69
#define INFIX_ENV_POSIX 1
70
#elif defined(__MINGW32__) || defined(__MINGW64__)
71
#define INFIX_ENV_MINGW 1
72
#endif
73
#elif defined(__TERMUX__)
74
#define INFIX_OS_TERMUX
75
#define INFIX_OS_ANDROID
76
#define INFIX_OS_LINUX
77
#define INFIX_ENV_POSIX
78
#define INFIX_ENV_TERMUX 1
79
#elif defined(__ANDROID__)
80
#define INFIX_OS_ANDROID
81
#define INFIX_OS_LINUX
82
#define INFIX_ENV_POSIX
83
#elif defined(__APPLE__)
84
#define INFIX_ENV_POSIX
85
#define _DARWIN_C_SOURCE
86
#include <TargetConditionals.h>
87
#include <libkern/OSCacheControl.h>
88
#include <pthread.h>
89
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
90
#define INFIX_OS_IOS
91
#elif TARGET_OS_MAC
92
#define INFIX_OS_MACOS
93
#else
94
#error "Unsupported/unknown Apple platform"
95
#endif
96
#elif defined(__linux__)
97
#define INFIX_OS_LINUX
98
#define INFIX_ENV_POSIX
99
#elif defined(__FreeBSD__)
100
#define INFIX_OS_FREEBSD
101
#define INFIX_ENV_POSIX
102
#elif defined(__OpenBSD__)
103
#define INFIX_OS_OPENBSD
104
#define INFIX_ENV_POSIX
105
#elif defined(__NetBSD__)
106
#define INFIX_OS_NETBSD
107
#define INFIX_ENV_POSIX
108
#elif defined(__DragonFly__)
109
#define INFIX_OS_DRAGONFLY
110
#define INFIX_ENV_POSIX
111
#elif defined(__sun) && defined(__SVR4)
112
#define INFIX_OS_SOLARIS
113
#define INFIX_ENV_POSIX
114
#elif defined(__HAIKU__)
115
#define INFIX_OS_HAIKU
116
#define INFIX_ENV_POSIX
117
#else
118
#warning "Unsupported/unknown operating system"
119
#endif
120
// Compiler Detection
125
#if defined(__clang__)
126
#define INFIX_COMPILER_CLANG
127
#elif defined(_MSC_VER)
128
#define INFIX_COMPILER_MSVC
129
#elif defined(__GNUC__)
130
#define INFIX_COMPILER_GCC
131
#else
132
#warning "Compiler: Unknown compiler detected."
133
#define INFIX_COMPILER_NFI
134
#endif
135
// CPU Architecture Detection
141
#if defined(__aarch64__) || defined(_M_ARM64)
142
#define INFIX_ARCH_AARCH64
143
#elif defined(__riscv)
144
#if __riscv_xlen == 64
145
#define INFIX_ARCH_RISCV
146
#else
147
#error "Unsupported RISC-V variant. Only RV64 is currently supported."
148
#endif
149
#elif defined(__x86_64__) || defined(_M_X64)
150
#define INFIX_ARCH_X64
151
#else
152
#error "Unsupported architecture. Only x86-64, AArch64, and RV64 are currently supported."
153
#endif
154
// Target ABI Logic Selection
168
#if defined(INFIX_FORCE_ABI_WINDOWS_X64)
169
#define INFIX_ABI_WINDOWS_X64 1
170
#define INFIX_ABI_FORCED 1
171
#elif defined(INFIX_FORCE_ABI_SYSV_X64)
172
#define INFIX_ABI_SYSV_X64 1
173
#define INFIX_ABI_FORCED 1
174
#elif defined(INFIX_FORCE_ABI_AAPCS64)
175
#define INFIX_ABI_AAPCS64 1
176
#define INFIX_ABI_FORCED 1
177
#elif defined(INFIX_FORCE_ABI_RISCV64)
178
#define INFIX_ABI_RISCV64 1
179
#define INFIX_ABI_FORCED 1
180
#endif
181
// Automatic ABI detection if not forced by the user.
182
#ifndef INFIX_ABI_FORCED
183
#if defined(INFIX_ARCH_AARCH64)
184
// All AArch64 platforms (Linux, macOS, Windows) use the same base calling
185
// convention (AAPCS64), although with minor differences for variadic arguments
186
// that are handled within the `abi_arm64.c` implementation.
187
#define INFIX_ABI_AAPCS64
188
#elif defined(INFIX_ARCH_RISCV)
189
// RISC-V 64-bit platforms use the RISC-V ELF psABI (lp64d for hard-float Linux).
190
#define INFIX_ABI_RISCV64
191
#elif defined(INFIX_ARCH_X64)
192
#if defined(INFIX_OS_WINDOWS)
193
// Windows on x86-64 uses the Microsoft x64 calling convention.
194
#define INFIX_ABI_WINDOWS_X64
195
#else
196
// All other x86-64 platforms (Linux, macOS, BSDs, etc.) use the System V AMD64 ABI.
197
#define INFIX_ABI_SYSV_X64
198
#endif
199
#endif
200
#endif
// INFIX_ABI_FORCED
201
// Miscellaneous Constants
213
#define INFIX_TRAMPOLINE_HEADROOM 128
214
220
#ifndef INFIX_SANITY_CHECK_ENABLE
221
#define INFIX_SANITY_CHECK_ENABLE 0
222
#endif
223
229
#if (defined(__GNUC__) || defined(__clang__)) && !defined(_WIN32) && !defined(__CYGWIN__)
230
#define INFIX_INTERNAL __attribute__((visibility("hidden")))
231
#else
232
#define INFIX_INTERNAL
233
#endif
234
src
common
infix_config.h
Generated by
1.9.8