Make Rose callback types explicitly take scratch

This commit is contained in:
Justin Viiret
2016-01-13 13:20:38 +11:00
committed by Matthew Barr
parent 70620327cc
commit 4feabf7bd6
3 changed files with 105 additions and 31 deletions

View File

@@ -120,6 +120,29 @@ int roseEodRunIterator(const struct RoseEngine *t, u64a offset,
return MO_CONTINUE_MATCHING;
}
/**
* \brief Adapts an NfaCallback to the rose callback specified in the
* RoseContext.
*/
static
int eodNfaCallback(u64a offset, ReportID report, void *context) {
struct hs_scratch *scratch = context;
assert(scratch->magic == SCRATCH_MAGIC);
return scratch->tctxt.cb(offset, report, scratch);
}
/**
* \brief Adapts a SomNfaCallback to the rose SOM callback specified in the
* RoseContext.
*/
static
int eodNfaSomCallback(u64a from_offset, u64a to_offset, ReportID report,
void *context) {
struct hs_scratch *scratch = context;
assert(scratch->magic == SCRATCH_MAGIC);
return scratch->tctxt.cb_som(from_offset, to_offset, report, scratch);
}
/**
* \brief Check for (and deliver) reports from active output-exposed (suffix
* or outfix) NFAs.
@@ -167,8 +190,8 @@ void roseCheckNfaEod(const struct RoseEngine *t, char *state,
nfaExpandState(nfa, fstate, sstate, offset, key);
}
if (nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
scratch->tctxt.cb_som,
if (nfaCheckFinalState(nfa, fstate, sstate, offset, eodNfaCallback,
eodNfaSomCallback,
scratch) == MO_HALT_MATCHING) {
DEBUG_PRINTF("user instructed us to stop\n");
return;
@@ -216,8 +239,8 @@ void roseCheckEodSuffixes(const struct RoseEngine *t, char *state, u64a offset,
* history buffer. */
char rv = nfaQueueExecRose(q->nfa, q, MO_INVALID_IDX);
if (rv) { /* nfa is still alive */
if (nfaCheckFinalState(nfa, fstate, sstate, offset,
scratch->tctxt.cb, scratch->tctxt.cb_som,
if (nfaCheckFinalState(nfa, fstate, sstate, offset, eodNfaCallback,
eodNfaSomCallback,
scratch) == MO_HALT_MATCHING) {
DEBUG_PRINTF("user instructed us to stop\n");
return;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -31,13 +31,12 @@
#include "ue2common.h"
struct RoseEngine;
struct hs_scratch;
// Note: identical signature to NfaCallback, but all Rose callbacks must be
// passed scratch as their context ptr.
typedef int (*RoseCallback)(u64a offset, ReportID id,
struct hs_scratch *scratch);
typedef int (*RoseCallback)(u64a offset, ReportID id, void *context);
typedef int (*RoseCallbackSom)(u64a from_offset, u64a to_offset, ReportID id,
void *context);
struct hs_scratch *scratch);
#endif