aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/host.go10
-rw-r--r--prog/analysis.go22
-rw-r--r--prog/encoding.go8
-rw-r--r--prog/mutation.go20
-rw-r--r--prog/prio.go24
-rw-r--r--prog/prog.go22
-rw-r--r--prog/rand.go30
-rw-r--r--prog/validation.go10
-rw-r--r--sys/align.go10
-rw-r--r--sys/decl.go100
-rw-r--r--sysgen/sysgen.go50
11 files changed, 153 insertions, 153 deletions
diff --git a/host/host.go b/host/host.go
index 220f8aaf6..49cf78e57 100644
--- a/host/host.go
+++ b/host/host.go
@@ -60,11 +60,11 @@ func isSupportedSyzkall(c *sys.Call) bool {
case "syz_test":
return false
case "syz_open_dev":
- ptr, ok := c.Args[0].(sys.PtrType)
+ ptr, ok := c.Args[0].(*sys.PtrType)
if !ok {
return true
}
- fname, ok := ptr.Type.(sys.StrConstType)
+ fname, ok := ptr.Type.(*sys.StrConstType)
if !ok {
panic("first open arg is not a pointer to string const")
}
@@ -99,7 +99,7 @@ func isSupportedSyzkall(c *sys.Call) bool {
}
func isSupportedSocket(c *sys.Call) bool {
- af, ok := c.Args[0].(sys.ConstType)
+ af, ok := c.Args[0].(*sys.ConstType)
if !ok {
println(c.Name)
panic("socket family is not const")
@@ -112,11 +112,11 @@ func isSupportedSocket(c *sys.Call) bool {
}
func isSupportedOpen(c *sys.Call) bool {
- ptr, ok := c.Args[0].(sys.PtrType)
+ ptr, ok := c.Args[0].(*sys.PtrType)
if !ok {
panic("first open arg is not a pointer")
}
- fname, ok := ptr.Type.(sys.StrConstType)
+ fname, ok := ptr.Type.(*sys.StrConstType)
if !ok {
return true
}
diff --git a/prog/analysis.go b/prog/analysis.go
index baf87fbb5..d4ee93d10 100644
--- a/prog/analysis.go
+++ b/prog/analysis.go
@@ -51,16 +51,16 @@ 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:
+ case *sys.FilenameType:
if arg.Kind == ArgData && arg.Dir != DirOut {
s.files[string(arg.Data)] = true
}
- case sys.ResourceType:
+ case *sys.ResourceType:
if arg.Dir != 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:
+ case *sys.BufferType:
if typ.Kind == sys.BufferString && arg.Kind == ArgData && len(arg.Data) != 0 {
s.strings[string(arg.Data)] = true
}
@@ -164,7 +164,7 @@ func assignTypeAndDir(c *Call) error {
case ArgPointer:
arg.Dir = DirIn
switch typ1 := typ.(type) {
- case sys.PtrType:
+ case *sys.PtrType:
if arg.Res != nil {
if err := rec(arg.Res, typ1.Type, ArgDir(typ1.Dir)); err != nil {
return err
@@ -183,7 +183,7 @@ func assignTypeAndDir(c *Call) error {
return err
}
}
- case sys.ArrayType:
+ case *sys.ArrayType:
for _, arg1 := range arg.Inner {
if err := rec(arg1, typ1.Type, dir); err != nil {
return err
@@ -217,16 +217,16 @@ func assignTypeAndDir(c *Call) error {
return nil
}
-func generateSize(typ sys.Type, arg *Arg, lenType sys.LenType) *Arg {
+func generateSize(typ sys.Type, arg *Arg, lenType *sys.LenType) *Arg {
if arg == nil {
// Arg is an optional pointer, set size to 0.
return constArg(0)
}
switch typ.(type) {
- case sys.VmaType:
+ case *sys.VmaType:
return pageSizeArg(arg.AddrPagesNum, 0)
- case sys.ArrayType:
+ case *sys.ArrayType:
if lenType.ByteSize {
return constArg(arg.Size(typ))
} else {
@@ -268,7 +268,7 @@ func assignSizes(types []sys.Type, args []*Arg) {
// Fill in size arguments.
for i, typ := range types {
- if lenType, ok := typ.InnerType().(sys.LenType); ok {
+ if lenType, ok := typ.InnerType().(*sys.LenType); ok {
lenArg := args[i].InnerArg(typ)
if lenArg == nil {
// Pointer to optional len field, no need to fill in value.
@@ -298,7 +298,7 @@ func assignSizesCall(c *Call) {
switch arg.Kind {
case ArgPointer:
switch typ1 := typ.(type) {
- case sys.PtrType:
+ case *sys.PtrType:
if arg.Res != nil {
rec(arg.Res, typ1.Type)
}
@@ -313,7 +313,7 @@ func assignSizesCall(c *Call) {
rec(arg1, typ1.Fields[i])
}
assignSizes(typ1.Fields, arg.Inner)
- case sys.ArrayType:
+ case *sys.ArrayType:
for _, arg1 := range arg.Inner {
rec(arg1, typ1.Type)
}
diff --git a/prog/encoding.go b/prog/encoding.go
index 01438f5b9..d99f42f6f 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -93,7 +93,7 @@ func (a *Arg) serialize(buf io.Writer, vars map[*Arg]int, varSeq *int) {
switch a.Type.(type) {
case *sys.StructType:
delims = []byte{'{', '}'}
- case sys.ArrayType:
+ case *sys.ArrayType:
delims = []byte{'[', ']'}
default:
panic("unknown group type")
@@ -225,9 +225,9 @@ func parseArg(typ sys.Type, p *parser, vars map[string]*Arg) (*Arg, error) {
case '&':
var typ1 sys.Type
switch t1 := typ.(type) {
- case sys.PtrType:
+ case *sys.PtrType:
typ1 = t1.Type
- case sys.VmaType:
+ case *sys.VmaType:
default:
return nil, fmt.Errorf("& arg is not a pointer: %#v", typ)
}
@@ -291,7 +291,7 @@ func parseArg(typ sys.Type, p *parser, vars map[string]*Arg) (*Arg, error) {
}
arg = groupArg(inner)
case '[':
- t1, ok := typ.(sys.ArrayType)
+ t1, ok := typ.(*sys.ArrayType)
if !ok {
return nil, fmt.Errorf("'[' arg is not an array: %#v", typ)
}
diff --git a/prog/mutation.go b/prog/mutation.go
index 577e24796..1b8be02c5 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -60,10 +60,10 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
baseSize = base.Res.Size(base.Res.Type)
}
switch a := arg.Type.(type) {
- case sys.IntType, sys.FlagsType, sys.FileoffType, sys.ResourceType, sys.VmaType:
+ case *sys.IntType, *sys.FlagsType, *sys.FileoffType, *sys.ResourceType, *sys.VmaType:
arg1, calls1 := r.generateArg(s, arg.Type, arg.Dir)
p.replaceArg(arg, arg1, calls1)
- case sys.BufferType:
+ case *sys.BufferType:
switch a.Kind {
case sys.BufferBlobRand, sys.BufferBlobRange:
var data []byte
@@ -102,10 +102,10 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
default:
panic("unknown buffer kind")
}
- case sys.FilenameType:
+ case *sys.FilenameType:
filename := r.filename(s)
arg.Data = []byte(filename)
- case sys.ArrayType:
+ case *sys.ArrayType:
count := uintptr(0)
switch a.Kind {
case sys.ArrayRandLen:
@@ -144,7 +144,7 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
arg.Inner = arg.Inner[:count]
}
// TODO: swap elements of the array
- case sys.PtrType:
+ case *sys.PtrType:
// TODO: we don't know size for out args
size := uintptr(1)
if arg.Res != nil {
@@ -171,9 +171,9 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
opt, calls := r.generateArg(s, optType, arg.Dir)
arg1 := unionArg(opt, optType)
p.replaceArg(arg, arg1, calls)
- case sys.LenType:
+ case *sys.LenType:
panic("bad arg returned by mutationArgs: LenType")
- case sys.ConstType, sys.StrConstType:
+ case *sys.ConstType, *sys.StrConstType:
panic("bad arg returned by mutationArgs: ConstType")
default:
panic(fmt.Sprintf("bad arg returned by mutationArgs: %#v, type=%#v", *arg, arg.Type))
@@ -332,15 +332,15 @@ func mutationArgs(c *Call) (args, bases []*Arg) {
return
}
// These special structs are mutated as a whole.
- case sys.ArrayType:
+ case *sys.ArrayType:
// Don't mutate fixed-size arrays.
if typ.Kind == sys.ArrayRangeLen && typ.RangeBegin == typ.RangeEnd {
return
}
- case sys.LenType:
+ case *sys.LenType:
// Size is updated when the size-of arg change.
return
- case sys.ConstType, sys.StrConstType:
+ case *sys.ConstType, *sys.StrConstType:
// Well, this is const.
return
}
diff --git a/prog/prio.go b/prog/prio.go
index 8983c1c92..3ac1eafe5 100644
--- a/prog/prio.go
+++ b/prog/prio.go
@@ -52,7 +52,7 @@ func calcStaticPriorities() [][]float32 {
}
foreachArgType(c, func(t sys.Type, d ArgDir) {
switch a := t.(type) {
- case sys.ResourceType:
+ case *sys.ResourceType:
if a.Desc.Name == "pid" || a.Desc.Name == "uid" || a.Desc.Name == "gid" {
// Pid/uid/gid usually play auxiliary role,
// but massively happen in some structs.
@@ -68,17 +68,17 @@ func calcStaticPriorities() [][]float32 {
noteUsage(float32(w), str)
}
}
- case sys.PtrType:
+ case *sys.PtrType:
if _, ok := a.Type.(*sys.StructType); ok {
noteUsage(1.0, "ptrto-%v", a.Type.Name())
}
if _, ok := a.Type.(*sys.UnionType); ok {
noteUsage(1.0, "ptrto-%v", a.Type.Name())
}
- if arr, ok := a.Type.(sys.ArrayType); ok {
+ if arr, ok := a.Type.(*sys.ArrayType); ok {
noteUsage(1.0, "ptrto-%v", arr.Type.Name())
}
- case sys.BufferType:
+ case *sys.BufferType:
switch a.Kind {
case sys.BufferBlobRand, sys.BufferBlobRange, sys.BufferFilesystem, sys.BufferAlgType, sys.BufferAlgName:
case sys.BufferString:
@@ -88,11 +88,11 @@ func calcStaticPriorities() [][]float32 {
default:
panic("unknown buffer kind")
}
- case sys.VmaType:
+ case *sys.VmaType:
noteUsage(0.5, "vma")
- case sys.FilenameType:
+ case *sys.FilenameType:
noteUsage(1.0, "filename")
- case sys.IntType:
+ case *sys.IntType:
switch a.Kind {
case sys.IntPlain:
case sys.IntRange:
@@ -202,9 +202,9 @@ func foreachArgType(meta *sys.Call, f func(sys.Type, ArgDir)) {
rec = func(t sys.Type, d ArgDir) {
f(t, d)
switch a := t.(type) {
- case sys.ArrayType:
+ case *sys.ArrayType:
rec(a.Type, d)
- case sys.PtrType:
+ case *sys.PtrType:
rec(a.Type, ArgDir(a.Dir))
case *sys.StructType:
if seen[a] {
@@ -222,9 +222,9 @@ func foreachArgType(meta *sys.Call, f func(sys.Type, ArgDir)) {
for _, opt := range a.Options {
rec(opt, d)
}
- case sys.ResourceType, sys.FileoffType, sys.BufferType,
- sys.VmaType, sys.LenType, sys.FlagsType, sys.ConstType,
- sys.StrConstType, sys.IntType, sys.FilenameType:
+ case *sys.ResourceType, *sys.FileoffType, *sys.BufferType,
+ *sys.VmaType, *sys.LenType, *sys.FlagsType, *sys.ConstType,
+ *sys.StrConstType, *sys.IntType, *sys.FilenameType:
default:
panic("unknown type")
}
diff --git a/prog/prog.go b/prog/prog.go
index 9953f3ef0..aa5e1b86e 100644
--- a/prog/prog.go
+++ b/prog/prog.go
@@ -64,7 +64,7 @@ const (
// Returns inner arg for PtrType args
func (a *Arg) InnerArg(typ sys.Type) *Arg {
switch typ1 := typ.(type) {
- case sys.PtrType:
+ case *sys.PtrType:
if a.Res == nil {
if typ.Optional() {
return nil
@@ -98,15 +98,15 @@ func encodeValue(value, size uintptr, bigEndian bool) uintptr {
// Returns value taking endianness into consideration.
func (a *Arg) Value(typ sys.Type) uintptr {
switch t := typ.(type) {
- case sys.IntType:
+ case *sys.IntType:
return encodeValue(a.Val, t.Size(), t.BigEndian)
- case sys.ConstType:
+ case *sys.ConstType:
return encodeValue(a.Val, t.Size(), t.BigEndian)
- case sys.FlagsType:
+ case *sys.FlagsType:
return encodeValue(a.Val, t.Size(), t.BigEndian)
- case sys.LenType:
+ case *sys.LenType:
return encodeValue(a.Val, t.Size(), t.BigEndian)
- case sys.FileoffType:
+ case *sys.FileoffType:
return encodeValue(a.Val, t.Size(), t.BigEndian)
}
return a.Val
@@ -114,12 +114,12 @@ func (a *Arg) Value(typ sys.Type) uintptr {
func (a *Arg) Size(typ sys.Type) uintptr {
switch typ1 := typ.(type) {
- case sys.IntType, sys.LenType, sys.FlagsType, sys.ConstType, sys.StrConstType,
- sys.FileoffType, sys.ResourceType, sys.VmaType, sys.PtrType:
+ 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:
+ case *sys.FilenameType:
return uintptr(len(a.Data))
- case sys.BufferType:
+ case *sys.BufferType:
return uintptr(len(a.Data))
case *sys.StructType:
var size uintptr
@@ -129,7 +129,7 @@ func (a *Arg) Size(typ sys.Type) uintptr {
return size
case *sys.UnionType:
return a.Option.Size(a.OptionType)
- case sys.ArrayType:
+ case *sys.ArrayType:
var size uintptr
for _, in := range a.Inner {
size += in.Size(typ1.Type)
diff --git a/prog/rand.go b/prog/rand.go
index 18dceeaea..49726afcd 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -486,7 +486,7 @@ func (r *randGen) randPageAddr(s *state, npages uintptr, data *Arg, vma bool) *A
return pointerArg(page, 0, npages, data)
}
-func (r *randGen) createResource(s *state, res sys.ResourceType) (arg *Arg, calls []*Call) {
+func (r *randGen) createResource(s *state, res *sys.ResourceType) (arg *Arg, calls []*Call) {
if r.inCreateResource {
special := res.SpecialValues()
return constArg(special[r.Intn(len(special))]), nil
@@ -635,20 +635,20 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
// in subsequent calls. For the same reason we do generate pointer/array/struct
// output arguments (their elements can be referenced in subsequent calls).
switch typ.(type) {
- case sys.IntType, sys.FlagsType, sys.ConstType, sys.StrConstType, sys.FileoffType, sys.ResourceType:
+ case *sys.IntType, *sys.FlagsType, *sys.ConstType, *sys.StrConstType, *sys.FileoffType, *sys.ResourceType:
return constArg(0), nil
}
}
if typ.Optional() && r.oneOf(5) {
- if _, ok := typ.(sys.BufferType); ok {
+ if _, ok := typ.(*sys.BufferType); ok {
panic("impossible") // parent PtrType must be Optional instead
}
return constArg(typ.Default()), nil
}
switch a := typ.(type) {
- case sys.ResourceType:
+ case *sys.ResourceType:
r.choose(
1, func() {
special := a.SpecialValues()
@@ -675,7 +675,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
},
)
return arg, calls
- case sys.FileoffType:
+ case *sys.FileoffType:
// TODO: can do better
var arg *Arg
r.choose(
@@ -684,7 +684,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
1, func() { arg = constArg(r.randInt()) },
)
return arg, nil
- case sys.BufferType:
+ case *sys.BufferType:
switch a.Kind {
case sys.BufferBlobRand, sys.BufferBlobRange:
sz := r.randBufLen()
@@ -731,17 +731,17 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
default:
panic("unknown buffer kind")
}
- case sys.VmaType:
+ case *sys.VmaType:
npages := r.randPageCount()
arg := r.randPageAddr(s, npages, nil, true)
return arg, nil
- case sys.FlagsType:
+ case *sys.FlagsType:
return constArg(r.flags(a.Vals)), nil
- case sys.ConstType:
+ case *sys.ConstType:
return constArg(a.Val), nil
- case sys.StrConstType:
+ case *sys.StrConstType:
return dataArg([]byte(a.Val)), nil
- case sys.IntType:
+ case *sys.IntType:
v := r.randInt()
switch a.Kind {
case sys.IntSignalno:
@@ -754,10 +754,10 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
v = r.randRangeInt(a.RangeBegin, a.RangeEnd)
}
return constArg(v), nil
- case sys.FilenameType:
+ case *sys.FilenameType:
filename := r.filename(s)
return dataArg([]byte(filename)), nil
- case sys.ArrayType:
+ case *sys.ArrayType:
count := uintptr(0)
switch a.Kind {
case sys.ArrayRandLen:
@@ -785,7 +785,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
optType := a.Options[r.Intn(len(a.Options))]
opt, calls := r.generateArg(s, optType, dir)
return unionArg(opt, optType), calls
- case sys.PtrType:
+ case *sys.PtrType:
inner, calls := r.generateArg(s, a.Type, ArgDir(a.Dir))
if ArgDir(a.Dir) == DirOut && inner == nil {
// No data, but we should have got size.
@@ -804,7 +804,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type, dir ArgDir) (arg *Arg, cal
arg, calls1 := r.addr(s, inner.Size(a.Type), inner)
calls = append(calls, calls1...)
return arg, calls
- case sys.LenType:
+ case *sys.LenType:
// Return placeholder value of 0 while generating len args.
return constArg(0), nil
default:
diff --git a/prog/validation.go b/prog/validation.go
index a1b68ba1b..ec407721a 100644
--- a/prog/validation.go
+++ b/prog/validation.go
@@ -68,7 +68,7 @@ func (c *Call) validate(ctx *validCtx) error {
}
}
switch arg.Type.(type) {
- case sys.ResourceType:
+ case *sys.ResourceType:
switch arg.Kind {
case ArgResult:
case ArgReturn:
@@ -79,7 +79,7 @@ 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:
+ case *sys.FilenameType:
switch arg.Kind {
case ArgData:
default:
@@ -116,14 +116,14 @@ func (c *Call) validate(ctx *validCtx) error {
return fmt.Errorf("syscall %v: pointer arg '%v' has output direction", c.Meta.Name, typ.Name())
}
switch typ1 := typ.(type) {
- case sys.VmaType:
+ case *sys.VmaType:
if arg.Res != nil {
return fmt.Errorf("syscall %v: vma arg '%v' has data", c.Meta.Name, typ.Name())
}
if arg.AddrPagesNum == 0 {
return fmt.Errorf("syscall %v: vma arg '%v' has size 0", c.Meta.Name, typ.Name())
}
- case sys.PtrType:
+ case *sys.PtrType:
if arg.Res == nil && !typ.Optional() {
return fmt.Errorf("syscall %v: non optional pointer arg '%v' is nil", c.Meta.Name, typ.Name())
}
@@ -151,7 +151,7 @@ func (c *Call) validate(ctx *validCtx) error {
return err
}
}
- case sys.ArrayType:
+ case *sys.ArrayType:
for _, arg1 := range arg.Inner {
if err := checkArg(arg1, typ1.Type); err != nil {
return err
diff --git a/sys/align.go b/sys/align.go
index 055a433f8..1b1ea66ac 100644
--- a/sys/align.go
+++ b/sys/align.go
@@ -7,9 +7,9 @@ func initAlign() {
var rec func(t Type)
rec = func(t Type) {
switch t1 := t.(type) {
- case PtrType:
+ case *PtrType:
rec(t1.Type)
- case ArrayType:
+ case *ArrayType:
rec(t1.Type)
case *StructType:
if !t1.padded {
@@ -49,10 +49,10 @@ func addAlignment(t *StructType) {
fields = append(fields, makePad(pad))
}
fields = append(fields, f)
- if at, ok := f.(ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) {
+ if at, ok := f.(*ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) {
varLen = true
}
- if at, ok := f.(BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) {
+ if at, ok := f.(*BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) {
varLen = true
}
if varLen && i != len(t.Fields)-1 {
@@ -71,7 +71,7 @@ func addAlignment(t *StructType) {
}
func makePad(sz uintptr) Type {
- return ConstType{
+ return &ConstType{
TypeCommon: TypeCommon{TypeName: "pad", IsOptional: false},
TypeSize: sz,
Val: 0,
diff --git a/sys/decl.go b/sys/decl.go
index 89773b0dd..7f7c64c1d 100644
--- a/sys/decl.go
+++ b/sys/decl.go
@@ -29,7 +29,7 @@ type Type interface {
}
func IsPad(t Type) bool {
- if ct, ok := t.(ConstType); ok && ct.IsPad {
+ if ct, ok := t.(*ConstType); ok && ct.IsPad {
return true
}
return false
@@ -40,15 +40,15 @@ type TypeCommon struct {
IsOptional bool
}
-func (t TypeCommon) Name() string {
+func (t *TypeCommon) Name() string {
return t.TypeName
}
-func (t TypeCommon) Optional() bool {
+func (t *TypeCommon) Optional() bool {
return t.IsOptional
}
-func (t TypeCommon) Default() uintptr {
+func (t *TypeCommon) Default() uintptr {
return 0
}
@@ -68,23 +68,23 @@ type ResourceType struct {
Desc *ResourceDesc
}
-func (t ResourceType) Default() uintptr {
+func (t *ResourceType) Default() uintptr {
return t.Desc.Values[0]
}
-func (t ResourceType) SpecialValues() []uintptr {
+func (t *ResourceType) SpecialValues() []uintptr {
return t.Desc.Values
}
-func (t ResourceType) Size() uintptr {
+func (t *ResourceType) Size() uintptr {
return t.Desc.Type.Size()
}
-func (t ResourceType) Align() uintptr {
+func (t *ResourceType) Align() uintptr {
return t.Desc.Type.Align()
}
-func (t ResourceType) InnerType() Type {
+func (t *ResourceType) InnerType() Type {
return t
}
@@ -95,15 +95,15 @@ type FileoffType struct {
File string
}
-func (t FileoffType) Size() uintptr {
+func (t *FileoffType) Size() uintptr {
return t.TypeSize
}
-func (t FileoffType) Align() uintptr {
+func (t *FileoffType) Align() uintptr {
return t.Size()
}
-func (t FileoffType) InnerType() Type {
+func (t *FileoffType) InnerType() Type {
return t
}
@@ -126,7 +126,7 @@ type BufferType struct {
RangeEnd uintptr // for BufferBlobRange kind
}
-func (t BufferType) Size() uintptr {
+func (t *BufferType) Size() uintptr {
switch t.Kind {
case BufferAlgType:
return 14
@@ -142,11 +142,11 @@ func (t BufferType) Size() uintptr {
}
}
-func (t BufferType) Align() uintptr {
+func (t *BufferType) Align() uintptr {
return 1
}
-func (t BufferType) InnerType() Type {
+func (t *BufferType) InnerType() Type {
return t
}
@@ -154,15 +154,15 @@ type VmaType struct {
TypeCommon
}
-func (t VmaType) Size() uintptr {
+func (t *VmaType) Size() uintptr {
return ptrSize
}
-func (t VmaType) Align() uintptr {
+func (t *VmaType) Align() uintptr {
return t.Size()
}
-func (t VmaType) InnerType() Type {
+func (t *VmaType) InnerType() Type {
return t
}
@@ -174,15 +174,15 @@ type LenType struct {
Buf string
}
-func (t LenType) Size() uintptr {
+func (t *LenType) Size() uintptr {
return t.TypeSize
}
-func (t LenType) Align() uintptr {
+func (t *LenType) Align() uintptr {
return t.Size()
}
-func (t LenType) InnerType() Type {
+func (t *LenType) InnerType() Type {
return t
}
@@ -193,15 +193,15 @@ type FlagsType struct {
Vals []uintptr
}
-func (t FlagsType) Size() uintptr {
+func (t *FlagsType) Size() uintptr {
return t.TypeSize
}
-func (t FlagsType) Align() uintptr {
+func (t *FlagsType) Align() uintptr {
return t.Size()
}
-func (t FlagsType) InnerType() Type {
+func (t *FlagsType) InnerType() Type {
return t
}
@@ -213,15 +213,15 @@ type ConstType struct {
IsPad bool
}
-func (t ConstType) Size() uintptr {
+func (t *ConstType) Size() uintptr {
return t.TypeSize
}
-func (t ConstType) Align() uintptr {
+func (t *ConstType) Align() uintptr {
return t.Size()
}
-func (t ConstType) InnerType() Type {
+func (t *ConstType) InnerType() Type {
return t
}
@@ -231,15 +231,15 @@ type StrConstType struct {
Val string
}
-func (t StrConstType) Size() uintptr {
+func (t *StrConstType) Size() uintptr {
return uintptr(len(t.Val))
}
-func (t StrConstType) Align() uintptr {
+func (t *StrConstType) Align() uintptr {
return 1
}
-func (t StrConstType) InnerType() Type {
+func (t *StrConstType) InnerType() Type {
return t
}
@@ -262,15 +262,15 @@ type IntType struct {
RangeEnd int64
}
-func (t IntType) Size() uintptr {
+func (t *IntType) Size() uintptr {
return t.TypeSize
}
-func (t IntType) Align() uintptr {
+func (t *IntType) Align() uintptr {
return t.Size()
}
-func (t IntType) InnerType() Type {
+func (t *IntType) InnerType() Type {
return t
}
@@ -278,15 +278,15 @@ type FilenameType struct {
TypeCommon
}
-func (t FilenameType) Size() uintptr {
+func (t *FilenameType) Size() uintptr {
panic("filename size is not statically known")
}
-func (t FilenameType) Align() uintptr {
+func (t *FilenameType) Align() uintptr {
return 1
}
-func (t FilenameType) InnerType() Type {
+func (t *FilenameType) InnerType() Type {
return t
}
@@ -305,18 +305,18 @@ type ArrayType struct {
RangeEnd uintptr
}
-func (t ArrayType) Size() uintptr {
+func (t *ArrayType) Size() uintptr {
if t.RangeBegin == t.RangeEnd {
return t.RangeBegin * t.Type.Size()
}
return 0 // for trailing embed arrays
}
-func (t ArrayType) Align() uintptr {
+func (t *ArrayType) Align() uintptr {
return t.Type.Align()
}
-func (t ArrayType) InnerType() Type {
+func (t *ArrayType) InnerType() Type {
return t
}
@@ -326,15 +326,15 @@ type PtrType struct {
Dir Dir
}
-func (t PtrType) Size() uintptr {
+func (t *PtrType) Size() uintptr {
return ptrSize
}
-func (t PtrType) Align() uintptr {
+func (t *PtrType) Align() uintptr {
return t.Size()
}
-func (t PtrType) InnerType() Type {
+func (t *PtrType) InnerType() Type {
return t.Type.InnerType()
}
@@ -435,11 +435,11 @@ func resourceCtors(kind []string, precise bool) []*Call {
seen := make(map[Type]bool)
var checkArg func(typ Type, dir Dir) bool
checkArg = func(typ Type, dir Dir) bool {
- if resarg, ok := typ.(ResourceType); ok && dir != DirIn && isCompatibleResource(kind, resarg.Desc.Kind, precise) {
+ if resarg, ok := typ.(*ResourceType); ok && dir != DirIn && isCompatibleResource(kind, resarg.Desc.Kind, precise) {
return true
}
switch typ1 := typ.(type) {
- case ArrayType:
+ case *ArrayType:
if checkArg(typ1.Type, dir) {
return true
}
@@ -463,7 +463,7 @@ func resourceCtors(kind []string, precise bool) []*Call {
return true
}
}
- case PtrType:
+ case *PtrType:
if checkArg(typ1.Type, typ1.Dir) {
return true
}
@@ -524,19 +524,19 @@ func isCompatibleResource(dst, src []string, precise bool) bool {
return true
}
-func (c *Call) InputResources() []ResourceType {
- var resources []ResourceType
+func (c *Call) InputResources() []*ResourceType {
+ var resources []*ResourceType
seen := make(map[Type]bool)
var checkArg func(typ Type, dir Dir)
checkArg = func(typ Type, dir Dir) {
switch typ1 := typ.(type) {
- case ResourceType:
+ case *ResourceType:
if dir != DirOut && !typ1.IsOptional {
resources = append(resources, typ1)
}
- case ArrayType:
+ case *ArrayType:
checkArg(typ1.Type, dir)
- case PtrType:
+ case *PtrType:
checkArg(typ1.Type, typ1.Dir)
case *StructType:
if seen[typ1] {
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go
index d197b774b..cdc79794c 100644
--- a/sysgen/sysgen.go
+++ b/sysgen/sysgen.go
@@ -387,7 +387,7 @@ func generateArg(
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
}
- fmt.Fprintf(out, "FileoffType{%v, File: \"%v\", TypeSize: %v, BigEndian: %v}", common(), a[0], size, bigEndian)
+ fmt.Fprintf(out, "&FileoffType{%v, File: \"%v\", TypeSize: %v, BigEndian: %v}", common(), a[0], size, bigEndian)
case "buffer":
canBeArg = true
if want := 1; len(a) != want {
@@ -395,7 +395,7 @@ func generateArg(
}
commonHdr := common()
opt = false
- fmt.Fprintf(out, "PtrType{%v, Dir: %v, Type: BufferType{%v, Kind: BufferBlobRand}}", commonHdr, fmtDir(a[0]), common())
+ fmt.Fprintf(out, "&PtrType{%v, Dir: %v, Type: &BufferType{%v, Kind: BufferBlobRand}}", commonHdr, fmtDir(a[0]), common())
case "string":
canBeArg = true
if want := 0; len(a) != want {
@@ -403,7 +403,7 @@ func generateArg(
}
commonHdr := common()
opt = false
- fmt.Fprintf(out, "PtrType{%v, Dir: %v, Type: BufferType{%v, Kind: BufferString}}", commonHdr, fmtDir("in"), common())
+ fmt.Fprintf(out, "&PtrType{%v, Dir: %v, Type: &BufferType{%v, Kind: BufferString}}", commonHdr, fmtDir("in"), common())
case "filesystem":
canBeArg = true
if want := 0; len(a) != want {
@@ -411,28 +411,28 @@ func generateArg(
}
commonHdr := common()
opt = false
- fmt.Fprintf(out, "PtrType{%v, Dir: %v, Type: BufferType{%v, Kind: BufferFilesystem}}", commonHdr, fmtDir("in"), common())
+ fmt.Fprintf(out, "&PtrType{%v, Dir: %v, Type: &BufferType{%v, Kind: BufferFilesystem}}", commonHdr, fmtDir("in"), common())
case "sockaddr":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "BufferType{%v, Kind: BufferSockaddr}", common())
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferSockaddr}", common())
case "salg_type":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "BufferType{%v, Kind: BufferAlgType}", common())
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferAlgType}", common())
case "salg_name":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "BufferType{%v, Kind: BufferAlgName}", common())
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferAlgName}", common())
case "vma":
canBeArg = true
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "VmaType{%v}", common())
+ fmt.Fprintf(out, "&VmaType{%v}", common())
case "len", "bytesize":
canBeArg = true
size := uint64(ptrSize)
@@ -447,7 +447,7 @@ func generateArg(
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
}
- fmt.Fprintf(out, "LenType{%v, Buf: \"%v\", TypeSize: %v, BigEndian: %v, ByteSize: %v}", common(), a[0], size, bigEndian, typ == "bytesize")
+ fmt.Fprintf(out, "&LenType{%v, Buf: \"%v\", TypeSize: %v, BigEndian: %v, ByteSize: %v}", common(), a[0], size, bigEndian, typ == "bytesize")
case "flags":
canBeArg = true
size := uint64(ptrSize)
@@ -467,9 +467,9 @@ func generateArg(
failf("unknown flag %v", a[0])
}
if len(vals) == 0 {
- fmt.Fprintf(out, "IntType{%v, TypeSize: %v, BigEndian: %v}", common(), size, bigEndian)
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: %v, BigEndian: %v}", common(), size, bigEndian)
} else {
- fmt.Fprintf(out, "FlagsType{%v, TypeSize: %v, BigEndian: %v, Vals: []uintptr{%v}}", common(), size, bigEndian, strings.Join(vals, ","))
+ fmt.Fprintf(out, "&FlagsType{%v, TypeSize: %v, BigEndian: %v, Vals: []uintptr{%v}}", common(), size, bigEndian, strings.Join(vals, ","))
}
case "const":
canBeArg = true
@@ -494,22 +494,22 @@ func generateArg(
val = "0"
skipSyscall(fmt.Sprintf("missing const %v", a[0]))
}
- fmt.Fprintf(out, "ConstType{%v, TypeSize: %v, BigEndian: %v, Val: uintptr(%v)}", common(), size, bigEndian, val)
+ fmt.Fprintf(out, "&ConstType{%v, TypeSize: %v, BigEndian: %v, Val: uintptr(%v)}", common(), size, bigEndian, val)
case "strconst":
canBeArg = true
if want := 1; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "PtrType{%v, Dir: %v, Type: StrConstType{%v, Val: \"%v\"}}", common(), fmtDir("in"), common(), a[0]+"\\x00")
+ fmt.Fprintf(out, "&PtrType{%v, Dir: %v, Type: &StrConstType{%v, Val: \"%v\"}}", common(), fmtDir("in"), common(), a[0]+"\\x00")
case "int8", "int16", "int32", "int64", "intptr", "int16be", "int32be", "int64be", "intptrbe":
canBeArg = true
size, bigEndian := decodeIntType(typ)
switch len(a) {
case 0:
- fmt.Fprintf(out, "IntType{%v, TypeSize: %v, BigEndian: %v}", common(), size, bigEndian)
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: %v, BigEndian: %v}", common(), size, bigEndian)
case 1:
begin, end := parseRange(a[0], consts)
- fmt.Fprintf(out, "IntType{%v, TypeSize: %v, BigEndian: %v, Kind: IntRange, RangeBegin: %v, RangeEnd: %v}", common(), size, bigEndian, begin, end)
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: %v, BigEndian: %v, Kind: IntRange, RangeBegin: %v, RangeEnd: %v}", common(), size, bigEndian, begin, end)
default:
failf("wrong number of arguments for %v arg %v, want 0 or 1, got %v", typ, name, len(a))
}
@@ -518,17 +518,17 @@ func generateArg(
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "IntType{%v, TypeSize: 4, Kind: IntSignalno}", common())
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: 4, Kind: IntSignalno}", common())
case "in_addr":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "IntType{%v, TypeSize: 4, Kind: IntInaddr}", common())
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: 4, Kind: IntInaddr}", common())
case "in_port":
if want := 0; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "IntType{%v, TypeSize: 2, Kind: IntInport}", common())
+ fmt.Fprintf(out, "&IntType{%v, TypeSize: 2, Kind: IntInport}", common())
case "filename":
canBeArg = true
if want := 0; len(a) != want {
@@ -536,23 +536,23 @@ func generateArg(
}
commonHdr := common()
opt = false
- fmt.Fprintf(out, "PtrType{%v, Dir: DirIn, Type: FilenameType{%v}}", commonHdr, common())
+ fmt.Fprintf(out, "&PtrType{%v, Dir: DirIn, Type: &FilenameType{%v}}", commonHdr, 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))
}
if len(a) == 1 {
if a[0] == "int8" {
- fmt.Fprintf(out, "BufferType{%v, Kind: BufferBlobRand}", common())
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferBlobRand}", common())
} else {
- fmt.Fprintf(out, "ArrayType{%v, Type: %v, Kind: ArrayRandLen}", common(), generateType(a[0], desc, consts))
+ fmt.Fprintf(out, "&ArrayType{%v, Type: %v, Kind: ArrayRandLen}", common(), generateType(a[0], desc, consts))
}
} else {
begin, end := parseRange(a[1], consts)
if a[0] == "int8" {
- fmt.Fprintf(out, "BufferType{%v, Kind: BufferBlobRange, RangeBegin: %v, RangeEnd: %v}", common(), begin, end)
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferBlobRange, RangeBegin: %v, RangeEnd: %v}", common(), begin, end)
} else {
- fmt.Fprintf(out, "ArrayType{%v, Type: %v, Kind: ArrayRangeLen, RangeBegin: %v, RangeEnd: %v}", common(), generateType(a[0], desc, consts), begin, end)
+ fmt.Fprintf(out, "&ArrayType{%v, Type: %v, Kind: ArrayRangeLen, RangeBegin: %v, RangeEnd: %v}", common(), generateType(a[0], desc, consts), begin, end)
}
}
case "ptr":
@@ -560,7 +560,7 @@ func generateArg(
if want := 2; len(a) != want {
failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
}
- fmt.Fprintf(out, "PtrType{%v, Type: %v, Dir: %v}", common(), generateType(a[1], desc, consts), fmtDir(a[0]))
+ fmt.Fprintf(out, "&PtrType{%v, Type: %v, Dir: %v}", common(), generateType(a[1], desc, consts), fmtDir(a[0]))
default:
if strings.HasPrefix(typ, "unnamed") {
if inner, ok := desc.Unnamed[typ]; ok {
@@ -581,7 +581,7 @@ func generateArg(
if len(a) != 0 {
failf("resource '%v' has args", typ)
}
- fmt.Fprintf(out, "ResourceType{%v, Desc: Resources[\"%v\"]}", common(), typ)
+ fmt.Fprintf(out, "&ResourceType{%v, Desc: Resources[\"%v\"]}", common(), typ)
return
} else {
failf("unknown arg type \"%v\" for %v", typ, name)