diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-10-26 10:51:06 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-10-26 15:44:28 +0100 |
| commit | e6e35dba937599d098fc034eff2686e5ddc409e9 (patch) | |
| tree | 802be708d0bc84dee01b9285639690a53f1f6f94 /pkg/host | |
| parent | d46bc75207fea1d7671c1277dd660cf1a4d7847b (diff) | |
sys/targets: add OS/Arch name consts
We use strings to identify OS/Arch.
These strings are duplicated throughout the code base massively.
golangci-lint points to possiblity of typos and duplication.
We already had to define these names in pkg/csource
and disable checking for prog package. A future change triggers
such warnings in another package.
Add OS/Arch name consts to sys/targets so that they can be used
to refer to OS/Arch. Use the consts everywhere.
Diffstat (limited to 'pkg/host')
| -rw-r--r-- | pkg/host/features.go | 6 | ||||
| -rw-r--r-- | pkg/host/machine_info_linux_test.go | 28 | ||||
| -rw-r--r-- | pkg/host/syscalls_linux.go | 17 | ||||
| -rw-r--r-- | pkg/host/syscalls_linux_test.go | 17 |
4 files changed, 36 insertions, 32 deletions
diff --git a/pkg/host/features.go b/pkg/host/features.go index 8b78637fb..14d4f5c89 100644 --- a/pkg/host/features.go +++ b/pkg/host/features.go @@ -102,7 +102,7 @@ func Setup(target *prog.Target, features *Features, featureFlags csource.Feature if features[FeatureFault].Enabled { args = append(args, "fault") } - if target.OS == "linux" && featureFlags["binfmt_misc"].Enabled { + if target.OS == targets.Linux && featureFlags["binfmt_misc"].Enabled { args = append(args, "binfmt_misc") } if features[FeatureKCSAN].Enabled { @@ -117,6 +117,6 @@ func Setup(target *prog.Target, features *Features, featureFlags csource.Feature func noHostChecks(target *prog.Target) bool { // HostFuzzer targets can't run Go binaries on the targets, - // so we actually run on the host on another OS. The same for "test" OS. - return targets.Get(target.OS, target.Arch).HostFuzzer || target.OS == "test" + // so we actually run on the host on another OS. The same for targets.TestOS OS. + return targets.Get(target.OS, target.Arch).HostFuzzer || target.OS == targets.TestOS } diff --git a/pkg/host/machine_info_linux_test.go b/pkg/host/machine_info_linux_test.go index f09666659..5075751d5 100644 --- a/pkg/host/machine_info_linux_test.go +++ b/pkg/host/machine_info_linux_test.go @@ -10,6 +10,8 @@ import ( "runtime" "strings" "testing" + + "github.com/google/syzkaller/sys/targets" ) func TestReadCPUInfoLinux(t *testing.T) { @@ -42,14 +44,14 @@ func checkCPUInfo(t *testing.T, data []byte, arch string) { keys[key] = true } importantKeys := map[string][]string{ - "ppc64le": {"cpu", "revision", "platform", "model", "machine"}, - "amd64": {"vendor_id", "model", "flags"}, - "s390x": {"vendor_id", "processor 0", "features"}, - "386": {"vendor_id", "model", "flags"}, - "arm64": {"CPU implementer", "CPU part", "Features"}, - "arm": {"CPU implementer", "CPU part", "Features"}, - "mips64le": {"system type", "cpu model", "ASEs implemented"}, - "riscv64": {"processor", "isa", "mmu"}, + targets.PPC64LE: {"cpu", "revision", "platform", "model", "machine"}, + targets.AMD64: {"vendor_id", "model", "flags"}, + targets.S390x: {"vendor_id", "processor 0", "features"}, + targets.I386: {"vendor_id", "model", "flags"}, + targets.ARM64: {"CPU implementer", "CPU part", "Features"}, + targets.ARM: {"CPU implementer", "CPU part", "Features"}, + targets.MIPS64LE: {"system type", "cpu model", "ASEs implemented"}, + targets.RiscV64: {"processor", "isa", "mmu"}, } archKeys := importantKeys[arch] if len(archKeys) == 0 { @@ -149,7 +151,7 @@ type cannedTest struct { // nolint:lll var cpuInfoTests = []cannedTest{ { - arch: "ppc64le", + arch: targets.PPC64LE, data: ` processor : 0 cpu : POWER8 (architected), altivec supported @@ -179,7 +181,7 @@ MMU : Hash `, }, { - arch: "ppc64le", + arch: targets.PPC64LE, data: ` processor : 0 cpu : POWER8 (architected), altivec supported @@ -201,7 +203,7 @@ MMU : Hash `, }, { - arch: "ppc64le", + arch: targets.PPC64LE, data: ` processor : 0 cpu : POWER8E, altivec supported @@ -242,7 +244,7 @@ MMU : Hash `, }, { - arch: "amd64", + arch: targets.AMD64, data: ` processor : 0 vendor_id : GenuineIntel @@ -302,7 +304,7 @@ power management: `, }, { - arch: "amd64", + arch: targets.AMD64, data: ` processor : 0 vendor_id : GenuineIntel diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index ff41da68b..16cfbfa46 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -18,6 +18,7 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/prog" + "github.com/google/syzkaller/sys/targets" ) func isSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { @@ -74,17 +75,17 @@ func parseKallsyms(kallsyms []byte, arch string) map[string]bool { set := make(map[string]bool) var re *regexp.Regexp switch arch { - case "386", "amd64": + case targets.I386, targets.AMD64: re = regexp.MustCompile(` T (__ia32_|__x64_)?sys_([^\n]+)\n`) - case "arm", "arm64": + case targets.ARM, targets.ARM64: re = regexp.MustCompile(` T (__arm64_)?sys_([^\n]+)\n`) - case "ppc64le": + case targets.PPC64LE: re = regexp.MustCompile(` T ()?sys_([^\n]+)\n`) - case "mips64le": + case targets.MIPS64LE: re = regexp.MustCompile(` T sys_(mips_)?([^\n]+)\n`) - case "s390x": + case targets.S390x: re = regexp.MustCompile(` T (__s390_|__s390x_)?sys_([^\n]+)\n`) - case "riscv64": + case targets.RiscV64: re = regexp.MustCompile(` T sys_(riscv_)?([^\n]+)\n`) default: panic("unsupported arch for kallsyms parsing") @@ -191,11 +192,11 @@ func isWifiEmulationSupported(c *prog.Syscall, target *prog.Target, sandbox stri func isSyzKvmSetupCPUSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { switch c.Name { case "syz_kvm_setup_cpu$x86": - if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" { + if runtime.GOARCH == targets.AMD64 || runtime.GOARCH == targets.I386 { return true, "" } case "syz_kvm_setup_cpu$arm64": - if runtime.GOARCH == "arm64" { + if runtime.GOARCH == targets.ARM64 { return true, "" } } diff --git a/pkg/host/syscalls_linux_test.go b/pkg/host/syscalls_linux_test.go index 3ce2e3517..5d4f60082 100644 --- a/pkg/host/syscalls_linux_test.go +++ b/pkg/host/syscalls_linux_test.go @@ -11,11 +11,12 @@ import ( "testing" "github.com/google/syzkaller/prog" + "github.com/google/syzkaller/sys/targets" ) func TestSupportedSyscalls(t *testing.T) { t.Parallel() - target, err := prog.GetTarget("linux", runtime.GOARCH) + target, err := prog.GetTarget(targets.Linux, runtime.GOARCH) if err != nil { t.Fatal(err) } @@ -58,7 +59,7 @@ func TestKallsymsParse(t *testing.T) { SupportedSyscalls []string }{ { - "amd64", + targets.AMD64, []byte(` ffffffff817cdcc0 T __sys_bind ffffffff817cdda0 T __x64_sys_bind @@ -74,7 +75,7 @@ ffffffff817ce0a0 T __ia32_sys_accept4 []string{"bind", "listen", "accept4"}, }, { - "arm64", + targets.ARM64, []byte(` ffff000010a3ddf8 T __sys_bind ffff000010a3def8 T __arm64_sys_bind @@ -87,7 +88,7 @@ ffff000010a3e1f0 T __arm64_sys_accept4 []string{"bind", "listen", "accept4"}, }, { - "ppc64le", + targets.PPC64LE, []byte(` c0000000011ec810 T __sys_bind c0000000011eca10 T sys_bind @@ -103,7 +104,7 @@ c0000000011ed050 T __se_sys_accept4 []string{"bind", "listen", "accept4"}, }, { - "arm", + targets.ARM, []byte(` c037c67c T __se_sys_setfsuid c037c694 T __sys_setfsgid @@ -118,7 +119,7 @@ c037c7f8 T sys_getppid }, // Test kallsymsRenameMap. { - "ppc64le", + targets.PPC64LE, []byte(` c00000000037eb00 T sys_newstat `), @@ -126,7 +127,7 @@ c00000000037eb00 T sys_newstat []string{"stat"}, }, { - "s390x", + targets.S390x, []byte(` 0000000000e4f760 T __sys_bind 0000000000e4f8e8 T __s390_sys_bind @@ -145,7 +146,7 @@ c00000000037eb00 T sys_newstat []string{"bind", "listen", "accept4"}, }, { - "riscv64", + targets.RiscV64, []byte(` ffffffe0005c9b02 T __sys_bind ffffffe0005c9ba0 T sys_bind |
