From ed412cd9f55fe87fd32a69c86e1732690fc5c1b0 Mon Sep 17 00:00:00 2001 From: Nick Zavaritsky Date: Wed, 8 Jun 2016 12:33:54 +0300 Subject: [PATCH] Update cur_L on exceptional path LuaJIT tracks the active state (cur_L pointer in global_State). Fiber switching may render cur_L incorrect; may result in different states sharing the stack and changing values from under each other. Cur_L was properly updated on return from Lua-C function (BC_FUNCCC). Update cur_L when a function raises an error. --- src/vm_x64.dasc | 2 ++ src/vm_x86.dasc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc index 759e30ec0b..89f66654fa 100644 --- a/src/vm_x64.dasc +++ b/src/vm_x64.dasc @@ -492,6 +492,7 @@ static void build_subroutines(BuildCtx *ctx) |->vm_unwind_c_eh: // Landing pad for external unwinder. | mov L:RB, SAVE_L | mov GL:RB, L:RB->glref + | mov [GL:RB->cur_L], L:RB | mov dword GL:RB->vmstate, ~LJ_VMST_C | jmp ->vm_leave_unw | @@ -519,6 +520,7 @@ static void build_subroutines(BuildCtx *ctx) | mov [BASE-16], RA // Prepend false to error message. | mov [BASE-8], RB | mov RA, -16 // Results start at BASE+RA = BASE-16. + | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | set_vmstate INTERP | jmp ->vm_returnc // Increments RD/MULTRES and returns. | diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index f108c0b567..ac4121b8d4 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -558,6 +558,7 @@ static void build_subroutines(BuildCtx *ctx) |->vm_unwind_c_eh: // Landing pad for external unwinder. | mov L:RB, SAVE_L | mov GL:RB, L:RB->glref + | mov dword GL:RB->cur_L, L:RB | mov dword GL:RB->vmstate, ~LJ_VMST_C | jmp ->vm_leave_unw | @@ -587,6 +588,7 @@ static void build_subroutines(BuildCtx *ctx) | add DISPATCH, GG_G2DISP | mov PC, [BASE-4] // Fetch PC of previous frame. | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message. + | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | set_vmstate INTERP | jmp ->vm_returnc // Increments RD/MULTRES and returns. |