Skip to content

Commit

Permalink
Update cur_L on exceptional path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mejedi committed Jun 8, 2016
1 parent cb9d08a commit ed412cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm_x64.dasc
Expand Up @@ -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
|
Expand Down Expand Up @@ -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.
|
Expand Down
2 changes: 2 additions & 0 deletions src/vm_x86.dasc
Expand Up @@ -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
|
Expand Down Expand Up @@ -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.
|
Expand Down

0 comments on commit ed412cd

Please sign in to comment.