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 49F25A022EA; Thu, 1 Feb 2024 14:26:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 49F25A022EA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706786790; bh=j/ZW99AJRT6hLujGyViIr0rdHmVN9ehjKhNJMaT+2Kw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Ga/trXSYDSnHNQXNuVifohnXaP6+jJtfoBF2aVkoJ7fKDOuB8/fyIugKIjlPrGt4O f4V8F35Zpy9DwQvprg11uPt2znN1eW4PdtYTv5VkKLKBAisJD3ejfvRc8W7NRUVw/L dpalXd9ndcqVMqeksOZEK/v9+FNHCcVkFMTVLWws= Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 DFD49A022EC for ; Thu, 1 Feb 2024 14:25:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DFD49A022EC Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d04c0b1cacso10656421fa.0 for ; Thu, 01 Feb 2024 03:25:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706786706; x=1707391506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sjTOZspKBDsLuQrUjTZll6vZrgEPzxKcc5X5pMHETyw=; b=M+AlIr98RdpTggCQEL4GZJM1TIJQbYgWciWBg7wewD9Bgq0tX6JUJySStDIcfYLC3T 6MkoCNWfQZRo6lnKY+Dz3RQNI/+aufqjKAv+44PW6JzQYO8Nb3aesK7O/56OdpuV1Uuc BrrlzW/IalatXDddD1YJjHfdw9eAt/1EIdZO8Hyqi+KUQK5jeG2Gq8qcw6KkqZNdiZ9B 3PuqXk7JLbV0YdnSt8wv9C/FWS6Xuq4qNvoStVkXDPTDjP7fifOAmSD4fk3W8WvIAPbS JzlK4V+AUUk1woMBpDDZMceQ7P7lZpPO6DMqzk6uWmcL/8F+6E0at96tOnc/LNz29LXd YIMQ== X-Gm-Message-State: AOJu0YwZoyAyI9tWrWYw4EsH6YGJbHsp9lZkFKfaqOcdvKRF2HD7ZqDk Kw9YTmBGypuZK6pRR5wVTZsMdfBRxjX2SN62+EEAJO1TdlSvG9x1T4RFTxwi X-Google-Smtp-Source: AGHT+IGs/HvoktaO5twl9LsiUHXxoZw1zAUJN4/cmZZQQ5/0PyHUpXB9MpVAvKw0w26Wz6L6VSOerA== X-Received: by 2002:a2e:8781:0:b0:2d0:603b:6b13 with SMTP id n1-20020a2e8781000000b002d0603b6b13mr2829827lji.11.1706786705933; Thu, 01 Feb 2024 03:25:05 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXIuw7B69AZ8Jnk5zUKwRc3Jfeero1i2xzUUxVbfpb6toID0ew+iPdN/GgrwKLI9t2GvxG7+VATBmKETxYwGomTQ69zzKcpFKzQPLrq/YYRoeqUIRzKFCue/Kbi0w== Received: from localhost.localdomain (95-24-0-113.broadband.corbina.ru. [95.24.0.113]) by smtp.gmail.com with ESMTPSA id z9-20020a2e3509000000b002cdf37ee19dsm2372647ljz.7.2024.02.01.03.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 03:25:05 -0800 (PST) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Date: Thu, 1 Feb 2024 14:24:48 +0300 Message-ID: <59254cf9772988cdc98bc97ff639c22cad065bc9.1706786622.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v4 3/3] Follow-up fix for stack overflow handling cleanup. 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 (cherry-picked from commit aa6b15c1a8922848bd6f596ba384824ca3fe0f5f) The stack overflow error is thrown in `lj_state_growstack` only if the coroutine status is `OK`, however, stack overflow can happen on a yielded coroutine too. This patch fixes the condition for status, so now the error thrown on yielded coroutines too. Maxim Kokryashkin: * added the description and the test for the patch Part of tarantool/tarantool#9145 --- src/lj_state.c | 2 +- .../lj-962-premature-stack-overflow.test.c | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/lj_state.c b/src/lj_state.c index d8a5134c..01d4901a 100644 --- a/src/lj_state.c +++ b/src/lj_state.c @@ -126,7 +126,7 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) if (L->stacksize > LJ_STACK_MAXEX) lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */ /* 1. We are _at_ the limit after the last growth. */ - if (!L->status) { /* 2. Throw 'stack overflow'. */ + if (L->status < LUA_ERRRUN) { /* 2. Throw 'stack overflow'. */ L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */ lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */ } diff --git a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c index 12cb9004..3b006805 100644 --- a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c +++ b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c @@ -7,7 +7,9 @@ /* * XXX: The "lj_obj.h" header is included to calculate the * number of stack slots used from the bottom of the stack. + * XXX: The "lj_arch.h" header is included for the skipcond. */ +#include "lj_arch.h" #include "lj_obj.h" static int cur_slots = -1; @@ -24,6 +26,22 @@ static int fill_stack(lua_State *L) return 0; } +#if !LJ_NO_UNWIND +static int immediate_yield(lua_State *L) +{ + return lua_yield(L, 0); +} + +static int overflow_suspended_coro(lua_State *L) +{ + lua_State *newL = lua_newthread(L); + lua_pushcfunction(newL, immediate_yield); + lua_resume(newL, 0); + fill_stack(newL); + return 0; +} +#endif + static int premature_stackoverflow(void *test_state) { lua_State *L = test_state; @@ -50,12 +68,26 @@ static int stackoverflow_during_stackoverflow(void *test_state) return TEST_EXIT_SUCCESS; } +static int stackoverflow_on_suspended_coro(void *test_state) +{ +#if LJ_NO_UNWIND + UNUSED(test_state); + return skip("Internal unwinding can't catch this exception"); +#else + lua_State *L = test_state; + int status = lua_cpcall(L, overflow_suspended_coro, NULL); + assert_true(status == LUA_ERRRUN); + return TEST_EXIT_SUCCESS; +#endif +} + int main(void) { lua_State *L = utils_lua_init(); const struct test_unit tgroup[] = { test_unit_def(premature_stackoverflow), test_unit_def(stackoverflow_during_stackoverflow), + test_unit_def(stackoverflow_on_suspended_coro), }; const int test_result = test_run_group(tgroup, L); utils_lua_close(L); -- 2.43.0