infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
infix_config.h
Go to the documentation of this file.
1
34
#pragma once
35
36
// System Feature Test Macros
45
#if !defined(_POSIX_C_SOURCE)
46
#define _POSIX_C_SOURCE 200809L
47
#endif
48
#if (defined(__linux__) || defined(__gnu_linux__)) && !defined(_GNU_SOURCE)
49
#define _GNU_SOURCE
50
#endif
51
52
// Operating System Detection
58
#if defined(_WIN32)
59
#define INFIX_OS_WINDOWS
60
#include <windows.h>
// Included early for common types like SYSTEM_INFO, HANDLE, etc.
61
// Compatibility shim for POSIX types not present in Clang/MSVC headers.
62
#if !defined(__CYGWIN__)
// Cygwin provides its own full POSIX environment
63
#include <stddef.h>
// For ptrdiff_t
64
#ifndef ssize_t
65
// Define ssize_t as ptrdiff_t, the standard signed counterpart to size_t.
66
typedef
ptrdiff_t ssize_t;
67
#endif
68
#endif
69
#if defined(__MSYS__)
70
#define INFIX_ENV_MSYS 1
71
#elif defined(__CYGWIN__)
72
#define INFIX_ENV_CYGWIN 1
73
#define INFIX_ENV_POSIX 1
74
#elif defined(__MINGW32__) || defined(__MINGW64__)
75
#define INFIX_ENV_MINGW 1
76
#endif
77
#elif defined(__TERMUX__)
78
#define INFIX_OS_TERMUX
79
#define INFIX_OS_ANDROID
80
#define INFIX_OS_LINUX
81
#define INFIX_ENV_POSIX
82
#define INFIX_ENV_TERMUX 1
83
#elif defined(__ANDROID__)
84
#define INFIX_OS_ANDROID
85
#define INFIX_OS_LINUX
86
#define INFIX_ENV_POSIX
87
#elif defined(__APPLE__)
88
#define INFIX_ENV_POSIX
89
#define _DARWIN_C_SOURCE
90
#include <TargetConditionals.h>
91
#include <libkern/OSCacheControl.h>
92
#include <pthread.h>
93
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
94
#define INFIX_OS_IOS
95
#elif TARGET_OS_MAC
96
#define INFIX_OS_MACOS
97
#else
98
#error "Unsupported/unknown Apple platform"
99
#endif
100
#elif defined(__linux__)
101
#define INFIX_OS_LINUX
102
#define INFIX_ENV_POSIX
103
#elif defined(__FreeBSD__)
104
#define INFIX_OS_FREEBSD
105
#define INFIX_ENV_POSIX
106
#elif defined(__OpenBSD__)
107
#define INFIX_OS_OPENBSD
108
#define INFIX_ENV_POSIX
109
#elif defined(__NetBSD__)
110
#define INFIX_OS_NETBSD
111
#define INFIX_ENV_POSIX
112
#elif defined(__DragonFly__)
113
#define INFIX_OS_DRAGONFLY
114
#define INFIX_ENV_POSIX
115
#elif defined(__sun) && defined(__SVR4)
116
#define INFIX_OS_SOLARIS
117
#define INFIX_ENV_POSIX
118
#elif defined(__HAIKU__)
119
#define INFIX_OS_HAIKU
120
#define INFIX_ENV_POSIX
121
#else
122
#warning "Unsupported/unknown operating system"
123
#endif
124
125
// Compiler Detection
130
#if defined(__clang__)
131
#define INFIX_COMPILER_CLANG
132
#elif defined(_MSC_VER)
133
#define INFIX_COMPILER_MSVC
134
#elif defined(__GNUC__)
135
#define INFIX_COMPILER_GCC
136
#else
137
#warning "Compiler: Unknown compiler detected."
138
#define INFIX_COMPILER_NFI
139
#endif
140
141
// CPU Architecture Detection
147
#if defined(__aarch64__) || defined(_M_ARM64)
148
#define INFIX_ARCH_AARCH64
149
#elif defined(__x86_64__) || defined(_M_X64)
150
#define INFIX_ARCH_X64
151
#else
152
#error "Unsupported architecture. Only x86-64 and AArch64 are currently supported."
153
#endif
154
155
// Target ABI Logic Selection
170
#if defined(INFIX_FORCE_ABI_WINDOWS_X64)
171
#define INFIX_ABI_WINDOWS_X64 1
172
#define INFIX_ABI_FORCED 1
173
#elif defined(INFIX_FORCE_ABI_SYSV_X64)
174
#define INFIX_ABI_SYSV_X64 1
175
#define INFIX_ABI_FORCED 1
176
#elif defined(INFIX_FORCE_ABI_AAPCS64)
177
#define INFIX_ABI_AAPCS64 1
178
#define INFIX_ABI_FORCED 1
179
#endif
180
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_X64)
189
#if defined(INFIX_OS_WINDOWS)
190
// Windows on x86-64 uses the Microsoft x64 calling convention.
191
#define INFIX_ABI_WINDOWS_X64
192
#else
193
// All other x86-64 platforms (Linux, macOS, BSDs, etc.) use the System V AMD64 ABI.
194
#define INFIX_ABI_SYSV_X64
195
#endif
196
#endif
197
#endif
// INFIX_ABI_FORCED
198
199
// Miscellaneous Constants
211
#define INFIX_TRAMPOLINE_HEADROOM 128
212
src
common
infix_config.h
Generated by
1.9.8