diff options
author | Mike Pall <mike> | 2013-08-28 13:06:19 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-08-30 23:38:17 +0200 |
commit | 517500ba48a290699d5a2ec7465bf76a5109c49f (patch) | |
tree | b780b0919bd2b79db462d0f392158d4b1ee6339c /src/vm_x86.dasc | |
parent | 5120240b77e4544b9b7405b4849a6cc63cdbbe1e (diff) | |
download | luajit-517500ba48a290699d5a2ec7465bf76a5109c49f.tar.gz luajit-517500ba48a290699d5a2ec7465bf76a5109c49f.tar.bz2 luajit-517500ba48a290699d5a2ec7465bf76a5109c49f.zip |
Save currently executing lua_State in g->cur_L.
This is only a good approximation due to deficiencies in the design of
the Lua/C API. It indicates _some_ valid state that is/was executing.
Also reorder L->cframe stores to achieve a synchronously consistent state.
Diffstat (limited to '')
-rw-r--r-- | src/vm_x86.dasc | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index b8f1c449..7fe891b1 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc | |||
@@ -630,17 +630,18 @@ static void build_subroutines(BuildCtx *ctx) | |||
630 | | lea KBASEa, [esp+CFRAME_RESUME] | 630 | | lea KBASEa, [esp+CFRAME_RESUME] |
631 | | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. | 631 | | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. |
632 | | add DISPATCH, GG_G2DISP | 632 | | add DISPATCH, GG_G2DISP |
633 | | mov L:RB->cframe, KBASEa | ||
634 | | mov SAVE_PC, RD // Any value outside of bytecode is ok. | 633 | | mov SAVE_PC, RD // Any value outside of bytecode is ok. |
635 | | mov SAVE_CFRAME, RDa | 634 | | mov SAVE_CFRAME, RDa |
636 | |.if X64 | 635 | |.if X64 |
637 | | mov SAVE_NRES, RD | 636 | | mov SAVE_NRES, RD |
638 | | mov SAVE_ERRF, RD | 637 | | mov SAVE_ERRF, RD |
639 | |.endif | 638 | |.endif |
639 | | mov L:RB->cframe, KBASEa | ||
640 | | cmp byte L:RB->status, RDL | 640 | | cmp byte L:RB->status, RDL |
641 | | je >3 // Initial resume (like a call). | 641 | | je >2 // Initial resume (like a call). |
642 | | | 642 | | |
643 | | // Resume after yield (like a return). | 643 | | // Resume after yield (like a return). |
644 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | ||
644 | | set_vmstate INTERP | 645 | | set_vmstate INTERP |
645 | | mov byte L:RB->status, RDL | 646 | | mov byte L:RB->status, RDL |
646 | | mov BASE, L:RB->base | 647 | | mov BASE, L:RB->base |
@@ -680,20 +681,19 @@ static void build_subroutines(BuildCtx *ctx) | |||
680 | | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! | 681 | | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME! |
681 | |.endif | 682 | |.endif |
682 | | | 683 | | |
684 | | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. | ||
683 | | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. | 685 | | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. |
684 | | mov SAVE_CFRAME, KBASEa | 686 | | mov SAVE_CFRAME, KBASEa |
685 | | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. | 687 | | mov SAVE_PC, L:RB // Any value outside of bytecode is ok. |
688 | | add DISPATCH, GG_G2DISP | ||
686 | |.if X64 | 689 | |.if X64 |
687 | | mov L:RB->cframe, rsp | 690 | | mov L:RB->cframe, rsp |
688 | |.else | 691 | |.else |
689 | | mov L:RB->cframe, esp | 692 | | mov L:RB->cframe, esp |
690 | |.endif | 693 | |.endif |
691 | | | 694 | | |
692 | |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype). | 695 | |2: // Entry point for vm_resume/vm_cpcall (RA = base, RB = L, PC = ftype). |
693 | | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. | 696 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB |
694 | | add DISPATCH, GG_G2DISP | ||
695 | | | ||
696 | |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype). | ||
697 | | set_vmstate INTERP | 697 | | set_vmstate INTERP |
698 | | mov BASE, L:RB->base // BASE = old base (used in vmeta_call). | 698 | | mov BASE, L:RB->base // BASE = old base (used in vmeta_call). |
699 | | add PC, RA | 699 | | add PC, RA |
@@ -731,14 +731,17 @@ static void build_subroutines(BuildCtx *ctx) | |||
731 | | | 731 | | |
732 | | mov KBASE, L:RB->stack // Compute -savestack(L, L->top). | 732 | | mov KBASE, L:RB->stack // Compute -savestack(L, L->top). |
733 | | sub KBASE, L:RB->top | 733 | | sub KBASE, L:RB->top |
734 | | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table. | ||
734 | | mov SAVE_ERRF, 0 // No error function. | 735 | | mov SAVE_ERRF, 0 // No error function. |
735 | | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame. | 736 | | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame. |
737 | | add DISPATCH, GG_G2DISP | ||
736 | | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe). | 738 | | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe). |
737 | | | 739 | | |
738 | |.if X64 | 740 | |.if X64 |
739 | | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. | 741 | | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain. |
740 | | mov SAVE_CFRAME, KBASEa | 742 | | mov SAVE_CFRAME, KBASEa |
741 | | mov L:RB->cframe, rsp | 743 | | mov L:RB->cframe, rsp |
744 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | ||
742 | | | 745 | | |
743 | | call CARG4 // (lua_State *L, lua_CFunction func, void *ud) | 746 | | call CARG4 // (lua_State *L, lua_CFunction func, void *ud) |
744 | |.else | 747 | |.else |
@@ -749,6 +752,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
749 | | mov KBASE, L:RB->cframe // Add our C frame to cframe chain. | 752 | | mov KBASE, L:RB->cframe // Add our C frame to cframe chain. |
750 | | mov SAVE_CFRAME, KBASE | 753 | | mov SAVE_CFRAME, KBASE |
751 | | mov L:RB->cframe, esp | 754 | | mov L:RB->cframe, esp |
755 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | ||
752 | | | 756 | | |
753 | | call BASE // (lua_State *L, lua_CFunction func, void *ud) | 757 | | call BASE // (lua_State *L, lua_CFunction func, void *ud) |
754 | |.endif | 758 | |.endif |
@@ -1840,7 +1844,6 @@ static void build_subroutines(BuildCtx *ctx) | |||
1840 | | mov ARG3, RA | 1844 | | mov ARG3, RA |
1841 | |.endif | 1845 | |.endif |
1842 | | call ->vm_resume // (lua_State *L, TValue *base, 0, 0) | 1846 | | call ->vm_resume // (lua_State *L, TValue *base, 0, 0) |
1843 | | set_vmstate INTERP | ||
1844 | | | 1847 | | |
1845 | | mov L:RB, SAVE_L | 1848 | | mov L:RB, SAVE_L |
1846 | |.if X64 | 1849 | |.if X64 |
@@ -1849,6 +1852,9 @@ static void build_subroutines(BuildCtx *ctx) | |||
1849 | | mov L:PC, ARG1 // The callee doesn't modify SAVE_L. | 1852 | | mov L:PC, ARG1 // The callee doesn't modify SAVE_L. |
1850 | |.endif | 1853 | |.endif |
1851 | | mov BASE, L:RB->base | 1854 | | mov BASE, L:RB->base |
1855 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | ||
1856 | | set_vmstate INTERP | ||
1857 | | | ||
1852 | | cmp eax, LUA_YIELD | 1858 | | cmp eax, LUA_YIELD |
1853 | | ja >8 | 1859 | | ja >8 |
1854 | |4: | 1860 | |4: |
@@ -2705,7 +2711,7 @@ static void build_subroutines(BuildCtx *ctx) | |||
2705 | | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0 | 2711 | | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0 |
2706 | |.endif | 2712 | |.endif |
2707 | | // Caveat: RB is ebp. | 2713 | | // Caveat: RB is ebp. |
2708 | | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)] | 2714 | | mov L:RB, [DISPATCH+DISPATCH_GL(cur_L)] |
2709 | | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)] | 2715 | | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)] |
2710 | | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa | 2716 | | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa |
2711 | | mov L:RB->base, BASE | 2717 | | mov L:RB->base, BASE |
@@ -5382,7 +5388,6 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
5382 | | mov RDa, TRACE:RD->mcode | 5388 | | mov RDa, TRACE:RD->mcode |
5383 | | mov L:RB, SAVE_L | 5389 | | mov L:RB, SAVE_L |
5384 | | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE | 5390 | | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE |
5385 | | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB | ||
5386 | | mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB | 5391 | | mov [DISPATCH+DISPATCH_GL(tmpbuf.L)], L:RB |
5387 | | // Save additional callee-save registers only used in compiled code. | 5392 | | // Save additional callee-save registers only used in compiled code. |
5388 | |.if X64WIN | 5393 | |.if X64WIN |
@@ -5550,9 +5555,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | |||
5550 | | // (lua_State *L, lua_CFunction f) | 5555 | | // (lua_State *L, lua_CFunction f) |
5551 | | call aword [DISPATCH+DISPATCH_GL(wrapf)] | 5556 | | call aword [DISPATCH+DISPATCH_GL(wrapf)] |
5552 | } | 5557 | } |
5553 | | set_vmstate INTERP | ||
5554 | | // nresults returned in eax (RD). | 5558 | | // nresults returned in eax (RD). |
5555 | | mov BASE, L:RB->base | 5559 | | mov BASE, L:RB->base |
5560 | | mov [DISPATCH+DISPATCH_GL(cur_L)], L:RB | ||
5561 | | set_vmstate INTERP | ||
5556 | | lea RA, [BASE+RD*8] | 5562 | | lea RA, [BASE+RD*8] |
5557 | | neg RA | 5563 | | neg RA |
5558 | | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8 | 5564 | | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8 |