From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4F99A4BCFB6; Thu, 22 Jun 2023 17:34:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F99A4BCFB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1687444479; bh=VrW9AYqdxcKwCAxtgOmy5pbcAK+EmySxn0uEnHrXLBM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QoQPPGggAMARNXdS3Qvhmrb/ay/SZXrpLcgdahWB1/jbrg0B8OE+GI7LExAtVnlJs z4yy2AI31KqXcwFL+w/jPP1zuN35LDgmTuDfHcg2qcolkpsz+EscDJ73cWOOnNM+LB e6wIkQJQdagA1YQ4HN/YJrH6InmFmfOU4qUJarAk= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2E6C64BCFB6 for ; Thu, 22 Jun 2023 17:33:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2E6C64BCFB6 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1qCLNT-00053t-KV; Thu, 22 Jun 2023 17:33:40 +0300 To: Igor Munkin , Maxim Kokryashkin Date: Thu, 22 Jun 2023 17:29:19 +0300 Message-Id: <840ae735734b3b0074bb43659c7fb21f54664114.1687439049.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9C3255D34B386091E664FD7FA93D7B6BF6662C23C5EC5C6B6182A05F5380850404C228DA9ACA6FE27D27E0D9D5CEBC08F763266E3008214E02D02560F19F8ED7A2BCAD24D4AAAD5A4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72E4E5201E1C2E308EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375080A183704825A98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81A704BF0B38F57EBC662AB968B5F4181117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520C24E1E72F37C03A0C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5F366B29BDDD039A471B531DF90B25EEB94910A28F3200924F87CCE6106E1FC07E67D4AC08A07B9B0CE135D2742255B359C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFF72D1096A89CBF23E7FDA5D319BAA8C64A3266335666183EE080468F11AC1F7ABF40353A1B84A450B05B57073EAFDF97E4D10BA4877919AC143A79A7BD06D202A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojB41c+mu8Ac/aMomTr8HP4A== X-DA7885C5: C5DAE8714BF458FB6B43AC959B5F25397AC05CEB40BD53F23DD3BBFF1084A6C1262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BF329398C3C70BA3765BE1A67DD9A4DA20FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/2] Another fix for lua_yield() from C hook. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Reported by Jason Carr. (cherry picked from commit dd0f09f95f36caf1f2111c10fec02748116003bb) This commit is the follow up for the previous commit ("Fix lua_yield() from C hook."). In GC64 mode stack slot for a GC thread object is still miscalculated during creating a continuation frame for `lua_yield()`. This happens due to tricky usage of the previous slot instead of the given one in `setframe_gc()` macro. This patch changes the semantics of `setframe_gc()` macro to use the given as argument slot as the destination to store GC value. Also, it fixups all usages of this macro to match new semantics. Sergey Kaplun: * added the description for the problem Part of tarantool/tarantool#8516 --- src/lj_ccallback.c | 2 +- src/lj_err.c | 2 +- src/lj_frame.h | 2 +- src/lj_meta.c | 2 +- test/tarantool-c-tests/fix-yield-c-hook.test.c | 4 ---- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c index 9158c2d3..224b6b94 100644 --- a/src/lj_ccallback.c +++ b/src/lj_ccallback.c @@ -533,13 +533,13 @@ static void callback_conv_args(CTState *cts, lua_State *L) if (LJ_FR2) { (o++)->u64 = LJ_CONT_FFI_CALLBACK; (o++)->u64 = rid; - o++; } else { o->u32.lo = LJ_CONT_FFI_CALLBACK; o->u32.hi = rid; o++; } setframe_gc(o, obj2gco(fn), fntp); + if (LJ_FR2) o++; setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT); L->top = L->base = ++o; if (!ct) diff --git a/src/lj_err.c b/src/lj_err.c index d0223384..c400a9ba 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -707,9 +707,9 @@ LJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o) const BCIns *pc = cframe_Lpc(L); if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) { const char *tname = lj_typename(o); + setframe_gc(o, obj2gco(L), LJ_TTHREAD); if (LJ_FR2) o++; setframe_pc(o, pc); - setframe_gc(o, obj2gco(L), LJ_TTHREAD); L->top = L->base = o+1; err_msgv(L, LJ_ERR_BADCALL, tname); } diff --git a/src/lj_frame.h b/src/lj_frame.h index 1e4adaa3..2bdf3c48 100644 --- a/src/lj_frame.h +++ b/src/lj_frame.h @@ -46,7 +46,7 @@ enum { #define frame_gc(f) (gcval((f)-1)) #define frame_ftsz(f) ((ptrdiff_t)(f)->ftsz) #define frame_pc(f) ((const BCIns *)frame_ftsz(f)) -#define setframe_gc(f, p, tp) (setgcVraw((f)-1, (p), (tp))) +#define setframe_gc(f, p, tp) (setgcVraw((f), (p), (tp))) #define setframe_ftsz(f, sz) ((f)->ftsz = (sz)) #define setframe_pc(f, pc) ((f)->ftsz = (int64_t)(intptr_t)(pc)) #else diff --git a/src/lj_meta.c b/src/lj_meta.c index 0bd4d842..7ef7a8e0 100644 --- a/src/lj_meta.c +++ b/src/lj_meta.c @@ -86,8 +86,8 @@ int lj_meta_tailcall(lua_State *L, cTValue *tv) else top->u32.lo = LJ_CONT_TAILCALL; setframe_pc(top++, pc); - if (LJ_FR2) top++; setframe_gc(top, obj2gco(L), LJ_TTHREAD); /* Dummy frame object. */ + if (LJ_FR2) top++; setframe_ftsz(top, ((char *)(top+1) - (char *)base) + FRAME_CONT); L->base = L->top = top+1; /* diff --git a/test/tarantool-c-tests/fix-yield-c-hook.test.c b/test/tarantool-c-tests/fix-yield-c-hook.test.c index 9068360e..b84cdc7e 100644 --- a/test/tarantool-c-tests/fix-yield-c-hook.test.c +++ b/test/tarantool-c-tests/fix-yield-c-hook.test.c @@ -22,10 +22,6 @@ static void yield(lua_State *L, lua_Debug *ar) lua_yield(L, 0); } -/* - * XXX: This test still leads to core dump in the GC64 mode. - * This will be fixed in the next commit. - */ static int yield_in_c_hook(void *test_state) { lua_State *L = test_state; -- 2.34.1