| 1 |
/* |
| 2 |
** VM event handling. |
| 3 |
** Copyright (C) 2005-2025 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, 0x12d91467), |
| 28 |
VMEVENT_DEF(RECORD, 0x1284bf4f), |
| 29 |
VMEVENT_DEF(TEXIT, 0x129df2b0), |
| 30 |
VMEVENT_DEF(ERRFIN, 0x12d93888), |
| 31 |
LJ_VMEVENT__MAX |
| 32 |
} VMEvent; |
| 33 |
|
| 34 |
#ifdef LUAJIT_DISABLE_VMEVENT |
| 35 |
#define lj_vmevent_send(L, ev, args) UNUSED(L) |
| 36 |
#define lj_vmevent_send_(L, ev, args, post) UNUSED(L) |
| 37 |
#else |
| 38 |
#define lj_vmevent_send(L, ev, args) \ |
| 39 |
if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ |
| 40 |
ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ |
| 41 |
if (argbase) { \ |
| 42 |
args \ |
| 43 |
lj_vmevent_call(L, argbase); \ |
| 44 |
} \ |
| 45 |
} |
| 46 |
#define lj_vmevent_send_(L, ev, args, post) \ |
| 47 |
if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ |
| 48 |
ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ |
| 49 |
if (argbase) { \ |
| 50 |
args \ |
| 51 |
lj_vmevent_call(L, argbase); \ |
| 52 |
post \ |
| 53 |
} \ |
| 54 |
} |
| 55 |
|
| 56 |
LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev); |
| 57 |
LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase); |
| 58 |
#endif |
| 59 |
|
| 60 |
#endif |