Skip to content

Commit

Permalink
lj_ctype.c, lj_trace.c: Poll for ctypes to log on trace stop/abort
Browse files Browse the repository at this point in the history
Fix the problem that most interesting ctypes were not included in the
auditlog. The challenge was to find the right instrumentation point to
log these types and this simple solution was suggested by @fsfod.
  • Loading branch information
lukego committed May 10, 2018
1 parent 0a588b4 commit 90a15f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lj_ctype.c
Expand Up @@ -600,6 +600,7 @@ CTState *lj_ctype_init(lua_State *L)
cts->tab = ct;
cts->sizetab = CTTYPETAB_MIN;
cts->top = CTTYPEINFO_NUM;
cts->log = cts->top;
cts->L = NULL;
cts->g = G(L);
for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) {
Expand All @@ -623,6 +624,18 @@ CTState *lj_ctype_init(lua_State *L)
return cts;
}

/* Log all new ctypes. */
void lj_ctype_log(lua_State *L)
{
global_State *g = G(L);
CTState *cts = ctype_ctsG(g);
while (cts && cts->log < cts->top) {
int id = cts->log++;
GCstr *name = lj_ctype_repr(L, id, NULL);
lj_auditlog_new_ctypeid(id, strdata(name));
}
}

/* Free C type table and state. */
void lj_ctype_freestate(global_State *g)
{
Expand Down
2 changes: 2 additions & 0 deletions src/lj_ctype.h
Expand Up @@ -173,6 +173,7 @@ typedef LJ_ALIGN(8) struct CCallback {
typedef struct CTState {
CType *tab; /* C type table. */
CTypeID top; /* Current top of C type table. */
CTypeID log; /* Current top of logged C types table. */
MSize sizetab; /* Size of C type table. */
lua_State *L; /* Lua state (needed for errors and allocations). */
global_State *g; /* Global state. */
Expand Down Expand Up @@ -432,6 +433,7 @@ LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);
LJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size);
LJ_FUNC CTState *lj_ctype_init(lua_State *L);
LJ_FUNC void lj_ctype_log(lua_State *L);
LJ_FUNC void lj_ctype_freestate(global_State *g);


Expand Down
2 changes: 2 additions & 0 deletions src/lj_trace.c
Expand Up @@ -125,6 +125,7 @@ static void trace_save(jit_State *J, GCtrace *T)
setgcrefp(J->trace[T->traceno], T);
lj_gc_barriertrace(J2G(J), T->traceno);
lj_gdbjit_addtrace(J, T);
lj_ctype_log(J->L);
lj_auditlog_trace_stop(J, T);
}

Expand Down Expand Up @@ -525,6 +526,7 @@ static int trace_abort(jit_State *J)
/* Is this the last attempt at a side trace? */
if (J->parent && last_try(J)) J->final = 1;

lj_ctype_log(J->L);
lj_auditlog_trace_abort(J, e);

/* Is there anything to abort? */
Expand Down

0 comments on commit 90a15f7

Please sign in to comment.