OSX/iOS: Fix SDK incompatibility.
[luajit-2.0.git] / src / lj_arch.h
blobe6264398162cbf8bf09912ab3be14a393bd19a7c
1 /*
2 ** Target architecture selection.
3 ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #ifndef _LJ_ARCH_H
7 #define _LJ_ARCH_H
9 #include "lua.h"
11 /* -- Target definitions -------------------------------------------------- */
13 /* Target endianess. */
14 #define LUAJIT_LE 0
15 #define LUAJIT_BE 1
17 /* Target architectures. */
18 #define LUAJIT_ARCH_X86 1
19 #define LUAJIT_ARCH_x86 1
20 #define LUAJIT_ARCH_X64 2
21 #define LUAJIT_ARCH_x64 2
22 #define LUAJIT_ARCH_ARM 3
23 #define LUAJIT_ARCH_arm 3
24 #define LUAJIT_ARCH_ARM64 4
25 #define LUAJIT_ARCH_arm64 4
26 #define LUAJIT_ARCH_PPC 5
27 #define LUAJIT_ARCH_ppc 5
28 #define LUAJIT_ARCH_MIPS 6
29 #define LUAJIT_ARCH_mips 6
30 #define LUAJIT_ARCH_MIPS32 6
31 #define LUAJIT_ARCH_mips32 6
32 #define LUAJIT_ARCH_MIPS64 7
33 #define LUAJIT_ARCH_mips64 7
35 /* Target OS. */
36 #define LUAJIT_OS_OTHER 0
37 #define LUAJIT_OS_WINDOWS 1
38 #define LUAJIT_OS_LINUX 2
39 #define LUAJIT_OS_OSX 3
40 #define LUAJIT_OS_BSD 4
41 #define LUAJIT_OS_POSIX 5
43 /* Number mode. */
44 #define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
45 #define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
46 #define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
47 #define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
49 /* -- Target detection ---------------------------------------------------- */
51 /* Select native target if no target defined. */
52 #ifndef LUAJIT_TARGET
54 #if defined(__i386) || defined(__i386__) || defined(_M_IX86)
55 #define LUAJIT_TARGET LUAJIT_ARCH_X86
56 #elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
57 #define LUAJIT_TARGET LUAJIT_ARCH_X64
58 #elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
59 #define LUAJIT_TARGET LUAJIT_ARCH_ARM
60 #elif defined(__aarch64__) || defined(_M_ARM64)
61 #define LUAJIT_TARGET LUAJIT_ARCH_ARM64
62 #elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
63 #define LUAJIT_TARGET LUAJIT_ARCH_PPC
64 #elif defined(__mips64__) || defined(__mips64) || defined(__MIPS64__) || defined(__MIPS64)
65 #define LUAJIT_TARGET LUAJIT_ARCH_MIPS64
66 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
67 #define LUAJIT_TARGET LUAJIT_ARCH_MIPS32
68 #else
69 #error "Architecture not supported (in this version), see: https://luajit.org/status.html#architectures"
70 #endif
72 #endif
74 /* Select native OS if no target OS defined. */
75 #ifndef LUAJIT_OS
77 #if defined(_WIN32) && !defined(_XBOX_VER)
78 #define LUAJIT_OS LUAJIT_OS_WINDOWS
79 #elif defined(__linux__)
80 #define LUAJIT_OS LUAJIT_OS_LINUX
81 #elif defined(__MACH__) && defined(__APPLE__)
82 #include "TargetConditionals.h"
83 #define LUAJIT_OS LUAJIT_OS_OSX
84 #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
85 defined(__NetBSD__) || defined(__OpenBSD__) || \
86 defined(__DragonFly__)) && !defined(__ORBIS__) && !defined(__PROSPERO__)
87 #define LUAJIT_OS LUAJIT_OS_BSD
88 #elif (defined(__sun__) && defined(__svr4__))
89 #define LJ_TARGET_SOLARIS 1
90 #define LUAJIT_OS LUAJIT_OS_POSIX
91 #elif defined(__HAIKU__)
92 #define LUAJIT_OS LUAJIT_OS_POSIX
93 #elif defined(__CYGWIN__)
94 #define LJ_TARGET_CYGWIN 1
95 #define LUAJIT_OS LUAJIT_OS_POSIX
96 #elif defined(__QNX__)
97 #define LJ_TARGET_QNX 1
98 #define LUAJIT_OS LUAJIT_OS_POSIX
99 #else
100 #define LUAJIT_OS LUAJIT_OS_OTHER
101 #endif
103 #endif
105 /* Set target OS properties. */
106 #if LUAJIT_OS == LUAJIT_OS_WINDOWS
107 #define LJ_OS_NAME "Windows"
108 #elif LUAJIT_OS == LUAJIT_OS_LINUX
109 #define LJ_OS_NAME "Linux"
110 #elif LUAJIT_OS == LUAJIT_OS_OSX
111 #define LJ_OS_NAME "OSX"
112 #elif LUAJIT_OS == LUAJIT_OS_BSD
113 #define LJ_OS_NAME "BSD"
114 #elif LUAJIT_OS == LUAJIT_OS_POSIX
115 #define LJ_OS_NAME "POSIX"
116 #else
117 #define LJ_OS_NAME "Other"
118 #endif
120 #define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
121 #define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
122 #define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
123 #define LJ_TARGET_BSD (LUAJIT_OS == LUAJIT_OS_BSD)
124 #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
125 #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
127 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
128 #define LJ_TARGET_IOS 1
129 #else
130 #define LJ_TARGET_IOS 0
131 #endif
133 #ifdef __CELLOS_LV2__
134 #define LJ_TARGET_PS3 1
135 #define LJ_TARGET_CONSOLE 1
136 #endif
138 #ifdef __ORBIS__
139 #define LJ_TARGET_PS4 1
140 #define LJ_TARGET_CONSOLE 1
141 #undef NULL
142 #define NULL ((void*)0)
143 #endif
145 #ifdef __PROSPERO__
146 #define LJ_TARGET_PS5 1
147 #define LJ_TARGET_CONSOLE 1
148 #undef NULL
149 #define NULL ((void*)0)
150 #endif
152 #ifdef __psp2__
153 #define LJ_TARGET_PSVITA 1
154 #define LJ_TARGET_CONSOLE 1
155 #endif
157 #if _XBOX_VER >= 200
158 #define LJ_TARGET_XBOX360 1
159 #define LJ_TARGET_CONSOLE 1
160 #endif
162 #ifdef _DURANGO
163 #define LJ_TARGET_XBOXONE 1
164 #define LJ_TARGET_CONSOLE 1
165 #define LJ_TARGET_GC64 1
166 #endif
168 #ifdef __NX__
169 #define LJ_TARGET_NX 1
170 #define LJ_TARGET_CONSOLE 1
171 #undef NULL
172 #define NULL ((void*)0)
173 #endif
175 #ifdef _UWP
176 #define LJ_TARGET_UWP 1
177 #if LUAJIT_TARGET == LUAJIT_ARCH_X64
178 #define LJ_TARGET_GC64 1
179 #endif
180 #endif
182 /* -- Arch-specific settings ---------------------------------------------- */
184 /* Set target architecture properties. */
185 #if LUAJIT_TARGET == LUAJIT_ARCH_X86
187 #define LJ_ARCH_NAME "x86"
188 #define LJ_ARCH_BITS 32
189 #define LJ_ARCH_ENDIAN LUAJIT_LE
190 #define LJ_TARGET_X86 1
191 #define LJ_TARGET_X86ORX64 1
192 #define LJ_TARGET_EHRETREG 0
193 #define LJ_TARGET_EHRAREG 8
194 #define LJ_TARGET_MASKSHIFT 1
195 #define LJ_TARGET_MASKROT 1
196 #define LJ_TARGET_UNALIGNED 1
197 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
199 #elif LUAJIT_TARGET == LUAJIT_ARCH_X64
201 #define LJ_ARCH_NAME "x64"
202 #define LJ_ARCH_BITS 64
203 #define LJ_ARCH_ENDIAN LUAJIT_LE
204 #define LJ_TARGET_X64 1
205 #define LJ_TARGET_X86ORX64 1
206 #define LJ_TARGET_EHRETREG 0
207 #define LJ_TARGET_EHRAREG 16
208 #define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
209 #define LJ_TARGET_MASKSHIFT 1
210 #define LJ_TARGET_MASKROT 1
211 #define LJ_TARGET_UNALIGNED 1
212 #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
213 #ifndef LUAJIT_DISABLE_GC64
214 #define LJ_TARGET_GC64 1
215 #elif LJ_TARGET_OSX
216 #error "macOS requires GC64 -- don't disable it"
217 #endif
219 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
221 #define LJ_ARCH_NAME "arm"
222 #define LJ_ARCH_BITS 32
223 #define LJ_ARCH_ENDIAN LUAJIT_LE
224 #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
225 #define LJ_ARCH_HASFPU 0
226 #endif
227 #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
228 #define LJ_ABI_SOFTFP 1
229 #endif
230 #define LJ_ABI_EABI 1
231 #define LJ_TARGET_ARM 1
232 #define LJ_TARGET_EHRETREG 0
233 #define LJ_TARGET_EHRAREG 14
234 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
235 #define LJ_TARGET_MASKSHIFT 0
236 #define LJ_TARGET_MASKROT 1
237 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
238 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
240 #if __ARM_ARCH >= 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__
241 #define LJ_ARCH_VERSION 80
242 #elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
243 #define LJ_ARCH_VERSION 70
244 #elif __ARM_ARCH_6T2__
245 #define LJ_ARCH_VERSION 61
246 #elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
247 #define LJ_ARCH_VERSION 60
248 #else
249 #define LJ_ARCH_VERSION 50
250 #endif
252 #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
254 #define LJ_ARCH_BITS 64
255 #if defined(__AARCH64EB__)
256 #define LJ_ARCH_NAME "arm64be"
257 #define LJ_ARCH_ENDIAN LUAJIT_BE
258 #else
259 #define LJ_ARCH_NAME "arm64"
260 #define LJ_ARCH_ENDIAN LUAJIT_LE
261 #endif
262 #if !defined(LJ_ABI_PAUTH) && defined(__arm64e__)
263 #define LJ_ABI_PAUTH 1
264 #endif
265 #define LJ_TARGET_ARM64 1
266 #define LJ_TARGET_EHRETREG 0
267 #define LJ_TARGET_EHRAREG 30
268 #define LJ_TARGET_JUMPRANGE 27 /* +-2^27 = +-128MB */
269 #define LJ_TARGET_MASKSHIFT 1
270 #define LJ_TARGET_MASKROT 1
271 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
272 #define LJ_TARGET_GC64 1
273 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
275 #define LJ_ARCH_VERSION 80
277 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
279 #ifndef LJ_ARCH_ENDIAN
280 #if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
281 #define LJ_ARCH_ENDIAN LUAJIT_LE
282 #else
283 #define LJ_ARCH_ENDIAN LUAJIT_BE
284 #endif
285 #endif
287 #if _LP64
288 #define LJ_ARCH_BITS 64
289 #if LJ_ARCH_ENDIAN == LUAJIT_LE
290 #define LJ_ARCH_NAME "ppc64le"
291 #else
292 #define LJ_ARCH_NAME "ppc64"
293 #endif
294 #else
295 #define LJ_ARCH_BITS 32
296 #define LJ_ARCH_NAME "ppc"
298 #if !defined(LJ_ARCH_HASFPU)
299 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
300 #define LJ_ARCH_HASFPU 0
301 #else
302 #define LJ_ARCH_HASFPU 1
303 #endif
304 #endif
306 #if !defined(LJ_ABI_SOFTFP)
307 #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
308 #define LJ_ABI_SOFTFP 1
309 #else
310 #define LJ_ABI_SOFTFP 0
311 #endif
312 #endif
313 #endif
315 #if LJ_ABI_SOFTFP
316 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
317 #else
318 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
319 #endif
321 #define LJ_TARGET_PPC 1
322 #define LJ_TARGET_EHRETREG 3
323 #define LJ_TARGET_EHRAREG 65
324 #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
325 #define LJ_TARGET_MASKSHIFT 0
326 #define LJ_TARGET_MASKROT 1
327 #define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
329 #if LJ_TARGET_CONSOLE
330 #define LJ_ARCH_PPC32ON64 1
331 #define LJ_ARCH_NOFFI 1
332 #elif LJ_ARCH_BITS == 64
333 #error "No support for PPC64"
334 #undef LJ_TARGET_PPC
335 #endif
337 #if _ARCH_PWR7
338 #define LJ_ARCH_VERSION 70
339 #elif _ARCH_PWR6
340 #define LJ_ARCH_VERSION 60
341 #elif _ARCH_PWR5X
342 #define LJ_ARCH_VERSION 51
343 #elif _ARCH_PWR5
344 #define LJ_ARCH_VERSION 50
345 #elif _ARCH_PWR4
346 #define LJ_ARCH_VERSION 40
347 #else
348 #define LJ_ARCH_VERSION 0
349 #endif
350 #if _ARCH_PPCSQ
351 #define LJ_ARCH_SQRT 1
352 #endif
353 #if _ARCH_PWR5X
354 #define LJ_ARCH_ROUND 1
355 #endif
356 #if __PPU__
357 #define LJ_ARCH_CELL 1
358 #endif
359 #if LJ_TARGET_XBOX360
360 #define LJ_ARCH_XENON 1
361 #endif
363 #elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS32 || LUAJIT_TARGET == LUAJIT_ARCH_MIPS64
365 #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
366 #if __mips_isa_rev >= 6
367 #define LJ_TARGET_MIPSR6 1
368 #define LJ_TARGET_UNALIGNED 1
369 #endif
370 #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
371 #if LJ_TARGET_MIPSR6
372 #define LJ_ARCH_NAME "mips32r6el"
373 #else
374 #define LJ_ARCH_NAME "mipsel"
375 #endif
376 #else
377 #if LJ_TARGET_MIPSR6
378 #define LJ_ARCH_NAME "mips64r6el"
379 #else
380 #define LJ_ARCH_NAME "mips64el"
381 #endif
382 #endif
383 #define LJ_ARCH_ENDIAN LUAJIT_LE
384 #else
385 #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
386 #if LJ_TARGET_MIPSR6
387 #define LJ_ARCH_NAME "mips32r6"
388 #else
389 #define LJ_ARCH_NAME "mips"
390 #endif
391 #else
392 #if LJ_TARGET_MIPSR6
393 #define LJ_ARCH_NAME "mips64r6"
394 #else
395 #define LJ_ARCH_NAME "mips64"
396 #endif
397 #endif
398 #define LJ_ARCH_ENDIAN LUAJIT_BE
399 #endif
401 #if !defined(LJ_ARCH_HASFPU)
402 #ifdef __mips_soft_float
403 #define LJ_ARCH_HASFPU 0
404 #else
405 #define LJ_ARCH_HASFPU 1
406 #endif
407 #endif
409 #if !defined(LJ_ABI_SOFTFP)
410 #ifdef __mips_soft_float
411 #define LJ_ABI_SOFTFP 1
412 #else
413 #define LJ_ABI_SOFTFP 0
414 #endif
415 #endif
417 #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
418 #define LJ_ARCH_BITS 32
419 #define LJ_TARGET_MIPS32 1
420 #else
421 #define LJ_ARCH_BITS 64
422 #define LJ_TARGET_MIPS64 1
423 #define LJ_TARGET_GC64 1
424 #endif
425 #define LJ_TARGET_MIPS 1
426 #define LJ_TARGET_EHRETREG 4
427 #define LJ_TARGET_EHRAREG 31
428 #define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
429 #define LJ_TARGET_MASKSHIFT 1
430 #define LJ_TARGET_MASKROT 1
431 #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
432 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
434 #if LJ_TARGET_MIPSR6
435 #define LJ_ARCH_VERSION 60
436 #elif _MIPS_ARCH_MIPS32R2 || _MIPS_ARCH_MIPS64R2
437 #define LJ_ARCH_VERSION 20
438 #else
439 #define LJ_ARCH_VERSION 10
440 #endif
442 #else
443 #error "No target architecture defined"
444 #endif
446 /* -- Checks for requirements --------------------------------------------- */
448 /* Check for minimum required compiler versions. */
449 #if defined(__GNUC__)
450 #if LJ_TARGET_X86
451 #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
452 #error "Need at least GCC 3.4 or newer"
453 #endif
454 #elif LJ_TARGET_X64
455 #if __GNUC__ < 4
456 #error "Need at least GCC 4.0 or newer"
457 #endif
458 #elif LJ_TARGET_ARM
459 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
460 #error "Need at least GCC 4.2 or newer"
461 #endif
462 #elif LJ_TARGET_ARM64
463 #if __clang__
464 #if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)) && !defined(__NX_TOOLCHAIN_MAJOR__)
465 #error "Need at least Clang 3.5 or newer"
466 #endif
467 #else
468 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)
469 #error "Need at least GCC 4.8 or newer"
470 #endif
471 #endif
472 #elif !LJ_TARGET_PS3
473 #if __clang__
474 #if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5))
475 #error "Need at least Clang 3.5 or newer"
476 #endif
477 #else
478 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
479 #error "Need at least GCC 4.3 or newer"
480 #endif
481 #endif
482 #endif
483 #endif
485 /* Check target-specific constraints. */
486 #ifndef _BUILDVM_H
487 #if LJ_TARGET_X64
488 #if __USING_SJLJ_EXCEPTIONS__
489 #error "Need a C compiler with native exception handling on x64"
490 #endif
491 #elif LJ_TARGET_ARM
492 #if defined(__ARMEB__)
493 #error "No support for big-endian ARM"
494 #undef LJ_TARGET_ARM
495 #endif
496 #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
497 #error "No support for Cortex-M CPUs"
498 #undef LJ_TARGET_ARM
499 #endif
500 #if !(__ARM_EABI__ || LJ_TARGET_IOS)
501 #error "Only ARM EABI or iOS 3.0+ ABI is supported"
502 #undef LJ_TARGET_ARM
503 #endif
504 #elif LJ_TARGET_ARM64
505 #if defined(_ILP32)
506 #error "No support for ILP32 model on ARM64"
507 #undef LJ_TARGET_ARM64
508 #endif
509 #elif LJ_TARGET_PPC
510 #if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN))
511 #error "No support for little-endian PPC32"
512 #undef LJ_TARGET_PPC
513 #endif
514 #if defined(__NO_FPRS__) && !defined(_SOFT_FLOAT)
515 #error "No support for PPC/e500, use LuaJIT 2.0"
516 #undef LJ_TARGET_PPC
517 #endif
518 #elif LJ_TARGET_MIPS32
519 #if !((defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32) || (defined(_ABIO32) && _MIPS_SIM == _ABIO32))
520 #error "Only o32 ABI supported for MIPS32"
521 #undef LJ_TARGET_MIPS
522 #endif
523 #if LJ_TARGET_MIPSR6
524 /* Not that useful, since most available r6 CPUs are 64 bit. */
525 #error "No support for MIPS32R6"
526 #undef LJ_TARGET_MIPS
527 #endif
528 #elif LJ_TARGET_MIPS64
529 #if !((defined(_MIPS_SIM_ABI64) && _MIPS_SIM == _MIPS_SIM_ABI64) || (defined(_ABI64) && _MIPS_SIM == _ABI64))
530 /* MIPS32ON64 aka n32 ABI support might be desirable, but difficult. */
531 #error "Only n64 ABI supported for MIPS64"
532 #undef LJ_TARGET_MIPS
533 #endif
534 #endif
535 #endif
537 /* -- Derived defines ----------------------------------------------------- */
539 /* Enable or disable the dual-number mode for the VM. */
540 #if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
541 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
542 #error "No support for this number mode on this architecture"
543 #endif
544 #if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
545 (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
546 (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
547 #define LJ_DUALNUM 1
548 #else
549 #define LJ_DUALNUM 0
550 #endif
552 #if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
553 /* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
554 /* Ditto for the consoles. Complain to Sony or MS, not me. */
555 #ifndef LUAJIT_ENABLE_JIT
556 #define LJ_OS_NOJIT 1
557 #endif
558 #endif
560 /* 64 bit GC references. */
561 #if LJ_TARGET_GC64
562 #define LJ_GC64 1
563 #else
564 #define LJ_GC64 0
565 #endif
567 /* 2-slot frame info. */
568 #if LJ_GC64
569 #define LJ_FR2 1
570 #else
571 #define LJ_FR2 0
572 #endif
574 /* Disable or enable the JIT compiler. */
575 #if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
576 #define LJ_HASJIT 0
577 #else
578 #define LJ_HASJIT 1
579 #endif
581 /* Disable or enable the FFI extension. */
582 #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
583 #define LJ_HASFFI 0
584 #else
585 #define LJ_HASFFI 1
586 #endif
588 /* Disable or enable the string buffer extension. */
589 #if defined(LUAJIT_DISABLE_BUFFER)
590 #define LJ_HASBUFFER 0
591 #else
592 #define LJ_HASBUFFER 1
593 #endif
595 #if defined(LUAJIT_DISABLE_PROFILE)
596 #define LJ_HASPROFILE 0
597 #elif LJ_TARGET_POSIX
598 #define LJ_HASPROFILE 1
599 #define LJ_PROFILE_SIGPROF 1
600 #elif LJ_TARGET_PS3
601 #define LJ_HASPROFILE 1
602 #define LJ_PROFILE_PTHREAD 1
603 #elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360
604 #define LJ_HASPROFILE 1
605 #define LJ_PROFILE_WTHREAD 1
606 #else
607 #define LJ_HASPROFILE 0
608 #endif
610 #ifndef LJ_ARCH_HASFPU
611 #define LJ_ARCH_HASFPU 1
612 #endif
613 #ifndef LJ_ABI_SOFTFP
614 #define LJ_ABI_SOFTFP 0
615 #endif
616 #define LJ_SOFTFP (!LJ_ARCH_HASFPU)
617 #define LJ_SOFTFP32 (LJ_SOFTFP && LJ_32)
619 #ifndef LJ_ABI_PAUTH
620 #define LJ_ABI_PAUTH 0
621 #endif
623 #if LJ_ARCH_ENDIAN == LUAJIT_BE
624 #define LJ_LE 0
625 #define LJ_BE 1
626 #define LJ_ENDIAN_SELECT(le, be) be
627 #define LJ_ENDIAN_LOHI(lo, hi) hi lo
628 #else
629 #define LJ_LE 1
630 #define LJ_BE 0
631 #define LJ_ENDIAN_SELECT(le, be) le
632 #define LJ_ENDIAN_LOHI(lo, hi) lo hi
633 #endif
635 #if LJ_ARCH_BITS == 32
636 #define LJ_32 1
637 #define LJ_64 0
638 #else
639 #define LJ_32 0
640 #define LJ_64 1
641 #endif
643 #ifndef LJ_TARGET_UNALIGNED
644 #define LJ_TARGET_UNALIGNED 0
645 #endif
647 #ifndef LJ_PAGESIZE
648 #define LJ_PAGESIZE 4096
649 #endif
651 /* Various workarounds for embedded operating systems or weak C runtimes. */
652 #if defined(__ANDROID__) || defined(__symbian__) || LJ_TARGET_XBOX360 || LJ_TARGET_WINDOWS
653 #define LUAJIT_NO_LOG2
654 #endif
655 #if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
656 #define LJ_NO_SYSTEM 1
657 #endif
659 #if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
660 #define LJ_ABI_WIN 1
661 #else
662 #define LJ_ABI_WIN 0
663 #endif
665 #if LJ_TARGET_WINDOWS
666 #if LJ_TARGET_UWP
667 #define LJ_WIN_VALLOC VirtualAllocFromApp
668 #define LJ_WIN_VPROTECT VirtualProtectFromApp
669 extern void *LJ_WIN_LOADLIBA(const char *path);
670 #else
671 #define LJ_WIN_VALLOC VirtualAlloc
672 #define LJ_WIN_VPROTECT VirtualProtect
673 #define LJ_WIN_LOADLIBA(path) LoadLibraryExA((path), NULL, 0)
674 #endif
675 #endif
677 #if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5
678 #define LJ_NO_UNWIND 1
679 #endif
681 #if !LJ_NO_UNWIND && !defined(LUAJIT_UNWIND_INTERNAL) && (LJ_ABI_WIN || (defined(LUAJIT_UNWIND_EXTERNAL) && (defined(__GNUC__) || defined(__clang__))))
682 #define LJ_UNWIND_EXT 1
683 #else
684 #define LJ_UNWIND_EXT 0
685 #endif
687 #if LJ_UNWIND_EXT && LJ_HASJIT && !LJ_TARGET_ARM && !(LJ_ABI_WIN && LJ_TARGET_X86)
688 #define LJ_UNWIND_JIT 1
689 #else
690 #define LJ_UNWIND_JIT 0
691 #endif
693 /* Compatibility with Lua 5.1 vs. 5.2. */
694 #ifdef LUAJIT_ENABLE_LUA52COMPAT
695 #define LJ_52 1
696 #else
697 #define LJ_52 0
698 #endif
700 /* -- VM security --------------------------------------------------------- */
702 /* Don't make any changes here. Instead build with:
703 ** make "XCFLAGS=-DLUAJIT_SECURITY_flag=value"
705 ** Important note to distro maintainers: DO NOT change the defaults for a
706 ** regular distro build -- neither upwards, nor downwards!
707 ** These build-time configurable security flags are intended for embedders
708 ** who may have specific needs wrt. security vs. performance.
711 /* Security defaults. */
712 #ifndef LUAJIT_SECURITY_PRNG
713 /* PRNG init: 0 = fixed/insecure, 1 = secure from OS. */
714 #define LUAJIT_SECURITY_PRNG 1
715 #endif
717 #ifndef LUAJIT_SECURITY_STRHASH
718 /* String hash: 0 = sparse only, 1 = sparse + dense. */
719 #define LUAJIT_SECURITY_STRHASH 1
720 #endif
722 #ifndef LUAJIT_SECURITY_STRID
723 /* String IDs: 0 = linear, 1 = reseed < 255, 2 = reseed < 15, 3 = random. */
724 #define LUAJIT_SECURITY_STRID 1
725 #endif
727 #ifndef LUAJIT_SECURITY_MCODE
728 /* Machine code page protection: 0 = insecure RWX, 1 = secure RW^X. */
729 #define LUAJIT_SECURITY_MCODE 1
730 #endif
732 #define LJ_SECURITY_MODE \
733 ( 0u \
734 | ((LUAJIT_SECURITY_PRNG & 3) << 0) \
735 | ((LUAJIT_SECURITY_STRHASH & 3) << 2) \
736 | ((LUAJIT_SECURITY_STRID & 3) << 4) \
737 | ((LUAJIT_SECURITY_MCODE & 3) << 6) \
739 #define LJ_SECURITY_MODESTRING \
740 "\004prng\007strhash\005strid\005mcode"
742 #endif