mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
literal matchers: change context passed to callback to scratch
This commit is contained in:
committed by
Matthew Barr
parent
bc232d272f
commit
67a8f43355
@@ -170,7 +170,7 @@ void do_accel_streaming(const union AccelAux *aux, const u8 *hbuf, size_t hlen,
|
||||
}
|
||||
|
||||
hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len,
|
||||
size_t start, HWLMCallback cb, void *ctxt,
|
||||
size_t start, HWLMCallback cb, struct hs_scratch *scratch,
|
||||
hwlm_group_t groups) {
|
||||
assert(t);
|
||||
|
||||
@@ -184,7 +184,7 @@ hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len,
|
||||
|
||||
if (t->type == HWLM_ENGINE_NOOD) {
|
||||
DEBUG_PRINTF("calling noodExec\n");
|
||||
return noodExec(HWLM_C_DATA(t), buf, len, start, cb, ctxt);
|
||||
return noodExec(HWLM_C_DATA(t), buf, len, start, cb, scratch);
|
||||
}
|
||||
|
||||
assert(t->type == HWLM_ENGINE_FDR);
|
||||
@@ -195,12 +195,12 @@ hwlm_error_t hwlmExec(const struct HWLM *t, const u8 *buf, size_t len,
|
||||
}
|
||||
do_accel_block(aa, buf, len, &start);
|
||||
DEBUG_PRINTF("calling frankie (groups=%08llx, start=%zu)\n", groups, start);
|
||||
return fdrExec(HWLM_C_DATA(t), buf, len, start, cb, ctxt, groups);
|
||||
return fdrExec(HWLM_C_DATA(t), buf, len, start, cb, scratch, groups);
|
||||
}
|
||||
|
||||
hwlm_error_t hwlmExecStreaming(const struct HWLM *t, struct hs_scratch *scratch,
|
||||
size_t len, size_t start, HWLMCallback cb,
|
||||
void *ctxt, hwlm_group_t groups) {
|
||||
hwlm_error_t hwlmExecStreaming(const struct HWLM *t, size_t len, size_t start,
|
||||
HWLMCallback cb, struct hs_scratch *scratch,
|
||||
hwlm_group_t groups) {
|
||||
assert(t);
|
||||
assert(scratch);
|
||||
|
||||
@@ -222,10 +222,10 @@ hwlm_error_t hwlmExecStreaming(const struct HWLM *t, struct hs_scratch *scratch,
|
||||
// If we've been handed a start offset, we can use a block mode scan at
|
||||
// that offset.
|
||||
if (start) {
|
||||
return noodExec(HWLM_C_DATA(t), buf, len, start, cb, ctxt);
|
||||
return noodExec(HWLM_C_DATA(t), buf, len, start, cb, scratch);
|
||||
} else {
|
||||
return noodExecStreaming(HWLM_C_DATA(t), hbuf, hlen, buf, len, cb,
|
||||
ctxt);
|
||||
scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,5 +238,5 @@ hwlm_error_t hwlmExecStreaming(const struct HWLM *t, struct hs_scratch *scratch,
|
||||
do_accel_streaming(aa, hbuf, hlen, buf, len, &start);
|
||||
DEBUG_PRINTF("calling frankie (groups=%08llx, start=%zu)\n", groups, start);
|
||||
return fdrExecStreaming(HWLM_C_DATA(t), hbuf, hlen, buf, len, start, cb,
|
||||
ctxt, groups);
|
||||
scratch, groups);
|
||||
}
|
||||
|
@@ -95,7 +95,8 @@ struct HWLM;
|
||||
* belonging to the literal which was active at the when the end match location
|
||||
* was first reached.
|
||||
*/
|
||||
typedef hwlmcb_rv_t (*HWLMCallback)(size_t end, u32 id, void *context);
|
||||
typedef hwlmcb_rv_t (*HWLMCallback)(size_t end, u32 id,
|
||||
struct hs_scratch *scratch);
|
||||
|
||||
/** \brief Match strings in table.
|
||||
*
|
||||
@@ -112,29 +113,28 @@ typedef hwlmcb_rv_t (*HWLMCallback)(size_t end, u32 id, void *context);
|
||||
* the first possible match of a literal which is in the initial group mask.
|
||||
*/
|
||||
hwlm_error_t hwlmExec(const struct HWLM *tab, const u8 *buf, size_t len,
|
||||
size_t start, HWLMCallback callback, void *context,
|
||||
hwlm_group_t groups);
|
||||
size_t start, HWLMCallback callback,
|
||||
struct hs_scratch *scratch, hwlm_group_t groups);
|
||||
|
||||
/** \brief As for \ref hwlmExec, but a streaming case across two buffers.
|
||||
*
|
||||
* \p scratch is used to access fdr_temp_buf and to access the history buffer,
|
||||
* history length and the main buffer.
|
||||
*
|
||||
* \p len is the length of the main buffer to be scanned.
|
||||
*
|
||||
* \p start is an advisory hint representing the first offset at which a match
|
||||
* may start. Some underlying literal matches may not respect it.
|
||||
*
|
||||
* \p scratch is used to access the history buffer, history length and
|
||||
* the main buffer.
|
||||
*
|
||||
* Two buffers/lengths are provided. Matches that occur entirely within
|
||||
* the history buffer will not be reported by this function. The offsets
|
||||
* reported for the main buffer are relative to the start of that buffer (a
|
||||
* match at byte 10 of the main buffer is reported as 10). Matches that start
|
||||
* in the history buffer will have starts reported with 'negative' values.
|
||||
*/
|
||||
hwlm_error_t hwlmExecStreaming(const struct HWLM *tab,
|
||||
struct hs_scratch *scratch, size_t len,
|
||||
size_t start, HWLMCallback callback,
|
||||
void *context, hwlm_group_t groups);
|
||||
hwlm_error_t hwlmExecStreaming(const struct HWLM *tab, size_t len, size_t start,
|
||||
HWLMCallback callback,
|
||||
struct hs_scratch *scratch, hwlm_group_t groups);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "hwlm.h"
|
||||
#include "noodle_engine.h"
|
||||
#include "noodle_internal.h"
|
||||
#include "scratch.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/arch.h"
|
||||
#include "util/bitutils.h"
|
||||
@@ -50,7 +51,7 @@
|
||||
struct cb_info {
|
||||
HWLMCallback cb; //!< callback function called on match
|
||||
u32 id; //!< ID to pass to callback on match
|
||||
void *ctx; //!< caller-supplied context to pass to callback
|
||||
struct hs_scratch *scratch; //!< scratch to pass to callback
|
||||
size_t offsetAdj; //!< used in streaming mode
|
||||
};
|
||||
|
||||
@@ -129,7 +130,7 @@ hwlm_error_t final(const struct noodTable *n, const u8 *buf, UNUSED size_t len,
|
||||
match:
|
||||
pos -= cbi->offsetAdj;
|
||||
DEBUG_PRINTF("match @ %zu\n", pos + n->key_offset);
|
||||
hwlmcb_rv_t rv = cbi->cb(pos + n->key_offset - 1, cbi->id, cbi->ctx);
|
||||
hwlmcb_rv_t rv = cbi->cb(pos + n->key_offset - 1, cbi->id, cbi->scratch);
|
||||
if (rv == HWLM_TERMINATE_MATCHING) {
|
||||
return HWLM_TERMINATED;
|
||||
}
|
||||
@@ -371,10 +372,11 @@ hwlm_error_t scan(const struct noodTable *n, const u8 *buf, size_t len,
|
||||
|
||||
/** \brief Block-mode scanner. */
|
||||
hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len,
|
||||
size_t start, HWLMCallback cb, void *ctxt) {
|
||||
size_t start, HWLMCallback cb,
|
||||
struct hs_scratch *scratch) {
|
||||
assert(n && buf);
|
||||
|
||||
struct cb_info cbi = {cb, n->id, ctxt, 0};
|
||||
struct cb_info cbi = {cb, n->id, scratch, 0};
|
||||
DEBUG_PRINTF("nood scan of %zu bytes for %*s @ %p\n", len, n->msk_len,
|
||||
(const char *)&n->cmp, buf);
|
||||
|
||||
@@ -384,7 +386,7 @@ hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len,
|
||||
/** \brief Streaming-mode scanner. */
|
||||
hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
size_t hlen, const u8 *buf, size_t len,
|
||||
HWLMCallback cb, void *ctxt) {
|
||||
HWLMCallback cb, struct hs_scratch *scratch) {
|
||||
assert(n);
|
||||
|
||||
if (len + hlen < n->msk_len) {
|
||||
@@ -392,7 +394,7 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
return HWLM_SUCCESS;
|
||||
}
|
||||
|
||||
struct cb_info cbi = {cb, n->id, ctxt, 0};
|
||||
struct cb_info cbi = {cb, n->id, scratch, 0};
|
||||
DEBUG_PRINTF("nood scan of %zu bytes (%zu hlen) for %*s @ %p\n", len, hlen,
|
||||
n->msk_len, (const char *)&n->cmp, buf);
|
||||
|
||||
@@ -425,7 +427,7 @@ hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
if ((v & n->msk) == n->cmp) {
|
||||
size_t m_end = -tl1 + i + n->msk_len - 1;
|
||||
DEBUG_PRINTF("match @ %zu (i %zu)\n", m_end, i);
|
||||
hwlmcb_rv_t rv = cb(m_end, n->id, ctxt);
|
||||
hwlmcb_rv_t rv = cb(m_end, n->id, scratch);
|
||||
if (rv == HWLM_TERMINATE_MATCHING) {
|
||||
return HWLM_TERMINATED;
|
||||
}
|
||||
|
@@ -41,15 +41,17 @@ extern "C"
|
||||
#endif
|
||||
|
||||
struct noodTable;
|
||||
struct hs_scratch;
|
||||
|
||||
/** \brief Block-mode scanner. */
|
||||
hwlm_error_t noodExec(const struct noodTable *n, const u8 *buf, size_t len,
|
||||
size_t start, HWLMCallback cb, void *ctxt);
|
||||
size_t start, HWLMCallback cb,
|
||||
struct hs_scratch *scratch);
|
||||
|
||||
/** \brief Streaming-mode scanner. */
|
||||
hwlm_error_t noodExecStreaming(const struct noodTable *n, const u8 *hbuf,
|
||||
size_t hlen, const u8 *buf, size_t len,
|
||||
HWLMCallback cb, void *ctxt);
|
||||
HWLMCallback cb, struct hs_scratch *scratch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
Reference in New Issue
Block a user