runtime: add error for "scratch in use"

This commit adds the HS_SCRATCH_IN_USE error, which is returned when
Hyperscan detects that a scratch region is already in use on entry to an
API function.
This commit is contained in:
Justin Viiret
2016-04-28 09:34:37 +10:00
committed by Matthew Barr
parent 11896dcf42
commit c12b953131
7 changed files with 384 additions and 6 deletions

View File

@@ -129,6 +129,7 @@ hs_error_t alloc_scratch(const hs_scratch_t *proto, hs_scratch_t **scratch) {
*s = *proto;
s->magic = SCRATCH_MAGIC;
s->in_use = 1;
s->scratchSize = alloc_size;
s->scratch_alloc = (char *)s_tmp;
@@ -254,6 +255,9 @@ hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch) {
if ((*scratch)->magic != SCRATCH_MAGIC) {
return HS_INVALID;
}
if (markScratchInUse(*scratch)) {
return HS_SCRATCH_IN_USE;
}
}
const struct RoseEngine *rose = hs_get_bytecode(db);
@@ -355,6 +359,7 @@ hs_error_t hs_alloc_scratch(const hs_database_t *db, hs_scratch_t **scratch) {
hs_scratch_free(proto_tmp); /* kill off temp used for sizing */
}
unmarkScratchInUse(*scratch);
return HS_SUCCESS;
}
@@ -384,6 +389,10 @@ hs_error_t hs_free_scratch(hs_scratch_t *scratch) {
if (scratch->magic != SCRATCH_MAGIC) {
return HS_INVALID;
}
if (markScratchInUse(scratch)) {
return HS_SCRATCH_IN_USE;
}
scratch->magic = 0;
assert(scratch->scratch_alloc);
DEBUG_PRINTF("scratch %p is really at %p : freeing\n", scratch,