mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
Make Rose callback types explicitly take scratch
This commit is contained in:
parent
70620327cc
commit
4feabf7bd6
@ -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;
|
||||
|
@ -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
|
||||
|
@ -171,11 +171,12 @@ void setBroken(char *state, u8 broken) {
|
||||
}
|
||||
|
||||
static really_inline
|
||||
int roseAdaptor_i(u64a offset, ReportID id, void *context, char is_simple,
|
||||
char do_som) {
|
||||
int roseAdaptor_i(u64a offset, ReportID id, struct hs_scratch *scratch,
|
||||
char is_simple, char do_som) {
|
||||
assert(id != MO_INVALID_IDX); // Should never get an invalid ID.
|
||||
assert(scratch);
|
||||
assert(scratch->magic == SCRATCH_MAGIC);
|
||||
|
||||
struct hs_scratch *scratch = (struct hs_scratch *)context;
|
||||
struct core_info *ci = &scratch->core_info;
|
||||
const struct RoseEngine *rose = ci->rose;
|
||||
DEBUG_PRINTF("internal report %u\n", id);
|
||||
@ -326,12 +327,13 @@ exit:
|
||||
|
||||
static really_inline
|
||||
int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id,
|
||||
void *context, char is_simple) {
|
||||
struct hs_scratch *scratch, char is_simple) {
|
||||
assert(id != MO_INVALID_IDX); // Should never get an invalid ID.
|
||||
assert(scratch);
|
||||
assert(scratch->magic == SCRATCH_MAGIC);
|
||||
|
||||
u32 flags = 0;
|
||||
|
||||
struct hs_scratch *scratch = (struct hs_scratch *)context;
|
||||
struct core_info *ci = &scratch->core_info;
|
||||
const struct RoseEngine *rose = ci->rose;
|
||||
const struct internal_report *ri = getInternalReport(rose, id);
|
||||
@ -488,8 +490,8 @@ hwlmcb_rv_t multiDirectAdaptor(u64a real_end, ReportID direct_id, void *context,
|
||||
}
|
||||
|
||||
static
|
||||
int roseAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 0, 0);
|
||||
int roseAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
|
||||
return roseAdaptor_i(offset, id, scratch, 0, 0);
|
||||
}
|
||||
|
||||
static
|
||||
@ -513,8 +515,8 @@ hwlmcb_rv_t hwlmAdaptor(UNUSED size_t start, size_t end, u32 direct_id,
|
||||
}
|
||||
|
||||
static
|
||||
int roseSimpleAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 1, 0);
|
||||
int roseSimpleAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
|
||||
return roseAdaptor_i(offset, id, scratch, 1, 0);
|
||||
}
|
||||
|
||||
static
|
||||
@ -539,8 +541,8 @@ hwlmcb_rv_t hwlmSimpleAdaptor(UNUSED size_t start, size_t end, u32 direct_id,
|
||||
}
|
||||
|
||||
static
|
||||
int roseSomAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 0, 1);
|
||||
int roseSomAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
|
||||
return roseAdaptor_i(offset, id, scratch, 0, 1);
|
||||
}
|
||||
|
||||
static
|
||||
@ -564,8 +566,8 @@ hwlmcb_rv_t hwlmSomAdaptor(UNUSED size_t start, size_t end, u32 direct_id,
|
||||
}
|
||||
|
||||
static
|
||||
int roseSimpleSomAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 1, 1);
|
||||
int roseSimpleSomAdaptor(u64a offset, ReportID id, struct hs_scratch *scratch) {
|
||||
return roseAdaptor_i(offset, id, scratch, 1, 1);
|
||||
}
|
||||
|
||||
static
|
||||
@ -614,14 +616,14 @@ HWLMCallback selectHwlmAdaptor(const struct RoseEngine *rose) {
|
||||
|
||||
static
|
||||
int roseSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
|
||||
void *context) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, context, 0);
|
||||
struct hs_scratch *scratch) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, scratch, 0);
|
||||
}
|
||||
|
||||
static
|
||||
int roseSimpleSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
|
||||
void *context) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, context, 1);
|
||||
struct hs_scratch *scratch) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, scratch, 1);
|
||||
}
|
||||
|
||||
static really_inline
|
||||
@ -631,6 +633,56 @@ RoseCallbackSom selectSomAdaptor(const struct RoseEngine *rose) {
|
||||
return is_simple ? roseSimpleSomSomAdaptor : roseSomSomAdaptor;
|
||||
}
|
||||
|
||||
static
|
||||
int outfixSimpleSomAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 1, 1);
|
||||
}
|
||||
|
||||
static
|
||||
int outfixSimpleAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 1, 0);
|
||||
}
|
||||
|
||||
static
|
||||
int outfixSomAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 0, 1);
|
||||
}
|
||||
|
||||
static
|
||||
int outfixAdaptor(u64a offset, ReportID id, void *context) {
|
||||
return roseAdaptor_i(offset, id, context, 0, 0);
|
||||
}
|
||||
|
||||
static really_inline
|
||||
NfaCallback selectOutfixAdaptor(const struct RoseEngine *rose) {
|
||||
const char is_simple = rose->simpleCallback;
|
||||
const char do_som = rose->hasSom;
|
||||
|
||||
if (do_som) {
|
||||
return is_simple ? outfixSimpleSomAdaptor : outfixSomAdaptor;
|
||||
} else {
|
||||
return is_simple ? outfixSimpleAdaptor : outfixAdaptor;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int outfixSimpleSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
|
||||
void *context) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, context, 1);
|
||||
}
|
||||
|
||||
static
|
||||
int outfixSomSomAdaptor(u64a from_offset, u64a to_offset, ReportID id,
|
||||
void *context) {
|
||||
return roseSomAdaptor_i(from_offset, to_offset, id, context, 0);
|
||||
}
|
||||
|
||||
static really_inline
|
||||
SomNfaCallback selectOutfixSomAdaptor(const struct RoseEngine *rose) {
|
||||
const char is_simple = rose->simpleCallback;
|
||||
return is_simple ? outfixSimpleSomSomAdaptor : outfixSomSomAdaptor;
|
||||
}
|
||||
|
||||
static never_inline
|
||||
void processReportList(const struct RoseEngine *rose, u32 base_offset,
|
||||
u64a stream_offset, hs_scratch_t *scratch) {
|
||||
@ -720,8 +772,8 @@ void initQueue(struct mq *q, u32 qi, const struct RoseEngine *t,
|
||||
q->length = scratch->core_info.len;
|
||||
q->history = scratch->core_info.hbuf;
|
||||
q->hlength = scratch->core_info.hlen;
|
||||
q->cb = selectAdaptor(t);
|
||||
q->som_cb = selectSomAdaptor(t);
|
||||
q->cb = selectOutfixAdaptor(t);
|
||||
q->som_cb = selectOutfixSomAdaptor(t);
|
||||
q->context = scratch;
|
||||
q->report_current = 0;
|
||||
|
||||
@ -792,10 +844,10 @@ void runSmallWriteEngine(const struct SmallWriteEngine *smwr,
|
||||
assert(isMcClellanType(nfa->type));
|
||||
if (nfa->type == MCCLELLAN_NFA_8) {
|
||||
nfaExecMcClellan8_B(nfa, smwr->start_offset, local_buffer,
|
||||
local_alen, selectAdaptor(rose), scratch);
|
||||
local_alen, selectOutfixAdaptor(rose), scratch);
|
||||
} else {
|
||||
nfaExecMcClellan16_B(nfa, smwr->start_offset, local_buffer,
|
||||
local_alen, selectAdaptor(rose), scratch);
|
||||
local_alen, selectOutfixAdaptor(rose), scratch);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user