Compare commits

...

6 Commits

Author SHA1 Message Date
Jude Melton-Houghton
2c1183e12c
Merge dc809beb57 into 538a82133a 2025-03-12 16:42:27 +08:00
Mike Pall
538a82133a Change handling of nil value markers in template tables.
Reported by Bernhard M. Wiedemann. #1348 #1155
Fixes from Peter Cawley, Christian Clason, Lewis Russell.
2025-03-11 23:04:30 +01:00
Mike Pall
84cb21ffaf REVERT: Change handling of nil value markers in template tables. 2025-03-10 02:56:07 +01:00
Mike Pall
4f2bb199fe macOS: Fix Apple hardened runtime support and put behind build option.
Reported by vanc. #1334
2025-03-10 02:53:20 +01:00
Jude Melton-Houghton
dc809beb57 Simplify code 2022-09-20 14:24:06 -04:00
Jude Melton-Houghton
89213015a6 Compile unpack() given constant start and end 2022-09-20 13:03:24 -04:00
5 changed files with 46 additions and 6 deletions

View File

@ -224,7 +224,7 @@ LJLIB_CF(rawlen) LJLIB_REC(.)
}
#endif
LJLIB_CF(unpack)
LJLIB_CF(unpack) LJLIB_REC(.)
{
GCtab *t = lj_lib_checktab(L, 1);
int32_t n, i = lj_lib_optint(L, 2, 1);

View File

@ -191,7 +191,7 @@ static void bcread_ktabk(LexState *ls, TValue *o, GCtab *t)
} else if (tp == BCDUMP_KTAB_NUM) {
o->u32.lo = bcread_uleb128(ls);
o->u32.hi = bcread_uleb128(ls);
} else if (tp == BCDUMP_KTAB_NIL) { /* Restore nil value marker. */
} else if (t && tp == BCDUMP_KTAB_NIL) { /* Restore nil value marker. */
settabV(ls->L, o, t);
} else {
lj_assertLS(tp <= BCDUMP_KTAB_TRUE, "bad constant type %d", tp);
@ -209,13 +209,13 @@ static GCtab *bcread_ktab(LexState *ls)
MSize i;
TValue *o = tvref(t->array);
for (i = 0; i < narray; i++, o++)
bcread_ktabk(ls, o, t);
bcread_ktabk(ls, o, NULL);
}
if (nhash) { /* Read hash entries. */
MSize i;
for (i = 0; i < nhash; i++) {
TValue key;
bcread_ktabk(ls, &key, t);
bcread_ktabk(ls, &key, NULL);
lj_assertLS(!tvisnil(&key), "nil key");
bcread_ktabk(ls, lj_tab_set(ls->L, t, &key), t);
}

View File

@ -263,7 +263,7 @@ static void *callback_mcode_init(global_State *g, uint32_t *page)
#endif
/* Check for macOS hardened runtime. */
#if LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#if defined(LUAJIT_ENABLE_OSX_HRT) && LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#include <pthread.h>
#define CCMAP_CREATE MAP_JIT
#else

View File

@ -568,6 +568,44 @@ static void LJ_FASTCALL recff_next(jit_State *J, RecordFFData *rd)
#endif
}
static void LJ_FASTCALL recff_unpack(jit_State *J, RecordFFData *rd)
{
TRef tab = J->base[0], trstart = J->base[1], trend = J->base[2];
if (tref_istab(tab) && trstart && trend && tref_isk2(trstart, trend) &&
!tref_isnil(trend)) {
if (!tref_isnil(trstart))
trstart = lj_opt_narrow_toint(J, trstart);
trend = lj_opt_narrow_toint(J, trend);
if (tref_isk2(trstart, trend)) {
uint32_t nu;
int32_t start = tref_isnil(trstart) ? 1 : IR(tref_ref(trstart))->i;
int32_t end = IR(tref_ref(trend))->i;
if (start > end) {
rd->nres = 0;
return;
}
nu = (uint32_t)end - (uint32_t)start;
/* Check for space for the return values. */
if (nu <= INT32_MAX - LJ_MAX_JSLOTS && J->baseslot + nu < LJ_MAX_JSLOTS) {
int32_t i, n = (int32_t)(nu+1);
RecordIndex ix;
ix.tab = tab;
settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));
ix.val = 0;
ix.idxchain = 0;
for (i = 0; i < n; i++) {
ix.key = lj_ir_kint(J, start + i);
setintV(&ix.keyv, start + i);
J->base[i] = lj_record_idx(J, &ix);
}
rd->nres = n;
return;
}
}
}
recff_nyiu(J, rd);
}
/* -- Math library fast functions ----------------------------------------- */
static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd)

View File

@ -99,7 +99,7 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot)
#endif
/* Check for macOS hardened runtime. */
#if LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#if defined(LUAJIT_ENABLE_OSX_HRT) && LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#include <pthread.h>
#define MCMAP_CREATE MAP_JIT
#else
@ -111,6 +111,8 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot)
#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
#ifdef PROT_MPROTECT
#define MCPROT_CREATE (PROT_MPROTECT(MCPROT_RWX))
#elif MCMAP_CREATE
#define MCPROT_CREATE PROT_EXEC
#else
#define MCPROT_CREATE 0
#endif