diff options
| author | Siddharth M <siddharth.muralee@gmail.com> | 2019-01-25 22:46:51 +0530 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-01-25 18:16:51 +0100 |
| commit | ebf7a37c5bba2cd3884e0e05beb99714fbf432e7 (patch) | |
| tree | 33944cd324576c9f28cc5a80424cfe0289218b7a /pkg/build | |
| parent | a3d9f7e34dbad7e7c6804ee5107c3ddcf0bfef22 (diff) | |
pkg/build: add basic support for NetBSD
* Add pkg/build support for NetBSD
* Fix length of characters
Diffstat (limited to 'pkg/build')
| -rw-r--r-- | pkg/build/build.go | 2 | ||||
| -rw-r--r-- | pkg/build/netbsd.go | 68 |
2 files changed, 70 insertions, 0 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go index 3e9e73912..b7fdb1664 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -73,6 +73,8 @@ func getBuilder(targetOS, targetArch, vmType string) (builder, error) { return akaros{}, nil case targetOS == "openbsd" && targetArch == "amd64" && (vmType == "gce" || vmType == "vmm"): return openbsd{}, nil + case targetOS == "netbsd" && targetArch == "amd64" && vmType == "qemu": + return netbsd{}, nil default: return nil, fmt.Errorf("unsupported image type %v/%v/%v", targetOS, targetArch, vmType) } diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go new file mode 100644 index 000000000..2665d6415 --- /dev/null +++ b/pkg/build/netbsd.go @@ -0,0 +1,68 @@ +// 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 build + +import ( + "fmt" + "path/filepath" + "runtime" + "strconv" + "time" + + "github.com/google/syzkaller/pkg/osutil" +) + +type netbsd struct{} + +func (ctx netbsd) build(targetArch, vmType, kernelDir, outputDir, compiler, userspaceDir, + cmdlineFile, sysctlFile string, config []byte) error { + const kernelName = "GENERIC_SYZKALLER" + confDir := fmt.Sprintf("%v/sys/arch/%v/conf", kernelDir, targetArch) + compileDir := fmt.Sprintf("%v/sys/arch/%v/compile/obj/%v", kernelDir, targetArch, kernelName) + + // Compile the kernel with KASAN + conf := []byte(` +include "arch/amd64/conf/GENERIC" + +makeoptions KASAN=1 +options KASAN +no options SVS +`) + + if err := osutil.WriteFile(filepath.Join(confDir, kernelName), conf); err != nil { + return err + } + + // Build tools before building kernel + if _, err := osutil.RunCmd(10*time.Minute, kernelDir, "./build.sh", "-m", targetArch, + "-U", "-j"+strconv.Itoa(runtime.NumCPU()), "tools"); err != nil { + return err + } + + // Build kernel + if _, err := osutil.RunCmd(10*time.Minute, kernelDir, "./build.sh", "-m", targetArch, + "-U", "-j"+strconv.Itoa(runtime.NumCPU()), "kernel="+kernelName); err != nil { + return err + } + + for _, s := range []struct{ dir, src, dst string }{ + {compileDir, "netbsd", "kernel"}, + {compileDir, "netbsd.gdb", "netbsd.gdb"}, + } { + fullSrc := filepath.Join(s.dir, s.src) + fullDst := filepath.Join(outputDir, s.dst) + if err := osutil.CopyFile(fullSrc, fullDst); err != nil { + return fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err) + } + } + return nil +} + +func (ctx netbsd) clean(kernelDir string) error { + // Building clean is fast enough and incremental builds in face of + // changing config files don't work. Instead of optimizing for the + // case where humans have to think, let's bludgeon it with a + // machine. + return nil +} |
