diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2019-04-03 17:35:33 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-04-04 14:56:48 +0200 |
| commit | 1ee782d53c445be1996975e1c7fd2b7bb063d4b7 (patch) | |
| tree | 59d8cc23f56d818ae8198a0636d7ffe9634e65f6 /pkg/host/host_linux.go | |
| parent | 6a475fffec57cc3b1e51794c0ebed7d169f12349 (diff) | |
host: add kallsyms parsing tests
Start with a few simple tests that can be extended when needed.
Diffstat (limited to 'pkg/host/host_linux.go')
| -rw-r--r-- | pkg/host/host_linux.go | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/pkg/host/host_linux.go b/pkg/host/host_linux.go index ca98d927b..ae8d7af85 100644 --- a/pkg/host/host_linux.go +++ b/pkg/host/host_linux.go @@ -67,23 +67,7 @@ func isSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, st if len(kallsyms) == 0 { return } - var re *regexp.Regexp - switch target.Arch { - case "386", "amd64": - re = regexp.MustCompile(` T (__ia32_|__x64_)?sys_([^\n]+)\n`) - case "arm64": - re = regexp.MustCompile(` T (__arm64_)?sys_([^\n]+)\n`) - case "ppc64le": - re = regexp.MustCompile(` T ()?sys_([^\n]+)\n`) - default: - panic("unsupported arch for kallsyms parsing") - } - matches := re.FindAllSubmatch(kallsyms, -1) - for _, m := range matches { - name := string(m[2]) - log.Logf(2, "found in kallsyms: %v", name) - kallsymsSyscallSet[name] = true - } + kallsymsSyscallSet = parseKallsyms(kallsyms, target.Arch) }) if !testFallback && len(kallsymsSyscallSet) != 0 { r, v := isSupportedKallsyms(c) @@ -92,6 +76,28 @@ func isSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, st return isSupportedTrial(c) } +func parseKallsyms(kallsyms []byte, arch string) map[string]bool { + set := make(map[string]bool) + var re *regexp.Regexp + switch arch { + case "386", "amd64": + re = regexp.MustCompile(` T (__ia32_|__x64_)?sys_([^\n]+)\n`) + case "arm64": + re = regexp.MustCompile(` T (__arm64_)?sys_([^\n]+)\n`) + case "ppc64le": + re = regexp.MustCompile(` T ()?sys_([^\n]+)\n`) + default: + panic("unsupported arch for kallsyms parsing") + } + matches := re.FindAllSubmatch(kallsyms, -1) + for _, m := range matches { + name := string(m[2]) + log.Logf(2, "found in kallsyms: %v", name) + set[name] = true + } + return set +} + func isSupportedKallsyms(c *prog.Syscall) (bool, string) { name := c.CallName if newname := kallsymsRenameMap[name]; newname != "" { @@ -144,7 +150,7 @@ func init() { // Where umount is renamed to oldumount is unclear. var ( kallsymsOnce sync.Once - kallsymsSyscallSet = make(map[string]bool) + kallsymsSyscallSet map[string]bool kallsymsRenameMap = map[string]string{ "umount": "oldumount", "umount2": "umount", |
