Rose: replace internal_report with program

Replace the use of the internal_report structure (for reports from
engines, MPV etc) with the Rose program interpreter.

SOM processing was reworked to use a new som_operation structure that is
embedded in the appropriate instructions.
This commit is contained in:
Justin Viiret
2016-03-22 16:45:09 +11:00
committed by Matthew Barr
parent 68851742cc
commit 36150bbc19
31 changed files with 877 additions and 1356 deletions

84
src/som/som_operation.h Normal file
View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file
* \brief SOM runtime: data structures.
*
* Data structures used for SOM operations.
*/
#ifndef SOM_OPERATION_H
#define SOM_OPERATION_H
#include "ue2common.h"
#define SOM_EXTERNAL_CALLBACK_REL 1
#define SOM_INTERNAL_LOC_SET 2
#define SOM_INTERNAL_LOC_SET_IF_UNSET 3
#define SOM_INTERNAL_LOC_SET_IF_WRITABLE 4
#define SOM_INTERNAL_LOC_SET_REV_NFA 5
#define SOM_INTERNAL_LOC_SET_REV_NFA_IF_UNSET 6
#define SOM_INTERNAL_LOC_SET_REV_NFA_IF_WRITABLE 7
#define SOM_INTERNAL_LOC_COPY 8
#define SOM_INTERNAL_LOC_COPY_IF_WRITABLE 9
#define SOM_INTERNAL_LOC_MAKE_WRITABLE 10
#define SOM_EXTERNAL_CALLBACK_STORED 11
#define SOM_EXTERNAL_CALLBACK_ABS 12
#define SOM_EXTERNAL_CALLBACK_REV_NFA 13
#define SOM_INTERNAL_LOC_SET_FROM 14
#define SOM_INTERNAL_LOC_SET_FROM_IF_WRITABLE 15
struct som_operation {
/** \brief Report type, from the definitions above. */
u8 type;
/* \brief SOM loc to modify. */
u32 onmatch;
union {
/** \brief SOM distance value, use varies according to type.
*
* - for SOM_EXTERNAL_CALLBACK_REL, from-offset is this many bytes
* before the to-offset.
* - for SOM_EXTERNAL_CALLBACK_ABS, set from-offset to this value.
* - for SOM_INTERNAL_LOC_COPY*, som location read_from.
*/
u64a somDistance;
/** \brief Index of the reverse nfa.
*
* Used by SOM_EXTERNAL_CALLBACK_REV_NFA and
* SOM_INTERNAL_LOC_SET_REV_NFA*.
*/
u64a revNfaIndex;
} aux;
};
#endif // SOM_OPERATION_H

View File

