Skip to content

Commit

Permalink
auditlog: Log all loaded bytecode (GCproto objects)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Dec 1, 2017
1 parent b46e33a commit 4d8b3eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/lj_auditlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ static void log_GCtrace(GCtrace *T)
log_mem("GCtrace", T, sizeof(*T));
}

static void log_GCproto(GCproto *pt)
{
log_mem("GCproto", pt, pt->sizept); /* includes colocated arrays */
}

/* API functions */

/* Log a trace that has just been compiled. */
Expand All @@ -104,11 +109,21 @@ void lj_auditlog_trace_stop(jit_State *J, GCtrace *T)
str_16("jit_State"); /* = */ uint_64((uint64_t)J);
}

void lj_auditlog_trace_abort(jit_State *J, TraceError e) {
void lj_auditlog_trace_abort(jit_State *J, TraceError e)
{
ensure_log_open();
log_jit_State(J);
log_event("trace_abort", 2);
str_16("TraceError"); /* = */ uint_64(e);
str_16("jit_State"); /* = */ uint_64((uint64_t)J);
}

void lj_auditlog_new_prototype(GCproto *pt)
{
ensure_log_open();
log_GCproto(pt);
log_event("new_prototype", 1);
str_16("GCproto"); /* = */ uint_64((uint64_t)pt);;
}


1 change: 1 addition & 0 deletions src/lj_auditlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "lj_jit.h"
#include "lj_trace.h"

void lj_auditlog_new_prototype(GCproto *pt);
void lj_auditlog_trace_flush(jit_State *J);
void lj_auditlog_trace_stop(jit_State *J, GCtrace *T);
void lj_auditlog_trace_abort(jit_State *J, TraceError e);
Expand Down
2 changes: 2 additions & 0 deletions src/lj_bcread.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "lj_bcdump.h"
#include "lj_state.h"
#include "lj_strfmt.h"
#include "lj_auditlog.h"

/* Reuse some lexer fields for our own purposes. */
#define bcread_flags(ls) ls->level
Expand Down Expand Up @@ -371,6 +372,7 @@ GCproto *lj_bcread_proto(LexState *ls)
setmref(pt->uvinfo, NULL);
setmref(pt->varinfo, NULL);
}
lj_auditlog_new_prototype(pt);
return pt;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lj_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "lj_lex.h"
#include "lj_parse.h"
#include "lj_vm.h"
#include "lj_auditlog.h"

/* -- Parser structures and definitions ----------------------------------- */

Expand Down Expand Up @@ -1526,6 +1527,7 @@ static GCproto *fs_finish(LexState *ls, BCLine line)
ls->vtop = fs->vbase; /* Reset variable stack. */
ls->fs = fs->prev;
lua_assert(ls->fs != NULL || ls->tok == TK_eof);
lj_auditlog_new_prototype(pt);
return pt;
}

Expand Down

0 comments on commit 4d8b3eb

Please sign in to comment.