Compare commits

..

1 Commits

Author SHA1 Message Date
gns
6cb453770e
Merge fd1422f59e into f14556234c 2025-03-09 15:24:43 -04:00
6 changed files with 21 additions and 56 deletions

View File

@ -186,7 +186,7 @@ static void bcwrite_ktab(BCWriteCtx *ctx, char *p, const GCtab *t)
} else {
MSize i = nhash;
for (;; node--)
if (!tvisnil(&node->val)) {
if (!tvisnil(&node->key)) {
bcwrite_ktabk(ctx, &node->key, 0);
bcwrite_ktabk(ctx, &node->val, 1);
if (--i == 0) break;

View File

@ -299,14 +299,6 @@ static void *callback_mcode_init(global_State *g, uint32_t *page)
#define CCPROT_CREATE 0
#endif
/* Check for macOS hardened runtime. */
#if LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#include <pthread.h>
#define CCMAP_CREATE MAP_JIT
#else
#define CCMAP_CREATE 0
#endif
#endif
/* Allocate and initialize area for callback function pointers. */
@ -321,13 +313,10 @@ static void callback_mcode_new(CTState *cts)
if (!p)
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
#elif LJ_TARGET_POSIX
p = mmap(NULL, sz, PROT_READ|PROT_WRITE|CCPROT_CREATE,
MAP_PRIVATE|MAP_ANONYMOUS|CCMAP_CREATE, -1, 0);
p = mmap(NULL, sz, (PROT_READ|PROT_WRITE|CCPROT_CREATE), MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0);
if (p == MAP_FAILED)
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
#if CCMAP_CREATE
pthread_jit_write_protect_np(0);
#endif
#else
/* Fallback allocator. Fails if memory is not executable by default. */
p = lj_mem_new(cts->L, sz);
@ -344,12 +333,8 @@ static void callback_mcode_new(CTState *cts)
LJ_WIN_VPROTECT(p, sz, PAGE_EXECUTE_READ, &oprot);
}
#elif LJ_TARGET_POSIX
#if CCMAP_CREATE
pthread_jit_write_protect_np(1);
#else
mprotect(p, sz, (PROT_READ|PROT_EXEC));
#endif
#endif
}
/* Free area for callback function pointers. */

View File

@ -115,14 +115,6 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot)
#define MAP_ANONYMOUS MAP_ANON
#endif
/* Check for macOS hardened runtime. */
#if LUAJIT_SECURITY_MCODE != 0 && defined(MAP_JIT) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 110000
#include <pthread.h>
#define MCMAP_CREATE MAP_JIT
#else
#define MCMAP_CREATE 0
#endif
#define MCPROT_RW (PROT_READ|PROT_WRITE)
#define MCPROT_RX (PROT_READ|PROT_EXEC)
#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
@ -134,14 +126,10 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot)
static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
{
void *p = mmap((void *)hint, sz, prot|MCPROT_CREATE, MAP_PRIVATE|MAP_ANONYMOUS|MCMAP_CREATE, -1, 0);
void *p = mmap((void *)hint, sz, prot|MCPROT_CREATE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) {
if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);
p = NULL;
#if MCMAP_CREATE
} else {
pthread_jit_write_protect_np(0);
#endif
}
return p;
}
@ -154,12 +142,7 @@ static void mcode_free(jit_State *J, void *p, size_t sz)
static int mcode_setprot(void *p, size_t sz, int prot)
{
#if MCMAP_CREATE
pthread_jit_write_protect_np((prot & PROT_EXEC));
return 0;
#else
return mprotect(p, sz, prot);
#endif
}
#else

View File

@ -2079,7 +2079,6 @@ static TRef rec_tnew(jit_State *J, uint32_t ah)
/* -- Concatenation ------------------------------------------------------- */
typedef struct RecCatDataCP {
TValue savetv[5+LJ_FR2];
jit_State *J;
BCReg baseslot, topslot;
TRef tr;
@ -2120,9 +2119,7 @@ static TValue *rec_mm_concat_cp(lua_State *L, lua_CFunction dummy, void *ud)
return NULL;
}
/* Pass partial result. */
rcd->topslot = topslot = J->maxslot--;
/* Save updated range of slots. */
memcpy(rcd->savetv, &L->base[topslot-1], sizeof(rcd->savetv));
topslot = J->maxslot--;
*xbase = tr;
top = xbase;
setstrV(J->L, &ix.keyv, &J2G(J)->strempty); /* Simulate string result. */
@ -2142,18 +2139,16 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
{
lua_State *L = J->L;
ptrdiff_t delta = L->top - L->base;
TValue errobj;
TValue savetv[5+LJ_FR2], errobj;
RecCatDataCP rcd;
int errcode;
rcd.J = J;
rcd.baseslot = baseslot;
rcd.topslot = topslot;
/* Save slots. */
memcpy(rcd.savetv, &L->base[topslot-1], sizeof(rcd.savetv));
memcpy(savetv, &L->base[topslot-1], sizeof(savetv)); /* Save slots. */
errcode = lj_vm_cpcall(L, NULL, &rcd, rec_mm_concat_cp);
if (errcode) copyTV(L, &errobj, L->top-1);
/* Restore slots. */
memcpy(&L->base[rcd.topslot-1], rcd.savetv, sizeof(rcd.savetv));
memcpy(&L->base[topslot-1], savetv, sizeof(savetv)); /* Restore slots. */
if (errcode) {
L->top = L->base + delta;
copyTV(L, L->top++, &errobj);

View File

@ -222,6 +222,14 @@ static void trace_unpatch(jit_State *J, GCtrace *T)
bc_isret(op), "bad original bytecode %d", op);
*pc = T->startins;
break;
case BC_JMP:
lj_assertJ(op == BC_ITERL, "bad original bytecode %d", op);
pc += bc_j(*pc)+2;
if (bc_op(*pc) == BC_JITERL) {
lj_assertJ(traceref(J, bc_d(*pc)) == T, "JITERL references other trace");
*pc = T->startins;
}
break;
case BC_JFUNCF:
lj_assertJ(op == BC_FUNCF, "bad original bytecode %d", op);
*pc = T->startins;
@ -237,19 +245,18 @@ static void trace_flushroot(jit_State *J, GCtrace *T)
GCproto *pt = &gcref(T->startpt)->pt;
lj_assertJ(T->root == 0, "not a root trace");
lj_assertJ(pt != NULL, "trace has no prototype");
/* First unpatch any modified bytecode. */
trace_unpatch(J, T);
/* Unlink root trace from chain anchored in prototype. */
if (pt->trace == T->traceno) { /* Trace is first in chain. Easy. */
pt->trace = T->nextroot;
unpatch:
/* Unpatch modified bytecode only if the trace has not been flushed. */
trace_unpatch(J, T);
} else if (pt->trace) { /* Otherwise search in chain of root traces. */
GCtrace *T2 = traceref(J, pt->trace);
if (T2) {
for (; T2->nextroot; T2 = traceref(J, T2->nextroot))
if (T2->nextroot == T->traceno) {
T2->nextroot = T->nextroot; /* Unlink from chain. */
goto unpatch;
break;
}
}
}

View File

@ -8,8 +8,7 @@
@rem nogc64 disable LJ_GC64 mode for x64
@rem debug emit debug symbols
@rem amalg amalgamated build
@rem static create static lib to statically link into your project
@rem mixed create static lib to build a DLL in your project
@rem static static linkage
@if not defined INCLUDE goto :FAIL
@ -107,14 +106,12 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
@if "%1"=="static" goto :STATIC
%LJCOMPILE% %LJDYNBUILD% lj_*.c lib_*.c
@if errorlevel 1 goto :BAD
@if "%1"=="mixed" goto :STATICLIB
%LJLINK% /DLL /OUT:%LJDLLNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:STATIC
%LJCOMPILE% lj_*.c lib_*.c
@if errorlevel 1 goto :BAD
:STATICLIB
%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
@ -122,15 +119,13 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
@if "%2"=="static" goto :AMALGSTATIC
%LJCOMPILE% %LJDYNBUILD% ljamalg.c
@if errorlevel 1 goto :BAD
@if "%2"=="mixed" goto :AMALGSTATICLIB
%LJLINK% /DLL /OUT:%LJDLLNAME% ljamalg.obj lj_vm.obj
@if errorlevel 1 goto :BAD
@goto :MTDLL
:AMALGSTATIC
%LJCOMPILE% ljamalg.c
@if errorlevel 1 goto :BAD
:AMALGSTATICLIB
%LJLIB% /OUT:%LJLIBNAME% ljamalg.obj lj_vm.obj
%LJLINK% /OUT:%LJDLLNAME% ljamalg.obj lj_vm.obj
@if errorlevel 1 goto :BAD
:MTDLL
if exist %LJDLLNAME%.manifest^