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 452486ECE3; Tue, 23 Nov 2021 15:58:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 452486ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1637672305; bh=fN/2wD62ynkAhGmWQPJ9qs7NAQD2YsobbAKqcgNGC6g=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=kYL8RrgLfxja4h55zbSKn3FYBfX4XyIM3zONaopWJdjOC2mX3UM+tgm/y8uYrNps9 7Fl4tbpfEnnWPGR2IPLWbAuY+YOdfeBucXnkAlF0IGQckU3tIDj22JRyD+/rBy7wwb BVLCZSPyeaQUD5rXMIFQCoTkhsgFc/sNEa5/tu3U= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 970C76ECE3 for ; Tue, 23 Nov 2021 15:58:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 970C76ECE3 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mpVNA-0006Jc-Hk; Tue, 23 Nov 2021 15:58:09 +0300 Date: Tue, 23 Nov 2021 15:57:38 +0300 To: Sergey Kaplun Message-ID: References: <20211119164157.18344-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211119164157.18344-1-skaplun@tarantool.org> X-Clacks-Overhead: GNU Terry Pratchett X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9FE0487E502468146A248A7B8B31062F80ED88F6A42059E94182A05F5380850407FFFCFE64BD198198619390715095E94B6FEF051F36F58BAB19C94D39C4317AE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78887611F2F2455C9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637D84D274D72FCF47F8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84420786DB47A9F40E6876AC2556665EF117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6753C3A5E0A5AB5B7089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A52C32CFAE315816D4D5B1B56F4CB4966900B4697AD8F846B8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759F66ED85EB5F25FD410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3467D08F30473A5842F15A03014642F660557DEEB9419573E8ED08579EC57F1BB8796704F633F8ED8D1D7E09C32AA3244C850B3C1B633E4784101854BE123DB2D7259227199D06760A927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojutWt0++zX5Qv/4BBkjOaLA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC8493D68A99BA8AA99F326B1025ADB54A7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v2] Fix frame traversal for __gc handler frames. 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, Thanks for the fixes! LGTM, with a tiny nit. On 19.11.21, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Changochen. > > (cherry picked from 53f82e6e2e858a0a62fd1a2ff47e9866693382e6) > > A cframe unwinding is missed for a C protected frame during a search for > an error function to handle a runtime error. It leads to undefined > behaviour or crash, when raising a runtime error on stack with the CP > frame before an error function handler (for example, an error in __gc > handler). > > This patch adds missing unwinding for CP frame. > > Sergey Kaplun: > * added the description and the test for the problem > --- > > LuaJIT issue: https://github.com/LuaJIT/LuaJIT/issues/601 > Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-fix-gc-finderrfunc > Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-fix-gc-finderrfunc > > Changes in v2: > * Create CP and C stack manually in LuaC > > src/lj_err.c | 1 + > test/tarantool-tests/CMakeLists.txt | 1 + > .../lj-601-fix-gc-finderrfunc.test.lua | 35 ++++++++++++ > .../lj-601-fix-gc-finderrfunc/CMakeLists.txt | 1 + > .../lj-601-fix-gc-finderrfunc/mixcframe.c | 55 +++++++++++++++++++ > 5 files changed, 93 insertions(+) > create mode 100644 test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > create mode 100644 test/tarantool-tests/lj-601-fix-gc-finderrfunc/CMakeLists.txt > create mode 100644 test/tarantool-tests/lj-601-fix-gc-finderrfunc/mixcframe.c > > diff --git a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > new file mode 100644 > index 00000000..d4c44489 > --- /dev/null > +++ b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > @@ -0,0 +1,35 @@ > +local a = newproxy(true) > +getmetatable(a).__gc = function() > + -- Function to raise error via `lj_err_run()` inside __gc. > + error('raise error in __gc') > +end > +-- luacheck: no unused > +a = nil > + > +-- We need to get the following Lua stack format when raise an > +-- error: > +-- + L->stack > +-- | ... > +-- | CP -- any C protected frame. > +-- | ...[L/LP/V]... > +-- | C -- any C frame. > +-- | ...[L/LP/V]... > +-- | CP (with inherited errfunc) -- __gc frame. > +-- V > +-- Enter in the C to call CP func. Call `lua_gc()` inside. Minor: I'd adjust this comment the following way: | -- Enter in the C land to call a function in a protected C frame | -- (CP). Spoil host stack (and ergo cframe area) and later call | -- Lua C function, triggering full GC cycle in a non-protected | -- frame. As a result, error is raised in __gc metamethod above. Fixed, squashed, force-pushed to the branch. Diff is below: ================================================================================ diff --git a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua index d4c44489..2122c7a0 100644 --- a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua +++ b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua @@ -29,7 +29,10 @@ a = nil -- | ...[L/LP/V]... -- | CP (with inherited errfunc) -- __gc frame. -- V --- Enter in the C to call CP func. Call `lua_gc()` inside. +-- Enter in the C land to call a function in a protected C frame +-- (CP). Spoil host stack (and ergo cframe area) and later call +-- Lua C function, triggering full GC cycle in a non-protected +-- frame. As a result, error is raised in __gc metamethod above. test:ok(mixcframe.test_handle_err(), 'error in __gc is successfully handled') os.exit(test:check() and 0 or 1) ================================================================================ > +test:ok(mixcframe.test_handle_err(), 'error in __gc is successfully handled') > + > +os.exit(test:check() and 0 or 1) > -- > 2.31.0 > -- Best regards, IM