diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-28 16:45:15 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-28 16:45:15 -0300 |
| commit | 69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34 (patch) | |
| tree | d9505d7a0e89940c55ff0a1fd3c13311b9084197 /lvm.c | |
| parent | 6b6bc532a4f5e335540e6f19914cfe8435d064ed (diff) | |
| download | lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.tar.gz lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.tar.bz2 lua-69dd9461e5aeb98fe9bbc71f1e81859d03ec8a34.zip | |
bug: GC metamethod calls could mess C/Lua stack syncronization
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 23 |
1 files changed, 17 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.277 2003/02/27 11:52:30 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.278 2003/02/27 12:33:07 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -393,15 +393,21 @@ static void Arith (lua_State *L, StkId ra, | |||
| 393 | #define dojump(pc, i) ((pc) += (i)) | 393 | #define dojump(pc, i) ((pc) += (i)) |
| 394 | 394 | ||
| 395 | 395 | ||
| 396 | unsigned int count = 0; | ||
| 397 | |||
| 396 | StkId luaV_execute (lua_State *L) { | 398 | StkId luaV_execute (lua_State *L) { |
| 397 | LClosure *cl; | 399 | LClosure *cl; |
| 398 | TObject *k; | 400 | TObject *k; |
| 399 | const Instruction *pc; | 401 | const Instruction *pc; |
| 402 | unsigned int ii, ic, ir, io; | ||
| 403 | ii = count; | ||
| 400 | callentry: /* entry point when calling new functions */ | 404 | callentry: /* entry point when calling new functions */ |
| 405 | ic = count; | ||
| 401 | L->ci->u.l.pc = &pc; | 406 | L->ci->u.l.pc = &pc; |
| 402 | if (L->hookmask & LUA_MASKCALL) | 407 | if (L->hookmask & LUA_MASKCALL) |
| 403 | luaD_callhook(L, LUA_HOOKCALL, -1); | 408 | luaD_callhook(L, LUA_HOOKCALL, -1); |
| 404 | retentry: /* entry point when returning to old functions */ | 409 | retentry: /* entry point when returning to old functions */ |
| 410 | ir = count; | ||
| 405 | lua_assert(L->ci->state == CI_SAVEDPC || | 411 | lua_assert(L->ci->state == CI_SAVEDPC || |
| 406 | L->ci->state == (CI_SAVEDPC | CI_CALLING)); | 412 | L->ci->state == (CI_SAVEDPC | CI_CALLING)); |
| 407 | L->ci->state = CI_HASFRAME; /* activate frame */ | 413 | L->ci->state = CI_HASFRAME; /* activate frame */ |
| @@ -412,6 +418,7 @@ StkId luaV_execute (lua_State *L) { | |||
| 412 | for (;;) { | 418 | for (;;) { |
| 413 | const Instruction i = *pc++; | 419 | const Instruction i = *pc++; |
| 414 | StkId base, ra; | 420 | StkId base, ra; |
| 421 | count++; | ||
| 415 | if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && | 422 | if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && |
| 416 | (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { | 423 | (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) { |
| 417 | traceexec(L); | 424 | traceexec(L); |
| @@ -658,20 +665,24 @@ StkId luaV_execute (lua_State *L) { | |||
| 658 | break; | 665 | break; |
| 659 | } | 666 | } |
| 660 | case OP_RETURN: { | 667 | case OP_RETURN: { |
| 661 | CallInfo *ci = L->ci - 1; | 668 | CallInfo *ci = L->ci - 1; /* previous function frame */ |
| 662 | int b = GETARG_B(i); | 669 | int b = GETARG_B(i); |
| 670 | io = count; | ||
| 663 | if (b != 0) L->top = ra+b-1; | 671 | if (b != 0) L->top = ra+b-1; |
| 664 | lua_assert(L->ci->state & CI_HASFRAME); | 672 | lua_assert(L->ci->state & CI_HASFRAME); |
| 665 | if (L->openupval) luaF_close(L, base); | 673 | if (L->openupval) luaF_close(L, base); |
| 666 | L->ci->state = CI_SAVEDPC; /* deactivate current function */ | 674 | L->ci->state = CI_SAVEDPC; /* deactivate current function */ |
| 667 | L->ci->u.l.savedpc = pc; | 675 | L->ci->u.l.savedpc = pc; |
| 668 | /* previous function was running `here'? */ | 676 | /* previous function was running `here'? */ |
| 669 | if (!(ci->state & CI_CALLING)) | 677 | if (!(ci->state & CI_CALLING)) { |
| 678 | lua_assert((ci->state & CI_C) || ci->u.l.pc != &pc); | ||
| 670 | return ra; /* no: return */ | 679 | return ra; /* no: return */ |
| 671 | else { /* yes: continue its execution (go through) */ | 680 | } |
| 681 | else { /* yes: continue its execution */ | ||
| 672 | int nresults; | 682 | int nresults; |
| 673 | lua_assert(ttisfunction(ci->base - 1)); | 683 | lua_assert(ci->u.l.pc == &pc && |
| 674 | lua_assert(ci->state & CI_SAVEDPC); | 684 | ttisfunction(ci->base - 1) && |
| 685 | (ci->state & CI_SAVEDPC)); | ||
| 675 | lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL); | 686 | lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL); |
| 676 | nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1; | 687 | nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1; |
| 677 | luaD_poscall(L, nresults, ra); | 688 | luaD_poscall(L, nresults, ra); |
