Debian Codegraph @

libs/luajit/LuaJIT-src/src/lj_arch.h

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