aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@gmail.com>2017-01-23 18:15:39 +0100
committerGitHub <noreply@github.com>2017-01-23 18:15:39 +0100
commitbb1ff0b5592262d20e88397f56f18e48d47d56ea (patch)
tree6eb2d4bd3090f730f9b91fddd38e2726f1a31034 /sys
parentcd23722cf2dabd28d83fa321c3cbf50a956d3fb7 (diff)
parent07880f3c010a2a5d4078b8668e05a4894fd82046 (diff)
Merge pull request #113 from xairy/parent-parent
Make it possible to specify length of parent of parent
Diffstat (limited to 'sys')
-rw-r--r--sys/README.md30
-rw-r--r--sys/decl.go6
-rw-r--r--sys/test.txt22
3 files changed, 58 insertions, 0 deletions
diff --git a/sys/README.md b/sys/README.md
index 2e5f07ec1..b5b497bc6 100644
--- a/sys/README.md
+++ b/sys/README.md
@@ -133,6 +133,36 @@ accept(fd sock, ...) sock
listen(fd sock, backlog int32)
```
+### Length
+
+You can specify length of a particular field in struct or a named argument by using `len` and `bytesize` types, for example:
+```
+write(fd fd, buf buffer[in], count len[buf]) len[buf]
+
+sock_fprog {
+ len len[filter, int16]
+ filter ptr[in, array[sock_filter]]
+}
+```
+
+If `len`'s argument is a pointer (or a `buffer`), then the length of the pointee argument is used.
+
+To denote the length of a field in N-byte words use `bytesizeN`, possible values for N are 1, 2, 4 and 8.
+
+To denote the length of the parent struct, you can use `len[parent, int8]`.
+To denote the length of the higher level parent when structs are embedded into one another, you can specify the type name of the particular parent:
+```
+struct s1 {
+ f0 len[s2] # length of s2
+}
+
+struct s2 {
+ f0 s1
+ f1 array[int32]
+}
+
+```
+
### Proc
The `proc` type can be used to denote per process integers.
diff --git a/sys/decl.go b/sys/decl.go
index a495ffd4a..3c98d1038 100644
--- a/sys/decl.go
+++ b/sys/decl.go
@@ -29,6 +29,7 @@ const (
type Type interface {
Name() string
+ FieldName() string
Dir() Dir
Optional() bool
Default() uintptr
@@ -49,6 +50,7 @@ func IsPad(t Type) bool {
type TypeCommon struct {
TypeName string
+ FldName string // for struct fields and named args
ArgDir Dir
IsOptional bool
}
@@ -57,6 +59,10 @@ func (t *TypeCommon) Name() string {
return t.TypeName
}
+func (t *TypeCommon) FieldName() string {
+ return t.FldName
+}
+
func (t *TypeCommon) Optional() bool {
return t.IsOptional
}
diff --git a/sys/test.txt b/sys/test.txt
index e36af549d..0ce7ec819 100644
--- a/sys/test.txt
+++ b/sys/test.txt
@@ -186,6 +186,8 @@ syz_test$length17(a0 ptr[in, syz_length_bytesize2_struct])
syz_test$length18(a0 ptr[in, syz_length_bytesize3_struct])
syz_test$length19(a0 ptr[in, syz_length_bf_struct])
+syz_test$length20(a0 ptr[in, syz_length_parent2_struct])
+
syz_length_flags = 0, 1
syz_length_int_struct {
@@ -299,6 +301,26 @@ syz_length_bf_struct {
f3 bytesize4[f0, int8]
}
+syz_length_parent2_struct_inner_inner {
+ f1 len[parent, int8]
+ f2 len[syz_length_parent2_struct_inner_inner, int8]
+ f3 len[syz_length_parent2_struct_inner, int8]
+ f4 len[syz_length_parent2_struct, int8]
+}
+
+syz_length_parent2_struct_inner {
+ f0 syz_length_parent2_struct_inner_inner
+ f1 len[parent, int8]
+ f2 len[syz_length_parent2_struct_inner, int8]
+ f3 len[syz_length_parent2_struct, int8]
+}
+
+syz_length_parent2_struct {
+ f0 syz_length_parent2_struct_inner
+ f1 len[parent, int8]
+ f2 len[syz_length_parent2_struct, int8]
+}
+
# Big endian
syz_test$end0(a0 ptr[in, syz_end_int_struct])