Skip to content

Commit 1672bdc

Browse files
Mike Pallkyukhin
authored andcommitted
x64: Fix __call metamethod return dispatch.
After linking new cframe to the chain KBASEa still stores the address of the previous one. If the execution proceeds to <lj_vmeta_call> KBASE value (i.e. low 32 bits of the stored address) might be equal to the current BASE address value so the execution takes the invalid path. Such address parts clashing occurs only on x86_64 platform with disabled LJ_GC64, so 64-bit registers have to be compared in x64 build. NB: Though there is only 32-bit load to restore BASE value prior to the comparison, the high 32 bits of RDX are reset to zeros, according to x86 long mode semantics. Igor Munkin: * backported the original patch to tarantool/luajit repo * extended the original commit message with the rationale For more info and explanation see LuaJIT#636. Relates to tarantool/tarantool#4518 Relates to tarantool/tarantool#4649 Reviewed-by: Sergey Kaplun <[email protected]> Reviewed-by: Sergey Ostanevich <[email protected]> Signed-off-by: Igor Munkin <[email protected]>
1 parent 8fc103f commit 1672bdc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/vm_x86.dasc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,11 @@ static void build_subroutines(BuildCtx *ctx)
13741374
| mov LFUNC:RB, [RA-8]
13751375
| add NARGS:RD, 1
13761376
| // This is fragile. L->base must not move, KBASE must always be defined.
1377+
|.if x64
1378+
| cmp KBASEa, rdx // Continue with CALLT if flag set.
1379+
|.else
13771380
| cmp KBASE, BASE // Continue with CALLT if flag set.
1381+
|.endif
13781382
| je ->BC_CALLT_Z
13791383
| mov BASE, RA
13801384
| ins_call // Otherwise call resolved metamethod.

0 commit comments

Comments
 (0)