aboutsummaryrefslogtreecommitdiffstats
path: root/docs/syscall_descriptions_syntax.md
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-05-10 18:02:54 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-05-14 19:28:01 +0200
commiteea28fee309680462752ef7709f1a94178dce44d (patch)
tree29caff3a1e370c092522a94a9a231d83a767d20b /docs/syscall_descriptions_syntax.md
parent1886b2a4811a4d9adbfc509505a095848cc655eb (diff)
pkg/compiler: support complex len targets
This change adds compiler support for complex path expressions in len targets. E.g. it allows to refer to a sibling field as len[parent_struct:field:another_field]. See the docs change for details. This is just a compiler change. The feature is not yet supported by the prog package.
Diffstat (limited to 'docs/syscall_descriptions_syntax.md')
-rw-r--r--docs/syscall_descriptions_syntax.md47
1 files changed, 40 insertions, 7 deletions
diff --git a/docs/syscall_descriptions_syntax.md b/docs/syscall_descriptions_syntax.md
index 2fb245402..e3318d300 100644
--- a/docs/syscall_descriptions_syntax.md
+++ b/docs/syscall_descriptions_syntax.md
@@ -217,10 +217,11 @@ type optional[T] [
## Length
-You can specify length of a particular field in struct or a named argument by using `len`, `bytesize` and `bitsize` types, for example:
+You can specify length of a particular field in struct or a named argument by
+using `len`, `bytesize` and `bitsize` types, for example:
```
-write(fd fd, buf buffer[in], count len[buf]) len[buf]
+write(fd fd, buf ptr[in, array[int8]], count len[buf])
sock_fprog {
len len[filter, int16]
@@ -228,23 +229,55 @@ sock_fprog {
}
```
-If `len`'s argument is a pointer (or a `buffer`), then the length of the pointee argument is used.
+If `len`'s argument is a pointer, 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 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:
+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 {
+s1 {
f0 len[s2] # length of s2
}
-struct s2 {
+s2 {
f0 s1
f1 array[int32]
+ f2 len[parent, int32]
+}
+```
+
+`len` argument can also be a path expression which allows more complex
+addressing. Path expressions are similar to C field references, but also allow
+referencing parent and sibling elements. For example:
+
+```
+s1 {
+ a ptr[in, s2]
+ b ptr[in, s3]
+ c array[int8]
}
+s2 {
+ d array[int8]
+}
+
+s3 {
+# This refers to the array c in the parent s1.
+ e len[s1:c, int32]
+# This refers to the array d in the sibling s2.
+ f len[s1:a:d, int32]
+# This refers to the array k in the child s4.
+ g len[h:i, int32]
+ h ptr[in, s4]
+}
+
+s4 {
+ i array[int8]
+}
```
## Proc