Ensure forward progress on trace exit to BC_ITERN.

Also use a safer way to force a static dispatch for BC_RET*.
Reported by Bartel Eerdekens. Analyzed by Peter Cawley. #1000 #1045
This commit is contained in:
Mike Pall
2023-08-13 02:25:12 +02:00
parent 27af72e66f
commit 119fd1fab0
8 changed files with 146 additions and 35 deletions

View File

@@ -2196,8 +2196,8 @@ static void build_subroutines(BuildCtx *ctx)
|.if JIT
| ldr L, SAVE_L
|1:
| cmp CARG1, #0
| blt >9 // Check for error from exit.
| cmn CARG1, #LUA_ERRERR
| bhs >9 // Check for error from exit.
| lsl RC, CARG1, #3
| ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
| str RC, SAVE_MULTRES
@@ -2213,6 +2213,8 @@ static void build_subroutines(BuildCtx *ctx)
| ldr INS, [PC], #4
| lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
| st_vmstate CARG4
| cmn CARG1, #17 // Static dispatch?
| beq >5
| cmp OP, #BC_FUNCC+2 // Fast function?
| bhs >4
|2:
@@ -2238,6 +2240,17 @@ static void build_subroutines(BuildCtx *ctx)
| ldr KBASE, [CARG3, #PC2PROTO(k)]
| b <2
|
|5: // Dispatch to static entry of original ins replaced by BC_JLOOP.
| ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
| decode_RD RC, INS
| ldr TRACE:CARG1, [CARG1, RC, lsl #2]
| ldr INS, TRACE:CARG1->startins
| decode_OP OP, INS
| decode_RA8 RA, INS
| add OP, DISPATCH, OP, lsl #2
| decode_RD RC, INS
| ldr pc, [OP, #GG_DISP2STATIC]
|
|9: // Rethrow error from the right C frame.
| rsb CARG2, CARG1, #0
| mov CARG1, L