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