mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
fdr: add grey box control for flood detection
This commit is contained in:
parent
9363ae7486
commit
1be1293491
@ -74,6 +74,7 @@ namespace {
|
|||||||
class FDRCompiler : boost::noncopyable {
|
class FDRCompiler : boost::noncopyable {
|
||||||
private:
|
private:
|
||||||
const FDREngineDescription ŋ
|
const FDREngineDescription ŋ
|
||||||
|
const Grey &grey;
|
||||||
vector<u8> tab;
|
vector<u8> tab;
|
||||||
vector<hwlmLiteral> lits;
|
vector<hwlmLiteral> lits;
|
||||||
map<BucketIndex, std::vector<LiteralIndex> > bucketToLits;
|
map<BucketIndex, std::vector<LiteralIndex> > bucketToLits;
|
||||||
@ -90,9 +91,9 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
FDRCompiler(vector<hwlmLiteral> lits_in, const FDREngineDescription &eng_in,
|
FDRCompiler(vector<hwlmLiteral> lits_in, const FDREngineDescription &eng_in,
|
||||||
bool make_small_in)
|
bool make_small_in, const Grey &grey_in)
|
||||||
: eng(eng_in), tab(eng_in.getTabSizeBytes()), lits(move(lits_in)),
|
: eng(eng_in), grey(grey_in), tab(eng_in.getTabSizeBytes()),
|
||||||
make_small(make_small_in) {}
|
lits(move(lits_in)), make_small(make_small_in) {}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> build();
|
aligned_unique_ptr<FDR> build();
|
||||||
};
|
};
|
||||||
@ -146,7 +147,7 @@ void FDRCompiler::createInitialState(FDR *fdr) {
|
|||||||
aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
aligned_unique_ptr<FDR> FDRCompiler::setupFDR() {
|
||||||
size_t tabSize = eng.getTabSizeBytes();
|
size_t tabSize = eng.getTabSizeBytes();
|
||||||
|
|
||||||
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
auto floodControlTmp = setupFDRFloodControl(lits, eng, grey);
|
||||||
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
||||||
|
|
||||||
assert(ISALIGNED_16(tabSize));
|
assert(ISALIGNED_16(tabSize));
|
||||||
@ -543,7 +544,7 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
|||||||
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
|
DEBUG_PRINTF("cpu has %s\n", target.has_avx2() ? "avx2" : "no-avx2");
|
||||||
|
|
||||||
if (grey.fdrAllowTeddy) {
|
if (grey.fdrAllowTeddy) {
|
||||||
auto fdr = teddyBuildTableHinted(lits, make_small, hint, target);
|
auto fdr = teddyBuildTableHinted(lits, make_small, hint, target, grey);
|
||||||
if (fdr) {
|
if (fdr) {
|
||||||
DEBUG_PRINTF("build with teddy succeeded\n");
|
DEBUG_PRINTF("build with teddy succeeded\n");
|
||||||
return fdr;
|
return fdr;
|
||||||
@ -566,7 +567,7 @@ aligned_unique_ptr<FDR> fdrBuildTableInternal(const vector<hwlmLiteral> &lits,
|
|||||||
des->stride = 1;
|
des->stride = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FDRCompiler fc(lits, *des, make_small);
|
FDRCompiler fc(lits, *des, make_small, grey);
|
||||||
return fc.build();
|
return fc.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ typedef u32 PositionInBucket; // zero is 'we are matching right now!",
|
|||||||
class EngineDescription;
|
class EngineDescription;
|
||||||
class FDREngineDescription;
|
class FDREngineDescription;
|
||||||
struct hwlmStreamingControl;
|
struct hwlmStreamingControl;
|
||||||
|
struct Grey;
|
||||||
|
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t> setupFullConfs(
|
std::pair<aligned_unique_ptr<u8>, size_t> setupFullConfs(
|
||||||
const std::vector<hwlmLiteral> &lits, const EngineDescription &eng,
|
const std::vector<hwlmLiteral> &lits, const EngineDescription &eng,
|
||||||
@ -67,7 +68,7 @@ std::pair<aligned_unique_ptr<u8>, size_t> setupFullConfs(
|
|||||||
// right state yet to allow blindly advancing
|
// right state yet to allow blindly advancing
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t>
|
std::pair<aligned_unique_ptr<u8>, size_t>
|
||||||
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
setupFDRFloodControl(const std::vector<hwlmLiteral> &lits,
|
||||||
const EngineDescription &eng);
|
const EngineDescription &eng, const Grey &grey);
|
||||||
|
|
||||||
std::pair<aligned_unique_ptr<u8>, size_t>
|
std::pair<aligned_unique_ptr<u8>, size_t>
|
||||||
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
fdrBuildTableStreaming(const std::vector<hwlmLiteral> &lits,
|
||||||
|
@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -30,6 +30,7 @@
|
|||||||
#include "fdr_confirm.h"
|
#include "fdr_confirm.h"
|
||||||
#include "fdr_compile_internal.h"
|
#include "fdr_compile_internal.h"
|
||||||
#include "fdr_engine_description.h"
|
#include "fdr_engine_description.h"
|
||||||
|
#include "grey.h"
|
||||||
#include "ue2common.h"
|
#include "ue2common.h"
|
||||||
#include "util/alloc.h"
|
#include "util/alloc.h"
|
||||||
#include "util/bitutils.h"
|
#include "util/bitutils.h"
|
||||||
@ -92,7 +93,7 @@ void addFlood(vector<FDRFlood> &tmpFlood, u8 c, const hwlmLiteral &lit,
|
|||||||
|
|
||||||
pair<aligned_unique_ptr<u8>, size_t>
|
pair<aligned_unique_ptr<u8>, size_t>
|
||||||
setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
||||||
const EngineDescription &eng) {
|
const EngineDescription &eng, const Grey &grey) {
|
||||||
vector<FDRFlood> tmpFlood(N_CHARS);
|
vector<FDRFlood> tmpFlood(N_CHARS);
|
||||||
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
||||||
|
|
||||||
@ -187,6 +188,14 @@ setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// If flood detection has been switched off in the grey box, we comply by
|
||||||
|
// setting idCount too high for all floods.
|
||||||
|
if (!grey.fdrAllowFlood) {
|
||||||
|
for (auto &fl : tmpFlood) {
|
||||||
|
fl.idCount = FDR_FLOOD_MAX_IDS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
map<FDRFlood, CharReach, FloodComparator> flood2chars;
|
map<FDRFlood, CharReach, FloodComparator> flood2chars;
|
||||||
for (u32 i = 0; i < N_CHARS; i++) {
|
for (u32 i = 0; i < N_CHARS; i++) {
|
||||||
FDRFlood fl = tmpFlood[i];
|
FDRFlood fl = tmpFlood[i];
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "fdr_compile_internal.h"
|
#include "fdr_compile_internal.h"
|
||||||
#include "fdr_confirm.h"
|
#include "fdr_confirm.h"
|
||||||
#include "fdr_engine_description.h"
|
#include "fdr_engine_description.h"
|
||||||
|
#include "grey.h"
|
||||||
#include "ue2common.h"
|
#include "ue2common.h"
|
||||||
#include "util/alloc.h"
|
#include "util/alloc.h"
|
||||||
#include "util/compare.h"
|
#include "util/compare.h"
|
||||||
@ -66,13 +67,16 @@ namespace {
|
|||||||
|
|
||||||
class TeddyCompiler : boost::noncopyable {
|
class TeddyCompiler : boost::noncopyable {
|
||||||
const TeddyEngineDescription ŋ
|
const TeddyEngineDescription ŋ
|
||||||
|
const Grey &grey;
|
||||||
const vector<hwlmLiteral> &lits;
|
const vector<hwlmLiteral> &lits;
|
||||||
bool make_small;
|
bool make_small;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TeddyCompiler(const vector<hwlmLiteral> &lits_in,
|
TeddyCompiler(const vector<hwlmLiteral> &lits_in,
|
||||||
const TeddyEngineDescription &eng_in, bool make_small_in)
|
const TeddyEngineDescription &eng_in, bool make_small_in,
|
||||||
: eng(eng_in), lits(lits_in), make_small(make_small_in) {}
|
const Grey &grey_in)
|
||||||
|
: eng(eng_in), grey(grey_in), lits(lits_in), make_small(make_small_in) {
|
||||||
|
}
|
||||||
|
|
||||||
aligned_unique_ptr<FDR> build();
|
aligned_unique_ptr<FDR> build();
|
||||||
bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
|
bool pack(map<BucketIndex, std::vector<LiteralIndex> > &bucketToLits);
|
||||||
@ -307,7 +311,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
|||||||
|
|
||||||
size_t maskLen = eng.numMasks * 16 * 2 * maskWidth;
|
size_t maskLen = eng.numMasks * 16 * 2 * maskWidth;
|
||||||
|
|
||||||
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
auto floodControlTmp = setupFDRFloodControl(lits, eng, grey);
|
||||||
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
auto confirmTmp = setupFullConfs(lits, eng, bucketToLits, make_small);
|
||||||
|
|
||||||
size_t size = ROUNDUP_N(sizeof(Teddy) +
|
size_t size = ROUNDUP_N(sizeof(Teddy) +
|
||||||
@ -417,7 +421,8 @@ aligned_unique_ptr<FDR> TeddyCompiler::build() {
|
|||||||
|
|
||||||
aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
||||||
bool make_small, u32 hint,
|
bool make_small, u32 hint,
|
||||||
const target_t &target) {
|
const target_t &target,
|
||||||
|
const Grey &grey) {
|
||||||
unique_ptr<TeddyEngineDescription> des;
|
unique_ptr<TeddyEngineDescription> des;
|
||||||
if (hint == HINT_INVALID) {
|
if (hint == HINT_INVALID) {
|
||||||
des = chooseTeddyEngine(target, lits);
|
des = chooseTeddyEngine(target, lits);
|
||||||
@ -427,7 +432,7 @@ aligned_unique_ptr<FDR> teddyBuildTableHinted(const vector<hwlmLiteral> &lits,
|
|||||||
if (!des) {
|
if (!des) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
TeddyCompiler tc(lits, *des, make_small);
|
TeddyCompiler tc(lits, *des, make_small, grey);
|
||||||
return tc.build();
|
return tc.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,12 @@ struct target_t;
|
|||||||
|
|
||||||
namespace ue2 {
|
namespace ue2 {
|
||||||
|
|
||||||
|
struct Grey;
|
||||||
struct hwlmLiteral;
|
struct hwlmLiteral;
|
||||||
|
|
||||||
ue2::aligned_unique_ptr<FDR>
|
ue2::aligned_unique_ptr<FDR>
|
||||||
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
teddyBuildTableHinted(const std::vector<hwlmLiteral> &lits, bool make_small,
|
||||||
u32 hint, const target_t &target);
|
u32 hint, const target_t &target, const Grey &grey);
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ Grey::Grey(void) :
|
|||||||
allowDecoratedLiteral(true),
|
allowDecoratedLiteral(true),
|
||||||
allowNoodle(true),
|
allowNoodle(true),
|
||||||
fdrAllowTeddy(true),
|
fdrAllowTeddy(true),
|
||||||
|
fdrAllowFlood(true),
|
||||||
violetAvoidSuffixes(true),
|
violetAvoidSuffixes(true),
|
||||||
violetAvoidWeakInfixes(true),
|
violetAvoidWeakInfixes(true),
|
||||||
violetDoubleCut(true),
|
violetDoubleCut(true),
|
||||||
@ -226,6 +227,7 @@ void applyGreyOverrides(Grey *g, const string &s) {
|
|||||||
G_UPDATE(allowDecoratedLiteral);
|
G_UPDATE(allowDecoratedLiteral);
|
||||||
G_UPDATE(allowNoodle);
|
G_UPDATE(allowNoodle);
|
||||||
G_UPDATE(fdrAllowTeddy);
|
G_UPDATE(fdrAllowTeddy);
|
||||||
|
G_UPDATE(fdrAllowFlood);
|
||||||
G_UPDATE(violetAvoidSuffixes);
|
G_UPDATE(violetAvoidSuffixes);
|
||||||
G_UPDATE(violetAvoidWeakInfixes);
|
G_UPDATE(violetAvoidWeakInfixes);
|
||||||
G_UPDATE(violetDoubleCut);
|
G_UPDATE(violetDoubleCut);
|
||||||
|
@ -64,6 +64,7 @@ struct Grey {
|
|||||||
|
|
||||||
bool allowNoodle;
|
bool allowNoodle;
|
||||||
bool fdrAllowTeddy;
|
bool fdrAllowTeddy;
|
||||||
|
bool fdrAllowFlood;
|
||||||
|
|
||||||
u32 violetAvoidSuffixes; /* 0=never, 1=sometimes, 2=always */
|
u32 violetAvoidSuffixes; /* 0=never, 1=sometimes, 2=always */
|
||||||
bool violetAvoidWeakInfixes;
|
bool violetAvoidWeakInfixes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user