]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/stubs.go
[dev.cc] all: merge default (e4ab8f908aac) into dev.cc
[gostls13.git] / src / runtime / stubs.go
1 // Copyright 2014 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 runtime
6
7 import "unsafe"
8
9 // Declarations for runtime services implemented in C or assembly.
10
11 const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const
12 const regSize = 4 << (^uintreg(0) >> 63) // unsafe.Sizeof(uintreg(0)) but an ideal const
13
14 // Should be a built-in for unsafe.Pointer?
15 //go:nosplit
16 func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
17         return unsafe.Pointer(uintptr(p) + x)
18 }
19
20 // n must be a power of 2
21 func roundup(p unsafe.Pointer, n uintptr) unsafe.Pointer {
22         delta := -uintptr(p) & (n - 1)
23         return unsafe.Pointer(uintptr(p) + delta)
24 }
25
26 func getg() *g
27
28 // mcall switches from the g to the g0 stack and invokes fn(g),
29 // where g is the goroutine that made the call.
30 // mcall saves g's current PC/SP in g->sched so that it can be restored later.
31 // It is up to fn to arrange for that later execution, typically by recording
32 // g in a data structure, causing something to call ready(g) later.
33 // mcall returns to the original goroutine g later, when g has been rescheduled.
34 // fn must not return at all; typically it ends by calling schedule, to let the m
35 // run other goroutines.
36 //
37 // mcall can only be called from g stacks (not g0, not gsignal).
38 //go:noescape
39 func mcall(fn func(*g))
40
41 // systemstack runs fn on a system stack.
42 // If systemstack is called from the per-OS-thread (g0) stack, or
43 // if systemstack is called from the signal handling (gsignal) stack,
44 // systemstack calls fn directly and returns.
45 // Otherwise, systemstack is being called from the limited stack
46 // of an ordinary goroutine. In this case, systemstack switches
47 // to the per-OS-thread stack, calls fn, and switches back.
48 // It is common to use a func literal as the argument, in order
49 // to share inputs and outputs with the code around the call
50 // to system stack:
51 //
52 //      ... set up y ...
53 //      systemstack(func() {
54 //              x = bigcall(y)
55 //      })
56 //      ... use x ...
57 //
58 //go:noescape
59 func systemstack(fn func())
60
61 func badsystemstack() {
62         gothrow("systemstack called from unexpected goroutine")
63 }
64
65 // memclr clears n bytes starting at ptr.
66 // in memclr_*.s
67 //go:noescape
68 func memclr(ptr unsafe.Pointer, n uintptr)
69
70 // memmove copies n bytes from "from" to "to".
71 // in memmove_*.s
72 //go:noescape
73 func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr)
74
75 // exported value for testing
76 var hashLoad = loadFactor
77
78 // in asm_*.s
79 func fastrand1() uint32
80
81 // in asm_*.s
82 //go:noescape
83 func memeq(a, b unsafe.Pointer, size uintptr) bool
84
85 // noescape hides a pointer from escape analysis.  noescape is
86 // the identity function but escape analysis doesn't think the
87 // output depends on the input.  noescape is inlined and currently
88 // compiles down to a single xor instruction.
89 // USE CAREFULLY!
90 //go:nosplit
91 func noescape(p unsafe.Pointer) unsafe.Pointer {
92         x := uintptr(p)
93         return unsafe.Pointer(x ^ 0)
94 }
95
96 func cgocallback(fn, frame unsafe.Pointer, framesize uintptr)
97 func gogo(buf *gobuf)
98 func gosave(buf *gobuf)
99 func mincore(addr unsafe.Pointer, n uintptr, dst *byte) int32
100
101 //go:noescape
102 func jmpdefer(fv *funcval, argp uintptr)
103 func exit1(code int32)
104 func asminit()
105 func setg(gg *g)
106 func breakpoint()
107
108 func reflectcall(fn, arg unsafe.Pointer, n uint32, retoffset uint32)
109 func procyield(cycles uint32)
110 func cgocallback_gofunc(fv *funcval, frame unsafe.Pointer, framesize uintptr)
111 func goexit()
112
113 //go:noescape
114 func cas(ptr *uint32, old, new uint32) bool
115
116 // casp cannot have a go:noescape annotation, because
117 // while ptr and old do not escape, new does. If new is marked as
118 // not escaping, the compiler will make incorrect escape analysis
119 // decisions about the value being xchg'ed.
120 // Instead, make casp a wrapper around the actual atomic.
121 // When calling the wrapper we mark ptr as noescape explicitly.
122
123 //go:nosplit
124 func casp(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
125         return casp1((*unsafe.Pointer)(noescape(unsafe.Pointer(ptr))), noescape(old), new)
126 }
127
128 func casp1(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool
129
130 func nop() // call to prevent inlining of function body
131
132 //go:noescape
133 func casuintptr(ptr *uintptr, old, new uintptr) bool
134
135 //go:noescape
136 func atomicstoreuintptr(ptr *uintptr, new uintptr)
137
138 //go:noescape
139 func atomicloaduintptr(ptr *uintptr) uintptr
140
141 //go:noescape
142 func atomicloaduint(ptr *uint) uint
143
144 //go:noescape
145 func setcallerpc(argp unsafe.Pointer, pc uintptr)
146
147 // getcallerpc returns the program counter (PC) of its caller's caller.
148 // getcallersp returns the stack pointer (SP) of its caller's caller.
149 // For both, the argp must be a pointer to the caller's first function argument.
150 // The implementation may or may not use argp, depending on
151 // the architecture.
152 //
153 // For example:
154 //
155 //      func f(arg1, arg2, arg3 int) {
156 //              pc := getcallerpc(unsafe.Pointer(&arg1))
157 //              sp := getcallersp(unsafe.Pointer(&arg1))
158 //      }
159 //
160 // These two lines find the PC and SP immediately following
161 // the call to f (where f will return).
162 //
163 // The call to getcallerpc and getcallersp must be done in the
164 // frame being asked about. It would not be correct for f to pass &arg1
165 // to another function g and let g call getcallerpc/getcallersp.
166 // The call inside g might return information about g's caller or
167 // information about f's caller or complete garbage.
168 //
169 // The result of getcallersp is correct at the time of the return,
170 // but it may be invalidated by any subsequent call to a function
171 // that might relocate the stack in order to grow or shrink it.
172 // A general rule is that the result of getcallersp should be used
173 // immediately and can only be passed to nosplit functions.
174
175 //go:noescape
176 func getcallerpc(argp unsafe.Pointer) uintptr
177
178 //go:noescape
179 func getcallersp(argp unsafe.Pointer) uintptr
180
181 //go:noescape
182 func asmcgocall(fn, arg unsafe.Pointer)
183
184 //go:noescape
185 func asmcgocall_errno(fn, arg unsafe.Pointer) int32
186
187 // argp used in Defer structs when there is no argp.
188 const _NoArgs = ^uintptr(0)
189
190 func morestack()
191 func rt0_go()
192
193 // return0 is a stub used to return 0 from deferproc.
194 // It is called at the very end of deferproc to signal
195 // the calling Go function that it should not jump
196 // to deferreturn.
197 // in asm_*.s
198 func return0()
199
200 // thunk to call time.now.
201 func timenow() (sec int64, nsec int32)
202
203 // in asm_*.s
204 // not called directly; definitions here supply type information for traceback.
205 func call16(fn, arg unsafe.Pointer, n, retoffset uint32)
206 func call32(fn, arg unsafe.Pointer, n, retoffset uint32)
207 func call64(fn, arg unsafe.Pointer, n, retoffset uint32)
208 func call128(fn, arg unsafe.Pointer, n, retoffset uint32)
209 func call256(fn, arg unsafe.Pointer, n, retoffset uint32)
210 func call512(fn, arg unsafe.Pointer, n, retoffset uint32)
211 func call1024(fn, arg unsafe.Pointer, n, retoffset uint32)
212 func call2048(fn, arg unsafe.Pointer, n, retoffset uint32)
213 func call4096(fn, arg unsafe.Pointer, n, retoffset uint32)
214 func call8192(fn, arg unsafe.Pointer, n, retoffset uint32)
215 func call16384(fn, arg unsafe.Pointer, n, retoffset uint32)
216 func call32768(fn, arg unsafe.Pointer, n, retoffset uint32)
217 func call65536(fn, arg unsafe.Pointer, n, retoffset uint32)
218 func call131072(fn, arg unsafe.Pointer, n, retoffset uint32)
219 func call262144(fn, arg unsafe.Pointer, n, retoffset uint32)
220 func call524288(fn, arg unsafe.Pointer, n, retoffset uint32)
221 func call1048576(fn, arg unsafe.Pointer, n, retoffset uint32)
222 func call2097152(fn, arg unsafe.Pointer, n, retoffset uint32)
223 func call4194304(fn, arg unsafe.Pointer, n, retoffset uint32)
224 func call8388608(fn, arg unsafe.Pointer, n, retoffset uint32)
225 func call16777216(fn, arg unsafe.Pointer, n, retoffset uint32)
226 func call33554432(fn, arg unsafe.Pointer, n, retoffset uint32)
227 func call67108864(fn, arg unsafe.Pointer, n, retoffset uint32)
228 func call134217728(fn, arg unsafe.Pointer, n, retoffset uint32)
229 func call268435456(fn, arg unsafe.Pointer, n, retoffset uint32)
230 func call536870912(fn, arg unsafe.Pointer, n, retoffset uint32)
231 func call1073741824(fn, arg unsafe.Pointer, n, retoffset uint32)
232
233 func systemstack_switch()