From a7ce77be27d8e3728b97122a005bc5b23298cfc3 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 24 Aug 2021 15:50:19 +0000 Subject: all: introduce call properties Call properties let us specify how each individual call within a program must be executed. So far the only way to enforce extra rules was to pass extra program-level properties (e.g. that is how fault injection was done). However, it entangles the logic and not flexible enough. Implement an ability to pass properties along with each individual call. --- prog/decodeexec.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'prog/decodeexec.go') diff --git a/prog/decodeexec.go b/prog/decodeexec.go index e2ef2586c..ff1ab5727 100644 --- a/prog/decodeexec.go +++ b/prog/decodeexec.go @@ -5,6 +5,7 @@ package prog import ( "fmt" + "reflect" ) type ExecProg struct { @@ -14,6 +15,7 @@ type ExecProg struct { type ExecCall struct { Meta *Syscall + Props CallProps Index uint64 Args []ExecArg Copyin []ExecCopyin @@ -119,6 +121,7 @@ func (dec *execDecoder) parse() { dec.setErr(fmt.Errorf("bad syscall %v", instr)) return } + dec.readCallProps(&dec.call.Props) dec.call.Meta = dec.target.Syscalls[instr] dec.call.Index = dec.read() for i := dec.read(); i > 0; i-- { @@ -134,6 +137,18 @@ func (dec *execDecoder) parse() { } } +func (dec *execDecoder) readCallProps(props *CallProps) { + props.ForeachProp(func(_, _ string, value reflect.Value) { + arg := dec.read() + switch kind := value.Kind(); kind { + case reflect.Int: + value.SetInt(int64(arg)) + default: + panic("Unsupported (yet) kind: " + kind.String()) + } + }) +} + func (dec *execDecoder) readArg() ExecArg { switch typ := dec.read(); typ { case execArgConst: -- cgit mrf-deployment