Skip to content

Commit

Permalink
bugfix: fixed a segfault when unsinking 64-bit pointers.
Browse files Browse the repository at this point in the history
The unsinking code was not using the correct layout for GC64 IR
constants (value in adjacent slot) for this case.

This patch is a derivative of
raptorjit/raptorjit#246 ported for LuaJIT
itself.

Fixed after an intense debugging session with @lukego.

Co-authored-by: Luke Gorrie <lukego@gmail.com>
  • Loading branch information
thibaultcha and lukego committed Mar 28, 2019
1 parent dc13446 commit 83c82b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/lj_ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,19 @@ typedef union IRIns {
TValue tv; /* TValue constant (overlaps entire slot). */
} IRIns;

#define ir_isk64(ir) ((ir)->o == IR_KNUM || (ir)->o == IR_KINT64 || \
(LJ_GC64 && \
((ir)->o == IR_KGC || \
(ir)->o == IR_KPTR || (ir)->o == IR_KKPTR)))

#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)[LJ_GC64].gcr))
#define ir_kstr(ir) (gco2str(ir_kgc((ir))))
#define ir_ktab(ir) (gco2tab(ir_kgc((ir))))
#define ir_kfunc(ir) (gco2func(ir_kgc((ir))))
#define ir_kcdata(ir) (gco2cd(ir_kgc((ir))))
#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, &(ir)[1].tv)
#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, &(ir)[1].tv)
#define ir_k64(ir) \
check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64 || \
(LJ_GC64 && \
((ir)->o == IR_KGC || \
(ir)->o == IR_KPTR || (ir)->o == IR_KKPTR)), \
&(ir)[1].tv)
#define ir_k64(ir) check_exp(ir_isk64(ir), &(ir)[1].tv)
#define ir_kptr(ir) \
check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, \
mref((ir)[LJ_GC64].ptr, void))
Expand Down
2 changes: 1 addition & 1 deletion src/lj_snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ static void snap_restoredata(GCtrace *T, ExitState *ex,
int32_t *src;
uint64_t tmp;
if (irref_isk(ref)) {
if (ir->o == IR_KNUM || ir->o == IR_KINT64) {
if (ir_isk64(ir)) {
src = (int32_t *)&ir[1];
} else if (sz == 8) {
tmp = (uint64_t)(uint32_t)ir->i;
Expand Down

0 comments on commit 83c82b5

Please sign in to comment.