github.com/searKing/golang/go@v1.2.117/runtime/runtime.go (about)

     1  // Copyright 2020 The searKing Author. 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 runtime
     6  
     7  import (
     8  	_ "runtime"
     9  	"unsafe"
    10  
    11  	"github.com/searKing/golang/go/reflect"
    12  )
    13  
    14  // GetEIP returns the location, that is EIP after CALL
    15  //
    16  //go:linkname GetEIP github.com/searKing/golang/go/runtime.getEIP
    17  //go:nosplit
    18  //go:noinline
    19  func GetEIP(uintptr) uintptr
    20  
    21  // getEIP returns the location, that is EIP after CALL
    22  // -> arg+argsize-1(FP)
    23  // arg includes returns and arguments
    24  // call frame stack <-> argsize+tmpsize+framesize
    25  // tmp is for EIP AND EBP
    26  //
    27  //go:nosplit
    28  //go:noinline
    29  func getEIP(x uintptr) uintptr {
    30  	// x is an argument mainly so that we can return its address.
    31  	// plus reflect.PtrSize *2 for shrink call frame to zero, that is EIP
    32  	// ATTENTION NO BSP ON STACK FOR NO SUB FUNC CALL IN THIS FUNCTION, so plus 1: EIP,VAR
    33  	return uintptr(noescape(unsafe.Pointer(&x))) + reflect.PtrSize + x
    34  }
    35  
    36  // noescape hides a pointer from escape analysis. It is the identity function
    37  // but escape analysis doesn't think the output depends on the input.
    38  // noescape is inlined and currently compiles down to zero instructions.
    39  // USE CAREFULLY!
    40  // This was copied from the runtime; see issues 23382 and 7921.
    41  //
    42  //go:nosplit
    43  //go:nocheckptr
    44  func noescape(p unsafe.Pointer) unsafe.Pointer {
    45  	x := uintptr(p)
    46  	return unsafe.Pointer(x ^ 0)
    47  }