Tarantool development patches archive
 help / color / mirror / Atom feed
From: Evgeniy Temirgaleev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] Fix external C call stack check when using LUAJIT_MODE_WRAPCFUNC.
Date: Tue, 24 Nov 2026 18:25:56 +0300	[thread overview]
Message-ID: <219da3c3-27e6-4433-aaac-6c70bd48af01@tarantool.org> (raw)
In-Reply-To: <20261123070910.1354298-1-skaplun@tarantool.org>

Hi, Sergey! Thanks for the patch! LGTM

On 11/23/26 10:09 AM, Sergey Kaplun wrote:
> From: Mike Pall <mike>
> 
> Thanks to Peter Cawley.
> 
> (cherry picked from commit 14e2917e7ab3d6f043d6604298bfa66470c6f47d)
> 
> Enabling and disabling wrapped C function mode [1] unconditionally
> changes the bytecode to `BC_FUCC[W] 0 0`. The first operand (RA) is
> unused for x86/x64 VMs, but other VMs use it like the minimum available
> stack slots required for the function call (`LUA_MINSTACK` by default on
> VM startup). Hence, these bytecode rewriting lead to the different
> timing of the STACKOV error being raised (before the call or during the
> invocation of the C function).
> 
> This patch makes the behaviour consistent across VMs by modifying only
> the opcode without changing its operands. Hence the `LUA_MINSTACK`
> value of the first operand is preserved.
> 
> [1]: https://luajit.org/ext_c_api.html#mode_wrapcfunc
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Part of tarantool/tarantool#13442
> ---
> 
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1047-fix-funccw-arm64
> Related issues:
> * https://github.com/LuaJIT/LuaJIT/issues/1047
> * https://github.com/tarantool/tarantool/issues/13442
> 
> Side note: CI on macOS x86_64 is red due to runner issues.
> 
>   src/lj_dispatch.c                             |   4 +-
>   .../lj-1047-fix-funccw-arm64.test.c           | 105 ++++++++++++++++++
>   2 files changed, 107 insertions(+), 2 deletions(-)
>   create mode 100644 test/tarantool-c-tests/lj-1047-fix-funccw-arm64.test.c
> 
> diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c
> index e5f876b1..f16e00c6 100644
> --- a/src/lj_dispatch.c
> +++ b/src/lj_dispatch.c
> @@ -307,9 +307,9 @@ int luaJIT_setmode(lua_State *L, int idx, int mode)
>         } else {
>   	return 0;  /* Failed. */
>         }
> -      g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0);
> +      setbc_op(&g->bc_cfunc_ext, BC_FUNCCW);
>       } else {
> -      g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0);
> +      setbc_op(&g->bc_cfunc_ext, BC_FUNCC);
>       }
>       break;
>     default:
> diff --git a/test/tarantool-c-tests/lj-1047-fix-funccw-arm64.test.c b/test/tarantool-c-tests/lj-1047-fix-funccw-arm64.test.c
> new file mode 100644
> index 00000000..0c9b8794
> --- /dev/null
> +++ b/test/tarantool-c-tests/lj-1047-fix-funccw-arm64.test.c
<snipped>
--
Best regards,
Evgeniy Temirgaleev


      parent reply	other threads:[~2026-11-24 15:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  7:09 Sergey Kaplun via Tarantool-patches
2026-11-23 15:17 ` Sergey Bronnikov via Tarantool-patches
2026-11-24  7:49   ` Sergey Kaplun via Tarantool-patches
2026-11-24 15:25 ` Evgeniy Temirgaleev via Tarantool-patches [this message]

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=219da3c3-27e6-4433-aaac-6c70bd48af01@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=e.temirgaleev@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit] Fix external C call stack check when using LUAJIT_MODE_WRAPCFUNC.' \
    /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