MIPS: Fix handling of long-range spare jumps.

This commit is contained in:
Mike Pall
2021-03-23 00:26:08 +01:00
parent e131936133
commit dbb7863016
2 changed files with 34 additions and 25 deletions

View File

@@ -314,21 +314,21 @@ void lj_mcode_abort(jit_State *J)
/* Set/reset protection to allow patching of MCode areas. */
MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)
{
#if LUAJIT_SECURITY_MCODE == 0
UNUSED(J); UNUSED(ptr); UNUSED(finish);
return NULL;
#else
if (finish) {
#if LUAJIT_SECURITY_MCODE
if (J->mcarea == ptr)
mcode_protect(J, MCPROT_RUN);
else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN)))
mcode_protfail(J);
#endif
return NULL;
} else {
MCode *mc = J->mcarea;
/* Try current area first to use the protection cache. */
if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {
#if LUAJIT_SECURITY_MCODE
mcode_protect(J, MCPROT_GEN);
#endif
return mc;
}
/* Otherwise search through the list of MCode areas. */
@@ -336,13 +336,14 @@ MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)
mc = ((MCLink *)mc)->next;
lj_assertJ(mc != NULL, "broken MCode area chain");
if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {
#if LUAJIT_SECURITY_MCODE
if (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN)))
mcode_protfail(J);
#endif
return mc;
}
}
}
#endif
}
/* Limit of MCode reservation reached. */