github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/func.1.16.go (about)

     1  //go:build go1.16 && !go1.18
     2  // +build go1.16,!go1.18
     3  
     4  package goloader
     5  
     6  import "github.com/pkujhd/goloader/obj"
     7  
     8  // A funcID identifies particular functions that need to be treated
     9  // specially by the runtime.
    10  // Note that in some situations involving plugins, there may be multiple
    11  // copies of a particular special runtime function.
    12  // Note: this list must match the list in cmd/internal/objabi/funcid.go.
    13  type funcID uint8
    14  
    15  // Layout of in-memory per-function information prepared by linker
    16  // See https://golang.org/s/go12symtab.
    17  // Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab)
    18  // and with package debug/gosym and with symtab.go in package runtime.
    19  type _func struct {
    20  	Entry   uintptr // start pc
    21  	Nameoff int32   // function name
    22  
    23  	Args        int32  // in/out args size
    24  	Deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any.
    25  
    26  	Pcsp      uint32
    27  	Pcfile    uint32
    28  	Pcln      uint32
    29  	Npcdata   uint32
    30  	CuOffset  uint32  // runtime.cutab offset of this function's CU
    31  	FuncID    funcID  // set for certain special runtime functions
    32  	_         [2]byte // pad
    33  	Nfuncdata uint8   // must be last
    34  }
    35  
    36  func initfunc(symbol *obj.ObjSymbol, nameOff, pcspOff, pcfileOff, pclnOff, cuOff int) _func {
    37  	fdata := _func{
    38  		Entry:       uintptr(0),
    39  		Nameoff:     int32(nameOff),
    40  		Args:        int32(symbol.Func.Args),
    41  		Deferreturn: uint32(0),
    42  		Pcsp:        uint32(pcspOff),
    43  		Pcfile:      uint32(pcfileOff),
    44  		Pcln:        uint32(pclnOff),
    45  		Npcdata:     uint32(len(symbol.Func.PCData)),
    46  		CuOffset:    uint32(cuOff),
    47  		FuncID:      funcID(symbol.Func.FuncID),
    48  		Nfuncdata:   uint8(len(symbol.Func.FuncData)),
    49  	}
    50  	return fdata
    51  }
    52  
    53  func setfuncentry(f *_func, entry uintptr, text uintptr) {
    54  	f.Entry = entry
    55  }
    56  
    57  func getfuncentry(f *_func, text uintptr) uintptr {
    58  	return f.Entry
    59  }
    60  
    61  func getfuncname(f *_func, md *moduledata) string {
    62  	if f.Nameoff <= 0 || f.Nameoff >= int32(len(md.funcnametab)) {
    63  		return EmptyString
    64  	}
    65  	return gostringnocopy(&(md.funcnametab[f.Nameoff]))
    66  }
    67  
    68  func getfuncID(f *_func) uint8 {
    69  	return uint8(f.FuncID)
    70  }
    71  
    72  func adaptePCFile(linker *Linker, symbol *obj.ObjSymbol) {
    73  }