Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	Kirill Yukhin <kyukhin@tarantool.org>
Subject: [tarantool-patches] [PATCH 1/2] bugfix: fixed a segfault when unsinking 64-bit pointers.
Date: Thu, 23 May 2019 20:48:24 +0300	[thread overview]
Message-ID: <20190523174824.GF11013@uranus> (raw)
In-Reply-To: <20190523174634.32314-1-gorcunov@gmail.com>

From: Thibault Charbonnier <thibaultcha@me.com>

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 <lukego@gmail.com>
---
 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

  reply	other threads:[~2019-05-23 17:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 17:46 [tarantool-patches] [PATCH 0/2] luajit2: " Cyrill Gorcunov
2019-05-23 17:48 ` Cyrill Gorcunov [this message]
2019-05-23 17:49 ` [tarantool-patches] [PATCH 2/2] test/luajit-tap: Add unsink_64_kptr.test.lua Cyrill Gorcunov
2019-05-23 17:50 ` [tarantool-patches] Re: [PATCH 0/2] luajit2: bugfix: fixed a segfault when unsinking 64-bit pointers Cyrill Gorcunov
2019-05-24 17:38 ` Alexander Turenko
2019-05-24 20:39   ` Cyrill Gorcunov
2019-05-27  7:12 ` Alexander Turenko
2019-05-28  2:02 ` Kirill Yukhin
2019-05-28 12:01   ` Alexander Turenko
2019-05-28 12:11     ` Cyrill Gorcunov
2019-05-28 12:14       ` Alexander Turenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190523174824.GF11013@uranus \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 1/2] bugfix: fixed a segfault when unsinking 64-bit pointers.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox