mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-14 08:19:04 +00:00
pkg/ipc: move flags into subpackage
Move all ipc flags into pkg/ipc/ipcconfig package so that importing pkg/ipc does pull in the flags.
This commit is contained in:
parent
5ff1f9faec
commit
6bfd4f09db
@ -4,7 +4,6 @@
|
||||
package ipc
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -18,7 +17,6 @@ import (
|
||||
|
||||
"github.com/google/syzkaller/pkg/osutil"
|
||||
"github.com/google/syzkaller/prog"
|
||||
"github.com/google/syzkaller/sys/targets"
|
||||
)
|
||||
|
||||
// Configuration flags for Config.Flags.
|
||||
@ -49,35 +47,14 @@ const (
|
||||
FlagCollide // collide syscalls to provoke data races
|
||||
)
|
||||
|
||||
const (
|
||||
outputSize = 16 << 20
|
||||
|
||||
statusFail = 67
|
||||
statusError = 68
|
||||
statusRetry = 69
|
||||
)
|
||||
|
||||
var (
|
||||
flagExecutor = flag.String("executor", "./syz-executor", "path to executor binary")
|
||||
flagThreaded = flag.Bool("threaded", true, "use threaded mode in executor")
|
||||
flagCollide = flag.Bool("collide", true, "collide syscalls to provoke data races")
|
||||
flagSignal = flag.Bool("cover", false, "collect feedback signals (coverage)")
|
||||
flagSandbox = flag.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace)")
|
||||
flagDebug = flag.Bool("debug", false, "debug output from executor")
|
||||
flagTimeout = flag.Duration("timeout", 0, "execution timeout")
|
||||
flagAbortSignal = flag.Int("abort_signal", 0, "initial signal to send to executor"+
|
||||
" in error conditions; upgrades to SIGKILL if executor does not exit")
|
||||
flagBufferSize = flag.Uint64("buffer_size", 0, "internal buffer size (in bytes) for executor output")
|
||||
)
|
||||
|
||||
type ExecOpts struct {
|
||||
Flags ExecFlags
|
||||
FaultCall int // call index for fault injection (0-based)
|
||||
FaultNth int // fault n-th operation in the call (0-based)
|
||||
}
|
||||
|
||||
// ExecutorFailure is returned from MakeEnv or from env.Exec when executor terminates by calling fail function.
|
||||
// This is considered a logical error (a failed assert).
|
||||
// ExecutorFailure is returned from MakeEnv or from env.Exec when executor terminates
|
||||
// by calling fail function. This is considered a logical error (a failed assert).
|
||||
type ExecutorFailure string
|
||||
|
||||
func (err ExecutorFailure) Error() string {
|
||||
@ -106,51 +83,6 @@ type Config struct {
|
||||
RateLimit bool
|
||||
}
|
||||
|
||||
func DefaultConfig(target *prog.Target) (*Config, *ExecOpts, error) {
|
||||
c := &Config{
|
||||
Executor: *flagExecutor,
|
||||
Timeout: *flagTimeout,
|
||||
AbortSignal: *flagAbortSignal,
|
||||
BufferSize: *flagBufferSize,
|
||||
RateLimit: target.OS == "akaros",
|
||||
}
|
||||
if *flagSignal {
|
||||
c.Flags |= FlagSignal
|
||||
}
|
||||
if *flagDebug {
|
||||
c.Flags |= FlagDebug
|
||||
}
|
||||
switch *flagSandbox {
|
||||
case "none":
|
||||
case "setuid":
|
||||
c.Flags |= FlagSandboxSetuid
|
||||
case "namespace":
|
||||
c.Flags |= FlagSandboxNamespace
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("flag sandbox must contain one of none/setuid/namespace")
|
||||
}
|
||||
|
||||
sysTarget := targets.Get(target.OS, target.Arch)
|
||||
if sysTarget.ExecutorUsesShmem {
|
||||
c.Flags |= FlagUseShmem
|
||||
}
|
||||
if sysTarget.ExecutorUsesForkServer {
|
||||
c.Flags |= FlagUseForkServer
|
||||
}
|
||||
|
||||
opts := &ExecOpts{
|
||||
Flags: FlagDedupCover,
|
||||
}
|
||||
if *flagThreaded {
|
||||
opts.Flags |= FlagThreaded
|
||||
}
|
||||
if *flagCollide {
|
||||
opts.Flags |= FlagCollide
|
||||
}
|
||||
|
||||
return c, opts, nil
|
||||
}
|
||||
|
||||
type CallFlags uint32
|
||||
|
||||
const (
|
||||
@ -186,6 +118,12 @@ type Env struct {
|
||||
}
|
||||
|
||||
const (
|
||||
outputSize = 16 << 20
|
||||
|
||||
statusFail = 67
|
||||
statusError = 68
|
||||
statusRetry = 69
|
||||
|
||||
// Comparison types masks taken from KCOV headers.
|
||||
compSizeMask = 6
|
||||
compSize8 = 6
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright 2015 syzkaller project authors. All rights reserved.
|
||||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
||||
|
||||
package ipc
|
||||
package ipc_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -13,6 +13,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/syzkaller/pkg/csource"
|
||||
. "github.com/google/syzkaller/pkg/ipc"
|
||||
"github.com/google/syzkaller/pkg/ipc/ipcconfig"
|
||||
"github.com/google/syzkaller/pkg/osutil"
|
||||
"github.com/google/syzkaller/prog"
|
||||
_ "github.com/google/syzkaller/sys"
|
||||
@ -42,7 +44,7 @@ func initTest(t *testing.T) (*prog.Target, rand.Source, int, EnvFlags) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg, _, err := DefaultConfig(target)
|
||||
cfg, _, err := ipcconfig.Default(target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
71
pkg/ipc/ipcconfig/ipcconfig.go
Normal file
71
pkg/ipc/ipcconfig/ipcconfig.go
Normal file
@ -0,0 +1,71 @@
|
||||
// Copyright 2018 syzkaller project authors. All rights reserved.
|
||||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
||||
|
||||
package ipcconfig
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/syzkaller/pkg/ipc"
|
||||
"github.com/google/syzkaller/prog"
|
||||
"github.com/google/syzkaller/sys/targets"
|
||||
)
|
||||
|
||||
var (
|
||||
flagExecutor = flag.String("executor", "./syz-executor", "path to executor binary")
|
||||
flagThreaded = flag.Bool("threaded", true, "use threaded mode in executor")
|
||||
flagCollide = flag.Bool("collide", true, "collide syscalls to provoke data races")
|
||||
flagSignal = flag.Bool("cover", false, "collect feedback signals (coverage)")
|
||||
flagSandbox = flag.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace)")
|
||||
flagDebug = flag.Bool("debug", false, "debug output from executor")
|
||||
flagTimeout = flag.Duration("timeout", 0, "execution timeout")
|
||||
flagAbortSignal = flag.Int("abort_signal", 0, "initial signal to send to executor"+
|
||||
" in error conditions; upgrades to SIGKILL if executor does not exit")
|
||||
flagBufferSize = flag.Uint64("buffer_size", 0, "internal buffer size (in bytes) for executor output")
|
||||
)
|
||||
|
||||
func Default(target *prog.Target) (*ipc.Config, *ipc.ExecOpts, error) {
|
||||
c := &ipc.Config{
|
||||
Executor: *flagExecutor,
|
||||
Timeout: *flagTimeout,
|
||||
AbortSignal: *flagAbortSignal,
|
||||
BufferSize: *flagBufferSize,
|
||||
RateLimit: target.OS == "akaros",
|
||||
}
|
||||
if *flagSignal {
|
||||
c.Flags |= ipc.FlagSignal
|
||||
}
|
||||
if *flagDebug {
|
||||
c.Flags |= ipc.FlagDebug
|
||||
}
|
||||
switch *flagSandbox {
|
||||
case "none":
|
||||
case "setuid":
|
||||
c.Flags |= ipc.FlagSandboxSetuid
|
||||
case "namespace":
|
||||
c.Flags |= ipc.FlagSandboxNamespace
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("flag sandbox must contain one of none/setuid/namespace")
|
||||
}
|
||||
|
||||
sysTarget := targets.Get(target.OS, target.Arch)
|
||||
if sysTarget.ExecutorUsesShmem {
|
||||
c.Flags |= ipc.FlagUseShmem
|
||||
}
|
||||
if sysTarget.ExecutorUsesForkServer {
|
||||
c.Flags |= ipc.FlagUseForkServer
|
||||
}
|
||||
|
||||
opts := &ipc.ExecOpts{
|
||||
Flags: ipc.FlagDedupCover,
|
||||
}
|
||||
if *flagThreaded {
|
||||
opts.Flags |= ipc.FlagThreaded
|
||||
}
|
||||
if *flagCollide {
|
||||
opts.Flags |= ipc.FlagCollide
|
||||
}
|
||||
|
||||
return c, opts, nil
|
||||
}
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/google/syzkaller/pkg/hash"
|
||||
"github.com/google/syzkaller/pkg/host"
|
||||
"github.com/google/syzkaller/pkg/ipc"
|
||||
"github.com/google/syzkaller/pkg/ipc/ipcconfig"
|
||||
"github.com/google/syzkaller/pkg/log"
|
||||
"github.com/google/syzkaller/pkg/osutil"
|
||||
"github.com/google/syzkaller/pkg/rpctype"
|
||||
@ -110,7 +111,7 @@ func main() {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
config, execOpts, err := ipc.DefaultConfig(target)
|
||||
config, execOpts, err := ipcconfig.Default(target)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create default ipc config: %v", err)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/google/syzkaller/pkg/cover"
|
||||
"github.com/google/syzkaller/pkg/host"
|
||||
"github.com/google/syzkaller/pkg/ipc"
|
||||
"github.com/google/syzkaller/pkg/ipc/ipcconfig"
|
||||
"github.com/google/syzkaller/pkg/log"
|
||||
"github.com/google/syzkaller/pkg/osutil"
|
||||
"github.com/google/syzkaller/prog"
|
||||
@ -231,7 +232,7 @@ func loadPrograms(target *prog.Target, files []string) []*prog.LogEntry {
|
||||
|
||||
func createConfig(target *prog.Target, entries []*prog.LogEntry, features *host.Features) (
|
||||
*ipc.Config, *ipc.ExecOpts) {
|
||||
config, execOpts, err := ipc.DefaultConfig(target)
|
||||
config, execOpts, err := ipcconfig.Default(target)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/google/syzkaller/pkg/db"
|
||||
"github.com/google/syzkaller/pkg/host"
|
||||
"github.com/google/syzkaller/pkg/ipc"
|
||||
"github.com/google/syzkaller/pkg/ipc/ipcconfig"
|
||||
"github.com/google/syzkaller/pkg/log"
|
||||
"github.com/google/syzkaller/prog"
|
||||
_ "github.com/google/syzkaller/sys"
|
||||
@ -60,7 +61,7 @@ func main() {
|
||||
prios := target.CalculatePriorities(corpus)
|
||||
ct := target.BuildChoiceTable(prios, calls)
|
||||
|
||||
config, execOpts, err := ipc.DefaultConfig(target)
|
||||
config, execOpts, err := ipcconfig.Default(target)
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user