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 9756B903D40; Tue, 19 Dec 2023 14:57:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9756B903D40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1702987060; bh=O26PSQvzRUGXJFUTRHTQgB6gYVU4mYNLthWE1IS1+a4=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=TnlKubJa+aX2fkyrgfV6G9Wkab4KweKCZ0uTiiEs6BuPnCvW/VkRuPmqktF3mLM5B zfwYz1ZB2JgjT8u12jlZOU9QImnhD9xSHU3hRHtQjdUP6GbKO08lOnhjcp05rfcPg1 eerArfhgLi9ooYSlZ8Me6jgktSjtFo0afMBGAXVc= Received: from smtp35.i.mail.ru (smtp35.i.mail.ru [95.163.41.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 51881903D47 for ; Tue, 19 Dec 2023 14:57:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 51881903D47 Received: by smtp35.i.mail.ru with esmtpa (envelope-from ) id 1rFYjC-00FLRZ-0o; Tue, 19 Dec 2023 14:57:38 +0300 Message-ID: <361b3825-a883-4c17-acfa-f6f5b93693f2@tarantool.org> Date: Tue, 19 Dec 2023 14:57:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org, skaplun@tarantool.org References: <20231214114458.17929-1-m.kokryashkin@tarantool.org> In-Reply-To: <20231214114458.17929-1-m.kokryashkin@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97533543916A0F71A84F3C54A5E5B8DE1EEF7405543D6F01ACD62213F67905E7A7EF239642406D3698CCC39E7252723340C63F29370CD1AE547EEACAE9851930B X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77D3344F2D0C9F5BEEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378AE39DF5D4445BD38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D86C1F92E1610EE0060034D66C606B40BF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EECCD848CCB6FE560CC0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C33CCD70CEBBF18A2276E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C224936DA1BED736F9328E827F84554CEF50127C277FBC8AE2E8B8C7ADC89C2F0B2A5AAAE862A0553A39223F8577A6DFFEA7CDB14762BE8BDFCF043847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A536E888603C0C9C4D8E9BFD9DA4EB7BF9CAE5EE17E875C088F87CCE6106E1FC07E67D4AC08A07B9B062B3BD3CC35DA588CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFBAA7D3038525A794F9334561772FCDD726139699829E9F562A77F9D83D639F54FD9AF20B71F72F3AE190DC598EAEA94F08831142A492198ED19329A0827B3097E48CAC7CA610320002C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojgGTRFEPoGBTocrYjkULJlg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769D6E6D642A54468301E80F99E398F9D0738066306E4938E9FEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Avoid assertion in case of stack overflow from stitched trace. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Max! thanks for the patch! LGTM after addressing comments by Sergey. Sergey > won't be as long as the mentioned error is raised. Because of > that, we get the incorrect bytecode instruction in > `debug_framepc`. This patch fixes this behavior, so the > `debug_framepc` now returns `NO_BCPOS` for this case. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-913-avoid-assertion-stkov-from-stitched-trace > PR: https://github.com/tarantool/tarantool/pull/9484 > Issues: https://github.com/tarantool/tarantool/issues/9145 > https://github.com/LuaJIT/LuaJIT/issues/913 > > src/lj_debug.c | 9 +++++--- > ...-913-stackoverflow-stitched-trace.test.lua | 23 +++++++++++++++++++ > 2 files changed, 29 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > > diff --git a/src/lj_debug.c b/src/lj_debug.c > index 46c442c6..107f464c 100644 > --- a/src/lj_debug.c > +++ b/src/lj_debug.c > @@ -101,9 +101,12 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe) > pos = proto_bcpos(pt, ins) - 1; > #if LJ_HASJIT > if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */ > - GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); > - lj_assertL(bc_isret(bc_op(ins[-1])), "return bytecode expected"); > - pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); > + if (bc_isret(bc_op(ins[-1]))) { > + GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins)); > + pos = proto_bcpos(pt, mref(T->startpc, const BCIns)); > + } else { > + pos = NO_BCPOS; /* Punt in case of stack overflow for stitched trace. */ > + } > } > #endif > return pos; > diff --git a/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua b/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > new file mode 100644 > index 00000000..3c12f0d9 > --- /dev/null > +++ b/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > @@ -0,0 +1,23 @@ > +local tap = require('tap') > +-- Test to demonstrate the incorrect LuaJIT behavior when exiting > +-- from a snapshot for stitched trace. > +local test = tap.test('lj-913-stackoverflow-stitched-trace'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(3) > + > +-- Recursion to cause stack overflow. > +local function callee() > + -- `math.fmod()` is NYI, so trace will be stitched here. > + local _ = math.fmod(42, 42) > + callee() > +end > + > +local st, err = pcall(callee) > + > +test:ok(true, 'assertion is not triggered') > +test:ok(not st, 'error happened') > +test:like(err, 'stack overflow', 'stack overflow happened') > + > +test:done(true) > -- > 2.43.0 >