aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ipc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-08-03 18:12:24 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-08-03 18:12:24 +0200
commit6bfd4f09db1079ee95e0ee10f770e34499e9eeee (patch)
treedcad32286f42c6cb8533ec4b7f5ddfab4ba3c8b0 /pkg/ipc
parent5ff1f9faece0ff7318d05c21a3efd0b44a009ac8 (diff)
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.
Diffstat (limited to 'pkg/ipc')
-rw-r--r--pkg/ipc/ipc.go78
-rw-r--r--pkg/ipc/ipc_test.go6
-rw-r--r--pkg/ipc/ipcconfig/ipcconfig.go71
3 files changed, 83 insertions, 72 deletions
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
index 5ac380fe7..f1dda1e88 100644
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -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
diff --git a/pkg/ipc/ipc_test.go b/pkg/ipc/ipc_test.go
index 3a97d9c2d..55a8749bb 100644
--- a/pkg/ipc/ipc_test.go
+++ b/pkg/ipc/ipc_test.go
@@ -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)
}
diff --git a/pkg/ipc/ipcconfig/ipcconfig.go b/pkg/ipc/ipcconfig/ipcconfig.go
new file mode 100644
index 000000000..6f13ad137
--- /dev/null
+++ b/pkg/ipc/ipcconfig/ipcconfig.go
@@ -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
+}