/*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2022, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* callers.
*/
static really_inline
-char validScratch(const struct RoseEngine *t, const struct hs_scratch *s) {
+char validScratch(const struct hs_scratch *s, u32 crc) {
if (!ISALIGNED_CL(s)) {
DEBUG_PRINTF("bad alignment %p\n", s);
return 0;
return 0;
}
- if (t->mode == HS_MODE_BLOCK && t->stateOffsets.end > s->bStateSize) {
- DEBUG_PRINTF("bad state size\n");
+ /* add quick rose sanity checks by db crc*/
+ if (s->db_crc != crc) {
+ DEBUG_PRINTF("Improper scratch for current db\n");
return 0;
}
- if (t->queueCount > s->queueCount) {
- DEBUG_PRINTF("bad queue count\n");
- return 0;
- }
-
- /* TODO: add quick rose sanity checks */
-
return 1;
}
return HS_DB_MODE_ERROR;
}
- if (unlikely(!validScratch(rose, scratch))) {
+ if (unlikely(!validScratch(scratch, db->crc32))) {
return HS_INVALID;
}
static really_inline
void init_stream(struct hs_stream *s, const struct RoseEngine *rose,
- char init_history) {
+ char init_history, u32 crc) {
char *state = getMultiState(s);
if (init_history) {
s->rose = rose;
s->offset = 0;
+ s->crc32 = crc;
setStreamStatus(state, 0);
roseInitState(rose, state);
return HS_NOMEM;
}
- init_stream(s, rose, 1);
+ init_stream(s, rose, 1, db->crc32);
*stream = s;
return HS_SUCCESS;
}
if (onEvent) {
- if (!scratch || !validScratch(to_id->rose, scratch)) {
+ if (!scratch || !validScratch(scratch, to_id->crc32)) {
return HS_INVALID;
}
if (unlikely(markScratchInUse(scratch))) {
hs_scratch_t *scratch,
match_event_handler onEvent, void *context) {
if (unlikely(!id || !scratch || !data ||
- !validScratch(id->rose, scratch))) {
+ !validScratch(scratch, id->crc32))) {
return HS_INVALID;
}
}
if (onEvent) {
- if (!scratch || !validScratch(id->rose, scratch)) {
+ if (!scratch || !validScratch(scratch, id->crc32)) {
return HS_INVALID;
}
if (unlikely(markScratchInUse(scratch))) {
}
if (onEvent) {
- if (!scratch || !validScratch(id->rose, scratch)) {
+ if (!scratch || !validScratch(scratch, id->crc32)) {
return HS_INVALID;
}
if (unlikely(markScratchInUse(scratch))) {
}
// history already initialised
- init_stream(id, id->rose, 0);
+ init_stream(id, id->rose, 0, id->crc32);
return HS_SUCCESS;
}
return HS_DB_MODE_ERROR;
}
- if (unlikely(!validScratch(rose, scratch))) {
+ if (unlikely(!validScratch(scratch, db->crc32))) {
return HS_INVALID;
}
hs_stream_t *id = (hs_stream_t *)(scratch->bstate);
- init_stream(id, rose, 1); /* open stream */
+ init_stream(id, rose, 1, db->crc32); /* open stream */
for (u32 i = 0; i < count; i++) {
DEBUG_PRINTF("block %u/%u offset=%llu len=%u\n", i, count, id->offset,
const struct RoseEngine *rose = to_stream->rose;
if (onEvent) {
- if (!scratch || !validScratch(to_stream->rose, scratch)) {
+ if (!scratch || !validScratch(scratch, to_stream->crc32)) {
return HS_INVALID;
}
if (unlikely(markScratchInUse(scratch))) {
/*
- * Copyright (c) 2015-2019, Intel Corporation
+ * Copyright (c) 2015-2022, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
hs_scratch_free((*scratch)->scratch_alloc);
}
+ proto->db_crc = db->crc32;
hs_error_t alloc_ret = alloc_scratch(proto, scratch);
hs_scratch_free(proto_tmp); /* kill off temp used for sizing */
if (alloc_ret != HS_SUCCESS) {
return alloc_ret;
}
} else {
+ (*scratch)->db_crc = db->crc32;
hs_scratch_free(proto_tmp); /* kill off temp used for sizing */
unmarkScratchInUse(*scratch);
}