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