diff --git a/src/rose/block.c b/src/rose/block.c index a3174b63..3d4a008d 100644 --- a/src/rose/block.c +++ b/src/rose/block.c @@ -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; diff --git a/src/rose/catchup.c b/src/rose/catchup.c index 6893df0e..b302fbdd 100644 --- a/src/rose/catchup.c +++ b/src/rose/catchup.c @@ -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; diff --git a/src/rose/eod.c b/src/rose/eod.c index 3ababb83..2e414ad7 100644 --- a/src/rose/eod.c +++ b/src/rose/eod.c @@ -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); } diff --git a/src/rose/program_runtime.h b/src/rose/program_runtime.h index 309fee5b..f76689f4 100644 --- a/src/rose/program_runtime.h +++ b/src/rose/program_runtime.h @@ -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; diff --git a/src/rose/rose.h b/src/rose/rose.h index c855795e..16cfa435 100644 --- a/src/rose/rose.h +++ b/src/rose/rose.h @@ -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 diff --git a/src/rose/rose_types.h b/src/rose/rose_types.h index 1b80b2b2..1ba453fe 100644 --- a/src/rose/rose_types.h +++ b/src/rose/rose_types.h @@ -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); diff --git a/src/rose/stream.c b/src/rose/stream.c index 981f0018..71984e92 100644 --- a/src/rose/stream.c +++ b/src/rose/stream.c @@ -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; diff --git a/src/runtime.c b/src/runtime.c index 8890e53f..5276acf6 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -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)) { diff --git a/src/scratch.h b/src/scratch.h index fa112a56..150db3f2 100644 --- a/src/scratch.h +++ b/src/scratch.h @@ -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 */