github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/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/sys/targets"
    10  )
    11  
    12  type Impl struct {
    13  	Units           []*CompileUnit
    14  	Symbols         []*Symbol
    15  	Frames          []Frame
    16  	Symbolize       func(pcs map[*Module][]uint64) ([]Frame, error)
    17  	RestorePC       func(pc uint32) uint64
    18  	CallbackPoints  []uint64
    19  	PreciseCoverage bool
    20  }
    21  
    22  type Module struct {
    23  	Name string
    24  	Path string
    25  	Addr uint64
    26  }
    27  
    28  type CompileUnit struct {
    29  	ObjectUnit
    30  	Path   string
    31  	Module *Module
    32  }
    33  
    34  type Symbol struct {
    35  	ObjectUnit
    36  	Module     *Module
    37  	Unit       *CompileUnit
    38  	Start      uint64
    39  	End        uint64
    40  	Symbolized bool
    41  }
    42  
    43  // ObjectUnit represents either CompileUnit or Symbol.
    44  type ObjectUnit struct {
    45  	Name string
    46  	PCs  []uint64 // PCs we can get in coverage callbacks for this unit.
    47  	CMPs []uint64 // PCs we can get in comparison interception callbacks for this unit.
    48  }
    49  
    50  type Frame struct {
    51  	Module   *Module
    52  	PC       uint64
    53  	Name     string
    54  	FuncName string
    55  	Path     string
    56  	Inline   bool
    57  	Range
    58  }
    59  
    60  type Range struct {
    61  	StartLine int
    62  	StartCol  int
    63  	EndLine   int
    64  	EndCol    int
    65  }
    66  
    67  const LineEnd = 1 << 30
    68  
    69  func Make(target *targets.Target, vm, objDir, srcDir, buildDir string, splitBuild bool,
    70  	moduleObj []string, modules []KernelModule) (*Impl, error) {
    71  	if objDir == "" {
    72  		return nil, fmt.Errorf("kernel obj directory is not specified")
    73  	}
    74  	if target.OS == "darwin" {
    75  		return makeMachO(target, objDir, srcDir, buildDir, moduleObj, modules)
    76  	}
    77  	if vm == "gvisor" {
    78  		return makeGvisor(target, objDir, srcDir, buildDir, modules)
    79  	}
    80  	var delimiters []string
    81  	if splitBuild {
    82  		// Path prefixes used by Android Pixel kernels. See
    83  		// https://source.android.com/docs/setup/build/building-pixel-kernels for more
    84  		// details.
    85  		delimiters = []string{"/aosp/", "/private/"}
    86  	}
    87  	return makeELF(target, objDir, srcDir, buildDir, delimiters, moduleObj, modules)
    88  }