@@ -39,6 +39,7 @@
*/
#include "hs_internal.h"
#include "som_operation.h"
#include "som_runtime.h"
#include "scratch.h"
#include "ue2common.h"
@@ -47,11 +48,10 @@
#include "nfa/nfa_internal.h"
#include "util/fatbit.h"
#include "util/multibit.h"
#include "util/internal_report.h"
static really_inline
void setSomLoc(struct fatbit *som_set_now, u64a *som_store, u32 som_store_count,
const struct internal_report *ri, u64a to_offset) {
const struct som_operation *ri, u64a to_offset) {
/* validity handled by callers */
assert(to_offset >= ri->aux.somDistance);
u64a start_offset = to_offset - ri->aux.somDistance;
@@ -112,7 +112,7 @@ const struct NFA *getSomRevNFA(const struct RoseEngine *t, u32 i) {
}
static
void runRevNfa(struct hs_scratch *scratch, const struct internal_report *ri,
void runRevNfa(struct hs_scratch *scratch, const struct som_operation *ri,
const u64a to_offset, u64a *from_offset) {
struct core_info *ci = &scratch->core_info;
@@ -159,7 +159,7 @@ void runRevNfa(struct hs_scratch *scratch, const struct internal_report *ri,
static really_inline
void setSomLocRevNfa(struct hs_scratch *scratch, struct fatbit *som_set_now,
u64a *som_store, u32 som_store_count,
const struct internal_report *ri, u64a to_offset) {
const struct som_operation *ri, u64a to_offset) {
/* validity handled by callers */
u64a from_offset = 0;
runRevNfa(scratch, ri, to_offset, &from_offset);
@@ -178,7 +178,7 @@ void setSomLocRevNfa(struct hs_scratch *scratch, struct fatbit *som_set_now,
}
void handleSomInternal(struct hs_scratch *scratch,
const struct internal_report *ri, const u64a to_offset) {
const struct som_operation *ri, const u64a to_offset) {
assert(scratch);
assert(ri);
DEBUG_PRINTF("-->som action required at %llu\n", to_offset);
@@ -209,21 +209,21 @@ void handleSomInternal(struct hs_scratch *scratch,
}
switch (ri->type) {
case INTERNAL_SOM_LOC_SET:
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET\n");
case SOM_INTERNAL_LOC_SET:
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET\n");
mmbit_set(som_store_valid, som_store_count, ri->onmatch);
setSomLoc(som_set_now, som_store, som_store_count, ri, to_offset);
return;
case INTERNAL_SOM_LOC_SET_IF_UNSET:
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_IF_UNSET\n");
case SOM_INTERNAL_LOC_SET_IF_UNSET:
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_IF_UNSET\n");
if (ok_and_mark_if_unset(som_store_valid, som_set_now, som_store_count,
ri->onmatch)) {
setSomLoc(som_set_now, som_store, som_store_count, ri, to_offset);
}
return;
case INTERNAL_SOM_LOC_SET_IF_WRITABLE: {
case SOM_INTERNAL_LOC_SET_IF_WRITABLE: {
u32 slot = ri->onmatch;
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_IF_WRITABLE\n");
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_IF_WRITABLE\n");
if (ok_and_mark_if_write(som_store_valid, som_set_now,
som_store_writable, som_store_count, slot)) {
setSomLoc(som_set_now, som_store, som_store_count, ri, to_offset);
@@ -245,23 +245,23 @@ void handleSomInternal(struct hs_scratch *scratch,
}
return;
}
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA:
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_SOM_REV_NFA\n");
case SOM_INTERNAL_LOC_SET_REV_NFA:
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_REV_NFA\n");
mmbit_set(som_store_valid, som_store_count, ri->onmatch);
setSomLocRevNfa(scratch, som_set_now, som_store, som_store_count, ri,
to_offset);
return;
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_UNSET:
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_UNSET\n");
case SOM_INTERNAL_LOC_SET_REV_NFA_IF_UNSET:
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_REV_NFA_IF_UNSET\n");
if (ok_and_mark_if_unset(som_store_valid, som_set_now, som_store_count,
ri->onmatch)) {
setSomLocRevNfa(scratch, som_set_now, som_store, som_store_count,
ri, to_offset);
}
return;
case INTERNAL_SOM_LOC_SET_SOM_REV_NFA_IF_WRITABLE: {
case SOM_INTERNAL_LOC_SET_REV_NFA_IF_WRITABLE: {
u32 slot = ri->onmatch;
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_IF_WRITABLE\n");
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_IF_WRITABLE\n");
if (ok_and_mark_if_write(som_store_valid, som_set_now,
som_store_writable, som_store_count, slot)) {
setSomLocRevNfa(scratch, som_set_now, som_store, som_store_count,
@@ -285,10 +285,10 @@ void handleSomInternal(struct hs_scratch *scratch,
}
return;
}
case INTERNAL_SOM_LOC_COPY: {
case SOM_INTERNAL_LOC_COPY: {
u32 slot_in = ri->aux.somDistance;
u32 slot_out = ri->onmatch;
DEBUG_PRINTF("INTERNAL_SOM_LOC_COPY S[%u] = S[%u]\n", slot_out,
DEBUG_PRINTF("SOM_INTERNAL_LOC_COPY S[%u] = S[%u]\n", slot_out,
slot_in);
assert(mmbit_isset(som_store_valid, som_store_count, slot_in));
mmbit_set(som_store_valid, som_store_count, slot_out);
@@ -297,10 +297,10 @@ void handleSomInternal(struct hs_scratch *scratch,
return;
}
case INTERNAL_SOM_LOC_COPY_IF_WRITABLE: {
case SOM_INTERNAL_LOC_COPY_IF_WRITABLE: {
u32 slot_in = ri->aux.somDistance;
u32 slot_out = ri->onmatch;
DEBUG_PRINTF("INTERNAL_SOM_LOC_COPY_IF_WRITABLE S[%u] = S[%u]\n",
DEBUG_PRINTF("SOM_INTERNAL_LOC_COPY_IF_WRITABLE S[%u] = S[%u]\n",
slot_out, slot_in);
assert(mmbit_isset(som_store_valid, som_store_count, slot_in));
if (ok_and_mark_if_write(som_store_valid, som_set_now,
@@ -322,9 +322,9 @@ void handleSomInternal(struct hs_scratch *scratch,
}
return;
}
case INTERNAL_SOM_LOC_MAKE_WRITABLE: {
case SOM_INTERNAL_LOC_MAKE_WRITABLE: {
u32 slot = ri->onmatch;
DEBUG_PRINTF("INTERNAL_SOM_LOC_MAKE_WRITABLE\n");
DEBUG_PRINTF("SOM_INTERNAL_LOC_MAKE_WRITABLE\n");
/* if just written to the loc, ignore the racing escape */
if (fatbit_isset(som_set_now, som_store_count, slot)) {
DEBUG_PRINTF("just written\n");
@@ -347,14 +347,14 @@ void handleSomInternal(struct hs_scratch *scratch,
break;
}
// All valid internal_report types should be handled and returned above.
// All valid som_operation types should be handled and returned above.
assert(0);
return;
}
// Returns the SOM offset.
u64a handleSomExternal(struct hs_scratch *scratch,
const struct internal_report *ri,
const struct som_operation *ri,
const u64a to_offset) {
assert(scratch);
assert(ri);
@@ -368,20 +368,20 @@ u64a handleSomExternal(struct hs_scratch *scratch,
assert(rose->hasSom);
switch (ri->type) {
case EXTERNAL_CALLBACK_SOM_REL:
DEBUG_PRINTF("EXTERNAL_CALLBACK_SOM_REL: som is %llu chars back\n",
case SOM_EXTERNAL_CALLBACK_REL:
DEBUG_PRINTF("SOM_EXTERNAL_CALLBACK_REL: som is %llu chars back\n",
ri->aux.somDistance);
assert(to_offset >= ri->aux.somDistance);
return to_offset - ri->aux.somDistance;
case EXTERNAL_CALLBACK_SOM_ABS:
DEBUG_PRINTF("EXTERNAL_CALLBACK_SOM_ABS: som is at %llu\n",
case SOM_EXTERNAL_CALLBACK_ABS:
DEBUG_PRINTF("SOM_EXTERNAL_CALLBACK_ABS: som is at %llu\n",
ri->aux.somDistance);
assert(to_offset >= ri->aux.somDistance);
return ri->aux.somDistance;
case EXTERNAL_CALLBACK_SOM_STORED: {
case SOM_EXTERNAL_CALLBACK_STORED: {
const u64a *som_store = scratch->som_store;
u32 slot = ri->aux.somDistance;
DEBUG_PRINTF("EXTERNAL_CALLBACK_SOM_STORED: <- som_store[%u]=%llu\n",
DEBUG_PRINTF("SOM_EXTERNAL_CALLBACK_STORED: <- som_store[%u]=%llu\n",
slot, som_store[slot]);
UNUSED const u32 som_store_count = rose->somLocationCount;
@@ -391,8 +391,8 @@ u64a handleSomExternal(struct hs_scratch *scratch,
assert(mmbit_isset(som_store_valid, som_store_count, slot));
return som_store[slot];
}
case EXTERNAL_CALLBACK_SOM_REV_NFA: {
DEBUG_PRINTF("EXTERNAL_CALLBACK_REV_NFA\n");
case SOM_EXTERNAL_CALLBACK_REV_NFA: {
DEBUG_PRINTF("SOM_EXTERNAL_CALLBACK_REV_NFA\n");
u64a from_offset = 0;
runRevNfa(scratch, ri, to_offset, &from_offset);
return from_offset;
@@ -402,19 +402,19 @@ u64a handleSomExternal(struct hs_scratch *scratch,
break;
}
// All valid internal_report types should be handled and returned above.
// All valid som_operation types should be handled and returned above.
assert(0);
return 0;
}
void setSomFromSomAware(struct hs_scratch *scratch,
const struct internal_report *ri, u64a from_offset,
const struct som_operation *ri, u64a from_offset,
u64a to_offset) {
assert(scratch);
assert(ri);
assert(to_offset);
assert(ri->type == INTERNAL_SOM_LOC_SET_FROM
|| ri->type == INTERNAL_SOM_LOC_SET_FROM_IF_WRITABLE);
assert(ri->type == SOM_INTERNAL_LOC_SET_FROM
|| ri->type == SOM_INTERNAL_LOC_SET_FROM_IF_WRITABLE);
struct core_info *ci = &scratch->core_info;
const struct RoseEngine *rose = ci->rose;
@@ -435,12 +435,12 @@ void setSomFromSomAware(struct hs_scratch *scratch,
scratch->som_set_now_offset = to_offset;
}
if (ri->type == INTERNAL_SOM_LOC_SET_FROM) {
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_FROM\n");
if (ri->type == SOM_INTERNAL_LOC_SET_FROM) {
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_FROM\n");
mmbit_set(som_store_valid, som_store_count, ri->onmatch);
setSomLoc(som_set_now, som_store, som_store_count, ri, from_offset);
} else {
DEBUG_PRINTF("INTERNAL_SOM_LOC_SET_FROM_IF_WRITABLE\n");
DEBUG_PRINTF("SOM_INTERNAL_LOC_SET_FROM_IF_WRITABLE\n");
if (ok_and_mark_if_write(som_store_valid, som_set_now,
som_store_writable, som_store_count,
ri->onmatch)) {

View File

@@ -26,10 +26,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \file
/**
* \file
* \brief SOM runtime code.
*
*
* Runtime code for SOM handling called by the Rose callback adaptors.
*/
@@ -39,17 +39,17 @@
#include "scratch.h"
#include "ue2common.h"
struct internal_report;
struct som_operation;
void handleSomInternal(struct hs_scratch *scratch,
const struct internal_report *ri, const u64a to_offset);
const struct som_operation *ri, const u64a to_offset);
// Returns the from_offset.
u64a handleSomExternal(struct hs_scratch *scratch,
const struct internal_report *ri, const u64a to_offset);
const struct som_operation *ri, const u64a to_offset);
void setSomFromSomAware(struct hs_scratch *scratch,
const struct internal_report *ri, u64a from_offset,
const struct som_operation *ri, u64a from_offset,
u64a to_offset);
int flushStoredSomMatches_i(struct hs_scratch *scratch, u64a offset);