github.com/jxskiss/gopkg@v0.17.3/internal/linkname/runtime.go (about) 1 package linkname 2 3 import "unsafe" 4 5 import _ "runtime" 6 7 // Runtime_memclrNoHeapPointers clears n bytes starting at ptr. 8 // 9 // Usually you should use typedmemclr. Runtime_memclrNoHeapPointers should be 10 // used only when the caller knows that *ptr contains no heap pointers 11 // because either: 12 // 13 // *ptr is initialized memory and its type is pointer-free, or 14 // 15 // *ptr is uninitialized memory (e.g., memory that's being reused 16 // for a new allocation) and hence contains only "junk". 17 // 18 // Runtime_memclrNoHeapPointers ensures that if ptr is pointer-aligned, and n 19 // is a multiple of the pointer size, then any pointer-aligned, 20 // pointer-sized portion is cleared atomically. Despite the function 21 // name, this is necessary because this function is the underlying 22 // implementation of typedmemclr and memclrHasPointers. See the doc of 23 // memmove for more details. 24 // 25 // The (CPU-specific) implementations of this function are in memclr_*.s. 26 // 27 //go:noescape 28 //go:linkname Runtime_memclrNoHeapPointers runtime.memclrNoHeapPointers 29 func Runtime_memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) 30 31 //go:noescape 32 //go:linkname Runtime_fastrand runtime.fastrand 33 func Runtime_fastrand() uint32 34 35 //go:noescape 36 //go:linkname Runtime_fastrandn runtime.fastrandn 37 func Runtime_fastrandn(n uint32) uint32 38 39 // Runtime_procPin links to runtime.procPin. 40 // It pins current p, return pid. 41 // 42 // DON'T USE THIS if you don't know what it is. 43 //go:noescape 44 //go:linkname Runtime_procPin runtime.procPin 45 func Runtime_procPin() int 46 47 // Runtime_procUnpin links to runtime.procUnpin. 48 // It unpins current p. 49 // 50 //go:noescape 51 //go:linkname Runtime_procUnpin runtime.procUnpin 52 func Runtime_procUnpin() 53 54 // GetPid returns the id of current p. 55 func GetPid() int { 56 pid := Runtime_procPin() 57 Runtime_procUnpin() 58 return pid 59 } 60 61 // Runtime_stopTheWorld links to runtime.stopTheWorld. 62 // It stops all P's from executing goroutines, interrupting all goroutines 63 // at GC safe points and records reason as the reason for the stop. 64 // On return, only the current goroutine's P is running. 65 // 66 //go:linkname Runtime_stopTheWorld runtime.stopTheWorld 67 func Runtime_stopTheWorld() 68 69 //go:linkname Runtime_startTheWorld runtime.startTheWorld 70 func Runtime_startTheWorld() 71 72 //go:linkname Runtime_memhash8 runtime.memhash8 73 func Runtime_memhash8(p unsafe.Pointer, h uintptr) uintptr 74 75 //go:linkname Runtime_memhash16 runtime.memhash16 76 func Runtime_memhash16(p unsafe.Pointer, h uintptr) uintptr 77 78 //go:linkname Runtime_stringHash runtime.stringHash 79 func Runtime_stringHash(s string, seed uintptr) uintptr 80 81 //go:linkname Runtime_bytesHash runtime.bytesHash 82 func Runtime_bytesHash(b []byte, seed uintptr) uintptr 83 84 //go:linkname Runtime_int32Hash runtime.int32Hash 85 func Runtime_int32Hash(i uint32, seed uintptr) uintptr 86 87 //go:linkname Runtime_int64Hash runtime.int64Hash 88 func Runtime_int64Hash(i uint64, seed uintptr) uintptr 89 90 //go:linkname Runtime_f32hash runtime.f32hash 91 func Runtime_f32hash(p unsafe.Pointer, h uintptr) uintptr 92 93 //go:linkname Runtime_f64hash runtime.f64hash 94 func Runtime_f64hash(p unsafe.Pointer, h uintptr) uintptr 95 96 //go:linkname Runtime_c64hash runtime.c64hash 97 func Runtime_c64hash(p unsafe.Pointer, h uintptr) uintptr 98 99 //go:linkname Runtime_c128hash runtime.c128hash 100 func Runtime_c128hash(p unsafe.Pointer, h uintptr) uintptr 101 102 //go:linkname Runtime_efaceHash runtime.efaceHash 103 func Runtime_efaceHash(i interface{}, seed uintptr) uintptr 104 105 //go:linkname Runtime_typehash runtime.typehash 106 func Runtime_typehash(rtype unsafe.Pointer, p unsafe.Pointer, h uintptr) uintptr 107 108 //go:linkname Runtime_activeModules runtime.activeModules 109 func Runtime_activeModules() []unsafe.Pointer 110 111 //go:linkname sysBigEndian internal.sys.BigEndian 112 var sysBigEndian bool 113 114 // Runtime_readUnaligned32 reads memory pointed by p as a uint32 value. 115 // It performs the read with a native endianness. 116 // 117 // It is copied from runtime.readUnaligned32 instead of linked to help 118 // inlining. 119 func Runtime_readUnaligned32(p unsafe.Pointer) uint32 { 120 q := (*[4]byte)(p) 121 if sysBigEndian { 122 return uint32(q[3]) | uint32(q[2])<<8 | uint32(q[1])<<16 | uint32(q[0])<<24 123 } 124 return uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24 125 } 126 127 // Runtime_readUnaligned64 reads memory pointed by p as a uint64 value. 128 // It performs the read with a native endianness. 129 // 130 // It is copied from runtime.readUnaligned64 but instead of linked to 131 // help inlining. 132 func Runtime_readUnaligned64(p unsafe.Pointer) uint64 { 133 q := (*[8]byte)(p) 134 if sysBigEndian { 135 return uint64(q[7]) | uint64(q[6])<<8 | uint64(q[5])<<16 | uint64(q[4])<<24 | 136 uint64(q[3])<<32 | uint64(q[2])<<40 | uint64(q[1])<<48 | uint64(q[0])<<56 137 } 138 return uint64(q[0]) | uint64(q[1])<<8 | uint64(q[2])<<16 | uint64(q[3])<<24 | 139 uint64(q[4])<<32 | uint64(q[5])<<40 | uint64(q[6])<<48 | uint64(q[7])<<56 140 }