2015-10-12 08:16:57 +00:00
|
|
|
// 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 vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-11-20 18:58:27 +00:00
|
|
|
"regexp"
|
2015-10-12 08:16:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Instance interface {
|
|
|
|
Run()
|
|
|
|
}
|
|
|
|
|
2015-10-19 10:47:37 +00:00
|
|
|
type Config struct {
|
2015-10-19 10:53:24 +00:00
|
|
|
Workdir string
|
|
|
|
ManagerPort int
|
|
|
|
Params []byte
|
|
|
|
EnabledSyscalls string
|
2015-11-20 18:58:27 +00:00
|
|
|
Suppressions []*regexp.Regexp
|
2015-10-19 12:00:20 +00:00
|
|
|
NoCover bool
|
2015-12-16 18:17:25 +00:00
|
|
|
NoDropPrivs bool
|
2015-12-03 19:38:33 +00:00
|
|
|
Leak bool
|
2015-11-26 14:56:18 +00:00
|
|
|
Procs int
|
2015-10-19 10:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ctorFunc func(cfg *Config, index int) (Instance, error)
|
2015-10-12 08:16:57 +00:00
|
|
|
|
|
|
|
var ctors = make(map[string]ctorFunc)
|
|
|
|
|
|
|
|
func Register(typ string, ctor ctorFunc) {
|
|
|
|
ctors[typ] = ctor
|
|
|
|
}
|
|
|
|
|
2015-10-19 10:47:37 +00:00
|
|
|
func Create(typ string, cfg *Config, index int) (Instance, error) {
|
2015-10-12 08:16:57 +00:00
|
|
|
ctor := ctors[typ]
|
|
|
|
if ctor == nil {
|
|
|
|
return nil, fmt.Errorf("unknown instance type '%v'", typ)
|
|
|
|
}
|
2015-10-19 10:47:37 +00:00
|
|
|
return ctor(cfg, index)
|
2015-10-12 08:16:57 +00:00
|
|
|
}
|