aboutsummaryrefslogtreecommitdiffstats
path: root/sysgen
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2016-10-31 15:15:13 -0600
committerDmitry Vyukov <dvyukov@google.com>2016-11-11 14:33:37 -0800
commit588a542b2a23ba477031bf20b4c46b0f40a04b7d (patch)
tree9e517866f45cdb903505e72c0fcbf821c0b00dcd /sysgen
parent5ed6283b64f91c8aa036122b18974aabed4c5249 (diff)
sys: add string flags
Allow to define string flags in txt descriptions. E.g.: filesystem = "ext2", "ext3", "ext4" and then use it in string type: ptr[in, string[filesystem]]
Diffstat (limited to 'sysgen')
-rw-r--r--sysgen/sysgen.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go
index 7159ef70c..6913b9c81 100644
--- a/sysgen/sysgen.go
+++ b/sysgen/sysgen.go
@@ -407,19 +407,27 @@ func generateArg(
opt = false
fmt.Fprintf(out, "&PtrType{%v, Type: &BufferType{%v, Kind: BufferBlobRand}}", ptrCommonHdr, common())
case "string":
- if want := 0; len(a) != want {
- failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
+ if len(a) != 0 && len(a) != 1 {
+ failf("wrong number of arguments for %v arg %v, want 0 or 1, got %v", typ, name, len(a))
}
- fmt.Fprintf(out, "&BufferType{%v, Kind: BufferString}", common())
- case "filesystem":
- 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))
+ var vals []string
+ subkind := ""
+ if len(a) == 1 {
+ if a[0][0] == '"' {
+ vals = append(vals, a[0][1:len(a[0])-1])
+ } else {
+ ok := false
+ vals, ok = desc.StrFlags[a[0]]
+ if !ok {
+ failf("unknown string flags %v", a[0])
+ }
+ subkind = a[0]
+ }
+ for i, s := range vals {
+ vals[i] = s + "\x00"
+ }
}
- ptrCommonHdr := common()
- dir = "in"
- opt = false
- fmt.Fprintf(out, "&PtrType{%v, Type: &BufferType{%v, Kind: BufferFilesystem}}", ptrCommonHdr, common())
+ fmt.Fprintf(out, "&BufferType{%v, Kind: BufferString, SubKind: %q, Values: %#v}", common(), subkind, vals)
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))
@@ -503,15 +511,6 @@ func generateArg(
skipSyscall(fmt.Sprintf("missing const %v", a[0]))
}
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))
- }
- ptrCommonHdr := common()
- dir = "in"
- opt = false
- fmt.Fprintf(out, "&PtrType{%v, Type: &StrConstType{%v, Val: \"%v\"}}", ptrCommonHdr, common(), a[0]+"\\x00")
case "int8", "int16", "int32", "int64", "intptr", "int16be", "int32be", "int64be", "intptrbe":
canBeArg = true
size, bigEndian := decodeIntType(typ)