github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/cover/backend/backend.go (about)

     1  // Copyright 2020 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 backend
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/google/syzkaller/pkg/mgrconfig"
    10  	"github.com/google/syzkaller/pkg/vminfo"
    11  	"github.com/google/syzkaller/sys/targets"
    12  )
    13  
    14  type Impl struct {
    15  	Units           []*CompileUnit
    16  	Symbols         []*Symbol
    17  	Frames          []*Frame
    18  	Symbolize       func(pcs map[*vminfo.KernelModule][]uint64) ([]*Frame, error)
    19  	CallbackPoints  []uint64
    20  	PreciseCoverage bool
    21  }
    22  
    23  type CompileUnit struct {
    24  	ObjectUnit
    25  	Path   string
    26  	Module *vminfo.KernelModule
    27  }
    28  
    29  type Symbol struct {
    30  	ObjectUnit
    31  	Module     *vminfo.KernelModule
    32  	Unit       *CompileUnit
    33  	Start      uint64
    34  	End        uint64
    35  	Symbolized bool
    36  }
    37  
    38  // ObjectUnit represents either CompileUnit or Symbol.
    39  type ObjectUnit struct {
    40  	Name string
    41  	PCs  []uint64 // PCs we can get in coverage callbacks for this unit.
    42  	CMPs []uint64 // PCs we can get in comparison interception callbacks for this unit.
    43  }
    44  
    45  type Frame struct {
    46  	Module   *vminfo.KernelModule
    47  	PC       uint64
    48  	Name     string
    49  	FuncName string
    50  	Path     string
    51  	Inline   bool
    52  	Range
    53  }
    54  
    55  type Range struct {
    56  	StartLine int
    57  	StartCol  int
    58  	EndLine   int
    59  	EndCol    int
    60  }
    61  
    62  type SecRange struct {
    63  	Start uint64
    64  	End   uint64
    65  }
    66  
    67  const LineEnd = 1 << 30
    68  
    69  func Make(cfg *mgrconfig.Config, modules []*vminfo.KernelModule) (*Impl, error) {
    70  	kernelDirs := cfg.KernelDirs()
    71  	target := cfg.SysTarget
    72  	moduleObj := cfg.ModuleObj
    73  	vm := cfg.Type
    74  	if kernelDirs.Obj == "" {
    75  		return nil, fmt.Errorf("kernel obj directory is not specified")
    76  	}
    77  	if target.OS == targets.Darwin {
    78  		return makeMachO(target, kernelDirs, moduleObj, modules)
    79  	}
    80  	if vm == targets.GVisor {
    81  		return makeGvisor(target, kernelDirs, modules)
    82  	}
    83  	var delimiters []string
    84  	if cfg.AndroidSplitBuild {
    85  		// Path prefixes used by Android Pixel kernels. See
    86  		// https://source.android.com/docs/setup/build/building-pixel-kernels for more
    87  		// details.
    88  		delimiters = []string{"/aosp/", "/private/"}
    89  	}
    90  	return makeELF(target, kernelDirs, delimiters, moduleObj, modules)
    91  }
    92  
    93  func GetPCBase(cfg *mgrconfig.Config) (uint64, error) {
    94  	if cfg.Target.OS == targets.Linux && cfg.Type != targets.GVisor && cfg.Type != targets.Starnix {
    95  		return getLinuxPCBase(cfg)
    96  	}
    97  	return 0, nil
    98  }