mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
setupFDRFloodControl: return smart ptr
This commit is contained in:
parent
81880d5a8d
commit
9953a026f8
@ -144,7 +144,7 @@ void FDRCompiler::createInitialState(FDR *fdr) {
|
|||||||
aligned_unique_ptr<FDR> FDRCompiler::setupFDR(pair<u8 *, size_t> link) {
|
aligned_unique_ptr<FDR> FDRCompiler::setupFDR(pair<u8 *, size_t> link) {
|
||||||
size_t tabSize = eng.getTabSizeBytes();
|
size_t tabSize = eng.getTabSizeBytes();
|
||||||
|
|
||||||
pair<u8 *, size_t> floodControlTmp = setupFDRFloodControl(lits, eng);
|
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
||||||
|
|
||||||
pair<u8 *, size_t> confirmTmp =
|
pair<u8 *, size_t> confirmTmp =
|
||||||
setupFullMultiConfs(lits, eng, bucketToLits, make_small);
|
setupFullMultiConfs(lits, eng, bucketToLits, make_small);
|
||||||
@ -180,9 +180,8 @@ aligned_unique_ptr<FDR> FDRCompiler::setupFDR(pair<u8 *, size_t> link) {
|
|||||||
aligned_free(confirmTmp.first);
|
aligned_free(confirmTmp.first);
|
||||||
|
|
||||||
fdr->floodOffset = verify_u32(ptr - fdr_base);
|
fdr->floodOffset = verify_u32(ptr - fdr_base);
|
||||||
memcpy(ptr, floodControlTmp.first, floodControlTmp.second);
|
memcpy(ptr, floodControlTmp.first.get(), floodControlTmp.second);
|
||||||
ptr += floodControlTmp.second;
|
ptr += floodControlTmp.second;
|
||||||
aligned_free(floodControlTmp.first);
|
|
||||||
|
|
||||||
/* we are allowing domains 9 to 15 only */
|
/* we are allowing domains 9 to 15 only */
|
||||||
assert(eng.bits > 8 && eng.bits < 16);
|
assert(eng.bits > 8 && eng.bits < 16);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "ue2common.h"
|
#include "ue2common.h"
|
||||||
#include "hwlm/hwlm_literal.h"
|
#include "hwlm/hwlm_literal.h"
|
||||||
|
#include "util/alloc.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -65,7 +66,7 @@ std::pair<u8 *, size_t> setupFullMultiConfs(
|
|||||||
// we always read a full-scale flood "behind" us in terms of what's in our
|
// we always read a full-scale flood "behind" us in terms of what's in our
|
||||||
// state; if we don't have a flood that's long enough we won't be in the
|
// state; if we don't have a flood that's long enough we won't be in the
|
||||||
// right state yet to allow blindly advancing
|
// right state yet to allow blindly advancing
|
||||||
std::pair<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);
|
||||||
|
|
||||||
|
@ -90,8 +90,9 @@ void addFlood(vector<FDRFlood> &tmpFlood, u8 c, const hwlmLiteral &lit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<u8 *, size_t> setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
pair<aligned_unique_ptr<u8>, size_t>
|
||||||
const EngineDescription &eng) {
|
setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
||||||
|
const EngineDescription &eng) {
|
||||||
vector<FDRFlood> tmpFlood(N_CHARS);
|
vector<FDRFlood> tmpFlood(N_CHARS);
|
||||||
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
u32 default_suffix = eng.getDefaultFloodSuffixLength();
|
||||||
|
|
||||||
@ -195,11 +196,12 @@ pair<u8 *, size_t> setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
|||||||
size_t floodHeaderSize = sizeof(u32) * N_CHARS;
|
size_t floodHeaderSize = sizeof(u32) * N_CHARS;
|
||||||
size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods;
|
size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods;
|
||||||
size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize);
|
size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize);
|
||||||
u8 *buf = (u8 *)aligned_zmalloc(totalSize);
|
|
||||||
|
auto buf = aligned_zmalloc_unique<u8>(totalSize);
|
||||||
assert(buf); // otherwise would have thrown std::bad_alloc
|
assert(buf); // otherwise would have thrown std::bad_alloc
|
||||||
|
|
||||||
u32 *floodHeader = (u32 *)buf;
|
u32 *floodHeader = (u32 *)buf.get();
|
||||||
FDRFlood *layoutFlood = (FDRFlood * )(buf + floodHeaderSize);
|
FDRFlood *layoutFlood = (FDRFlood *)(buf.get() + floodHeaderSize);
|
||||||
|
|
||||||
u32 currentFloodIndex = 0;
|
u32 currentFloodIndex = 0;
|
||||||
for (const auto &m : flood2chars) {
|
for (const auto &m : flood2chars) {
|
||||||
@ -215,7 +217,7 @@ pair<u8 *, size_t> setupFDRFloodControl(const vector<hwlmLiteral> &lits,
|
|||||||
DEBUG_PRINTF("made a flood structure with %zu + %zu = %zu\n",
|
DEBUG_PRINTF("made a flood structure with %zu + %zu = %zu\n",
|
||||||
floodHeaderSize, floodStructSize, totalSize);
|
floodHeaderSize, floodStructSize, totalSize);
|
||||||
|
|
||||||
return make_pair((u8 *)buf, totalSize);
|
return make_pair(move(buf), totalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ue2
|
} // namespace ue2
|
||||||
|
@ -314,7 +314,7 @@ aligned_unique_ptr<FDR> TeddyCompiler::build(pair<u8 *, size_t> link) {
|
|||||||
|
|
||||||
size_t maskLen = eng.numMasks * 16 * 2 * maskWidth;
|
size_t maskLen = eng.numMasks * 16 * 2 * maskWidth;
|
||||||
|
|
||||||
pair<u8 *, size_t> floodControlTmp = setupFDRFloodControl(lits, eng);
|
auto floodControlTmp = setupFDRFloodControl(lits, eng);
|
||||||
pair<u8 *, size_t> confirmTmp
|
pair<u8 *, size_t> confirmTmp
|
||||||
= setupFullMultiConfs(lits, eng, bucketToLits, make_small);
|
= setupFullMultiConfs(lits, eng, bucketToLits, make_small);
|
||||||
|
|
||||||
@ -339,9 +339,8 @@ aligned_unique_ptr<FDR> TeddyCompiler::build(pair<u8 *, size_t> link) {
|
|||||||
aligned_free(confirmTmp.first);
|
aligned_free(confirmTmp.first);
|
||||||
|
|
||||||
teddy->floodOffset = verify_u32(ptr - teddy_base);
|
teddy->floodOffset = verify_u32(ptr - teddy_base);
|
||||||
memcpy(ptr, floodControlTmp.first, floodControlTmp.second);
|
memcpy(ptr, floodControlTmp.first.get(), floodControlTmp.second);
|
||||||
ptr += floodControlTmp.second;
|
ptr += floodControlTmp.second;
|
||||||
aligned_free(floodControlTmp.first);
|
|
||||||
|
|
||||||
if (link.first) {
|
if (link.first) {
|
||||||
teddy->link = verify_u32(ptr - teddy_base);
|
teddy->link = verify_u32(ptr - teddy_base);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user