|
| 1 | +Add missing GC steps for io.* functions. |
| 2 | +MIPS: Fix cache flush/sync for JIT-compiled code jump area. |
| 3 | +ARM: Fix cache flush/sync for exit stubs of JIT-compiled code. |
| 4 | +Fix MSVC intrinsics for older versions. |
| 5 | +Fix memory access check for fast string interning. |
| 6 | + |
| 7 | +--- a/src/lib_io.c |
| 8 | ++++ b/src/lib_io.c |
| 9 | +@@ -17,6 +17,7 @@ |
| 10 | + #include "lualib.h" |
| 11 | + |
| 12 | + #include "lj_obj.h" |
| 13 | ++#include "lj_gc.h" |
| 14 | + #include "lj_err.h" |
| 15 | + #include "lj_str.h" |
| 16 | + #include "lj_state.h" |
| 17 | +@@ -152,6 +153,7 @@ static int io_file_readline(lua_State *L, FILE *fp, MSize chop) |
| 18 | + if (n >= m - 64) m += m; |
| 19 | + } |
| 20 | + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); |
| 21 | ++ lj_gc_check(L); |
| 22 | + return (int)ok; |
| 23 | + } |
| 24 | + |
| 25 | +@@ -163,6 +165,7 @@ static void io_file_readall(lua_State *L, FILE *fp) |
| 26 | + n += (MSize)fread(buf+n, 1, m-n, fp); |
| 27 | + if (n != m) { |
| 28 | + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); |
| 29 | ++ lj_gc_check(L); |
| 30 | + return; |
| 31 | + } |
| 32 | + } |
| 33 | +@@ -174,6 +177,7 @@ static int io_file_readlen(lua_State *L, FILE *fp, MSize m) |
| 34 | + char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); |
| 35 | + MSize n = (MSize)fread(buf, 1, m, fp); |
| 36 | + setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); |
| 37 | ++ lj_gc_check(L); |
| 38 | + return (n > 0 || m == 0); |
| 39 | + } else { |
| 40 | + int c = getc(fp); |
| 41 | +--- a/src/lj_asm_arm.h |
| 42 | ++++ b/src/lj_asm_arm.h |
| 43 | +@@ -91,6 +91,7 @@ static MCode *asm_exitstub_gen(ASMState *as, ExitNo group) |
| 44 | + *mxp++ = group*EXITSTUBS_PER_GROUP; |
| 45 | + for (i = 0; i < EXITSTUBS_PER_GROUP; i++) |
| 46 | + *mxp++ = ARMI_B|((-6-i)&0x00ffffffu); |
| 47 | ++ lj_mcode_sync(as->mcbot, mxp); |
| 48 | + lj_mcode_commitbot(as->J, mxp); |
| 49 | + as->mcbot = mxp; |
| 50 | + as->mclim = as->mcbot + MCLIM_REDZONE; |
| 51 | +--- a/src/lj_asm_mips.h |
| 52 | ++++ b/src/lj_asm_mips.h |
| 53 | +@@ -71,6 +71,7 @@ static void asm_sparejump_setup(ASMState *as) |
| 54 | + memset(mxp+2, 0, MIPS_SPAREJUMP*8); |
| 55 | + mxp += MIPS_SPAREJUMP*2; |
| 56 | + lua_assert(mxp < as->mctop); |
| 57 | ++ lj_mcode_sync(as->mcbot, mxp); |
| 58 | + lj_mcode_commitbot(as->J, mxp); |
| 59 | + as->mcbot = mxp; |
| 60 | + as->mclim = as->mcbot + MCLIM_REDZONE; |
| 61 | +--- a/src/lj_def.h |
| 62 | ++++ b/src/lj_def.h |
| 63 | +@@ -243,17 +243,17 @@ static LJ_AINLINE uint32_t lj_getu32(const void *p) |
| 64 | + #endif |
| 65 | + |
| 66 | + #ifdef _M_PPC |
| 67 | +-#pragma intrinsic(_CountLeadingZeros) |
| 68 | + unsigned int _CountLeadingZeros(long); |
| 69 | ++#pragma intrinsic(_CountLeadingZeros) |
| 70 | + static LJ_AINLINE uint32_t lj_fls(uint32_t x) |
| 71 | + { |
| 72 | + return _CountLeadingZeros(x) ^ 31; |
| 73 | + } |
| 74 | + #else |
| 75 | +-#pragma intrinsic(_BitScanForward) |
| 76 | +-#pragma intrinsic(_BitScanReverse) |
| 77 | + unsigned char _BitScanForward(uint32_t *, unsigned long); |
| 78 | + unsigned char _BitScanReverse(uint32_t *, unsigned long); |
| 79 | ++#pragma intrinsic(_BitScanForward) |
| 80 | ++#pragma intrinsic(_BitScanReverse) |
| 81 | + |
| 82 | + static LJ_AINLINE uint32_t lj_ffs(uint32_t x) |
| 83 | + { |
| 84 | +--- a/src/lj_str.c |
| 85 | ++++ b/src/lj_str.c |
| 86 | +@@ -48,7 +48,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len) |
| 87 | + { |
| 88 | + MSize i = 0; |
| 89 | + lua_assert(len > 0); |
| 90 | +- lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); |
| 91 | ++ lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4); |
| 92 | + do { /* Note: innocuous access up to end of string + 3. */ |
| 93 | + uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i); |
| 94 | + if (v) { |
| 95 | +@@ -121,7 +121,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx) |
| 96 | + h ^= b; h -= lj_rol(b, 16); |
| 97 | + /* Check if the string has already been interned. */ |
| 98 | + o = gcref(g->strhash[h & g->strmask]); |
| 99 | +- if (LJ_LIKELY((((uintptr_t)str + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { |
| 100 | ++ if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) { |
| 101 | + while (o != NULL) { |
| 102 | + GCstr *sx = gco2str(o); |
| 103 | + if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) { |
0 commit comments