exhaust: Update interface

- Only use functions in exhaust.h for valid ekeys
 - Use INVALID_EKEY everywhere (remove dupe END_EXHAUST sentinel)
This commit is contained in:
Justin Viiret 2016-04-07 16:33:11 +10:00 committed by Matthew Barr
parent d75cc809fe
commit 50885f210a
4 changed files with 22 additions and 23 deletions

View File

@ -243,7 +243,7 @@ int roseAdaptor_i(u64a offset, ReportID id, struct hs_scratch *scratch,
} }
} }
if (!is_simple && if (!is_simple && ir->ekey != INVALID_EKEY &&
unlikely(isExhausted(ci->rose, ci->exhaustionVector, ir->ekey))) { unlikely(isExhausted(ci->rose, ci->exhaustionVector, ir->ekey))) {
DEBUG_PRINTF("ate exhausted match\n"); DEBUG_PRINTF("ate exhausted match\n");
return MO_CONTINUE_MATCHING; return MO_CONTINUE_MATCHING;
@ -296,7 +296,7 @@ exit:
return MO_HALT_MATCHING; return MO_HALT_MATCHING;
} }
if (!is_simple && ir->ekey != END_EXHAUST) { if (!is_simple && ir->ekey != INVALID_EKEY) {
markAsMatched(ci->rose, ci->exhaustionVector, ir->ekey); markAsMatched(ci->rose, ci->exhaustionVector, ir->ekey);
return MO_CONTINUE_MATCHING; return MO_CONTINUE_MATCHING;
} else { } else {
@ -400,7 +400,7 @@ int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id,
int halt = 0; int halt = 0;
if (!is_simple && if (!is_simple && ir->ekey != INVALID_EKEY &&
unlikely(isExhausted(ci->rose, ci->exhaustionVector, ir->ekey))) { unlikely(isExhausted(ci->rose, ci->exhaustionVector, ir->ekey))) {
DEBUG_PRINTF("ate exhausted match\n"); DEBUG_PRINTF("ate exhausted match\n");
goto exit; goto exit;
@ -446,7 +446,7 @@ int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id,
halt = ci->userCallback((unsigned int)ir->onmatch, from_offset, to_offset, halt = ci->userCallback((unsigned int)ir->onmatch, from_offset, to_offset,
flags, ci->userContext); flags, ci->userContext);
if (!is_simple) { if (!is_simple && ir->ekey != INVALID_EKEY) {
markAsMatched(ci->rose, ci->exhaustionVector, ir->ekey); markAsMatched(ci->rose, ci->exhaustionVector, ir->ekey);
} }

View File

@ -119,9 +119,9 @@ char roseSuffixInfoIsExhausted(const struct RoseEngine *t,
DEBUG_PRINTF("check exhaustion -> start at %u\n", info->ekeyListOffset); DEBUG_PRINTF("check exhaustion -> start at %u\n", info->ekeyListOffset);
/* END_EXHAUST terminated list */ /* INVALID_EKEY terminated list */
const u32 *ekeys = (const u32 *)((const char *)t + info->ekeyListOffset); const u32 *ekeys = (const u32 *)((const char *)t + info->ekeyListOffset);
while (*ekeys != END_EXHAUST) { while (*ekeys != INVALID_EKEY) {
DEBUG_PRINTF("check %u\n", *ekeys); DEBUG_PRINTF("check %u\n", *ekeys);
if (!isExhausted(t, exhausted, *ekeys)) { if (!isExhausted(t, exhausted, *ekeys)) {
DEBUG_PRINTF("not exhausted -> alive\n"); DEBUG_PRINTF("not exhausted -> alive\n");

View File

@ -428,7 +428,7 @@ hs_error_t hs_scan(const hs_database_t *db, const char *data, unsigned length,
populateCoreInfo(scratch, rose, scratch->bstate, onEvent, userCtx, data, populateCoreInfo(scratch, rose, scratch->bstate, onEvent, userCtx, data,
length, NULL, 0, 0, 0, flags); length, NULL, 0, 0, 0, flags);
clearEvec(scratch->core_info.exhaustionVector, rose); clearEvec(rose, scratch->core_info.exhaustionVector);
// Rose program execution (used for some report paths) depends on these // Rose program execution (used for some report paths) depends on these
// values being initialised. // values being initialised.
@ -561,7 +561,7 @@ void init_stream(struct hs_stream *s, const struct RoseEngine *rose) {
setStreamStatus(state, 0); setStreamStatus(state, 0);
roseInitState(rose, state); roseInitState(rose, state);
clearEvec((char *)state + rose->stateOffsets.exhausted, rose); clearEvec(rose, state + rose->stateOffsets.exhausted);
// SOM state multibit structures. // SOM state multibit structures.
initSomState(rose, state); initSomState(rose, state);

View File

@ -34,19 +34,18 @@
#define EXHAUST_H #define EXHAUST_H
#include "rose/rose_internal.h" #include "rose/rose_internal.h"
#include "util/internal_report.h"
#include "util/multibit.h" #include "util/multibit.h"
#include "ue2common.h" #include "ue2common.h"
/** \brief Sentinel value meaning no further exhaustion keys. */ /** \brief Test whether the given key (\a ekey) is set in the exhaustion vector
#define END_EXHAUST (~(u32)0)
/** \brief Test whether the given key (\a eoff) is set in the exhaustion vector
* \a evec. */ * \a evec. */
static really_inline static really_inline
int isExhausted(const struct RoseEngine *t, const char *evec, u32 eoff) { int isExhausted(const struct RoseEngine *t, const char *evec, u32 ekey) {
DEBUG_PRINTF("checking exhaustion %p %u\n", evec, eoff); DEBUG_PRINTF("checking exhaustion %p %u\n", evec, ekey);
return eoff != END_EXHAUST && assert(ekey != INVALID_EKEY);
mmbit_isset((const u8 *)evec, t->ekeyCount, eoff); assert(ekey < t->ekeyCount);
return mmbit_isset((const u8 *)evec, t->ekeyCount, ekey);
} }
/** \brief Returns 1 if all exhaustion keys in the bitvector are on. */ /** \brief Returns 1 if all exhaustion keys in the bitvector are on. */
@ -59,18 +58,18 @@ int isAllExhausted(const struct RoseEngine *t, const char *evec) {
return mmbit_all((const u8 *)evec, t->ekeyCount); return mmbit_all((const u8 *)evec, t->ekeyCount);
} }
/** \brief Mark key \a eoff on in the exhaustion vector. */ /** \brief Mark key \a ekey on in the exhaustion vector. */
static really_inline static really_inline
void markAsMatched(const struct RoseEngine *t, char *evec, u32 eoff) { void markAsMatched(const struct RoseEngine *t, char *evec, u32 ekey) {
if (eoff != END_EXHAUST) { DEBUG_PRINTF("marking as exhausted key %u\n", ekey);
DEBUG_PRINTF("marking as exhausted key %u\n", eoff); assert(ekey != INVALID_EKEY);
mmbit_set((u8 *)evec, t->ekeyCount, eoff); assert(ekey < t->ekeyCount);
} mmbit_set((u8 *)evec, t->ekeyCount, ekey);
} }
/** \brief Clear all keys in the exhaustion vector. */ /** \brief Clear all keys in the exhaustion vector. */
static really_inline static really_inline
void clearEvec(char *evec, const struct RoseEngine *t) { void clearEvec(const struct RoseEngine *t, char *evec) {
DEBUG_PRINTF("clearing evec %p %u\n", evec, t->ekeyCount); DEBUG_PRINTF("clearing evec %p %u\n", evec, t->ekeyCount);
mmbit_clear((u8 *)evec, t->ekeyCount); mmbit_clear((u8 *)evec, t->ekeyCount);
} }