immunio 0.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +234 -0
- data/README.md +147 -0
- data/bin/immunio +5 -0
- data/lib/immunio.rb +29 -0
- data/lib/immunio/agent.rb +260 -0
- data/lib/immunio/authentication.rb +96 -0
- data/lib/immunio/blocked_app.rb +38 -0
- data/lib/immunio/channel.rb +432 -0
- data/lib/immunio/cli.rb +39 -0
- data/lib/immunio/context.rb +114 -0
- data/lib/immunio/errors.rb +43 -0
- data/lib/immunio/immunio_ca.crt +45 -0
- data/lib/immunio/logger.rb +87 -0
- data/lib/immunio/plugins/action_dispatch.rb +45 -0
- data/lib/immunio/plugins/action_view.rb +431 -0
- data/lib/immunio/plugins/active_record.rb +707 -0
- data/lib/immunio/plugins/active_record_relation.rb +370 -0
- data/lib/immunio/plugins/authlogic.rb +80 -0
- data/lib/immunio/plugins/csrf.rb +24 -0
- data/lib/immunio/plugins/devise.rb +40 -0
- data/lib/immunio/plugins/environment_reporter.rb +69 -0
- data/lib/immunio/plugins/eval.rb +51 -0
- data/lib/immunio/plugins/exception_handler.rb +55 -0
- data/lib/immunio/plugins/gems_tracker.rb +5 -0
- data/lib/immunio/plugins/haml.rb +36 -0
- data/lib/immunio/plugins/http_finisher.rb +50 -0
- data/lib/immunio/plugins/http_tracker.rb +203 -0
- data/lib/immunio/plugins/io.rb +96 -0
- data/lib/immunio/plugins/redirect.rb +42 -0
- data/lib/immunio/plugins/warden.rb +66 -0
- data/lib/immunio/processor.rb +234 -0
- data/lib/immunio/rails.rb +26 -0
- data/lib/immunio/request.rb +139 -0
- data/lib/immunio/rufus_lua_ext/ref.rb +27 -0
- data/lib/immunio/rufus_lua_ext/state.rb +157 -0
- data/lib/immunio/rufus_lua_ext/table.rb +137 -0
- data/lib/immunio/rufus_lua_ext/utils.rb +13 -0
- data/lib/immunio/version.rb +5 -0
- data/lib/immunio/vm.rb +291 -0
- data/lua-hooks/ext/all.c +78 -0
- data/lua-hooks/ext/bitop/README +22 -0
- data/lua-hooks/ext/bitop/bit.c +189 -0
- data/lua-hooks/ext/extconf.rb +38 -0
- data/lua-hooks/ext/libinjection/COPYING +37 -0
- data/lua-hooks/ext/libinjection/libinjection.h +65 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.c +847 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.h +54 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.c +2301 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.h +295 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +9349 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.c +531 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.h +21 -0
- data/lua-hooks/ext/libinjection/lualib.c +109 -0
- data/lua-hooks/ext/lpeg/HISTORY +90 -0
- data/lua-hooks/ext/lpeg/lpcap.c +537 -0
- data/lua-hooks/ext/lpeg/lpcap.h +43 -0
- data/lua-hooks/ext/lpeg/lpcode.c +986 -0
- data/lua-hooks/ext/lpeg/lpcode.h +34 -0
- data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
- data/lua-hooks/ext/lpeg/lpeg.html +1429 -0
- data/lua-hooks/ext/lpeg/lpprint.c +244 -0
- data/lua-hooks/ext/lpeg/lpprint.h +35 -0
- data/lua-hooks/ext/lpeg/lptree.c +1238 -0
- data/lua-hooks/ext/lpeg/lptree.h +77 -0
- data/lua-hooks/ext/lpeg/lptypes.h +149 -0
- data/lua-hooks/ext/lpeg/lpvm.c +355 -0
- data/lua-hooks/ext/lpeg/lpvm.h +58 -0
- data/lua-hooks/ext/lpeg/makefile +55 -0
- data/lua-hooks/ext/lpeg/re.html +498 -0
- data/lua-hooks/ext/lpeg/test.lua +1409 -0
- data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +45 -0
- data/lua-hooks/ext/lua-cmsgpack/README.md +115 -0
- data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +957 -0
- data/lua-hooks/ext/lua-cmsgpack/test.lua +570 -0
- data/lua-hooks/ext/lua-snapshot/LICENSE +7 -0
- data/lua-hooks/ext/lua-snapshot/Makefile +12 -0
- data/lua-hooks/ext/lua-snapshot/README.md +18 -0
- data/lua-hooks/ext/lua-snapshot/dump.lua +15 -0
- data/lua-hooks/ext/lua-snapshot/snapshot.c +455 -0
- data/lua-hooks/ext/lua/COPYRIGHT +34 -0
- data/lua-hooks/ext/lua/lapi.c +1087 -0
- data/lua-hooks/ext/lua/lapi.h +16 -0
- data/lua-hooks/ext/lua/lauxlib.c +652 -0
- data/lua-hooks/ext/lua/lauxlib.h +174 -0
- data/lua-hooks/ext/lua/lbaselib.c +659 -0
- data/lua-hooks/ext/lua/lcode.c +831 -0
- data/lua-hooks/ext/lua/lcode.h +76 -0
- data/lua-hooks/ext/lua/ldblib.c +398 -0
- data/lua-hooks/ext/lua/ldebug.c +638 -0
- data/lua-hooks/ext/lua/ldebug.h +33 -0
- data/lua-hooks/ext/lua/ldo.c +519 -0
- data/lua-hooks/ext/lua/ldo.h +57 -0
- data/lua-hooks/ext/lua/ldump.c +164 -0
- data/lua-hooks/ext/lua/lfunc.c +174 -0
- data/lua-hooks/ext/lua/lfunc.h +34 -0
- data/lua-hooks/ext/lua/lgc.c +710 -0
- data/lua-hooks/ext/lua/lgc.h +110 -0
- data/lua-hooks/ext/lua/linit.c +38 -0
- data/lua-hooks/ext/lua/liolib.c +556 -0
- data/lua-hooks/ext/lua/llex.c +463 -0
- data/lua-hooks/ext/lua/llex.h +81 -0
- data/lua-hooks/ext/lua/llimits.h +128 -0
- data/lua-hooks/ext/lua/lmathlib.c +263 -0
- data/lua-hooks/ext/lua/lmem.c +86 -0
- data/lua-hooks/ext/lua/lmem.h +49 -0
- data/lua-hooks/ext/lua/loadlib.c +705 -0
- data/lua-hooks/ext/lua/loadlib_rel.c +760 -0
- data/lua-hooks/ext/lua/lobject.c +214 -0
- data/lua-hooks/ext/lua/lobject.h +381 -0
- data/lua-hooks/ext/lua/lopcodes.c +102 -0
- data/lua-hooks/ext/lua/lopcodes.h +268 -0
- data/lua-hooks/ext/lua/loslib.c +243 -0
- data/lua-hooks/ext/lua/lparser.c +1339 -0
- data/lua-hooks/ext/lua/lparser.h +82 -0
- data/lua-hooks/ext/lua/lstate.c +214 -0
- data/lua-hooks/ext/lua/lstate.h +169 -0
- data/lua-hooks/ext/lua/lstring.c +111 -0
- data/lua-hooks/ext/lua/lstring.h +31 -0
- data/lua-hooks/ext/lua/lstrlib.c +871 -0
- data/lua-hooks/ext/lua/ltable.c +588 -0
- data/lua-hooks/ext/lua/ltable.h +40 -0
- data/lua-hooks/ext/lua/ltablib.c +287 -0
- data/lua-hooks/ext/lua/ltm.c +75 -0
- data/lua-hooks/ext/lua/ltm.h +54 -0
- data/lua-hooks/ext/lua/lua.c +392 -0
- data/lua-hooks/ext/lua/lua.def +131 -0
- data/lua-hooks/ext/lua/lua.h +388 -0
- data/lua-hooks/ext/lua/lua.rc +28 -0
- data/lua-hooks/ext/lua/lua_dll.rc +26 -0
- data/lua-hooks/ext/lua/luac.c +200 -0
- data/lua-hooks/ext/lua/luac.rc +1 -0
- data/lua-hooks/ext/lua/luaconf.h +763 -0
- data/lua-hooks/ext/lua/luaconf.h.in +724 -0
- data/lua-hooks/ext/lua/luaconf.h.orig +763 -0
- data/lua-hooks/ext/lua/lualib.h +53 -0
- data/lua-hooks/ext/lua/lundump.c +227 -0
- data/lua-hooks/ext/lua/lundump.h +36 -0
- data/lua-hooks/ext/lua/lvm.c +767 -0
- data/lua-hooks/ext/lua/lvm.h +36 -0
- data/lua-hooks/ext/lua/lzio.c +82 -0
- data/lua-hooks/ext/lua/lzio.h +67 -0
- data/lua-hooks/ext/lua/print.c +227 -0
- data/lua-hooks/ext/luautf8/README.md +152 -0
- data/lua-hooks/ext/luautf8/lutf8lib.c +1274 -0
- data/lua-hooks/ext/luautf8/unidata.h +3064 -0
- data/lua-hooks/lib/boot.lua +254 -0
- data/lua-hooks/lib/encode.lua +4 -0
- data/lua-hooks/lib/lexers/LICENSE +21 -0
- data/lua-hooks/lib/lexers/bash.lua +134 -0
- data/lua-hooks/lib/lexers/bash_dqstr.lua +62 -0
- data/lua-hooks/lib/lexers/css.lua +216 -0
- data/lua-hooks/lib/lexers/html.lua +106 -0
- data/lua-hooks/lib/lexers/javascript.lua +68 -0
- data/lua-hooks/lib/lexers/lexer.lua +1575 -0
- data/lua-hooks/lib/lexers/markers.lua +33 -0
- metadata +308 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
|
3
|
+
** Lua Parser
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lparser_h
|
8
|
+
#define lparser_h
|
9
|
+
|
10
|
+
#include "llimits.h"
|
11
|
+
#include "lobject.h"
|
12
|
+
#include "lzio.h"
|
13
|
+
|
14
|
+
|
15
|
+
/*
|
16
|
+
** Expression descriptor
|
17
|
+
*/
|
18
|
+
|
19
|
+
typedef enum {
|
20
|
+
VVOID, /* no value */
|
21
|
+
VNIL,
|
22
|
+
VTRUE,
|
23
|
+
VFALSE,
|
24
|
+
VK, /* info = index of constant in `k' */
|
25
|
+
VKNUM, /* nval = numerical value */
|
26
|
+
VLOCAL, /* info = local register */
|
27
|
+
VUPVAL, /* info = index of upvalue in `upvalues' */
|
28
|
+
VGLOBAL, /* info = index of table; aux = index of global name in `k' */
|
29
|
+
VINDEXED, /* info = table register; aux = index register (or `k') */
|
30
|
+
VJMP, /* info = instruction pc */
|
31
|
+
VRELOCABLE, /* info = instruction pc */
|
32
|
+
VNONRELOC, /* info = result register */
|
33
|
+
VCALL, /* info = instruction pc */
|
34
|
+
VVARARG /* info = instruction pc */
|
35
|
+
} expkind;
|
36
|
+
|
37
|
+
typedef struct expdesc {
|
38
|
+
expkind k;
|
39
|
+
union {
|
40
|
+
struct { int info, aux; } s;
|
41
|
+
lua_Number nval;
|
42
|
+
} u;
|
43
|
+
int t; /* patch list of `exit when true' */
|
44
|
+
int f; /* patch list of `exit when false' */
|
45
|
+
} expdesc;
|
46
|
+
|
47
|
+
|
48
|
+
typedef struct upvaldesc {
|
49
|
+
lu_byte k;
|
50
|
+
lu_byte info;
|
51
|
+
} upvaldesc;
|
52
|
+
|
53
|
+
|
54
|
+
struct BlockCnt; /* defined in lparser.c */
|
55
|
+
|
56
|
+
|
57
|
+
/* state needed to generate code for a given function */
|
58
|
+
typedef struct FuncState {
|
59
|
+
Proto *f; /* current function header */
|
60
|
+
Table *h; /* table to find (and reuse) elements in `k' */
|
61
|
+
struct FuncState *prev; /* enclosing function */
|
62
|
+
struct LexState *ls; /* lexical state */
|
63
|
+
struct lua_State *L; /* copy of the Lua state */
|
64
|
+
struct BlockCnt *bl; /* chain of current blocks */
|
65
|
+
int pc; /* next position to code (equivalent to `ncode') */
|
66
|
+
int lasttarget; /* `pc' of last `jump target' */
|
67
|
+
int jpc; /* list of pending jumps to `pc' */
|
68
|
+
int freereg; /* first free register */
|
69
|
+
int nk; /* number of elements in `k' */
|
70
|
+
int np; /* number of elements in `p' */
|
71
|
+
short nlocvars; /* number of elements in `locvars' */
|
72
|
+
lu_byte nactvar; /* number of active local variables */
|
73
|
+
upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
|
74
|
+
unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
|
75
|
+
} FuncState;
|
76
|
+
|
77
|
+
|
78
|
+
LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
79
|
+
const char *name);
|
80
|
+
|
81
|
+
|
82
|
+
#endif
|
@@ -0,0 +1,214 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
|
3
|
+
** Global State
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#include <stddef.h>
|
9
|
+
|
10
|
+
#define lstate_c
|
11
|
+
#define LUA_CORE
|
12
|
+
|
13
|
+
#include "lua.h"
|
14
|
+
|
15
|
+
#include "ldebug.h"
|
16
|
+
#include "ldo.h"
|
17
|
+
#include "lfunc.h"
|
18
|
+
#include "lgc.h"
|
19
|
+
#include "llex.h"
|
20
|
+
#include "lmem.h"
|
21
|
+
#include "lstate.h"
|
22
|
+
#include "lstring.h"
|
23
|
+
#include "ltable.h"
|
24
|
+
#include "ltm.h"
|
25
|
+
|
26
|
+
|
27
|
+
#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
|
28
|
+
#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
|
29
|
+
#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
|
30
|
+
|
31
|
+
|
32
|
+
/*
|
33
|
+
** Main thread combines a thread state and the global state
|
34
|
+
*/
|
35
|
+
typedef struct LG {
|
36
|
+
lua_State l;
|
37
|
+
global_State g;
|
38
|
+
} LG;
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
static void stack_init (lua_State *L1, lua_State *L) {
|
43
|
+
/* initialize CallInfo array */
|
44
|
+
L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
|
45
|
+
L1->ci = L1->base_ci;
|
46
|
+
L1->size_ci = BASIC_CI_SIZE;
|
47
|
+
L1->end_ci = L1->base_ci + L1->size_ci - 1;
|
48
|
+
/* initialize stack array */
|
49
|
+
L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
|
50
|
+
L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
|
51
|
+
L1->top = L1->stack;
|
52
|
+
L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
|
53
|
+
/* initialize first ci */
|
54
|
+
L1->ci->func = L1->top;
|
55
|
+
setnilvalue(L1->top++); /* `function' entry for this `ci' */
|
56
|
+
L1->base = L1->ci->base = L1->top;
|
57
|
+
L1->ci->top = L1->top + LUA_MINSTACK;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
static void freestack (lua_State *L, lua_State *L1) {
|
62
|
+
luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
|
63
|
+
luaM_freearray(L, L1->stack, L1->stacksize, TValue);
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
/*
|
68
|
+
** open parts that may cause memory-allocation errors
|
69
|
+
*/
|
70
|
+
static void f_luaopen (lua_State *L, void *ud) {
|
71
|
+
global_State *g = G(L);
|
72
|
+
UNUSED(ud);
|
73
|
+
stack_init(L, L); /* init stack */
|
74
|
+
sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
|
75
|
+
sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
|
76
|
+
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
|
77
|
+
luaT_init(L);
|
78
|
+
luaX_init(L);
|
79
|
+
luaS_fix(luaS_newliteral(L, MEMERRMSG));
|
80
|
+
g->GCthreshold = 4*g->totalbytes;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
static void preinit_state (lua_State *L, global_State *g) {
|
85
|
+
G(L) = g;
|
86
|
+
L->stack = NULL;
|
87
|
+
L->stacksize = 0;
|
88
|
+
L->errorJmp = NULL;
|
89
|
+
L->hook = NULL;
|
90
|
+
L->hookmask = 0;
|
91
|
+
L->basehookcount = 0;
|
92
|
+
L->allowhook = 1;
|
93
|
+
resethookcount(L);
|
94
|
+
L->openupval = NULL;
|
95
|
+
L->size_ci = 0;
|
96
|
+
L->nCcalls = L->baseCcalls = 0;
|
97
|
+
L->status = 0;
|
98
|
+
L->base_ci = L->ci = NULL;
|
99
|
+
L->savedpc = NULL;
|
100
|
+
L->errfunc = 0;
|
101
|
+
setnilvalue(gt(L));
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
static void close_state (lua_State *L) {
|
106
|
+
global_State *g = G(L);
|
107
|
+
luaF_close(L, L->stack); /* close all upvalues for this thread */
|
108
|
+
luaC_freeall(L); /* collect all objects */
|
109
|
+
lua_assert(g->rootgc == obj2gco(L));
|
110
|
+
lua_assert(g->strt.nuse == 0);
|
111
|
+
luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
|
112
|
+
luaZ_freebuffer(L, &g->buff);
|
113
|
+
freestack(L, L);
|
114
|
+
lua_assert(g->totalbytes == sizeof(LG));
|
115
|
+
(*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
lua_State *luaE_newthread (lua_State *L) {
|
120
|
+
lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
|
121
|
+
luaC_link(L, obj2gco(L1), LUA_TTHREAD);
|
122
|
+
preinit_state(L1, G(L));
|
123
|
+
stack_init(L1, L); /* init stack */
|
124
|
+
setobj2n(L, gt(L1), gt(L)); /* share table of globals */
|
125
|
+
L1->hookmask = L->hookmask;
|
126
|
+
L1->basehookcount = L->basehookcount;
|
127
|
+
L1->hook = L->hook;
|
128
|
+
resethookcount(L1);
|
129
|
+
lua_assert(iswhite(obj2gco(L1)));
|
130
|
+
return L1;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
void luaE_freethread (lua_State *L, lua_State *L1) {
|
135
|
+
luaF_close(L1, L1->stack); /* close all upvalues for this thread */
|
136
|
+
lua_assert(L1->openupval == NULL);
|
137
|
+
luai_userstatefree(L1);
|
138
|
+
freestack(L, L1);
|
139
|
+
luaM_freemem(L, fromstate(L1), state_size(lua_State));
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
144
|
+
int i;
|
145
|
+
lua_State *L;
|
146
|
+
global_State *g;
|
147
|
+
void *l = (*f)(ud, NULL, 0, state_size(LG));
|
148
|
+
if (l == NULL) return NULL;
|
149
|
+
L = tostate(l);
|
150
|
+
g = &((LG *)L)->g;
|
151
|
+
L->next = NULL;
|
152
|
+
L->tt = LUA_TTHREAD;
|
153
|
+
g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
|
154
|
+
L->marked = luaC_white(g);
|
155
|
+
set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
|
156
|
+
preinit_state(L, g);
|
157
|
+
g->frealloc = f;
|
158
|
+
g->ud = ud;
|
159
|
+
g->mainthread = L;
|
160
|
+
g->uvhead.u.l.prev = &g->uvhead;
|
161
|
+
g->uvhead.u.l.next = &g->uvhead;
|
162
|
+
g->GCthreshold = 0; /* mark it as unfinished state */
|
163
|
+
g->strt.size = 0;
|
164
|
+
g->strt.nuse = 0;
|
165
|
+
g->strt.hash = NULL;
|
166
|
+
setnilvalue(registry(L));
|
167
|
+
luaZ_initbuffer(L, &g->buff);
|
168
|
+
g->panic = NULL;
|
169
|
+
g->gcstate = GCSpause;
|
170
|
+
g->rootgc = obj2gco(L);
|
171
|
+
g->sweepstrgc = 0;
|
172
|
+
g->sweepgc = &g->rootgc;
|
173
|
+
g->gray = NULL;
|
174
|
+
g->grayagain = NULL;
|
175
|
+
g->weak = NULL;
|
176
|
+
g->tmudata = NULL;
|
177
|
+
g->totalbytes = sizeof(LG);
|
178
|
+
g->gcpause = LUAI_GCPAUSE;
|
179
|
+
g->gcstepmul = LUAI_GCMUL;
|
180
|
+
g->gcdept = 0;
|
181
|
+
for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
|
182
|
+
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
|
183
|
+
/* memory allocation error: free partial state */
|
184
|
+
close_state(L);
|
185
|
+
L = NULL;
|
186
|
+
}
|
187
|
+
else
|
188
|
+
luai_userstateopen(L);
|
189
|
+
return L;
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
static void callallgcTM (lua_State *L, void *ud) {
|
194
|
+
UNUSED(ud);
|
195
|
+
luaC_callGCTM(L); /* call GC metamethods for all udata */
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
LUA_API void lua_close (lua_State *L) {
|
200
|
+
L = G(L)->mainthread; /* only the main thread can be closed */
|
201
|
+
lua_lock(L);
|
202
|
+
luaF_close(L, L->stack); /* close all upvalues for this thread */
|
203
|
+
luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
|
204
|
+
L->errfunc = 0; /* no error function during GC metamethods */
|
205
|
+
do { /* repeat until no more errors */
|
206
|
+
L->ci = L->base_ci;
|
207
|
+
L->base = L->top = L->ci->base;
|
208
|
+
L->nCcalls = L->baseCcalls = 0;
|
209
|
+
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
|
210
|
+
lua_assert(G(L)->tmudata == NULL);
|
211
|
+
luai_userstateclose(L);
|
212
|
+
close_state(L);
|
213
|
+
}
|
214
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
|
3
|
+
** Global State
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lstate_h
|
8
|
+
#define lstate_h
|
9
|
+
|
10
|
+
#include "lua.h"
|
11
|
+
|
12
|
+
#include "lobject.h"
|
13
|
+
#include "ltm.h"
|
14
|
+
#include "lzio.h"
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
struct lua_longjmp; /* defined in ldo.c */
|
19
|
+
|
20
|
+
|
21
|
+
/* table of globals */
|
22
|
+
#define gt(L) (&L->l_gt)
|
23
|
+
|
24
|
+
/* registry */
|
25
|
+
#define registry(L) (&G(L)->l_registry)
|
26
|
+
|
27
|
+
|
28
|
+
/* extra stack space to handle TM calls and some other extras */
|
29
|
+
#define EXTRA_STACK 5
|
30
|
+
|
31
|
+
|
32
|
+
#define BASIC_CI_SIZE 8
|
33
|
+
|
34
|
+
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
typedef struct stringtable {
|
39
|
+
GCObject **hash;
|
40
|
+
lu_int32 nuse; /* number of elements */
|
41
|
+
int size;
|
42
|
+
} stringtable;
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
** informations about a call
|
47
|
+
*/
|
48
|
+
typedef struct CallInfo {
|
49
|
+
StkId base; /* base for this function */
|
50
|
+
StkId func; /* function index in the stack */
|
51
|
+
StkId top; /* top for this function */
|
52
|
+
const Instruction *savedpc;
|
53
|
+
int nresults; /* expected number of results from this function */
|
54
|
+
int tailcalls; /* number of tail calls lost under this entry */
|
55
|
+
} CallInfo;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
#define curr_func(L) (clvalue(L->ci->func))
|
60
|
+
#define ci_func(ci) (clvalue((ci)->func))
|
61
|
+
#define f_isLua(ci) (!ci_func(ci)->c.isC)
|
62
|
+
#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
|
63
|
+
|
64
|
+
|
65
|
+
/*
|
66
|
+
** `global state', shared by all threads of this state
|
67
|
+
*/
|
68
|
+
typedef struct global_State {
|
69
|
+
stringtable strt; /* hash table for strings */
|
70
|
+
lua_Alloc frealloc; /* function to reallocate memory */
|
71
|
+
void *ud; /* auxiliary data to `frealloc' */
|
72
|
+
lu_byte currentwhite;
|
73
|
+
lu_byte gcstate; /* state of garbage collector */
|
74
|
+
int sweepstrgc; /* position of sweep in `strt' */
|
75
|
+
GCObject *rootgc; /* list of all collectable objects */
|
76
|
+
GCObject **sweepgc; /* position of sweep in `rootgc' */
|
77
|
+
GCObject *gray; /* list of gray objects */
|
78
|
+
GCObject *grayagain; /* list of objects to be traversed atomically */
|
79
|
+
GCObject *weak; /* list of weak tables (to be cleared) */
|
80
|
+
GCObject *tmudata; /* last element of list of userdata to be GC */
|
81
|
+
Mbuffer buff; /* temporary buffer for string concatentation */
|
82
|
+
lu_mem GCthreshold;
|
83
|
+
lu_mem totalbytes; /* number of bytes currently allocated */
|
84
|
+
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
85
|
+
lu_mem gcdept; /* how much GC is `behind schedule' */
|
86
|
+
int gcpause; /* size of pause between successive GCs */
|
87
|
+
int gcstepmul; /* GC `granularity' */
|
88
|
+
lua_CFunction panic; /* to be called in unprotected errors */
|
89
|
+
TValue l_registry;
|
90
|
+
struct lua_State *mainthread;
|
91
|
+
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
92
|
+
struct Table *mt[NUM_TAGS]; /* metatables for basic types */
|
93
|
+
TString *tmname[TM_N]; /* array with tag-method names */
|
94
|
+
} global_State;
|
95
|
+
|
96
|
+
|
97
|
+
/*
|
98
|
+
** `per thread' state
|
99
|
+
*/
|
100
|
+
struct lua_State {
|
101
|
+
CommonHeader;
|
102
|
+
lu_byte status;
|
103
|
+
StkId top; /* first free slot in the stack */
|
104
|
+
StkId base; /* base of current function */
|
105
|
+
global_State *l_G;
|
106
|
+
CallInfo *ci; /* call info for current function */
|
107
|
+
const Instruction *savedpc; /* `savedpc' of current function */
|
108
|
+
StkId stack_last; /* last free slot in the stack */
|
109
|
+
StkId stack; /* stack base */
|
110
|
+
CallInfo *end_ci; /* points after end of ci array*/
|
111
|
+
CallInfo *base_ci; /* array of CallInfo's */
|
112
|
+
int stacksize;
|
113
|
+
int size_ci; /* size of array `base_ci' */
|
114
|
+
unsigned short nCcalls; /* number of nested C calls */
|
115
|
+
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
|
116
|
+
lu_byte hookmask;
|
117
|
+
lu_byte allowhook;
|
118
|
+
int basehookcount;
|
119
|
+
int hookcount;
|
120
|
+
lua_Hook hook;
|
121
|
+
TValue l_gt; /* table of globals */
|
122
|
+
TValue env; /* temporary place for environments */
|
123
|
+
GCObject *openupval; /* list of open upvalues in this stack */
|
124
|
+
GCObject *gclist;
|
125
|
+
struct lua_longjmp *errorJmp; /* current error recover point */
|
126
|
+
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
127
|
+
};
|
128
|
+
|
129
|
+
|
130
|
+
#define G(L) (L->l_G)
|
131
|
+
|
132
|
+
|
133
|
+
/*
|
134
|
+
** Union of all collectable objects
|
135
|
+
*/
|
136
|
+
union GCObject {
|
137
|
+
GCheader gch;
|
138
|
+
union TString ts;
|
139
|
+
union Udata u;
|
140
|
+
union Closure cl;
|
141
|
+
struct Table h;
|
142
|
+
struct Proto p;
|
143
|
+
struct UpVal uv;
|
144
|
+
struct lua_State th; /* thread */
|
145
|
+
};
|
146
|
+
|
147
|
+
|
148
|
+
/* macros to convert a GCObject into a specific value */
|
149
|
+
#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
|
150
|
+
#define gco2ts(o) (&rawgco2ts(o)->tsv)
|
151
|
+
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
|
152
|
+
#define gco2u(o) (&rawgco2u(o)->uv)
|
153
|
+
#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
|
154
|
+
#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
|
155
|
+
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
|
156
|
+
#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
157
|
+
#define ngcotouv(o) \
|
158
|
+
check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
159
|
+
#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
|
160
|
+
|
161
|
+
/* macro to convert any Lua object into a GCObject */
|
162
|
+
#define obj2gco(v) (cast(GCObject *, (v)))
|
163
|
+
|
164
|
+
|
165
|
+
LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
|
166
|
+
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
167
|
+
|
168
|
+
#endif
|
169
|
+
|