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 B3942C242C1; Fri, 16 Feb 2024 14:11:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B3942C242C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1708081918; bh=GD90NYs/s5BxLcQbUKOrKGlqArRINsGxWTAyKIr844E=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ju1zYbY5/byveqi4chdoHBzXabgHiRiHvnYW57s7spgo9Im2ceZNyiGvStv/NwtQ7 uJY6IG5jue908oG2NXyN7WJolK8MBkjMVTC7BlXc3XgsCzTCTdfMp/4G5odQnBzibD 4vKdboDpYGi1GbaUm6JOgAxAwgoGD2003+L7b83M= Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 D3BD7C242D9 for ; Fri, 16 Feb 2024 14:11:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D3BD7C242D9 Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5118290fcd8so2298787e87.3 for ; Fri, 16 Feb 2024 03:11:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708081916; x=1708686716; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h4LzDPjvTj3YG3vQ4sRKbhj0htnpFNRKWlH4QRqqljQ=; b=v+5X0duwD7rIjPfTfdlTt+EXZtA3F03JiL68ea4deVltURw1DjoLTugQ4elCB3zIw6 Ad7HPnU3pR0hIroK/4y2tVlPXmjM7F1HhL4h76TBCy/MmpXAhB92JbuaM6gWs4ig+/3J wRsGhmNiHyyQc4aegtEZ4oRXRafaYyx+C7P9Vqp80WJd5isT79HtyknrSsSvmSsWAizW WrDPpcIhuWvn4FpDlR2ICzRQ125Q2VDgw/LqRXyhTYL/k6vU5A7DHjEM6ZqV4cmVGsLk X1hkXaHJEVvF7K7LomrBmV5NaygTJNsrMjl1QvlCB9Rx5t7s0Arj2g3MYqKm3uef8s8n lOWQ== X-Gm-Message-State: AOJu0YwjW45YsgzGFAl4JVEeuIapdo1F6yLuHebj1utn+b00fpX5C6JV l5HJgP69n5zxMHD+1JPVCQQvMvLZSrqfaGAoDdjl56jLnzcGVQVPyizW48UA X-Google-Smtp-Source: AGHT+IHK9cs6BIO3RocJyu6fciREJskqonVOndlzQAqIDl+3+3crJTH1VO7heqJlBQdq/O41xtTdwQ== X-Received: by 2002:a05:6512:202f:b0:511:79ce:8a01 with SMTP id s15-20020a056512202f00b0051179ce8a01mr2645172lfs.46.1708081915388; Fri, 16 Feb 2024 03:11:55 -0800 (PST) Received: from localhost.localdomain (95-24-0-113.broadband.corbina.ru. [95.24.0.113]) by smtp.gmail.com with ESMTPSA id eq6-20020a056512488600b005115a9cc9a8sm576602lfb.191.2024.02.16.03.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 03:11:54 -0800 (PST) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Date: Fri, 16 Feb 2024 14:11:47 +0300 Message-ID: <20240216111152.152025-1-m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit] Throw any errors before stack changes in trace stitching. 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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Thanks to doujiang24. (cherry-picked from commit 3f9389edc6cdf3f78a6896d550c236860aed62b2) The Lua stack is changed in the `lj_record_stop`, so if the trace is aborted, for example, when the `maxsnap` is reached, and an error is thrown from there, the execution continues with an unbalanced stack. Since the only error that is thrown from the `lj_record_stop` with modified stack is `LJ_TRERR_SNAPOV`, this patch adds a check for snapshot overflow to the `recff_stitch`. Maxim Kokryashkin: * added the description and the test for the problem Part of tarantool/tarantool#9595 --- Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-pr-720-errors-before-stitch PR: https://github.com/tarantool/tarantool/pull/9703 Issues: https://github.com/tarantool/tarantool/issues/9595 https://github.com/LuaJIT/LuaJIT/pull/720 src/lj_ffrecord.c | 4 ++++ .../lj-pr-720-errors-before-stitch.test.lua | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 1b2ddb72..e3ed80fb 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -107,6 +107,10 @@ static void recff_stitch(jit_State *J) const BCIns *pc = frame_pc(base-1); TValue *pframe = frame_prevl(base-1); + /* Check for this now. Throwing in lj_record_stop messes up the stack. */ + if (J->cur.nsnap >= (MSize)J->param[JIT_P_maxsnap]) + lj_trace_err(J, LJ_TRERR_SNAPOV); + /* Move func + args up in Lua stack and insert continuation. */ memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot); setframe_ftsz(nframe, ((char *)nframe - (char *)pframe) + FRAME_CONT); diff --git a/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua b/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua new file mode 100644 index 00000000..53b7b5ea --- /dev/null +++ b/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua @@ -0,0 +1,20 @@ +local tap = require('tap') +local test = tap.test('lj-pr-720-errors-before-stitch'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) +test:plan(1) + +-- `math.modf` recording is NYI. +local modf = require('math').modf +jit.opt.start('hotloop=1', 'maxsnap=1') + +-- The loop has only two iterations: the first to detect its +-- hotness and the second to record it. The snapshot limit is +-- set to one and is certainly reached. +for _ = 1, 2 do + -- Forcify stitch. + modf(1.2) +end + +test:ok(true, 'stack is balanced') +test:done(true) -- 2.43.0