]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
exhaust: Update interface
authorJustin Viiret <justin.viiret@intel.com>
Thu, 7 Apr 2016 06:33:11 +0000 (16:33 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 20 Apr 2016 03:34:55 +0000 (13:34 +1000)
 - Only use functions in exhaust.h for valid ekeys
 - Use INVALID_EKEY everywhere (remove dupe END_EXHAUST sentinel)

src/report.h
src/rose/runtime.h
src/runtime.c
src/util/exhaust.h

index 6f5cec1bfece9b43b85e0b9a73c7872a7bb2b9cd..28560907ccb9c8994958f0ed6c088eed99c6bc97 100644 (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))) {
         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);
     }
 
index 46ccc2a1344761e07cac7e608d34383faa5e1b3b..2716c3fa2ba45ff8c7410df13eceac3c41b1ac15 100644 (file)
@@ -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");
index 09c0deb68c567735a313a1840b4e34d5f1ef814e..6bc601412966ce13e28ac8240fc4cf882cdcf14a 100644 (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,
                      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);
index 3b5bff4ed0ccb0f0c2b5b056ad78d48659c06bd9..f7b7d6e957da99e238880d03c3635dce842b2a26 100644 (file)
 #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);
 }