1 | /* |
2 | ** VM event handling. |
3 | ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h |
4 | */ |
5 | |
6 | #ifndef _LJ_VMEVENT_H |
7 | #define _LJ_VMEVENT_H |
8 | |
9 | #include "lj_obj.h" |
10 | |
11 | /* Registry key for VM event handler table. */ |
12 | #define LJ_VMEVENTS_REGKEY "_VMEVENTS" |
13 | #define LJ_VMEVENTS_HSIZE 4 |
14 | |
15 | #define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7)) |
16 | #define VMEVENT_HASH(ev) ((int)(ev) & ~7) |
17 | #define VMEVENT_HASHIDX(h) ((int)(h) << 3) |
18 | #define VMEVENT_NOCACHE 255 |
19 | |
20 | #define VMEVENT_DEF(name, hash) \ |
21 | LJ_VMEVENT_##name##_, \ |
22 | LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3) |
23 | |
24 | /* VM event IDs. */ |
25 | typedef enum { |
26 | VMEVENT_DEF(BC, 0x00003883), |
27 | VMEVENT_DEF(TRACE, 0xb2d91467), |
28 | VMEVENT_DEF(RECORD, 0x9284bf4f), |
29 | VMEVENT_DEF(TEXIT, 0xb29df2b0), |
30 | LJ_VMEVENT__MAX |
31 | } VMEvent; |
32 | |
33 | #ifdef LUAJIT_DISABLE_VMEVENT |
34 | #define lj_vmevent_send(L, ev, args) UNUSED(L) |
35 | #define lj_vmevent_send_(L, ev, args, post) UNUSED(L) |
36 | #else |
37 | #define lj_vmevent_send(L, ev, args) \ |
38 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ |
39 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ |
40 | if (argbase) { \ |
41 | args \ |
42 | lj_vmevent_call(L, argbase); \ |
43 | } \ |
44 | } |
45 | #define lj_vmevent_send_(L, ev, args, post) \ |
46 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ |
47 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ |
48 | if (argbase) { \ |
49 | args \ |
50 | lj_vmevent_call(L, argbase); \ |
51 | post \ |
52 | } \ |
53 | } |
54 | |
55 | LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev); |
56 | LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase); |
57 | #endif |
58 | |
59 | #endif |
60 | |