github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/syz-extract/freebsd.go (about) 1 // Copyright 2017 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package main 5 6 import ( 7 "fmt" 8 "os" 9 "path/filepath" 10 "strings" 11 12 "github.com/google/syzkaller/pkg/compiler" 13 ) 14 15 type freebsd struct{} 16 17 func (*freebsd) prepare(sourcedir string, build bool, arches []*Arch) error { 18 if !build { 19 return fmt.Errorf("freebsd requires -build flag") 20 } 21 return nil 22 } 23 24 func (*freebsd) prepareArch(arch *Arch) error { 25 archName := arch.target.Arch 26 // Use the the correct name for FreeBSD/i386 27 if archName == "386" { 28 archName = "i386" 29 } 30 31 if archName == "riscv64" { 32 archName = "riscv" 33 } 34 35 if err := os.Symlink(filepath.Join(arch.sourceDir, "sys", archName, "include"), 36 filepath.Join(arch.buildDir, "machine")); err != nil { 37 return fmt.Errorf("failed to create link: %w", err) 38 } 39 if err := os.Symlink(filepath.Join(arch.sourceDir, "sys", "x86", "include"), 40 filepath.Join(arch.buildDir, "x86")); err != nil { 41 return fmt.Errorf("failed to create link: %w", err) 42 } 43 return nil 44 } 45 46 func (*freebsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) { 47 args := []string{ 48 "-fmessage-length=0", 49 "-nostdinc", 50 "-DGENOFFSET", 51 "-D_KERNEL", 52 "-D__BSD_VISIBLE=1", 53 "-DCOMPAT_FREEBSD13", 54 "-DCOMPAT_FREEBSD14", 55 "-I", filepath.Join(arch.sourceDir, "sys"), 56 "-I", filepath.Join(arch.sourceDir, "sys", "sys"), 57 "-I", filepath.Join(arch.sourceDir, "sys", "contrib", "ck", "include"), 58 "-I", filepath.Join(arch.sourceDir, "include"), 59 "-I", arch.buildDir, 60 } 61 for _, incdir := range info.Incdirs { 62 args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir)) 63 } 64 if arch.includeDirs != "" { 65 for _, dir := range strings.Split(arch.includeDirs, ",") { 66 args = append(args, "-I"+dir) 67 } 68 } 69 args = append(args, arch.target.CFlags...) 70 params := &extractParams{ 71 AddSource: "#include <sys/syscall.h>", 72 DeclarePrintf: true, 73 ExtractFromELF: true, 74 TargetEndian: arch.target.HostEndian, 75 } 76 cc := arch.target.CCompiler 77 return extract(info, cc, args, params) 78 }