/* Set/reset protection to allow patching of MCode areas. */ MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish) { #ifdef LUAJIT_UNPROTECT_MCODE UNUSED(J); UNUSED(ptr); UNUSED(finish); return NULL; #else if (finish) { if (J->mcarea == ptr) mcode_protect(J, MCPROT_RUN); else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN))) mcode_protfail(J); 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)) { mcode_protect(J, MCPROT_GEN); return mc; } /* Otherwise search through the list of MCode areas. */ for (;;) { mc = ((MCLink *)mc)->next; lua_assert(mc != NULL); if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) { if (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN))) mcode_protfail(J); return mc; } } } #endif }
/* Reserve the remainder of the current MCode area. */ MCode *lj_mcode_reserve(jit_State *J, MCode **lim) { if (!J->mcarea) mcode_allocarea(J); else mcode_protect(J, MCPROT_GEN); *lim = J->mcbot; return J->mctop; }
/* Abort the reservation. */ void lj_mcode_abort(jit_State *J) { if (J->mcarea) mcode_protect(J, MCPROT_RUN); }
/* Commit the top part of the current MCode area. */ void lj_mcode_commit(jit_State *J, MCode *top) { J->mctop = top; mcode_protect(J, MCPROT_RUN); }
/* Abort the reservation. */ void lj_mcode_abort(jit_State *J) { mcode_protect(J, MCPROT_RUN); }