From ebf7a37c5bba2cd3884e0e05beb99714fbf432e7 Mon Sep 17 00:00:00 2001 From: Siddharth M Date: Fri, 25 Jan 2019 22:46:51 +0530 Subject: pkg/build: add basic support for NetBSD * Add pkg/build support for NetBSD * Fix length of characters --- pkg/build/build.go | 2 ++ pkg/build/netbsd.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 pkg/build/netbsd.go (limited to 'pkg') 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 +} -- cgit mrf-deployment