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

     1  //go:build go1.10 && !go1.16
     2  // +build go1.10,!go1.16
     3  
     4  package goloader
     5  
     6  const magic uint32 = 0xFFFFFFFB
     7  
     8  // pcHeader holds data used by the pclntab lookups.
     9  type pcHeader struct {
    10  	magic      uint32 // 0xFFFFFFFB
    11  	pad1, pad2 uint8  // 0,0
    12  	minLC      uint8  // min instruction size
    13  	ptrSize    uint8  // size of a ptr in bytes
    14  }
    15  
    16  // moduledata records information about the layout of the executable
    17  // image. It is written by the linker. Any changes here must be
    18  // matched changes to the code in cmd/internal/ld/symtab.go:symtab.
    19  // moduledata is stored in read-only memory; none of the pointers here
    20  // are visible to the garbage collector.
    21  type moduledata struct {
    22  	pclntable    []byte
    23  	ftab         []functab
    24  	filetab      []uint32
    25  	findfunctab  uintptr
    26  	minpc, maxpc uintptr
    27  
    28  	text, etext           uintptr
    29  	noptrdata, enoptrdata uintptr
    30  	data, edata           uintptr
    31  	bss, ebss             uintptr
    32  	noptrbss, enoptrbss   uintptr
    33  	end, gcdata, gcbss    uintptr
    34  	types, etypes         uintptr
    35  
    36  	textsectmap []textsect
    37  	typelinks   []int32 // offsets from types
    38  	itablinks   []*itab
    39  
    40  	ptab []ptabEntry
    41  
    42  	pluginpath string
    43  	pkghashes  []modulehash
    44  
    45  	modulename   string
    46  	modulehashes []modulehash
    47  
    48  	hasmain uint8 // 1 if module contains the main function, 0 otherwise
    49  
    50  	gcdatamask, gcbssmask bitvector
    51  
    52  	typemap map[typeOff]uintptr // offset to *_rtype in previous module
    53  
    54  	bad bool // module failed to load and should be ignored
    55  
    56  	next *moduledata
    57  }
    58  
    59  func initmodule(module *moduledata, linker *Linker) {
    60  	module.filetab = linker.Filetab
    61  	module.hasmain = 0
    62  	module.bad = false
    63  }