From: Maxim Kokryashkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Subject: [Tarantool-patches] [PATCH luajit v4 3/3] Follow-up fix for stack overflow handling cleanup. Date: Thu, 1 Feb 2024 14:24:48 +0300 [thread overview] Message-ID: <59254cf9772988cdc98bc97ff639c22cad065bc9.1706786622.git.m.kokryashkin@tarantool.org> (raw) In-Reply-To: <cover.1706786622.git.m.kokryashkin@tarantool.org> From: Mike Pall <mike> (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
next prev parent reply other threads:[~2024-02-01 11:26 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-01 11:24 [Tarantool-patches] [PATCH luajit v4 0/3] Improve error reporting on stack overflow Maxim Kokryashkin via Tarantool-patches 2024-02-01 11:24 ` [Tarantool-patches] [PATCH luajit v4 1/3] " Maxim Kokryashkin via Tarantool-patches 2024-02-01 11:24 ` [Tarantool-patches] [PATCH luajit v4 2/3] Cleanup stack overflow handling Maxim Kokryashkin via Tarantool-patches 2024-02-01 11:24 ` Maxim Kokryashkin via Tarantool-patches [this message] 2024-02-01 14:11 ` [Tarantool-patches] [PATCH luajit v4 0/3] Improve error reporting on stack overflow Sergey Bronnikov via Tarantool-patches 2024-02-01 15:07 ` Sergey Kaplun via Tarantool-patches 2024-02-15 13:40 ` Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=59254cf9772988cdc98bc97ff639c22cad065bc9.1706786622.git.m.kokryashkin@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=max.kokryashkin@gmail.com \ --cc=sergeyb@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit v4 3/3] Follow-up fix for stack overflow handling cleanup.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox