Browse Source

MIPS: Fix handling of spare long-range jump slots.

Contributed by Djordje Kovacevic and Stefan Pejic.
Mike Pall 8 years ago
parent
commit
c7c3c4da43
3 changed files with 11 additions and 10 deletions
  1. 5 4
      src/lj_asm_mips.h
  2. 6 0
      src/lj_jit.h
  3. 0 6
      src/lj_mcode.c

+ 5 - 4
src/lj_asm_mips.h

@@ -65,10 +65,9 @@ static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
 static void asm_sparejump_setup(ASMState *as)
 static void asm_sparejump_setup(ASMState *as)
 {
 {
   MCode *mxp = as->mcbot;
   MCode *mxp = as->mcbot;
-  /* Assumes sizeof(MCLink) == 8. */
-  if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == 8) {
+  if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == sizeof(MCLink)) {
     lua_assert(MIPSI_NOP == 0);
     lua_assert(MIPSI_NOP == 0);
-    memset(mxp+2, 0, MIPS_SPAREJUMP*8);
+    memset(mxp, 0, MIPS_SPAREJUMP*2*sizeof(MCode));
     mxp += MIPS_SPAREJUMP*2;
     mxp += MIPS_SPAREJUMP*2;
     lua_assert(mxp < as->mctop);
     lua_assert(mxp < as->mctop);
     lj_mcode_sync(as->mcbot, mxp);
     lj_mcode_sync(as->mcbot, mxp);
@@ -1947,7 +1946,9 @@ void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
 	  if (!cstart) cstart = p-1;
 	  if (!cstart) cstart = p-1;
 	} else {  /* Branch out of range. Use spare jump slot in mcarea. */
 	} else {  /* Branch out of range. Use spare jump slot in mcarea. */
 	  int i;
 	  int i;
-	  for (i = 2; i < 2+MIPS_SPAREJUMP*2; i += 2) {
+	  for (i = (int)(sizeof(MCLink)/sizeof(MCode));
+	       i < (int)(sizeof(MCLink)/sizeof(MCode)+MIPS_SPAREJUMP*2);
+	       i += 2) {
 	    if (mcarea[i] == tjump) {
 	    if (mcarea[i] == tjump) {
 	      delta = mcarea+i - p;
 	      delta = mcarea+i - p;
 	      goto patchbranch;
 	      goto patchbranch;

+ 6 - 0
src/lj_jit.h

@@ -155,6 +155,12 @@ typedef uint8_t MCode;
 typedef uint32_t MCode;
 typedef uint32_t MCode;
 #endif
 #endif
 
 
+/* Linked list of MCode areas. */
+typedef struct MCLink {
+  MCode *next;		/* Next area. */
+  size_t size;		/* Size of current area. */
+} MCLink;
+
 /* Stack snapshot header. */
 /* Stack snapshot header. */
 typedef struct SnapShot {
 typedef struct SnapShot {
   uint16_t mapofs;	/* Offset into snapshot map. */
   uint16_t mapofs;	/* Offset into snapshot map. */

+ 0 - 6
src/lj_mcode.c

@@ -272,12 +272,6 @@ static void *mcode_alloc(jit_State *J, size_t sz)
 
 
 /* -- MCode area management ----------------------------------------------- */
 /* -- MCode area management ----------------------------------------------- */
 
 
-/* Linked list of MCode areas. */
-typedef struct MCLink {
-  MCode *next;		/* Next area. */
-  size_t size;		/* Size of current area. */
-} MCLink;
-
 /* Allocate a new MCode area. */
 /* Allocate a new MCode area. */
 static void mcode_allocarea(jit_State *J)
 static void mcode_allocarea(jit_State *J)
 {
 {