From 50885f210a23f360dbc0043d56438727c573bdaf Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 7 Apr 2016 16:33:11 +1000 Subject: [PATCH] exhaust: Update interface - Only use functions in exhaust.h for valid ekeys - Use INVALID_EKEY everywhere (remove dupe END_EXHAUST sentinel) --- src/report.h | 8 ++++---- src/rose/runtime.h | 4 ++-- src/runtime.c | 4 ++-- src/util/exhaust.h | 29 ++++++++++++++--------------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/report.h b/src/report.h index 6f5cec1b..28560907 100644 --- a/src/report.h +++ b/src/report.h @@ -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))) { DEBUG_PRINTF("ate exhausted match\n"); return MO_CONTINUE_MATCHING; @@ -296,7 +296,7 @@ exit: 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); return MO_CONTINUE_MATCHING; } else { @@ -400,7 +400,7 @@ int roseSomAdaptor_i(u64a from_offset, u64a to_offset, ReportID id, int halt = 0; - if (!is_simple && + if (!is_simple && ir->ekey != INVALID_EKEY && unlikely(isExhausted(ci->rose, ci->exhaustionVector, ir->ekey))) { DEBUG_PRINTF("ate exhausted match\n"); 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, flags, ci->userContext); - if (!is_simple) { + if (!is_simple && ir->ekey != INVALID_EKEY) { markAsMatched(ci->rose, ci->exhaustionVector, ir->ekey); } diff --git a/src/rose/runtime.h b/src/rose/runtime.h index 46ccc2a1..2716c3fa 100644 --- a/src/rose/runtime.h +++ b/src/rose/runtime.h @@ -119,9 +119,9 @@ char roseSuffixInfoIsExhausted(const struct RoseEngine *t, 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); - while (*ekeys != END_EXHAUST) { + while (*ekeys != INVALID_EKEY) { DEBUG_PRINTF("check %u\n", *ekeys); if (!isExhausted(t, exhausted, *ekeys)) { DEBUG_PRINTF("not exhausted -> alive\n"); diff --git a/src/runtime.c b/src/runtime.c index 09c0deb6..6bc60141 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -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, 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 // values being initialised. @@ -561,7 +561,7 @@ void init_stream(struct hs_stream *s, const struct RoseEngine *rose) { setStreamStatus(state, 0); roseInitState(rose, state); - clearEvec((char *)state + rose->stateOffsets.exhausted, rose); + clearEvec(rose, state + rose->stateOffsets.exhausted); // SOM state multibit structures. initSomState(rose, state); diff --git a/src/util/exhaust.h b/src/util/exhaust.h index 3b5bff4e..f7b7d6e9 100644 --- a/src/util/exhaust.h +++ b/src/util/exhaust.h @@ -34,19 +34,18 @@ #define EXHAUST_H #include "rose/rose_internal.h" +#include "util/internal_report.h" #include "util/multibit.h" #include "ue2common.h" -/** \brief Sentinel value meaning no further exhaustion keys. */ -#define END_EXHAUST (~(u32)0) - -/** \brief Test whether the given key (\a eoff) is set in the exhaustion vector +/** \brief Test whether the given key (\a ekey) is set in the exhaustion vector * \a evec. */ static really_inline -int isExhausted(const struct RoseEngine *t, const char *evec, u32 eoff) { - DEBUG_PRINTF("checking exhaustion %p %u\n", evec, eoff); - return eoff != END_EXHAUST && - mmbit_isset((const u8 *)evec, t->ekeyCount, eoff); +int isExhausted(const struct RoseEngine *t, const char *evec, u32 ekey) { + DEBUG_PRINTF("checking exhaustion %p %u\n", evec, ekey); + assert(ekey != INVALID_EKEY); + 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. */ @@ -59,18 +58,18 @@ int isAllExhausted(const struct RoseEngine *t, const char *evec) { 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 -void markAsMatched(const struct RoseEngine *t, char *evec, u32 eoff) { - if (eoff != END_EXHAUST) { - DEBUG_PRINTF("marking as exhausted key %u\n", eoff); - mmbit_set((u8 *)evec, t->ekeyCount, eoff); - } +void markAsMatched(const struct RoseEngine *t, char *evec, u32 ekey) { + DEBUG_PRINTF("marking as exhausted key %u\n", ekey); + assert(ekey != INVALID_EKEY); + assert(ekey < t->ekeyCount); + mmbit_set((u8 *)evec, t->ekeyCount, ekey); } /** \brief Clear all keys in the exhaustion vector. */ 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); mmbit_clear((u8 *)evec, t->ekeyCount); }