]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Remove RoseContext::userCtx
authorJustin Viiret <justin.viiret@intel.com>
Wed, 13 Jan 2016 01:39:28 +0000 (12:39 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:29:04 +0000 (11:29 +1100)
All Rose callbacks receive scratch as their context.

src/rose/block.c
src/rose/catchup.c
src/rose/eod.c
src/rose/program_runtime.h
src/rose/rose.h
src/rose/rose_types.h
src/rose/stream.c
src/runtime.c
src/scratch.h

index a3174b637aa3713837e9855d95d62662f5d60531..3d4a008db18de32aef80d7c471486845be14737b 100644 (file)
@@ -135,7 +135,7 @@ void init_outfixes_for_block(const struct RoseEngine *t,
 static really_inline
 void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch,
                     RoseCallback callback, RoseCallbackSom som_callback,
-                    void *ctxt, char *state, char is_small_block) {
+                    char *state, char is_small_block) {
     init_state_for_block(t, state);
 
     struct RoseContext *tctxt = &scratch->tctxt;
@@ -147,7 +147,6 @@ void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch,
     tctxt->filledDelayedSlots = 0;
     tctxt->cb = callback;
     tctxt->cb_som = som_callback;
-    tctxt->userCtx = ctxt;
     tctxt->lastMatchOffset = 0;
     tctxt->minMatchOffset = 0;
     tctxt->minNonMpvMatchOffset = 0;
@@ -166,8 +165,7 @@ void init_for_block(const struct RoseEngine *t, struct hs_scratch *scratch,
 }
 
 void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch,
-                     RoseCallback callback, RoseCallbackSom som_callback,
-                     void *ctx) {
+                     RoseCallback callback, RoseCallbackSom som_callback) {
     assert(t);
     assert(scratch);
     assert(scratch->core_info.buf);
@@ -185,7 +183,7 @@ void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch,
 
     char *state = scratch->core_info.state;
 
-    init_for_block(t, scratch, callback, som_callback, ctx, state,
+    init_for_block(t, scratch, callback, som_callback, state,
                    is_small_block);
 
     struct RoseContext *tctxt = &scratch->tctxt;
index 6893df0eb8e35b786b3d56e83b83c3243d477d45..b302fbdd7e154b05f5cea486875bc6b750e0e10a 100644 (file)
@@ -338,7 +338,7 @@ int roseNfaFinalBlastAdaptor(u64a offset, ReportID id, void *context) {
         return MO_CONTINUE_MATCHING;
     }
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -364,7 +364,7 @@ int roseNfaFinalBlastAdaptorNoInternal(u64a offset, ReportID id,
                  offset, id);
     updateLastMatchOffset(tctxt, offset);
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -544,7 +544,7 @@ int roseNfaBlastAdaptor(u64a offset, ReportID id, void *context) {
 
     updateLastMatchOffset(tctxt, offset);
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -574,7 +574,7 @@ int roseNfaBlastAdaptorNoInternal(u64a offset, ReportID id, void *context) {
                  offset, id);
     updateLastMatchOffset(tctxt, offset);
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -600,7 +600,7 @@ int roseNfaBlastAdaptorNoChain(u64a offset, ReportID id, void *context) {
         return MO_CONTINUE_MATCHING;
     }
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -624,7 +624,7 @@ int roseNfaBlastAdaptorNoInternalNoChain(u64a offset, ReportID id,
                  offset, id);
     updateLastMatchOffset(tctxt, offset);
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -656,7 +656,7 @@ int roseNfaBlastSomAdaptor(u64a from_offset, u64a offset, ReportID id,
     updateLastMatchOffset(tctxt, offset);
 
     /* must be a external report as haig cannot directly participate in chain */
-    int cb_rv = tctxt->cb_som(from_offset, offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb_som(from_offset, offset, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         return MO_HALT_MATCHING;
     } else if (cb_rv == ROSE_CONTINUE_MATCHING_NO_EXHAUST) {
@@ -679,7 +679,7 @@ int roseNfaAdaptor(u64a offset, ReportID id, void *context) {
         return MO_CONTINUE_MATCHING;
     }
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(offset, id, scratch);
     return cb_rv;
 }
 
@@ -688,8 +688,7 @@ int roseNfaAdaptorNoInternal(u64a offset, ReportID id, void *context) {
     DEBUG_PRINTF("masky got himself a match @%llu id %u !woot!\n", offset, id);
     updateLastMatchOffset(tctxt, offset);
 
-    int cb_rv = tctxt->cb(offset, id, tctxt->userCtx);
-    return cb_rv;
+    return tctxt->cb(offset, id, tctxtToScratch(tctxt));
 }
 
 int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id,
@@ -699,8 +698,7 @@ int roseNfaSomAdaptor(u64a from_offset, u64a offset, ReportID id,
     updateLastMatchOffset(tctxt, offset);
 
     /* must be a external report as haig cannot directly participate in chain */
-    int cb_rv = tctxt->cb_som(from_offset, offset, id, tctxt->userCtx);
-    return cb_rv;
+    return tctxt->cb_som(from_offset, offset, id, tctxtToScratch(tctxt));
 }
 
 static really_inline
@@ -1155,7 +1153,7 @@ hwlmcb_rv_t roseCatchUpAll_i(s64a loc, struct hs_scratch *scratch,
             goto next;
         }
 
-        if (tctxt->cb(anchored_end, anchored_report, tctxt->userCtx)
+        if (tctxt->cb(anchored_end, anchored_report, scratch)
             == MO_HALT_MATCHING) {
             DEBUG_PRINTF("termination requested\n");
             return HWLM_TERMINATE_MATCHING;
@@ -1271,7 +1269,7 @@ hwlmcb_rv_t roseCatchUpAnchoredOnly(s64a loc, struct hs_scratch *scratch) {
             goto next;
         }
 
-        if (tctxt->cb(anchored_end, anchored_report, tctxt->userCtx)
+        if (tctxt->cb(anchored_end, anchored_report, scratch)
                         == MO_HALT_MATCHING) {
             DEBUG_PRINTF("termination requested\n");
             return HWLM_TERMINATE_MATCHING;
index 3ababb830536c8d889bed03f295a758380315165..2e414ad7eb6b919a85210ac2e3f59b941fdf0a66 100644 (file)
@@ -35,7 +35,7 @@
 static really_inline
 void initContext(const struct RoseEngine *t, char *state, u64a offset,
                  struct hs_scratch *scratch, RoseCallback callback,
-                 RoseCallbackSom som_callback, void *ctx) {
+                 RoseCallbackSom som_callback) {
     struct RoseContext *tctxt = &scratch->tctxt;
     tctxt->groups = loadGroups(t, state); /* TODO: diff groups for eod */
     tctxt->lit_offset_adjust = scratch->core_info.buf_offset
@@ -46,7 +46,6 @@ void initContext(const struct RoseEngine *t, char *state, u64a offset,
     tctxt->filledDelayedSlots = 0;
     tctxt->cb = callback;
     tctxt->cb_som = som_callback;
-    tctxt->userCtx = ctx;
     tctxt->lastMatchOffset = 0;
     tctxt->minMatchOffset = 0;
     tctxt->minNonMpvMatchOffset = 0;
@@ -170,7 +169,7 @@ void roseCheckNfaEod(const struct RoseEngine *t, char *state,
 
         if (nfaCheckFinalState(nfa, fstate, sstate, offset, scratch->tctxt.cb,
                                scratch->tctxt.cb_som,
-                               scratch->tctxt.userCtx) == MO_HALT_MATCHING) {
+                               scratch) == MO_HALT_MATCHING) {
             DEBUG_PRINTF("user instructed us to stop\n");
             return;
         }
@@ -219,8 +218,7 @@ void roseCheckEodSuffixes(const struct RoseEngine *t, char *state, u64a offset,
         if (rv) { /* nfa is still alive */
             if (nfaCheckFinalState(nfa, fstate, sstate, offset,
                                    scratch->tctxt.cb, scratch->tctxt.cb_som,
-                                   scratch->tctxt.userCtx) ==
-                MO_HALT_MATCHING) {
+                                   scratch) == MO_HALT_MATCHING) {
                 DEBUG_PRINTF("user instructed us to stop\n");
                 return;
             }
@@ -298,10 +296,9 @@ void roseEodExec_i(const struct RoseEngine *t, char *state, u64a offset,
 
 void roseEodExec(const struct RoseEngine *t, u64a offset,
                  struct hs_scratch *scratch, RoseCallback callback,
-                 RoseCallbackSom som_callback, void *context) {
+                 RoseCallbackSom som_callback) {
     assert(scratch);
     assert(callback);
-    assert(context);
     assert(t->requiresEodCheck);
     DEBUG_PRINTF("ci buf %p/%zu his %p/%zu\n", scratch->core_info.buf,
                  scratch->core_info.len, scratch->core_info.hbuf,
@@ -317,7 +314,7 @@ void roseEodExec(const struct RoseEngine *t, u64a offset,
     char *state = scratch->core_info.state;
     assert(state);
 
-    initContext(t, state, offset, scratch, callback, som_callback, context);
+    initContext(t, state, offset, scratch, callback, som_callback);
 
     roseEodExec_i(t, state, offset, scratch, 1);
 }
index 309fee5ba237433b2ab2413edc6a11cdbf78432c..f76689f4aebe606da00c46a0311d9853e60b613c 100644 (file)
@@ -205,6 +205,22 @@ found_miracle:
     return 1;
 }
 
+static rose_inline
+hwlmcb_rv_t roseHaltIfExhausted(const struct RoseEngine *t,
+                                struct hs_scratch *scratch) {
+    struct core_info *ci = &scratch->core_info;
+    if (isAllExhausted(t, ci->exhaustionVector)) {
+        if (!ci->broken) {
+            ci->broken = BROKEN_EXHAUSTED;
+        }
+        scratch->tctxt.groups = 0;
+        DEBUG_PRINTF("all exhausted, termination requested\n");
+        return HWLM_TERMINATE_MATCHING;
+    }
+
+    return HWLM_CONTINUE_MATCHING;
+}
+
 static really_inline
 hwlmcb_rv_t ensureQueueFlushed_i(const struct RoseEngine *t,
                                  struct hs_scratch *scratch, u32 qi, s64a loc,
@@ -266,16 +282,7 @@ done_queue_empty:
 
     assert(!isQueueFull(q));
 
-    if (isAllExhausted(t, scratch->core_info.exhaustionVector)) {
-        if (!scratch->core_info.broken) {
-            scratch->core_info.broken = BROKEN_EXHAUSTED;
-        }
-        tctxt->groups = 0;
-        DEBUG_PRINTF("termination requested\n");
-        return HWLM_TERMINATE_MATCHING;
-    }
-
-    return HWLM_CONTINUE_MATCHING;
+    return roseHaltIfExhausted(t, scratch);
 }
 
 static really_inline
@@ -575,7 +582,7 @@ hwlmcb_rv_t roseHandleMatch(const struct RoseEngine *t, char *state,
     DEBUG_PRINTF("firing callback reportId=%u, end=%llu\n", id, end);
     updateLastMatchOffset(tctxt, end);
 
-    int cb_rv = tctxt->cb(end, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb(end, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         DEBUG_PRINTF("termination requested\n");
         return HWLM_TERMINATE_MATCHING;
@@ -585,16 +592,7 @@ hwlmcb_rv_t roseHandleMatch(const struct RoseEngine *t, char *state,
         return HWLM_CONTINUE_MATCHING;
     }
 
-    if (isAllExhausted(t, scratch->core_info.exhaustionVector)) {
-        if (!scratch->core_info.broken) {
-            scratch->core_info.broken = BROKEN_EXHAUSTED;
-        }
-        tctxt->groups = 0;
-        DEBUG_PRINTF("termination requested\n");
-        return HWLM_TERMINATE_MATCHING;
-    }
-
-    return HWLM_CONTINUE_MATCHING;
+    return roseHaltIfExhausted(t, scratch);
 }
 
 /* catches up engines enough to ensure any earlier mpv triggers are enqueued
@@ -665,7 +663,9 @@ static rose_inline
 hwlmcb_rv_t roseHandleSomMatch(const struct RoseEngine *t, char *state,
                                ReportID id, u64a start, u64a end,
                                struct RoseContext *tctxt, char in_anchored) {
-    if (roseCatchUpTo(t, state, end, tctxtToScratch(tctxt), in_anchored)
+    struct hs_scratch *scratch = tctxtToScratch(tctxt);
+
+    if (roseCatchUpTo(t, state, end, scratch, in_anchored)
         == HWLM_TERMINATE_MATCHING) {
         return HWLM_TERMINATE_MATCHING;
     }
@@ -676,7 +676,7 @@ hwlmcb_rv_t roseHandleSomMatch(const struct RoseEngine *t, char *state,
     assert(end == tctxt->minMatchOffset);
 
     updateLastMatchOffset(tctxt, end);
-    int cb_rv = tctxt->cb_som(start, end, id, tctxt->userCtx);
+    int cb_rv = tctxt->cb_som(start, end, id, scratch);
     if (cb_rv == MO_HALT_MATCHING) {
         DEBUG_PRINTF("termination requested\n");
         return HWLM_TERMINATE_MATCHING;
@@ -686,17 +686,7 @@ hwlmcb_rv_t roseHandleSomMatch(const struct RoseEngine *t, char *state,
         return HWLM_CONTINUE_MATCHING;
     }
 
-    struct core_info *ci = &tctxtToScratch(tctxt)->core_info;
-    if (isAllExhausted(t, ci->exhaustionVector)) {
-        if (!ci->broken) {
-            ci->broken = BROKEN_EXHAUSTED;
-        }
-        tctxt->groups = 0;
-        DEBUG_PRINTF("termination requested\n");
-        return HWLM_TERMINATE_MATCHING;
-    }
-
-    return HWLM_CONTINUE_MATCHING;
+    return roseHaltIfExhausted(t, scratch);
 }
 
 static rose_inline
@@ -1064,8 +1054,7 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t, u32 programOffset,
             PROGRAM_NEXT_INSTRUCTION
 
             PROGRAM_CASE(REPORT_EOD) {
-                if (tctxt->cb(end, ri->report, tctxt->userCtx) ==
-                    MO_HALT_MATCHING) {
+                if (tctxt->cb(end, ri->report, scratch) == MO_HALT_MATCHING) {
                     return HWLM_TERMINATE_MATCHING;
                 }
                 work_done = 1;
index c855795e4b149c4f26efeb897b9cf705c0ad6452..16cfa435359447bfab0408306da09468de07a2b2 100644 (file)
@@ -42,8 +42,7 @@ void roseInitState(const struct RoseEngine *t, char *state);
 void roseBlockEodExec(const struct RoseEngine *t, u64a offset,
                       struct hs_scratch *scratch);
 void roseBlockExec_i(const struct RoseEngine *t, struct hs_scratch *scratch,
-                     RoseCallback callback, RoseCallbackSom som_callback,
-                     void *context);
+                     RoseCallback callback, RoseCallbackSom som_callback);
 
 static really_inline
 int roseBlockHasEodWork(const struct RoseEngine *t,
@@ -81,8 +80,7 @@ int roseBlockHasEodWork(const struct RoseEngine *t,
 /* assumes core_info in scratch has been init to point to data */
 static really_inline
 void roseBlockExec(const struct RoseEngine *t, struct hs_scratch *scratch,
-                   RoseCallback callback, RoseCallbackSom som_callback,
-                   void *context) {
+                   RoseCallback callback, RoseCallbackSom som_callback) {
     assert(t);
     assert(scratch);
     assert(scratch->core_info.buf);
@@ -99,7 +97,7 @@ void roseBlockExec(const struct RoseEngine *t, struct hs_scratch *scratch,
     assert(t->maxBiAnchoredWidth == ROSE_BOUND_INF
            || length <= t->maxBiAnchoredWidth);
 
-    roseBlockExec_i(t, scratch, callback, som_callback, context);
+    roseBlockExec_i(t, scratch, callback, som_callback);
 
     if (!t->requiresEodCheck) {
         return;
@@ -120,12 +118,11 @@ void roseBlockExec(const struct RoseEngine *t, struct hs_scratch *scratch,
 
 /* assumes core_info in scratch has been init to point to data */
 void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
-                    RoseCallback callback, RoseCallbackSom som_callback,
-                    void *context);
+                    RoseCallback callback, RoseCallbackSom som_callback);
 
 void roseEodExec(const struct RoseEngine *t, u64a offset,
                  struct hs_scratch *scratch, RoseCallback callback,
-                 RoseCallbackSom som_callback, void *context);
+                 RoseCallbackSom som_callback);
 
 #define ROSE_CONTINUE_MATCHING_NO_EXHAUST 2
 
index 1b80b2b2039bf70dc799d80c20eb1ad175e8b60c..1ba453fe2312f104fa2e5d51dcafc534f8d4ed07 100644 (file)
@@ -33,7 +33,9 @@
 
 struct RoseEngine;
 
-// Note: identical signature to NfaCallback
+// Note: identical signature to NfaCallback, but all Rose callbacks must be
+// passed scratch as their context ptr.
+
 typedef int (*RoseCallback)(u64a offset, ReportID id, void *context);
 typedef int (*RoseCallbackSom)(u64a from_offset, u64a to_offset, ReportID id,
                                void *context);
index 981f0018126df5074a4c81c03fe8977a92011ec2..71984e92feb633cda7ec3847dd6f835af9992e05 100644 (file)
@@ -424,8 +424,7 @@ void do_rebuild(const struct RoseEngine *t, const struct HWLM *ftable,
 }
 
 void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
-                    RoseCallback callback, RoseCallbackSom som_callback,
-                    void *ctx) {
+                    RoseCallback callback, RoseCallbackSom som_callback) {
     DEBUG_PRINTF("OH HAI\n");
     assert(t);
     assert(scratch->core_info.hbuf);
@@ -458,7 +457,6 @@ void roseStreamExec(const struct RoseEngine *t, struct hs_scratch *scratch,
     tctxt->filledDelayedSlots = 0;
     tctxt->cb = callback;
     tctxt->cb_som = som_callback;
-    tctxt->userCtx = ctx;
     tctxt->lastMatchOffset = 0;
     tctxt->minMatchOffset = offset;
     tctxt->minNonMpvMatchOffset = offset;
index 8890e53f950ace60fc8156f468a64a194d0c557b..5276acf6e0a14abdd62d7be15e4842a78edd79c7 100644 (file)
@@ -687,7 +687,7 @@ void rawBlockExec(const struct RoseEngine *rose, struct hs_scratch *scratch) {
     DEBUG_PRINTF("blockmode scan len=%zu\n", scratch->core_info.len);
 
     roseBlockExec(rose, scratch, selectAdaptor(rose),
-                  selectSomAdaptor(rose), scratch);
+                  selectSomAdaptor(rose));
 }
 
 static really_inline
@@ -1018,7 +1018,7 @@ void rawEodExec(hs_stream_t *id, hs_scratch_t *scratch) {
     }
 
     roseEodExec(rose, id->offset, scratch, selectAdaptor(rose),
-                selectSomAdaptor(rose), scratch);
+                selectSomAdaptor(rose));
 }
 
 static never_inline
@@ -1190,8 +1190,7 @@ void rawStreamExec(struct hs_stream *stream_state, struct hs_scratch *scratch) {
 
     const struct RoseEngine *rose = stream_state->rose;
     assert(rose);
-    roseStreamExec(rose, scratch, selectAdaptor(rose), selectSomAdaptor(rose),
-                   scratch);
+    roseStreamExec(rose, scratch, selectAdaptor(rose), selectSomAdaptor(rose));
 
     if (!told_to_stop_matching(scratch) &&
         isAllExhausted(rose, scratch->core_info.exhaustionVector)) {
index fa112a568871b1a40ab539ca637c3a38c090f748..150db3f241341e1c0d92f7a925a684c648f8384a 100644 (file)
@@ -122,7 +122,6 @@ struct RoseContext {
                            * match, cleared if top events arrive */
     RoseCallback cb;
     RoseCallbackSom cb_som;
-    void *userCtx;
     u32 filledDelayedSlots;
     u32 curr_anchored_loc;   /**< last read/written row */
     u32 curr_row_offset; /**< last read/written entry */