github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/syz-extract/darwin.go (about)

     1  // Copyright 2021 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  	"path/filepath"
     9  	"strings"
    10  
    11  	"github.com/google/syzkaller/pkg/compiler"
    12  )
    13  
    14  type darwin struct{}
    15  
    16  func (*darwin) prepare(sourcedir string, build bool, arches []*Arch) error {
    17  	return nil
    18  }
    19  
    20  func (*darwin) prepareArch(arch *Arch) error {
    21  	return nil
    22  }
    23  
    24  func (*darwin) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
    25  	args := []string{
    26  		"-nostdinc",
    27  		"-DPRIVATE",
    28  		"-DPF",
    29  		"-I", filepath.Join(arch.sourceDir, "bsd"),
    30  		"-I", filepath.Join(arch.sourceDir, "bsd", "sys"),
    31  		"-I", filepath.Join(arch.sourceDir, "osfmk"),
    32  	}
    33  	for _, incdir := range info.Incdirs {
    34  		args = append(args, "-I"+filepath.Join(arch.sourceDir, incdir))
    35  	}
    36  	fmt.Printf("dirs: %v", arch.includeDirs)
    37  	if arch.includeDirs != "" {
    38  		for _, dir := range strings.Split(arch.includeDirs, ",") {
    39  			args = append(args, "-I"+dir)
    40  		}
    41  	}
    42  	// TODO(HerrSpace): investigate use of bsd/kern/syscalls.master and
    43  	// osfmk/mach/mach_traps.h here.
    44  	params := &extractParams{
    45  		AddSource:     "#include <sys/syscall.h>",
    46  		DeclarePrintf: true,
    47  		TargetEndian:  arch.target.HostEndian,
    48  	}
    49  	return extract(info, "clang", args, params)
    50  }