mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-27 05:10:43 +00:00
pkg/ipc: move target characteristics out of config flags
They don't belong there, executor does not know about them. In preparation for future changes.
This commit is contained in:
parent
aa27601f9e
commit
a129861adb
@ -39,9 +39,6 @@ const (
|
||||
FlagEnableCgroups // setup cgroups for testing
|
||||
FlagEnableCloseFds // close fds after each program
|
||||
FlagEnableDevlinkPCI // setup devlink PCI device
|
||||
// Executor does not know about these:
|
||||
FlagUseShmem // use shared memory instead of pipes for communication
|
||||
FlagUseForkServer // use extended protocol with handshake
|
||||
)
|
||||
|
||||
// Per-exec flags for ExecOpts.Flags:
|
||||
@ -67,6 +64,9 @@ type Config struct {
|
||||
// Path to executor binary.
|
||||
Executor string
|
||||
|
||||
UseShmem bool // use shared memory instead of pipes for communication
|
||||
UseForkServer bool // use extended protocol with handshake
|
||||
|
||||
// Flags are configuation flags, defined above.
|
||||
Flags EnvFlags
|
||||
|
||||
@ -155,7 +155,7 @@ func FlagsToSandbox(flags EnvFlags) string {
|
||||
func MakeEnv(config *Config, pid int) (*Env, error) {
|
||||
var inf, outf *os.File
|
||||
var inmem, outmem []byte
|
||||
if config.Flags&FlagUseShmem != 0 {
|
||||
if config.UseShmem {
|
||||
var err error
|
||||
inf, inmem, err = osutil.CreateMemMappedFile(prog.ExecBufferSize)
|
||||
if err != nil {
|
||||
@ -254,7 +254,7 @@ func (env *Env) Exec(opts *ExecOpts, p *prog.Prog) (output []byte, info *ProgInf
|
||||
return
|
||||
}
|
||||
var progData []byte
|
||||
if env.config.Flags&FlagUseShmem == 0 {
|
||||
if !env.config.UseShmem {
|
||||
progData = env.in[:progSize]
|
||||
}
|
||||
// Zero out the first two words (ncmd and nsig), so that we don't have garbage there
|
||||
@ -288,7 +288,7 @@ func (env *Env) Exec(opts *ExecOpts, p *prog.Prog) (output []byte, info *ProgInf
|
||||
if info != nil && env.config.Flags&FlagSignal == 0 {
|
||||
addFallbackSignal(p, info)
|
||||
}
|
||||
if env.config.Flags&FlagUseForkServer == 0 {
|
||||
if !env.config.UseForkServer {
|
||||
env.cmd.close()
|
||||
env.cmd = nil
|
||||
}
|
||||
@ -620,7 +620,7 @@ func makeCommand(pid int, bin []string, config *Config, inFile, outFile *os.File
|
||||
// reading from inrp will hang since we hold another end of the pipe open.
|
||||
inwp.Close()
|
||||
|
||||
if c.config.Flags&FlagUseForkServer != 0 {
|
||||
if c.config.UseForkServer {
|
||||
if err := c.handshake(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -809,14 +809,14 @@ func sanitizeTimeout(config *Config) time.Duration {
|
||||
// Executor can be slow due to global locks in namespaces and other things,
|
||||
// so let's better wait than report false misleading crashes.
|
||||
timeout = time.Minute
|
||||
if config.Flags&FlagUseForkServer == 0 {
|
||||
if !config.UseForkServer {
|
||||
// If there is no fork server, executor does not have internal timeout.
|
||||
timeout = executorTimeout
|
||||
}
|
||||
}
|
||||
// IPC timeout must be larger then executor timeout.
|
||||
// Otherwise IPC will kill parent executor but leave child executor alive.
|
||||
if config.Flags&FlagUseForkServer != 0 && timeout < minTimeout {
|
||||
if config.UseForkServer && timeout < minTimeout {
|
||||
timeout = minTimeout
|
||||
}
|
||||
return timeout
|
||||
|
@ -31,7 +31,7 @@ func buildExecutor(t *testing.T, target *prog.Target) string {
|
||||
return bin
|
||||
}
|
||||
|
||||
func initTest(t *testing.T) (*prog.Target, rand.Source, int, EnvFlags) {
|
||||
func initTest(t *testing.T) (*prog.Target, rand.Source, int, bool, bool) {
|
||||
t.Parallel()
|
||||
iters := 100
|
||||
if testing.Short() {
|
||||
@ -51,8 +51,7 @@ func initTest(t *testing.T) (*prog.Target, rand.Source, int, EnvFlags) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flags := cfg.Flags & (FlagUseShmem | FlagUseForkServer)
|
||||
return target, rs, iters, flags
|
||||
return target, rs, iters, cfg.UseShmem, cfg.UseForkServer
|
||||
}
|
||||
|
||||
// TestExecutor runs all internal executor unit tests.
|
||||
@ -72,7 +71,7 @@ func TestExecutor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
target, _, _, configFlags := initTest(t)
|
||||
target, _, _, useShmem, useForkServer := initTest(t)
|
||||
|
||||
bin := buildExecutor(t, target)
|
||||
defer os.Remove(bin)
|
||||
@ -81,9 +80,10 @@ func TestExecute(t *testing.T) {
|
||||
for _, flag := range flags {
|
||||
t.Logf("testing flags 0x%x\n", flag)
|
||||
cfg := &Config{
|
||||
Executor: bin,
|
||||
Flags: configFlags,
|
||||
Timeout: timeout,
|
||||
Executor: bin,
|
||||
UseShmem: useShmem,
|
||||
UseForkServer: useForkServer,
|
||||
Timeout: timeout,
|
||||
}
|
||||
env, err := MakeEnv(cfg, 0)
|
||||
if err != nil {
|
||||
@ -117,12 +117,13 @@ func TestExecute(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParallel(t *testing.T) {
|
||||
target, _, _, configFlags := initTest(t)
|
||||
target, _, _, useShmem, useForkServer := initTest(t)
|
||||
bin := buildExecutor(t, target)
|
||||
defer os.Remove(bin)
|
||||
cfg := &Config{
|
||||
Executor: bin,
|
||||
Flags: configFlags,
|
||||
Executor: bin,
|
||||
UseShmem: useShmem,
|
||||
UseForkServer: useForkServer,
|
||||
}
|
||||
const P = 10
|
||||
errs := make(chan error, P)
|
||||
|
@ -38,13 +38,8 @@ func Default(target *prog.Target) (*ipc.Config, *ipc.ExecOpts, error) {
|
||||
}
|
||||
c.Flags |= sandboxFlags
|
||||
sysTarget := targets.Get(target.OS, target.Arch)
|
||||
if sysTarget.ExecutorUsesShmem {
|
||||
c.Flags |= ipc.FlagUseShmem
|
||||
}
|
||||
if sysTarget.ExecutorUsesForkServer {
|
||||
c.Flags |= ipc.FlagUseForkServer
|
||||
}
|
||||
|
||||
c.UseShmem = sysTarget.ExecutorUsesShmem
|
||||
c.UseForkServer = sysTarget.ExecutorUsesForkServer
|
||||
opts := &ipc.ExecOpts{
|
||||
Flags: ipc.FlagDedupCover,
|
||||
}
|
||||
|
@ -352,12 +352,8 @@ func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bo
|
||||
sysTarget := targets.Get(p.Target.OS, p.Target.Arch)
|
||||
cfg := new(ipc.Config)
|
||||
opts := new(ipc.ExecOpts)
|
||||
if sysTarget.ExecutorUsesShmem {
|
||||
cfg.Flags |= ipc.FlagUseShmem
|
||||
}
|
||||
if sysTarget.ExecutorUsesForkServer {
|
||||
cfg.Flags |= ipc.FlagUseForkServer
|
||||
}
|
||||
cfg.UseShmem = sysTarget.ExecutorUsesShmem
|
||||
cfg.UseForkServer = sysTarget.ExecutorUsesForkServer
|
||||
sandboxFlags, err := ipc.SandboxToFlags(sandbox)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user