literal matchers: change context passed to callback to scratch

This commit is contained in:
Wang, Xiang W
2017-07-04 12:24:11 -04:00
committed by Matthew Barr
parent bc232d272f
commit 67a8f43355
17 changed files with 203 additions and 188 deletions

View File

@@ -32,6 +32,7 @@
#include "fdr_internal.h"
#include "fdr_loadval.h"
#include "flood_runtime.h"
#include "scratch.h"
#include "teddy.h"
#include "teddy_internal.h"
#include "util/arch.h"
@@ -824,8 +825,8 @@ static const FDRFUNCTYPE funcs[] = {
static const u8 fake_history[FAKE_HISTORY_SIZE];
hwlm_error_t fdrExec(const struct FDR *fdr, const u8 *buf, size_t len,
size_t start, HWLMCallback cb, void *ctxt,
hwlm_group_t groups) {
size_t start, HWLMCallback cb,
struct hs_scratch *scratch, hwlm_group_t groups) {
// We guarantee (for safezone construction) that it is safe to read 16
// bytes before the end of the history buffer.
const u8 *hbuf = fake_history + FAKE_HISTORY_SIZE;
@@ -837,7 +838,7 @@ hwlm_error_t fdrExec(const struct FDR *fdr, const u8 *buf, size_t len,
0,
start,
cb,
ctxt,
scratch,
nextFloodDetect(buf, len, FLOOD_BACKOFF_START),
0
};
@@ -851,7 +852,8 @@ hwlm_error_t fdrExec(const struct FDR *fdr, const u8 *buf, size_t len,
hwlm_error_t fdrExecStreaming(const struct FDR *fdr, const u8 *hbuf,
size_t hlen, 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) {
struct FDR_Runtime_Args a = {
buf,
@@ -860,7 +862,7 @@ hwlm_error_t fdrExecStreaming(const struct FDR *fdr, const u8 *hbuf,
hlen,
start,
cb,
ctxt,
scratch,
nextFloodDetect(buf, len, FLOOD_BACKOFF_START),
/* we are guaranteed to always have 16 initialised bytes at the end of
* the history buffer (they may be garbage). */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -42,6 +42,7 @@ extern "C" {
#endif
struct FDR;
struct hs_scratch;
/**
* \brief Block-mode scan.
@@ -51,11 +52,11 @@ struct FDR;
* \param len Length of buffer to scan.
* \param start First offset in buf at which a match may end.
* \param cb Callback to call when a match is found.
* \param ctxt Caller-provided context pointer supplied to callback on match.
* \param scratch Scratch supplied to callback on match.
* \param groups Initial groups mask.
*/
hwlm_error_t fdrExec(const struct FDR *fdr, 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);
/**
@@ -68,12 +69,13 @@ hwlm_error_t fdrExec(const struct FDR *fdr, const u8 *buf, size_t len,
* \param len Length of buffer to scan (buf).
* \param start First offset in buf at which a match may end.
* \param cb Callback to call when a match is found.
* \param ctxt Caller-provided context pointer supplied to callback on match.
* \param scratch Scratch supplied to callback on match.
* \param groups Initial groups mask.
*/
hwlm_error_t fdrExecStreaming(const struct FDR *fdr, const u8 *hbuf,
size_t hlen, 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);
#ifdef __cplusplus

View File

@@ -88,7 +88,7 @@ void confWithBit(const struct FDRConfirm *fdrc, const struct FDR_Runtime_Args *a
}
*last_match = li->id;
*control = a->cb(i, li->id, a->ctxt);
*control = a->cb(i, li->id, a->scratch);
out:
oldNext = li->next; // oldNext is either 0 or an 'adjust' value
li++;

View File

@@ -36,6 +36,8 @@
#include "ue2common.h"
#include "hwlm/hwlm.h" // for hwlm_group_t, HWLMCallback
struct hs_scratch;
typedef enum {
NOT_CAUTIOUS, //!< not near a boundary (quantify?)
VECTORING //!< potentially vectoring
@@ -95,7 +97,7 @@ struct FDR_Runtime_Args {
size_t len_history;
size_t start_offset;
HWLMCallback cb;
void *ctxt;
struct hs_scratch *scratch;
const u8 *firstFloodDetect;
const u64a histBytes;
};

View File

@@ -94,7 +94,7 @@ const u8 * floodDetect(const struct FDR * fdr,
const u8 * buf = a->buf;
const size_t len = a->len;
HWLMCallback cb = a->cb;
void * ctxt = a->ctxt;
struct hs_scratch *scratch = a->scratch;
const u8 * ptr = *ptrPtr;
// tryFloodDetect is never put in places where unconditional
@@ -197,67 +197,67 @@ const u8 * floodDetect(const struct FDR * fdr,
t += 4) {
DEBUG_PRINTF("aaa %u %llx\n", t, fl->groups[0]);
if (*control & fl->groups[0]) {
*control = cb(i + t + 0, fl->ids[0], ctxt);
*control = cb(i + t + 0, fl->ids[0], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 1, fl->ids[0], ctxt);
*control = cb(i + t + 1, fl->ids[0], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 2, fl->ids[0], ctxt);
*control = cb(i + t + 2, fl->ids[0], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 3, fl->ids[0], ctxt);
*control = cb(i + t + 3, fl->ids[0], scratch);
}
}
break;
case 2:
for (u32 t = 0; t < floodSize && (*control & fl->allGroups); t += 4) {
if (*control & fl->groups[0]) {
*control = cb(i + t, fl->ids[0], ctxt);
*control = cb(i + t, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t, fl->ids[1], ctxt);
*control = cb(i + t, fl->ids[1], scratch);
}
if (*control & fl->groups[0]) {
*control =
cb(i + t + 1, fl->ids[0], ctxt);
cb(i + t + 1, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t + 1, fl->ids[1], ctxt);
*control = cb(i + t + 1, fl->ids[1], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 2, fl->ids[0], ctxt);
*control = cb(i + t + 2, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t + 2, fl->ids[1], ctxt);
*control = cb(i + t + 2, fl->ids[1], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 3, fl->ids[0], ctxt);
*control = cb(i + t + 3, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t + 3, fl->ids[1], ctxt);
*control = cb(i + t + 3, fl->ids[1], scratch);
}
}
break;
case 3:
for (u32 t = 0; t < floodSize && (*control & fl->allGroups); t += 2) {
if (*control & fl->groups[0]) {
*control = cb(i + t, fl->ids[0], ctxt);
*control = cb(i + t, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t, fl->ids[1], ctxt);
*control = cb(i + t, fl->ids[1], scratch);
}
if (*control & fl->groups[2]) {
*control = cb(i + t, fl->ids[2], ctxt);
*control = cb(i + t, fl->ids[2], scratch);
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 1, fl->ids[0], ctxt);
*control = cb(i + t + 1, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t + 1, fl->ids[1], ctxt);
*control = cb(i + t + 1, fl->ids[1], scratch);
}
if (*control & fl->groups[2]) {
*control = cb(i + t + 1, fl->ids[2], ctxt);
*control = cb(i + t + 1, fl->ids[2], scratch);
}
}
break;
@@ -266,40 +266,40 @@ const u8 * floodDetect(const struct FDR * fdr,
for (u32 t = 0; t < floodSize && (*control & fl->allGroups); t += 2) {
if (*control & fl->groups[0]) {
*control = cb(i + t, fl->ids[0], ctxt);
*control = cb(i + t, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t, fl->ids[1], ctxt);
*control = cb(i + t, fl->ids[1], scratch);
}
if (*control & fl->groups[2]) {
*control = cb(i + t, fl->ids[2], ctxt);
*control = cb(i + t, fl->ids[2], scratch);
}
if (*control & fl->groups[3]) {
*control = cb(i + t, fl->ids[3], ctxt);
*control = cb(i + t, fl->ids[3], scratch);
}
for (u32 t2 = 4; t2 < fl->idCount; t2++) {
if (*control & fl->groups[t2]) {
*control = cb(i + t, fl->ids[t2], ctxt);
*control = cb(i + t, fl->ids[t2], scratch);
}
}
if (*control & fl->groups[0]) {
*control = cb(i + t + 1, fl->ids[0], ctxt);
*control = cb(i + t + 1, fl->ids[0], scratch);
}
if (*control & fl->groups[1]) {
*control = cb(i + t + 1, fl->ids[1], ctxt);
*control = cb(i + t + 1, fl->ids[1], scratch);
}
if (*control & fl->groups[2]) {
*control = cb(i + t + 1, fl->ids[2], ctxt);
*control = cb(i + t + 1, fl->ids[2], scratch);
}
if (*control & fl->groups[3]) {
*control = cb(i + t + 1, fl->ids[3], ctxt);
*control = cb(i + t + 1, fl->ids[3], scratch);
}
for (u32 t2 = 4; t2 < fl->idCount; t2++) {
if (*control & fl->groups[t2]) {
*control = cb(i + t + 1, fl->ids[t2], ctxt);
*control = cb(i + t + 1, fl->ids[t2], scratch);
}
}
}
@@ -310,7 +310,7 @@ const u8 * floodDetect(const struct FDR * fdr,
for (u32 t = 0; t < floodSize && (*control & fl->allGroups); t++) {
for (u32 t2 = 0; t2 < fl->idCount; t2++) {
if (*control & fl->groups[t2]) {
*control = cb(i + t, fl->ids[t2], ctxt);
*control = cb(i + t, fl->ids[t2], scratch);
}
}
}