From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id CE4C32FB3A for ; Thu, 23 May 2019 13:48:27 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Hc8mwiy768l3 for ; Thu, 23 May 2019 13:48:27 -0400 (EDT) Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 8101D2FB1C for ; Thu, 23 May 2019 13:48:27 -0400 (EDT) Received: by mail-lf1-f66.google.com with SMTP id f1so5031520lfl.6 for ; Thu, 23 May 2019 10:48:27 -0700 (PDT) Date: Thu, 23 May 2019 20:48:24 +0300 From: Cyrill Gorcunov Subject: [tarantool-patches] [PATCH 1/2] bugfix: fixed a segfault when unsinking 64-bit pointers. Message-ID: <20190523174824.GF11013@uranus> References: <20190523174634.32314-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190523174634.32314-1-gorcunov@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tml Cc: Alexander Turenko , Kirill Yukhin From: Thibault Charbonnier 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 https://github.com/raptorjit/raptorjit/pull/246 ported for LuaJIT itself. Fixed after an intense debugging session with @lukego. Co-authored-by: Luke Gorrie --- src/lj_ir.h | 12 ++++++------ src/lj_snap.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lj_ir.h b/src/lj_ir.h index 34c2785..3059bf6 100644 --- a/src/lj_ir.h +++ b/src/lj_ir.h @@ -560,6 +560,11 @@ 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)))) @@ -567,12 +572,7 @@ typedef union IRIns { #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)) diff --git a/src/lj_snap.c b/src/lj_snap.c index 18ce715..7554caf 100644 --- a/src/lj_snap.c +++ b/src/lj_snap.c @@ -685,7 +685,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; -- 2.20.1