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

     1  //go:build go1.8 && !go1.18
     2  // +build go1.8,!go1.18
     3  
     4  package goloader
     5  
     6  import (
     7  	"unsafe"
     8  
     9  	"github.com/pkujhd/goloader/obj"
    10  )
    11  
    12  type functab struct {
    13  	entry   uintptr
    14  	funcoff uintptr
    15  }
    16  
    17  func initfunctab(entry, funcoff, text uintptr) functab {
    18  	functabdata := functab{
    19  		entry:   uintptr(entry),
    20  		funcoff: uintptr(funcoff),
    21  	}
    22  	return functabdata
    23  }
    24  
    25  func addfuncdata(module *moduledata, Func *obj.Func, _func *_func) {
    26  	funcdata := make([]uintptr, 0)
    27  	for _, v := range Func.FuncData {
    28  		if v != 0 {
    29  			funcdata = append(funcdata, v+module.noptrdata)
    30  		} else {
    31  			funcdata = append(funcdata, v)
    32  		}
    33  	}
    34  	grow(&module.pclntable, alignof(len(module.pclntable), PtrSize))
    35  	append2Slice(&module.pclntable, uintptr(unsafe.Pointer(&funcdata[0])), PtrSize*int(_func.Nfuncdata))
    36  }