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.
14 type mscratch struct {
19 waitsema uintptr // semaphore for parking on locks
20 perrno *int32 // pointer to tls errno
21 // these are here because they are too large to be on the stack
22 // of low-level NOSPLIT functions.
30 //go:linkname asmsysvicall6x runtime.asmsysvicall6
31 var asmsysvicall6x libcFunc // name to take addr of asmsysvicall6
33 func asmsysvicall6() // declared for vet; do NOT call
36 func sysvicall0(fn *libcFunc) uintptr {
37 // Leave caller's PC/SP around for traceback.
43 if mp != nil && mp.libcallsp == 0 {
45 mp.libcallpc = getcallerpc()
46 // sp must be the last, because once async cpu profiler finds
47 // all three values to be non-zero, it will use them
48 mp.libcallsp = getcallersp()
50 mp = nil // See comment in sys_darwin.go:libcCall
54 libcall.fn = uintptr(unsafe.Pointer(fn))
56 libcall.args = uintptr(unsafe.Pointer(fn)) // it's unused but must be non-nil, otherwise crashes
57 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
65 func sysvicall1(fn *libcFunc, a1 uintptr) uintptr {
66 r1, _ := sysvicall1Err(fn, a1)
70 // sysvicall1Err returns both the system call result and the errno value.
71 // This is used by sysvicall1 and pipe.
74 func sysvicall1Err(fn *libcFunc, a1 uintptr) (r1, err uintptr) {
75 // Leave caller's PC/SP around for traceback.
81 if mp != nil && mp.libcallsp == 0 {
83 mp.libcallpc = getcallerpc()
84 // sp must be the last, because once async cpu profiler finds
85 // all three values to be non-zero, it will use them
86 mp.libcallsp = getcallersp()
92 libcall.fn = uintptr(unsafe.Pointer(fn))
94 // TODO(rsc): Why is noescape necessary here and below?
95 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
96 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
100 return libcall.r1, libcall.err
104 func sysvicall2(fn *libcFunc, a1, a2 uintptr) uintptr {
105 r1, _ := sysvicall2Err(fn, a1, a2)
112 // sysvicall2Err returns both the system call result and the errno value.
113 // This is used by sysvicall2 and pipe2.
114 func sysvicall2Err(fn *libcFunc, a1, a2 uintptr) (uintptr, uintptr) {
115 // Leave caller's PC/SP around for traceback.
121 if mp != nil && mp.libcallsp == 0 {
123 mp.libcallpc = getcallerpc()
124 // sp must be the last, because once async cpu profiler finds
125 // all three values to be non-zero, it will use them
126 mp.libcallsp = getcallersp()
132 libcall.fn = uintptr(unsafe.Pointer(fn))
134 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
135 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
139 return libcall.r1, libcall.err
143 func sysvicall3(fn *libcFunc, a1, a2, a3 uintptr) uintptr {
144 r1, _ := sysvicall3Err(fn, a1, a2, a3)
151 // sysvicall3Err returns both the system call result and the errno value.
152 // This is used by sysvicall3 and write1.
153 func sysvicall3Err(fn *libcFunc, a1, a2, a3 uintptr) (r1, err uintptr) {
154 // Leave caller's PC/SP around for traceback.
160 if mp != nil && mp.libcallsp == 0 {
162 mp.libcallpc = getcallerpc()
163 // sp must be the last, because once async cpu profiler finds
164 // all three values to be non-zero, it will use them
165 mp.libcallsp = getcallersp()
171 libcall.fn = uintptr(unsafe.Pointer(fn))
173 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
174 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
178 return libcall.r1, libcall.err
183 func sysvicall4(fn *libcFunc, a1, a2, a3, a4 uintptr) uintptr {
184 // Leave caller's PC/SP around for traceback.
190 if mp != nil && mp.libcallsp == 0 {
192 mp.libcallpc = getcallerpc()
193 // sp must be the last, because once async cpu profiler finds
194 // all three values to be non-zero, it will use them
195 mp.libcallsp = getcallersp()
201 libcall.fn = uintptr(unsafe.Pointer(fn))
203 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
204 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
213 func sysvicall5(fn *libcFunc, a1, a2, a3, a4, a5 uintptr) uintptr {
214 // Leave caller's PC/SP around for traceback.
220 if mp != nil && mp.libcallsp == 0 {
222 mp.libcallpc = getcallerpc()
223 // sp must be the last, because once async cpu profiler finds
224 // all three values to be non-zero, it will use them
225 mp.libcallsp = getcallersp()
231 libcall.fn = uintptr(unsafe.Pointer(fn))
233 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
234 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
243 func sysvicall6(fn *libcFunc, a1, a2, a3, a4, a5, a6 uintptr) uintptr {
244 // Leave caller's PC/SP around for traceback.
250 if mp != nil && mp.libcallsp == 0 {
252 mp.libcallpc = getcallerpc()
253 // sp must be the last, because once async cpu profiler finds
254 // all three values to be non-zero, it will use them
255 mp.libcallsp = getcallersp()
261 libcall.fn = uintptr(unsafe.Pointer(fn))
263 libcall.args = uintptr(noescape(unsafe.Pointer(&a1)))
264 asmcgocall(unsafe.Pointer(&asmsysvicall6x), unsafe.Pointer(&libcall))
271 func issetugid() int32 {
272 return int32(sysvicall0(&libc_issetugid))