]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
limex: add CANNOT_DIE flag and loop without test
authorJustin Viiret <justin.viiret@intel.com>
Mon, 3 Apr 2017 01:40:42 +0000 (11:40 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:19:35 +0000 (15:19 +1000)
src/nfa/limex_compile.cpp
src/nfa/limex_internal.h
src/nfa/limex_runtime_impl.h

index e064420d7a42175b1e5df911bbf749cef60bc904..92ec4205d276c3c6af64793aeb1320ccac7fca2b 100644 (file)
@@ -2237,6 +2237,10 @@ struct Factory {
         limex->shiftCount = shiftCount;
         writeShiftMasks(args, limex);
 
+        if (hasInitDsStates(args.h, args.state_ids)) {
+            setLimexFlag(limex, LIMEX_FLAG_CANNOT_DIE);
+        }
+
         // Determine the state required for our state vector.
         findStateSize(args, limex);
 
index ccbf342232f17b1b6516e9456e03c21930735f00..db703f039273f211114e24ab212329a11829384b 100644 (file)
@@ -85,6 +85,7 @@
 
 #define LIMEX_FLAG_COMPRESS_STATE  1 /**< pack state into stream state */
 #define LIMEX_FLAG_COMPRESS_MASKED 2 /**< use reach mask-based compression */
+#define LIMEX_FLAG_CANNOT_DIE      4 /**< limex cannot have no states on */
 
 enum LimExTrigger {
     LIMEX_TRIGGER_NONE = 0,
index ca761924af232cc4e88e157623d46eb74eb76d93..b9002c916e7d9abb88a17cf280e65d10aeaa5794 100644 (file)
@@ -216,11 +216,32 @@ char STREAM_FN(const IMPL_NFA_T *limex, const u8 *input, size_t length,
     size_t min_accel_offset = 0;
     if (!limex->accelCount || length < ACCEL_MIN_LEN) {
         min_accel_offset = length;
-        goto without_accel;
+        if (limex->flags & LIMEX_FLAG_CANNOT_DIE) {
+            goto cannot_die;
+        } else {
+            goto without_accel;
+        }
     } else {
         goto with_accel;
     }
 
+cannot_die:
+    for (; i != min_accel_offset; i++) {
+        DUMP_INPUT(i);
+
+        STATE_T succ;
+        NFA_EXEC_GET_LIM_SUCC(limex, s, succ);
+
+        if (RUN_EXCEPTIONS_FN(limex, exceptions, s, EXCEPTION_MASK, i, offset,
+                              &succ, final_loc, ctx, flags, 0, first_match)) {
+            return MO_HALT_MATCHING;
+        }
+
+        u8 c = input[i];
+        s = AND_STATE(succ, LOAD_FROM_ENG(&reach[limex->reachMap[c]]));
+    }
+    goto finished;
+
 without_accel:
     for (; i != min_accel_offset; i++) {
         DUMP_INPUT(i);
@@ -292,6 +313,7 @@ with_accel:
         s = AND_STATE(succ, LOAD_FROM_ENG(&reach[limex->reachMap[c]]));
     }
 
+finished:
     ctx->s = s;
 
     if ((first_match || (flags & CALLBACK_OUTPUT)) && limex->acceptCount) {