aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-02-26 15:00:46 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-02-26 15:00:46 +0100
commit14dae29c2abebd8886909c7a09c5795ffdd11515 (patch)
tree50ed602aa0d992d51393bee841b2925a459ae0d4 /prog
parent41f6f2579b51e89b33bff9f02830510d2b74d7c3 (diff)
executor: use proper default values for resources
We currently use -1 as default value for resources when the actual value is not available. -1 is good for fd's, but is not the right default value for pointers/keys/etc. Pass from prog and use in executor proper default value for resources.
Diffstat (limited to 'prog')
-rw-r--r--prog/any_test.go2
-rw-r--r--prog/decodeexec.go38
-rw-r--r--prog/encodingexec.go1
-rw-r--r--prog/encodingexec_test.go2
-rw-r--r--prog/minimization_test.go4
-rw-r--r--prog/prog.go4
6 files changed, 31 insertions, 20 deletions
diff --git a/prog/any_test.go b/prog/any_test.go
index eff50e946..104f77f9d 100644
--- a/prog/any_test.go
+++ b/prog/any_test.go
@@ -40,7 +40,7 @@ func TestSquash(t *testing.T) {
}{
{
`foo$any0(&(0x7f0000000000)={0x11, 0x11223344, 0x2233, 0x1122334455667788, [{0x0, @res32=0x0, 0x0, @i8=0x44, "aabb"}, {0x0, @res64=0x1, 0x0, @i32=0x11223344, "1122334455667788"}]})`,
- `foo$any0(&(0x7f0000000000)=ANY=[@ANYBLOB="1100000044332211223300000000000088776655443322110000000000000000", @ANYRES32, @ANYBLOB="00000000000000000000000044aabb000000000000000000", @ANYRES64=0x1, @ANYBLOB="0000000000000000443322111122334455667788"])`,
+ `foo$any0(&(0x7f0000000000)=ANY=[@ANYBLOB="1100000044332211223300000000000088776655443322110000000000000000", @ANYRES32=0x0, @ANYBLOB="00000000000000000000000044aabb000000000000000000", @ANYRES64=0x1, @ANYBLOB="0000000000000000443322111122334455667788"])`,
},
}
for i, test := range tests {
diff --git a/prog/decodeexec.go b/prog/decodeexec.go
index a16461782..f8c29a517 100644
--- a/prog/decodeexec.go
+++ b/prog/decodeexec.go
@@ -8,8 +8,8 @@ import (
)
type ExecProg struct {
- Calls []ExecCall
- NumVars uint64
+ Calls []ExecCall
+ Vars []uint64
}
type ExecCall struct {
@@ -43,10 +43,11 @@ type ExecArgConst struct {
}
type ExecArgResult struct {
- Size uint64
- Index uint64
- DivOp uint64
- AddOp uint64
+ Size uint64
+ Index uint64
+ DivOp uint64
+ AddOp uint64
+ Default uint64
}
type ExecArgData struct {
@@ -71,9 +72,13 @@ func (target *Target) DeserializeExec(exec []byte) (ExecProg, error) {
if dec.err != nil {
return ExecProg{}, dec.err
}
+ if uint64(len(dec.vars)) != dec.numVars {
+ return ExecProg{}, fmt.Errorf("mismatching number of vars: %v/%v",
+ len(dec.vars), dec.numVars)
+ }
p := ExecProg{
- Calls: dec.calls,
- NumVars: dec.numVars,
+ Calls: dec.calls,
+ Vars: dec.vars,
}
return p, nil
}
@@ -83,6 +88,7 @@ type execDecoder struct {
data []byte
err error
numVars uint64
+ vars []uint64
call ExecCall
calls []ExecCall
}
@@ -139,12 +145,18 @@ func (dec *execDecoder) readArg() ExecArg {
BigEndian: (meta & (1 << 8)) != 0,
}
case execArgResult:
- return ExecArgResult{
- Size: dec.read(),
- Index: dec.read(),
- DivOp: dec.read(),
- AddOp: dec.read(),
+ arg := ExecArgResult{
+ Size: dec.read(),
+ Index: dec.read(),
+ DivOp: dec.read(),
+ AddOp: dec.read(),
+ Default: dec.read(),
+ }
+ for uint64(len(dec.vars)) <= arg.Index {
+ dec.vars = append(dec.vars, 0)
}
+ dec.vars[arg.Index] = arg.Default
+ return arg
case execArgData:
return ExecArgData{
Data: dec.readBlob(dec.read()),
diff --git a/prog/encodingexec.go b/prog/encodingexec.go
index 8ecec3a03..ea01560d9 100644
--- a/prog/encodingexec.go
+++ b/prog/encodingexec.go
@@ -247,6 +247,7 @@ func (w *execContext) writeArg(arg Arg) {
w.write(info.Idx)
w.write(a.OpDiv)
w.write(a.OpAdd)
+ w.write(a.Type().(*ResourceType).Default())
}
case *PointerArg:
w.writeConstArg(a.Size(), w.target.PhysicalAddr(a), 0, 0, 0, false)
diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go
index 2ad19598e..1b3fb14b4 100644
--- a/prog/encodingexec_test.go
+++ b/prog/encodingexec_test.go
@@ -58,7 +58,6 @@ func TestSerializeForExec(t *testing.T) {
Index: ExecNoCopyout,
},
},
- NumVars: 0,
},
},
{
@@ -341,7 +340,6 @@ func TestSerializeForExec(t *testing.T) {
},
},
},
- NumVars: 0,
},
},
{
diff --git a/prog/minimization_test.go b/prog/minimization_test.go
index 5979ce7a2..70137fa65 100644
--- a/prog/minimization_test.go
+++ b/prog/minimization_test.go
@@ -20,7 +20,7 @@ func TestMinimize(t *testing.T) {
{
"mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x3, 0x32, 0xffffffffffffffff, 0x0)\n" +
"sched_yield()\n" +
- "pipe2(&(0x7f0000000000)={0x0, 0x0}, 0x0)\n",
+ "pipe2(&(0x7f0000000000), 0x0)\n",
2,
func(p *Prog, callIndex int) bool {
if len(p.Calls) == 0 {
@@ -47,7 +47,7 @@ func TestMinimize(t *testing.T) {
return len(p.Calls) == 2 && p.Calls[0].Meta.Name == "mmap" && p.Calls[1].Meta.Name == "pipe2"
},
"mmap(&(0x7f0000000000/0x1000)=nil, 0x1000, 0x0, 0x0, 0xffffffffffffffff, 0x0)\n" +
- "pipe2(&(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}, 0x0)\n",
+ "pipe2(&(0x7f0000000000), 0x0)\n",
1,
},
// Remove two dependent calls.
diff --git a/prog/prog.go b/prog/prog.go
index dadc02cd5..f9f088760 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -333,7 +333,7 @@ func (target *Target) defaultArg(t Type) Arg {
case *IntType, *ConstType, *FlagsType, *LenType, *ProcType, *CsumType:
return MakeConstArg(t, t.Default())
case *ResourceType:
- return MakeResultArg(t, nil, typ.Desc.Type.Default())
+ return MakeResultArg(t, nil, typ.Default())
case *BufferType:
if t.Dir() == DirOut {
var sz uint64
@@ -432,7 +432,7 @@ func (target *Target) isDefaultArg(arg Arg) bool {
case *ResultArg:
t := a.Type().(*ResourceType)
return a.Res == nil && a.OpDiv == 0 && a.OpAdd == 0 &&
- len(a.uses) == 0 && a.Val == t.Desc.Type.Default()
+ len(a.uses) == 0 && a.Val == t.Default()
}
return false
}