From 9398123383119d4ac45336fee98bd8349cfba725 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 25 May 2024 14:56:15 +0200
Subject: [PATCH 1/6] Fix internal link in docs.
Thanks to GitSparTV. #1219
---
doc/ext_buffer.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/ext_buffer.html b/doc/ext_buffer.html
index 61f425f1..54bb66f6 100644
--- a/doc/ext_buffer.html
+++ b/doc/ext_buffer.html
@@ -85,7 +85,7 @@ operations.
Date: Sat, 25 May 2024 15:48:07 +0200
Subject: [PATCH 2/6] FFI: Clarify scalar boxing behavior.
Prevent misunderstandings like in #1216
---
doc/ext_ffi_semantics.html | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html
index 5ba82a1e..b56e57a1 100644
--- a/doc/ext_ffi_semantics.html
+++ b/doc/ext_ffi_semantics.html
@@ -440,6 +440,19 @@ If you don't do this, the default Lua number → double
conversion rule applies. A vararg C function expecting an integer
will see a garbled or uninitialized value.
+
+Note: this is the only place where creating a boxed scalar number type is
+actually useful. Never use ffi.new("int"), ffi.new("float")
+etc. anywhere else!
+
+
+Ditto for ffi.cast(). Explicitly boxing scalars does not
+improve performance or force int or float arithmetic! It
+just adds costly boxing, unboxing and conversions steps. And it may lead
+to surprise results, because
+cdata arithmetic on scalar numbers
+is always performed on 64 bit integers.
+
Initializers
From 4fc48c50fe3f3f5a9680bada5c0c0d0d7eb345a3 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 25 May 2024 16:22:39 +0200
Subject: [PATCH 3/6] Limit number of string format elements to compile.
Reported by pwnhacker0x18. #1203
---
src/lj_ffrecord.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index 923824d9..b298d3f7 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -1005,6 +1005,7 @@ static void recff_format(jit_State *J, RecordFFData *rd, TRef hdr, int sbufx)
GCstr *fmt = argv2str(J, &rd->argv[arg]);
FormatState fs;
SFormat sf;
+ int nfmt = 0;
/* Specialize to the format string. */
emitir(IRTG(IR_EQ, IRT_STR), trfmt, lj_ir_kstr(J, fmt));
lj_strfmt_init(&fs, strdata(fmt), fmt->len);
@@ -1082,6 +1083,7 @@ static void recff_format(jit_State *J, RecordFFData *rd, TRef hdr, int sbufx)
recff_nyiu(J, rd);
return;
}
+ if (++nfmt > 100) lj_trace_err(J, LJ_TRERR_TRACEOV);
}
if (sbufx) {
emitir(IRT(IR_USE, IRT_NIL), tr, 0);
From 80c1c65bced91affaabb34e696eb715cdd583fa1 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 25 May 2024 16:25:35 +0200
Subject: [PATCH 4/6] Typo.
---
src/lj_jit.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 6902fba3..59f92e55 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -460,8 +460,8 @@ typedef struct jit_State {
#endif
IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
- IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
- IRRef irbotlim; /* Lower limit of instuction buffer (biased). */
+ IRRef irtoplim; /* Upper limit of instruction buffer (biased). */
+ IRRef irbotlim; /* Lower limit of instruction buffer (biased). */
IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
MSize sizesnap; /* Size of temp. snapshot buffer. */
From 4a22050df9e76a28ef904382e4b4c69578973cd5 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 25 May 2024 16:38:05 +0200
Subject: [PATCH 5/6] Prevent sanitizer warning in snap_restoredata().
Thanks to Sergey Kaplun. #1193
---
src/lj_snap.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/lj_snap.c b/src/lj_snap.c
index 4a773048..9858c110 100644
--- a/src/lj_snap.c
+++ b/src/lj_snap.c
@@ -731,7 +731,6 @@ static void snap_restoredata(GCtrace *T, ExitState *ex,
*(lua_Number *)dst = (lua_Number)*(int32_t *)dst;
return;
}
- src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];
#if !LJ_SOFTFP
if (r >= RID_MAX_GPR) {
src = (int32_t *)&ex->fpr[r-RID_MIN_FPR];
@@ -743,8 +742,11 @@ static void snap_restoredata(GCtrace *T, ExitState *ex,
#else
if (LJ_BE && sz == 4) src++;
#endif
- }
+ } else
#endif
+ {
+ src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];
+ }
}
}
lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8);
From 93e87998b24021b94de8d1c8db244444c46fb6e9 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 25 May 2024 19:01:18 +0200
Subject: [PATCH 6/6] Update Nintendo Switch build script.
Thanks to IoriBranford. #1214
---
src/nxbuild.bat | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/nxbuild.bat b/src/nxbuild.bat
index 7f84b747..91513397 100644
--- a/src/nxbuild.bat
+++ b/src/nxbuild.bat
@@ -99,20 +99,21 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
@if errorlevel 1 goto :BAD
@rem ---- Cross compiler ----
+@set NXCOMPILER_ROOT="%NINTENDO_SDK_ROOT%\Compilers\NintendoClang"
@if "%platform%" neq "x64" goto :NX32_CROSSBUILD
-@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
-@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-ar" rc
+@set LJCOMPILE="%NXCOMPILER_ROOT%\bin\clang" --target=aarch64-nintendo-nx-elf -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
+@set LJLIB="%NXCOMPILER_ROOT%\bin\llvm-ar" rc
@set TARGETLIB_SUFFIX=nx64
-%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-as -o lj_vm.o lj_vm.s
+%NXCOMPILER_ROOT%\bin\clang --target=aarch64-nintendo-nx-elf -o lj_vm.o -c lj_vm.s
goto :DEBUGCHECK
:NX32_CROSSBUILD
-@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
-@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar" rc
+@set LJCOMPILE="%NXCOMPILER_ROOT%\bin\clang" --target=armv7l-nintendo-nx-eabihf -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
+@set LJLIB="%NXCOMPILER_ROOT%\bin\llvm-ar" rc
@set TARGETLIB_SUFFIX=nx32
-%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-as -o lj_vm.o lj_vm.s
+%NXCOMPILER_ROOT%\bin\clang --target=armv7l-nintendo-nx-eabihf -o lj_vm.o -c lj_vm.s
:DEBUGCHECK
@if "%1" neq "debug" goto :NODEBUG