diff options
author | Mike Pall <mike> | 2016-04-24 17:32:12 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2016-04-24 17:32:12 +0200 |
commit | ac42037db0ea0e0c8f4934b5103db522ab405129 (patch) | |
tree | be659548215b60726dfd6f34c1fdf545d81a7b1a | |
parent | d8ac6230ed95a60b79e58a4aa2ba7f6d0b132e9e (diff) | |
download | luajit-ac42037db0ea0e0c8f4934b5103db522ab405129.tar.gz luajit-ac42037db0ea0e0c8f4934b5103db522ab405129.tar.bz2 luajit-ac42037db0ea0e0c8f4934b5103db522ab405129.zip |
Constrain value range of lj_ir_kptr() to unsigned 32 bit pointers.
Thanks to Peter Cawley.
-rw-r--r-- | src/lj_ffrecord.c | 8 | ||||
-rw-r--r-- | src/lj_ir.c | 2 | ||||
-rw-r--r-- | src/lj_obj.h | 8 | ||||
-rw-r--r-- | src/lj_record.c | 7 |
4 files changed, 9 insertions, 16 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index a960ea50..942ecdb2 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -104,7 +104,6 @@ static void recff_stitch(jit_State *J) | |||
104 | TValue *base = L->base; | 104 | TValue *base = L->base; |
105 | const BCIns *pc = frame_pc(base-1); | 105 | const BCIns *pc = frame_pc(base-1); |
106 | TValue *pframe = frame_prevl(base-1); | 106 | TValue *pframe = frame_prevl(base-1); |
107 | TRef trcont; | ||
108 | 107 | ||
109 | lua_assert(!LJ_FR2); /* TODO_FR2: handle frame shift. */ | 108 | lua_assert(!LJ_FR2); /* TODO_FR2: handle frame shift. */ |
110 | /* Move func + args up in Lua stack and insert continuation. */ | 109 | /* Move func + args up in Lua stack and insert continuation. */ |
@@ -118,12 +117,7 @@ static void recff_stitch(jit_State *J) | |||
118 | 117 | ||
119 | /* Ditto for the IR. */ | 118 | /* Ditto for the IR. */ |
120 | memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1)); | 119 | memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1)); |
121 | #if LJ_64 | 120 | J->base[0] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT; |
122 | trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin)); | ||
123 | #else | ||
124 | trcont = lj_ir_kptr(J, (void *)cont); | ||
125 | #endif | ||
126 | J->base[0] = trcont | TREF_CONT; | ||
127 | J->ktracep = lj_ir_k64_reserve(J); | 121 | J->ktracep = lj_ir_k64_reserve(J); |
128 | lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); | 122 | lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); |
129 | J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0); | 123 | J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0); |
diff --git a/src/lj_ir.c b/src/lj_ir.c index 63c98254..b4087aa7 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -345,7 +345,7 @@ TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) | |||
345 | { | 345 | { |
346 | IRIns *ir, *cir = J->cur.ir; | 346 | IRIns *ir, *cir = J->cur.ir; |
347 | IRRef ref; | 347 | IRRef ref; |
348 | lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr); | 348 | lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr); |
349 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) | 349 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) |
350 | if (mref(cir[ref].ptr, void) == ptr) | 350 | if (mref(cir[ref].ptr, void) == ptr) |
351 | goto found; | 351 | goto found; |
diff --git a/src/lj_obj.h b/src/lj_obj.h index 059eb132..25da9455 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -843,12 +843,16 @@ static LJ_AINLINE void setlightudV(TValue *o, void *p) | |||
843 | #endif | 843 | #endif |
844 | 844 | ||
845 | #if LJ_FR2 | 845 | #if LJ_FR2 |
846 | #define setcont(o, f) ((o)->u64 = (uint64_t)(uintptr_t)(void *)(f)) | 846 | #define contptr(f) ((void *)(f)) |
847 | #define setcont(o, f) ((o)->u64 = (uint64_t)(uintptr_t)contptr(f)) | ||
847 | #elif LJ_64 | 848 | #elif LJ_64 |
849 | #define contptr(f) \ | ||
850 | ((void *)(uintptr_t)(uint32_t)((intptr_t)(f) - (intptr_t)lj_vm_asm_begin)) | ||
848 | #define setcont(o, f) \ | 851 | #define setcont(o, f) \ |
849 | ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) | 852 | ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) |
850 | #else | 853 | #else |
851 | #define setcont(o, f) setlightudV((o), (void *)(f)) | 854 | #define contptr(f) ((void *)(f)) |
855 | #define setcont(o, f) setlightudV((o), contptr(f)) | ||
852 | #endif | 856 | #endif |
853 | 857 | ||
854 | #define tvchecklive(L, o) \ | 858 | #define tvchecklive(L, o) \ |
diff --git a/src/lj_record.c b/src/lj_record.c index 306a85cb..8a72b0c9 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -882,12 +882,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) | |||
882 | static BCReg rec_mm_prep(jit_State *J, ASMFunction cont) | 882 | static BCReg rec_mm_prep(jit_State *J, ASMFunction cont) |
883 | { | 883 | { |
884 | BCReg s, top = cont == lj_cont_cat ? J->maxslot : curr_proto(J->L)->framesize; | 884 | BCReg s, top = cont == lj_cont_cat ? J->maxslot : curr_proto(J->L)->framesize; |
885 | #if LJ_64 | 885 | J->base[top] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT; |
886 | TRef trcont = lj_ir_kptr(J, (void *)((int64_t)cont-(int64_t)lj_vm_asm_begin)); | ||
887 | #else | ||
888 | TRef trcont = lj_ir_kptr(J, (void *)cont); | ||
889 | #endif | ||
890 | J->base[top] = trcont | TREF_CONT; | ||
891 | J->framedepth++; | 886 | J->framedepth++; |
892 | for (s = J->maxslot; s < top; s++) | 887 | for (s = J->maxslot; s < top; s++) |
893 | J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */ | 888 | J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */ |