github.com/gernest/nezuko@v0.1.2/internal/objabi/funcid.go (about)

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package objabi
     6  
     7  import (
     8  	"strconv"
     9  	"strings"
    10  )
    11  
    12  // A FuncID identifies particular functions that need to be treated
    13  // specially by the runtime.
    14  // Note that in some situations involving plugins, there may be multiple
    15  // copies of a particular special runtime function.
    16  // Note: this list must match the list in runtime/symtab.go.
    17  type FuncID uint8
    18  
    19  const (
    20  	FuncID_normal FuncID = iota // not a special function
    21  	FuncID_runtime_main
    22  	FuncID_goexit
    23  	FuncID_jmpdefer
    24  	FuncID_mcall
    25  	FuncID_morestack
    26  	FuncID_mstart
    27  	FuncID_rt0_go
    28  	FuncID_asmcgocall
    29  	FuncID_sigpanic
    30  	FuncID_runfinq
    31  	FuncID_gcBgMarkWorker
    32  	FuncID_systemstack_switch
    33  	FuncID_systemstack
    34  	FuncID_cgocallback_gofunc
    35  	FuncID_gogo
    36  	FuncID_externalthreadhandler
    37  	FuncID_debugCallV1
    38  	FuncID_gopanic
    39  	FuncID_panicwrap
    40  	FuncID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
    41  )
    42  
    43  // Get the function ID for the named function in the named file.
    44  // The function should be package-qualified.
    45  func GetFuncID(name, file string) FuncID {
    46  	switch name {
    47  	case "runtime.main":
    48  		return FuncID_runtime_main
    49  	case "runtime.goexit":
    50  		return FuncID_goexit
    51  	case "runtime.jmpdefer":
    52  		return FuncID_jmpdefer
    53  	case "runtime.mcall":
    54  		return FuncID_mcall
    55  	case "runtime.morestack":
    56  		return FuncID_morestack
    57  	case "runtime.mstart":
    58  		return FuncID_mstart
    59  	case "runtime.rt0_go":
    60  		return FuncID_rt0_go
    61  	case "runtime.asmcgocall":
    62  		return FuncID_asmcgocall
    63  	case "runtime.sigpanic":
    64  		return FuncID_sigpanic
    65  	case "runtime.runfinq":
    66  		return FuncID_runfinq
    67  	case "runtime.gcBgMarkWorker":
    68  		return FuncID_gcBgMarkWorker
    69  	case "runtime.systemstack_switch":
    70  		return FuncID_systemstack_switch
    71  	case "runtime.systemstack":
    72  		return FuncID_systemstack
    73  	case "runtime.cgocallback_gofunc":
    74  		return FuncID_cgocallback_gofunc
    75  	case "runtime.gogo":
    76  		return FuncID_gogo
    77  	case "runtime.externalthreadhandler":
    78  		return FuncID_externalthreadhandler
    79  	case "runtime.debugCallV1":
    80  		return FuncID_debugCallV1
    81  	case "runtime.gopanic":
    82  		return FuncID_gopanic
    83  	case "runtime.panicwrap":
    84  		return FuncID_panicwrap
    85  	}
    86  	if file == "<autogenerated>" {
    87  		return FuncID_wrapper
    88  	}
    89  	if strings.HasPrefix(name, "runtime.call") {
    90  		if _, err := strconv.Atoi(name[12:]); err == nil {
    91  			// runtime.callXX reflect call wrappers.
    92  			return FuncID_wrapper
    93  		}
    94  	}
    95  	if strings.HasSuffix(name, "-fm") {
    96  		return FuncID_wrapper
    97  	}
    98  	return FuncID_normal
    99  }