diff options
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | CONTRIBUTORS | 1 | ||||
| -rw-r--r-- | docs/syscall_descriptions_syntax.md | 2 | ||||
| -rw-r--r-- | sys/sysparser/lexer.go | 16 | ||||
| -rw-r--r-- | sys/syz-extract/extract.go | 2 | ||||
| -rw-r--r-- | sys/syz-extract/fetch.go | 14 |
6 files changed, 28 insertions, 8 deletions
@@ -12,3 +12,4 @@ Jeremy Huang Shuai Bai Alexander Popov Jean-Baptiste Cayrou +Yuzhe Han diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b5a1821cc..e2dfa5de7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -17,3 +17,4 @@ Jeremy Huang Shuai Bai Alexander Popov Jean-Baptiste Cayrou +Yuzhe Han diff --git a/docs/syscall_descriptions_syntax.md b/docs/syscall_descriptions_syntax.md index 443a625f7..83bbe2566 100644 --- a/docs/syscall_descriptions_syntax.md +++ b/docs/syscall_descriptions_syntax.md @@ -159,5 +159,5 @@ As a result the executor number `n` will get values in the `[20000 + n * 4, 2000 ## Misc -Description files also contain `include` directives that refer to Linux kernel header files +Description files also contain `include` directives that refer to Linux kernel header files, `incdir` directives that refer to custom Linux kernel header directories and `define` directives that define symbolic constant values. See the following section for details. diff --git a/sys/sysparser/lexer.go b/sys/sysparser/lexer.go index 505b52059..c6a0f802e 100644 --- a/sys/sysparser/lexer.go +++ b/sys/sysparser/lexer.go @@ -14,6 +14,7 @@ import ( type Description struct { Includes []string + Incdirs []string Defines map[string]string Syscalls []Syscall Structs map[string]*Struct @@ -48,6 +49,7 @@ type Resource struct { func Parse(in io.Reader) *Description { p := newParser(in) var includes []string + var incdirs []string defines := make(map[string]string) var syscalls []Syscall structs := make(map[string]*Struct) @@ -164,6 +166,19 @@ func Parse(in io.Reader) *Description { failf("struct '%v' is redefined as resource", name) } resources[id] = Resource{id, base, vals} + } else if name == "incdir" { + p.Parse('"') + var incdir []byte + for { + ch := p.Char() + if ch == '"' { + break + } + p.Parse(ch) + incdir = append(incdir, ch) + } + p.Parse('"') + incdirs = append(incdirs, string(incdir)) } else { switch ch := p.Char(); ch { case '(': @@ -237,6 +252,7 @@ func Parse(in io.Reader) *Description { sort.Sort(syscallArray(syscalls)) return &Description{ Includes: includes, + Incdirs: incdirs, Defines: defines, Syscalls: syscalls, Structs: structs, diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go index 344151856..4972b6bbc 100644 --- a/sys/syz-extract/extract.go +++ b/sys/syz-extract/extract.go @@ -121,7 +121,7 @@ func compileConsts(arch *Arch, desc *Description) map[string]uint64 { return nil } - consts, err := fetchValues(arch.KernelHeaderArch, valArr, append(desc.Includes, arch.KernelInclude), desc.Defines, arch.CFlags) + consts, err := fetchValues(arch.KernelHeaderArch, valArr, append(desc.Includes, arch.KernelInclude), desc.Incdirs, desc.Defines, arch.CFlags) if err != nil { failf("%v", err) } diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go index 79c080807..691b64481 100644 --- a/sys/syz-extract/fetch.go +++ b/sys/syz-extract/fetch.go @@ -16,8 +16,8 @@ import ( // fetchValues converts literal constants (e.g. O_APPEND) or any other C expressions // into their respective numeric values. It does so by builting and executing a C program // that prints values of the provided expressions. -func fetchValues(arch string, vals []string, includes []string, defines map[string]string, cflags []string) (map[string]uint64, error) { - bin, out, err := runCompiler(arch, nil, includes, nil, cflags, nil) +func fetchValues(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string) (map[string]uint64, error) { + bin, out, err := runCompiler(arch, nil, includes, incdirs, nil, cflags, nil) if err != nil { return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out)) } @@ -29,7 +29,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri } undeclared := make(map[string]bool) - bin, out, err = runCompiler(arch, vals, includes, defines, cflags, undeclared) + bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared) if err != nil { for _, errMsg := range []string{ "error: ‘([a-zA-Z0-9_]+)’ undeclared", @@ -45,7 +45,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri } } } - bin, out, err = runCompiler(arch, vals, includes, defines, cflags, undeclared) + bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared) if err != nil { return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out)) } @@ -79,7 +79,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri return res, nil } -func runCompiler(arch string, vals []string, includes []string, defines map[string]string, cflags []string, undeclared map[string]bool) (bin string, out []byte, err error) { +func runCompiler(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string, undeclared map[string]bool) (bin string, out []byte, err error) { includeText := "" for _, inc := range includes { includeText += fmt.Sprintf("#include <%v>\n", inc) @@ -130,7 +130,9 @@ func runCompiler(arch string, vals []string, includes []string, defines map[stri "-I" + *flagLinux, "-include", *flagLinux + "/include/linux/kconfig.h", }...) - + for _, incdir := range incdirs { + args = append(args, "-I" + *flagLinux + "/" + incdir,) + } cmd := exec.Command("gcc", args...) cmd.Stdin = strings.NewReader(src) out, err = cmd.CombinedOutput() |
