aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-10-29 15:55:35 -0600
committerDmitry Vyukov <dvyukov@google.com>2016-11-11 14:32:19 -0800
commit8b731ed4b705c3049af917f1c01db5b4a0bc59a1 (patch)
treec88367ff3b97ab93635983abb599dd93e63c2fe7
parentb40d502736438fcd899cda22e92fd0a159eecf4f (diff)
sys: replace FilenameType with BufferType{Kind: BufferFilename}
FilenameType is effectively a buffer, there is no need for a separate type.
-rw-r--r--prog/analysis.go13
-rw-r--r--prog/mutation.go5
-rw-r--r--prog/prio.go4
-rw-r--r--prog/prog.go2
-rw-r--r--prog/rand.go6
-rw-r--r--prog/validation.go6
-rw-r--r--sys/decl.go15
-rw-r--r--sysgen/sysgen.go2
8 files changed, 17 insertions, 36 deletions
diff --git a/prog/analysis.go b/prog/analysis.go
index 98973d4c7..4bf6506f1 100644
--- a/prog/analysis.go
+++ b/prog/analysis.go
@@ -51,18 +51,19 @@ func newState(ct *ChoiceTable) *state {
func (s *state) analyze(c *Call) {
foreachArgArray(&c.Args, c.Ret, func(arg, base *Arg, _ *[]*Arg) {
switch typ := arg.Type.(type) {
- case *sys.FilenameType:
- if arg.Kind == ArgData && arg.Type.Dir() != sys.DirOut {
- s.files[string(arg.Data)] = true
- }
case *sys.ResourceType:
if arg.Type.Dir() != sys.DirIn {
s.resources[typ.Desc.Name] = append(s.resources[typ.Desc.Name], arg)
// TODO: negative PIDs and add them as well (that's process groups).
}
case *sys.BufferType:
- if typ.Kind == sys.BufferString && arg.Kind == ArgData && len(arg.Data) != 0 {
- s.strings[string(arg.Data)] = true
+ if arg.Type.Dir() != sys.DirOut && arg.Kind == ArgData && len(arg.Data) != 0 {
+ switch typ.Kind {
+ case sys.BufferString:
+ s.strings[string(arg.Data)] = true
+ case sys.BufferFilename:
+ s.files[string(arg.Data)] = true
+ }
}
}
})
diff --git a/prog/mutation.go b/prog/mutation.go
index da8ad83bf..166d5a065 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -93,6 +93,8 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
}
case sys.BufferFilesystem:
arg.Data = r.filesystem(s)
+ case sys.BufferFilename:
+ arg.Data = []byte(r.filename(s))
case sys.BufferSockaddr:
arg.Data = r.sockaddr(s)
case sys.BufferAlgType:
@@ -102,9 +104,6 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
default:
panic("unknown buffer kind")
}
- case *sys.FilenameType:
- filename := r.filename(s)
- arg.Data = []byte(filename)
case *sys.ArrayType:
count := uintptr(0)
switch a.Kind {
diff --git a/prog/prio.go b/prog/prio.go
index a21218dd1..b5e4ba666 100644
--- a/prog/prio.go
+++ b/prog/prio.go
@@ -85,13 +85,13 @@ func calcStaticPriorities() [][]float32 {
noteUsage(0.2, "str")
case sys.BufferSockaddr:
noteUsage(1.0, "sockaddr")
+ case sys.BufferFilename:
+ noteUsage(1.0, "filename")
default:
panic("unknown buffer kind")
}
case *sys.VmaType:
noteUsage(0.5, "vma")
- case *sys.FilenameType:
- noteUsage(1.0, "filename")
case *sys.IntType:
switch a.Kind {
case sys.IntPlain:
diff --git a/prog/prog.go b/prog/prog.go
index 26e7dc0b8..8e8d3018e 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -106,8 +106,6 @@ func (a *Arg) Size() uintptr {
case *sys.IntType, *sys.LenType, *sys.FlagsType, *sys.ConstType, *sys.StrConstType,
*sys.FileoffType, *sys.ResourceType, *sys.VmaType, *sys.PtrType:
return typ.Size()
- case *sys.FilenameType:
- return uintptr(len(a.Data))
case *sys.BufferType:
return uintptr(len(a.Data))
case *sys.StructType:
diff --git a/prog/rand.go b/prog/rand.go
index 99fcd96a5..15db64d4e 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -732,6 +732,9 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg *Arg, calls []*Call)
case sys.BufferFilesystem:
data := r.filesystem(s)
return dataArg(a, data), nil
+ case sys.BufferFilename:
+ filename := r.filename(s)
+ return dataArg(a, []byte(filename)), nil
case sys.BufferSockaddr:
data := r.sockaddr(s)
if a.Dir() == sys.DirOut {
@@ -782,9 +785,6 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg *Arg, calls []*Call)
v = r.randRangeInt(a.RangeBegin, a.RangeEnd)
}
return constArg(a, v), nil
- case *sys.FilenameType:
- filename := r.filename(s)
- return dataArg(a, []byte(filename)), nil
case *sys.ArrayType:
count := uintptr(0)
switch a.Kind {
diff --git a/prog/validation.go b/prog/validation.go
index 1628e38fa..701d0ce3d 100644
--- a/prog/validation.go
+++ b/prog/validation.go
@@ -76,12 +76,6 @@ func (c *Call) validate(ctx *validCtx) error {
default:
return fmt.Errorf("syscall %v: fd arg '%v' has bad kind %v", c.Meta.Name, typ.Name(), arg.Kind)
}
- case *sys.FilenameType:
- switch arg.Kind {
- case ArgData:
- default:
- return fmt.Errorf("syscall %v: filename arg '%v' has bad kind %v", c.Meta.Name, typ.Name(), arg.Kind)
- }
case *sys.StructType, *sys.ArrayType:
switch arg.Kind {
case ArgGroup:
diff --git a/sys/decl.go b/sys/decl.go
index 66dc4370a..997298e8a 100644
--- a/sys/decl.go
+++ b/sys/decl.go
@@ -118,6 +118,7 @@ const (
BufferBlobRand BufferKind = iota
BufferBlobRange
BufferString
+ BufferFilename
BufferSockaddr
BufferFilesystem
BufferAlgType
@@ -251,18 +252,6 @@ func (t *IntType) Align() uintptr {
return t.Size()
}
-type FilenameType struct {
- TypeCommon
-}
-
-func (t *FilenameType) Size() uintptr {
- panic("filename size is not statically known")
-}
-
-func (t *FilenameType) Align() uintptr {
- return 1
-}
-
type ArrayKind int
const (
@@ -513,7 +502,7 @@ func ForeachType(meta *Call, f func(Type)) {
}
case *ResourceType, *FileoffType, *BufferType,
*VmaType, *LenType, *FlagsType, *ConstType,
- *StrConstType, *IntType, *FilenameType:
+ *StrConstType, *IntType:
default:
panic("unknown type")
}
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go
index c66f2af7a..bf3f57d8f 100644
--- a/sysgen/sysgen.go
+++ b/sysgen/sysgen.go
@@ -552,7 +552,7 @@ func generateArg(
ptrCommonHdr := common()
dir = "in"
opt = false
- fmt.Fprintf(out, "&PtrType{%v, Type: &FilenameType{%v}}", ptrCommonHdr, common())
+ fmt.Fprintf(out, "&PtrType{%v, Type: &BufferType{%v, Kind: BufferFilename}}", ptrCommonHdr, common())
case "array":
if len(a) != 1 && len(a) != 2 {
failf("wrong number of arguments for %v arg %v, want 1 or 2, got %v", typ, name, len(a))