github.com/Rookout/GoSDK@v0.1.48/pkg/services/instrumentation/hooker/prologue/morestack.go (about)

     1  package prologue
     2  
     3  import (
     4  	_ "unsafe"
     5  
     6  	"github.com/Rookout/GoSDK/pkg/logger"
     7  	"github.com/Rookout/GoSDK/pkg/rookoutErrors"
     8  	"github.com/Rookout/GoSDK/pkg/services/instrumentation/binary_info"
     9  )
    10  
    11  var morestackAddrs = make(map[uintptr]struct{})
    12  var morestackAddr uintptr
    13  
    14  //go:linkname morestack runtime.morestack
    15  func morestack()
    16  
    17  //go:linkname morestack_noctxt runtime.morestack_noctxt
    18  func morestack_noctxt()
    19  
    20  func addMorestackFunc(binaryInfo *binary_info.BinaryInfo, morestack func()) {
    21  	addr, err := binaryInfo.GetUnwrappedFuncPointer(morestack)
    22  	if err != nil {
    23  		logger.Logger().Warningf("Error while trying to get unwrapped morestack pointer: %v", err)
    24  		return
    25  	}
    26  
    27  	morestackAddrs[addr] = struct{}{}
    28  }
    29  
    30  func Init(binaryInfo *binary_info.BinaryInfo) rookoutErrors.RookoutError {
    31  	var err rookoutErrors.RookoutError
    32  	morestackAddr, err = binaryInfo.GetUnwrappedFuncPointer(morestack)
    33  	if err != nil {
    34  		return err
    35  	}
    36  	addMorestackFunc(binaryInfo, morestack)
    37  	addMorestackFunc(binaryInfo, morestack_noctxt)
    38  	return nil
    39  }