diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-04-18 10:59:34 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-30 09:36:03 +0000 |
| commit | c142aa8dbff8ac1ecb65cf4ecc90b32a3478967f (patch) | |
| tree | 4c2466c799a6192b54904f1573cc87a582697867 /pkg | |
| parent | b55e33926118ca417bb0ce0c76ceec7c220f65bc (diff) | |
pkg/ipc: dedup features to flags conversion
Currently it's duplicated 4 times, dedup it.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/ipc/ipc.go | 41 | ||||
| -rw-r--r-- | pkg/runtest/run.go | 27 |
2 files changed, 42 insertions, 26 deletions
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index ebdca1ef8..818c88a84 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -16,6 +16,8 @@ import ( "unsafe" "github.com/google/syzkaller/pkg/cover" + "github.com/google/syzkaller/pkg/csource" + "github.com/google/syzkaller/pkg/host" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/signal" "github.com/google/syzkaller/prog" @@ -154,6 +156,45 @@ func FlagsToSandbox(flags EnvFlags) string { return "none" } +// nolint: gocyclo +func FeaturesToFlags(feat *host.Features, manual csource.Features) EnvFlags { + var flags EnvFlags + if manual == nil || manual["net_reset"].Enabled { + flags |= FlagEnableNetReset + } + if manual == nil || manual["cgroups"].Enabled { + flags |= FlagEnableCgroups + } + if manual == nil || manual["close_fds"].Enabled { + flags |= FlagEnableCloseFds + } + if feat[host.FeatureExtraCoverage].Enabled { + flags |= FlagExtraCover + } + if feat[host.FeatureDelayKcovMmap].Enabled { + flags |= FlagDelayKcovMmap + } + if feat[host.FeatureNetInjection].Enabled && (manual == nil || manual["tun"].Enabled) { + flags |= FlagEnableTun + } + if feat[host.FeatureNetDevices].Enabled && (manual == nil || manual["net_dev"].Enabled) { + flags |= FlagEnableNetDev + } + if feat[host.FeatureDevlinkPCI].Enabled && (manual == nil || manual["devlink_pci"].Enabled) { + flags |= FlagEnableDevlinkPCI + } + if feat[host.FeatureNicVF].Enabled && (manual == nil || manual["nic_vf"].Enabled) { + flags |= FlagEnableNicVF + } + if feat[host.FeatureVhciInjection].Enabled && (manual == nil || manual["vhci"].Enabled) { + flags |= FlagEnableVhciInjection + } + if feat[host.FeatureWifiEmulation].Enabled && (manual == nil || manual["wifi"].Enabled) { + flags |= FlagEnableWifi + } + return flags +} + func MakeEnv(config *Config, pid int) (*Env, error) { if config.Timeouts.Slowdown == 0 || config.Timeouts.Scale == 0 || config.Timeouts.Syscall == 0 || config.Timeouts.Program == 0 { diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index 9e111377d..5c00bf982 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -419,32 +419,7 @@ func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bo opts.ExecFlags |= ipc.FlagCollectSignal opts.ExecFlags |= ipc.FlagCollectCover } - if ctx.Features[host.FeatureExtraCoverage].Enabled { - opts.EnvFlags |= ipc.FlagExtraCover - } - if ctx.Features[host.FeatureDelayKcovMmap].Enabled { - opts.EnvFlags |= ipc.FlagDelayKcovMmap - } - if ctx.Features[host.FeatureNetInjection].Enabled { - opts.EnvFlags |= ipc.FlagEnableTun - } - if ctx.Features[host.FeatureNetDevices].Enabled { - opts.EnvFlags |= ipc.FlagEnableNetDev - } - opts.EnvFlags |= ipc.FlagEnableNetReset - opts.EnvFlags |= ipc.FlagEnableCgroups - if ctx.Features[host.FeatureDevlinkPCI].Enabled { - opts.EnvFlags |= ipc.FlagEnableDevlinkPCI - } - if ctx.Features[host.FeatureNicVF].Enabled { - opts.EnvFlags |= ipc.FlagEnableNicVF - } - if ctx.Features[host.FeatureVhciInjection].Enabled { - opts.EnvFlags |= ipc.FlagEnableVhciInjection - } - if ctx.Features[host.FeatureWifiEmulation].Enabled { - opts.EnvFlags |= ipc.FlagEnableWifi - } + opts.EnvFlags |= ipc.FeaturesToFlags(ctx.Features, nil) if ctx.Debug { opts.EnvFlags |= ipc.FlagDebug } |
