From 85b1f93f8dbbc767c564e494a6353aa3517d5d49 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 16 Oct 2017 12:18:50 +0200 Subject: executor, pkg/ipc: unify ipc protocol between linux and other OSes We currently use more complex and functional protocol on linux, and a simple ad-hoc protocol on other OSes. This leads to code duplication in both ipc and executor. Linux supports coverage, shared memory communication and fork server, which would also be useful for most other OSes. Unify communication protocol and parametrize it by (1) use of shmem or only pipes, (2) use of fork server. This reduces duplication in ipc and executor and will allow to support the useful features for other OSes easily. Finally, this fixes akaros support as it currently uses syz-stress running on host (linux) and executor running on akaros. --- pkg/ipc/ipc_simple.go | 109 -------------------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 pkg/ipc/ipc_simple.go (limited to 'pkg/ipc/ipc_simple.go') diff --git a/pkg/ipc/ipc_simple.go b/pkg/ipc/ipc_simple.go deleted file mode 100644 index 50dcce661..000000000 --- a/pkg/ipc/ipc_simple.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2017 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. - -// +build freebsd fuchsia windows - -package ipc - -import ( - "bytes" - "encoding/binary" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "sync/atomic" - "time" - - "github.com/google/syzkaller/pkg/osutil" - "github.com/google/syzkaller/prog" -) - -type Env struct { - bin []string - pid int - config Config - - StatExecs uint64 - StatRestarts uint64 -} - -func MakeEnv(bin string, pid int, config Config) (*Env, error) { - if config.Timeout < 7*time.Second { - config.Timeout = 7 * time.Second - } - env := &Env{ - bin: strings.Split(bin, " "), - pid: pid, - config: config, - } - if len(env.bin) == 0 { - return nil, fmt.Errorf("binary is empty string") - } - env.bin[0] = osutil.Abs(env.bin[0]) - base := filepath.Base(env.bin[0]) - pidStr := fmt.Sprint(pid) - if len(base)+len(pidStr) >= 16 { - // TASK_COMM_LEN is currently set to 16 - base = base[:15-len(pidStr)] - } - binCopy := filepath.Join(filepath.Dir(env.bin[0]), base+pidStr) - if err := os.Link(env.bin[0], binCopy); err == nil { - env.bin[0] = binCopy - } - return env, nil -} - -func (env *Env) Close() error { - return nil -} - -func (env *Env) Exec(opts *ExecOpts, p *prog.Prog) (output []byte, info []CallInfo, failed, hanged bool, err0 error) { - atomic.AddUint64(&env.StatExecs, 1) - dir, err := ioutil.TempDir("./", "syzkaller-testdir") - if err != nil { - err0 = fmt.Errorf("failed to create temp dir: %v", err) - return - } - defer os.RemoveAll(dir) - - data := make([]byte, prog.ExecBufferSize) - n, err := p.SerializeForExec(data, env.pid) - if err != nil { - err0 = err - return - } - inbuf := new(bytes.Buffer) - binary.Write(inbuf, binary.LittleEndian, uint64(env.config.Flags)) - binary.Write(inbuf, binary.LittleEndian, uint64(opts.Flags)) - binary.Write(inbuf, binary.LittleEndian, uint64(env.pid)) - inbuf.Write(data[:n]) - - cmd := exec.Command(env.bin[0], env.bin[1:]...) - cmd.Env = []string{} - cmd.Dir = dir - cmd.Stdin = inbuf - if env.config.Flags&FlagDebug != 0 { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stdout - } - if err := cmd.Start(); err != nil { - err0 = fmt.Errorf("failed to start %d/%+v: %v", dir, env.bin, err) - return - } - done := make(chan error) - go func() { - done <- cmd.Wait() - }() - t := time.NewTimer(env.config.Timeout) - select { - case <-done: - t.Stop() - case <-t.C: - cmd.Process.Kill() - <-done - } - return -} -- cgit mrf-deployment