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#if !defined(_CRT_SECURE_NO_WARNINGS)
49#define _CRT_SECURE_NO_WARNINGS 1
50#endif
51
58#if (defined(__sun) || defined(__sun__)) && !defined(__EXTENSIONS__)
59#define __EXTENSIONS__ 1
60#endif
61
62// Operating System Detection
68#if defined(_WIN32) || defined(__CYGWIN__)
69#define INFIX_OS_WINDOWS
70#include <windows.h> // Included early for common types like SYSTEM_INFO, HANDLE, etc.
71// Compatibility shim for POSIX types not present in Clang/MSVC headers.
72#if !defined(__CYGWIN__) // Cygwin provides its own full POSIX environment
73#include <stddef.h> // For ptrdiff_t
74#ifndef ssize_t
75// Define ssize_t as ptrdiff_t, the standard signed counterpart to size_t.
76typedef ptrdiff_t ssize_t;
77#endif
78#endif
79#if defined(__MSYS__)
80#define INFIX_ENV_MSYS 1
81#elif defined(__CYGWIN__)
82#define INFIX_ENV_CYGWIN 1
83#define INFIX_ENV_POSIX 1
84#elif defined(__MINGW32__) || defined(__MINGW64__)
85#define INFIX_ENV_MINGW 1
86#endif
87#elif defined(__TERMUX__)
88#define INFIX_OS_TERMUX
89#define INFIX_OS_ANDROID
90#define INFIX_OS_LINUX
91#define INFIX_ENV_POSIX
92#define INFIX_ENV_TERMUX 1
93#elif defined(__ANDROID__)
94#define INFIX_OS_ANDROID
95#define INFIX_OS_LINUX
96#define INFIX_ENV_POSIX
97#elif defined(__APPLE__)
98#define INFIX_ENV_POSIX
99#define _DARWIN_C_SOURCE
100#include <TargetConditionals.h>
101#include <libkern/OSCacheControl.h>
102#include <pthread.h>
103#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
104#define INFIX_OS_IOS
105#elif TARGET_OS_MAC
106#define INFIX_OS_MACOS
107#else
108#error "Unsupported/unknown Apple platform"
109#endif
110#elif defined(__linux__)
111#define INFIX_OS_LINUX
112#define INFIX_ENV_POSIX
113#elif defined(__FreeBSD__)
114#define INFIX_OS_FREEBSD
115#define INFIX_ENV_POSIX
116#elif defined(__OpenBSD__)
117#define INFIX_OS_OPENBSD
118#define INFIX_ENV_POSIX
119#elif defined(__NetBSD__)
120#define INFIX_OS_NETBSD
121#define INFIX_ENV_POSIX
122#elif defined(__DragonFly__)
123#define INFIX_OS_DRAGONFLY
124#define INFIX_ENV_POSIX
125#elif defined(__sun) && defined(__SVR4)
126#define INFIX_OS_SOLARIS
127#define INFIX_ENV_POSIX
128#elif defined(__HAIKU__)
129#define INFIX_OS_HAIKU
130#define INFIX_ENV_POSIX
131#else
132#warning "Unsupported/unknown operating system"
133#endif
134// Compiler Detection
139#if defined(__clang__)
140#define INFIX_COMPILER_CLANG
141#elif defined(_MSC_VER)
142#define INFIX_COMPILER_MSVC
143#elif defined(__GNUC__)
144#define INFIX_COMPILER_GCC
145#else
146#warning "Compiler: Unknown compiler detected."
147#define INFIX_COMPILER_NFI
148#endif
149// CPU Architecture Detection
155#if defined(__aarch64__) || defined(_M_ARM64)
156#define INFIX_ARCH_AARCH64
157#elif defined(__riscv)
158#if __riscv_xlen == 64
159#define INFIX_ARCH_RISCV
160#else
161#error "Unsupported RISC-V variant. Only RV64 is currently supported."
162#endif
163#elif defined(__x86_64__) || defined(_M_X64)
164#define INFIX_ARCH_X64
165#else
166#error "Unsupported architecture. Only x86-64, AArch64, and RV64 are currently supported."
167#endif
168// Target ABI Logic Selection
182#if defined(INFIX_FORCE_ABI_WINDOWS_X64)
183#define INFIX_ABI_WINDOWS_X64 1
184#define INFIX_ABI_FORCED 1
185#elif defined(INFIX_FORCE_ABI_SYSV_X64)
186#define INFIX_ABI_SYSV_X64 1
187#define INFIX_ABI_FORCED 1
188#elif defined(INFIX_FORCE_ABI_AAPCS64)
189#define INFIX_ABI_AAPCS64 1
190#define INFIX_ABI_FORCED 1
191#elif defined(INFIX_FORCE_ABI_RISCV64)
192#define INFIX_ABI_RISCV64 1
193#define INFIX_ABI_FORCED 1
194#endif
195// Automatic ABI detection if not forced by the user.
196#ifndef INFIX_ABI_FORCED
197#if defined(INFIX_ARCH_AARCH64)
198// All AArch64 platforms (Linux, macOS, Windows) use the same base calling
199// convention (AAPCS64), although with minor differences for variadic arguments
200// that are handled within the `abi_arm64.c` implementation.
201#define INFIX_ABI_AAPCS64
202#elif defined(INFIX_ARCH_RISCV)
203// RISC-V 64-bit platforms use the RISC-V ELF psABI (lp64d for hard-float Linux).
204#define INFIX_ABI_RISCV64
205#elif defined(INFIX_ARCH_X64)
206#if defined(INFIX_OS_WINDOWS)
207// Windows on x86-64 uses the Microsoft x64 calling convention.
208#define INFIX_ABI_WINDOWS_X64
209#else
210// All other x86-64 platforms (Linux, macOS, BSDs, etc.) use the System V AMD64 ABI.
211#define INFIX_ABI_SYSV_X64
212#endif
213#endif
214#endif // INFIX_ABI_FORCED
215// Miscellaneous Constants
227#define INFIX_TRAMPOLINE_HEADROOM 128
228
234#ifndef INFIX_SANITY_CHECK_ENABLE
235#define INFIX_SANITY_CHECK_ENABLE 0
236#endif
237
243#if (defined(__GNUC__) || defined(__clang__)) && !defined(_WIN32) && !defined(__CYGWIN__)
244#define INFIX_INTERNAL __attribute__((visibility("hidden")))
245#else
246#define INFIX_INTERNAL
247#endif
248