aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-05-27 17:29:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-05-27 15:38:45 +0000
commit0cdd36fc443630fa8b6c5d7903cb7adc0baac5b5 (patch)
treef5c27bbb4a809970d83cba87df5bf7638639763c
parent1f9b5e5c3aa41af3a1403e3933f20a2776eb5f4b (diff)
sys/targets: add consts for gvisor/starnix
Lint started warning about duplicate "gvisor" const in pkg/cover. Add gvisor/starnix consts to sys/targets package to avoid duplication.
-rw-r--r--pkg/build/build.go2
-rw-r--r--pkg/cover/backend/backend.go4
-rw-r--r--pkg/cover/backend/pc.go4
-rw-r--r--pkg/mgrconfig/load.go2
-rw-r--r--pkg/report/report.go6
-rw-r--r--pkg/vcs/linux.go2
-rw-r--r--sys/targets/targets.go4
-rw-r--r--vm/gvisor/gvisor.go7
-rw-r--r--vm/starnix/starnix.go3
-rw-r--r--vm/vm_test.go2
10 files changed, 21 insertions, 15 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go
index a489f04dc..4d6e3bce3 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -133,7 +133,7 @@ type builder interface {
func getBuilder(targetOS, targetArch, vmType string) (builder, error) {
if targetOS == targets.Linux {
- if vmType == "gvisor" {
+ if vmType == targets.GVisor {
return gvisor{}, nil
} else if vmType == "cuttlefish" {
return cuttlefish{}, nil
diff --git a/pkg/cover/backend/backend.go b/pkg/cover/backend/backend.go
index b390f5cad..631201480 100644
--- a/pkg/cover/backend/backend.go
+++ b/pkg/cover/backend/backend.go
@@ -70,10 +70,10 @@ func Make(target *targets.Target, vm, objDir, srcDir, buildDir string, splitBuil
if objDir == "" {
return nil, fmt.Errorf("kernel obj directory is not specified")
}
- if target.OS == "darwin" {
+ if target.OS == targets.Darwin {
return makeMachO(target, objDir, srcDir, buildDir, moduleObj, modules)
}
- if vm == "gvisor" {
+ if vm == targets.GVisor {
return makeGvisor(target, objDir, srcDir, buildDir, modules)
}
var delimiters []string
diff --git a/pkg/cover/backend/pc.go b/pkg/cover/backend/pc.go
index 24b4b296e..da8ae6d56 100644
--- a/pkg/cover/backend/pc.go
+++ b/pkg/cover/backend/pc.go
@@ -10,7 +10,7 @@ import (
)
func PreviousInstructionPC(target *targets.Target, vm string, pc uint64) uint64 {
- if vm == "gvisor" {
+ if vm == targets.GVisor {
// gVisor coverage returns real PCs that don't need adjustment.
return pc
}
@@ -25,7 +25,7 @@ func PreviousInstructionPC(target *targets.Target, vm string, pc uint64) uint64
}
func NextInstructionPC(target *targets.Target, vm string, pc uint64) uint64 {
- if vm == "gvisor" {
+ if vm == targets.GVisor {
return pc
}
offset := instructionLen(target.Arch)
diff --git a/pkg/mgrconfig/load.go b/pkg/mgrconfig/load.go
index db44caa89..2bccdc7df 100644
--- a/pkg/mgrconfig/load.go
+++ b/pkg/mgrconfig/load.go
@@ -207,7 +207,7 @@ func (cfg *Config) initTimeouts() {
// Assuming qemu emulation.
// Quick tests of mmap syscall on arm64 show ~9x slowdown.
slowdown = 10
- case cfg.Type == "gvisor" && cfg.Cover && strings.Contains(cfg.Name, "-race"):
+ case cfg.Type == targets.GVisor && cfg.Cover && strings.Contains(cfg.Name, "-race"):
// Go coverage+race has insane slowdown of ~350x. We can't afford such large value,
// but a smaller value should be enough to finish at least some syscalls.
// Note: the name check is a hack.
diff --git a/pkg/report/report.go b/pkg/report/report.go
index 2003b8b83..b211a140e 100644
--- a/pkg/report/report.go
+++ b/pkg/report/report.go
@@ -83,7 +83,7 @@ const unspecifiedType = crash.Type("UNSPECIFIED")
// NewReporter creates reporter for the specified OS/Type.
func NewReporter(cfg *mgrconfig.Config) (*Reporter, error) {
typ := cfg.TargetOS
- if cfg.Type == "gvisor" || cfg.Type == "starnix" {
+ if cfg.Type == targets.GVisor || cfg.Type == targets.Starnix {
typ = cfg.Type
}
ctor := ctors[typ]
@@ -139,8 +139,8 @@ const (
var ctors = map[string]fn{
targets.Linux: ctorLinux,
- "starnix": ctorFuchsia,
- "gvisor": ctorGvisor,
+ targets.Starnix: ctorFuchsia,
+ targets.GVisor: ctorGvisor,
targets.FreeBSD: ctorFreebsd,
targets.Darwin: ctorDarwin,
targets.NetBSD: ctorNetbsd,
diff --git a/pkg/vcs/linux.go b/pkg/vcs/linux.go
index d5a4d138c..41716e50c 100644
--- a/pkg/vcs/linux.go
+++ b/pkg/vcs/linux.go
@@ -193,7 +193,7 @@ func linuxGCCPath(tags map[string]bool, binDir, defaultCompiler string) string {
}
func (ctx *linux) PrepareBisect() error {
- if ctx.vmType != "gvisor" {
+ if ctx.vmType != targets.GVisor {
// Some linux repos we fuzz don't import the upstream release git tags. We need tags
// to decide which compiler versions to use. Let's fetch upstream for its tags.
err := ctx.git.fetchRemote("https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git", "")
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index f5092b8c1..d444f55aa 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -135,6 +135,10 @@ const (
Trusty = "trusty"
Windows = "windows"
+ // These are VM types, but we put them here to prevent string duplication.
+ GVisor = "gvisor"
+ Starnix = "starnix"
+
AMD64 = "amd64"
ARM64 = "arm64"
ARM = "arm"
diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go
index 45c076b23..ed3018a51 100644
--- a/vm/gvisor/gvisor.go
+++ b/vm/gvisor/gvisor.go
@@ -21,11 +21,12 @@ import (
"github.com/google/syzkaller/pkg/log"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
+ "github.com/google/syzkaller/sys/targets"
"github.com/google/syzkaller/vm/vmimpl"
)
func init() {
- vmimpl.Register("gvisor", ctor, true)
+ vmimpl.Register(targets.GVisor, ctor, true)
}
type Config struct {
@@ -146,8 +147,8 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
tee = os.Stdout
}
merger := vmimpl.NewOutputMerger(tee)
- merger.Add("gvisor", rpipe)
- merger.Add("gvisor-goruntime", panicLogReadFD)
+ merger.Add("runsc", rpipe)
+ merger.Add("runsc-goruntime", panicLogReadFD)
inst := &instance{
cfg: pool.cfg,
diff --git a/vm/starnix/starnix.go b/vm/starnix/starnix.go
index 51f2f670f..61c893305 100644
--- a/vm/starnix/starnix.go
+++ b/vm/starnix/starnix.go
@@ -17,12 +17,13 @@ import (
"github.com/google/syzkaller/pkg/log"
"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/pkg/report"
+ "github.com/google/syzkaller/sys/targets"
"github.com/google/syzkaller/vm/vmimpl"
)
func init() {
var _ vmimpl.Infoer = (*instance)(nil)
- vmimpl.Register("starnix", ctor, true)
+ vmimpl.Register(targets.Starnix, ctor, true)
}
type Config struct {
diff --git a/vm/vm_test.go b/vm/vm_test.go
index 4a6c91f41..4f0e2836d 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -431,7 +431,7 @@ func TestVMType(t *testing.T) {
in string
want string
}{
- {"gvisor", "gvisor"},
+ {targets.GVisor, targets.GVisor},
{"proxyapp:android", "proxyapp"},
}