| 1 |
// Copyright 2018 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 ( |
| 8 |
"internal/abi" |
| 9 |
"internal/runtime/atomic" |
| 10 |
"unsafe" |
| 11 |
) |
| 12 |
|
| 13 |
func libc_error_trampoline() |
| 14 |
|
| 15 |
// libc_error_addr puts the libc error |
| 16 |
// address into addr. |
| 17 |
// |
| 18 |
//go:nosplit |
| 19 |
//go:cgo_unsafe_args |
| 20 |
func libc_error_addr(addr **int32) { |
| 21 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(libc_error_trampoline)), unsafe.Pointer(&addr)) |
| 22 |
} |
| 23 |
|
| 24 |
// libcCallInfo is a structure used to pass parameters to the system call. |
| 25 |
type libcCallInfo struct { |
| 26 |
fn uintptr |
| 27 |
n uintptr // number of parameters |
| 28 |
args uintptr // parameters |
| 29 |
r1, r2 uintptr // return values |
| 30 |
} |
| 31 |
|
| 32 |
// syscall_syscalln is a wrapper around the libc call with variable arguments. |
| 33 |
// |
| 34 |
//go:linkname syscall_syscalln syscall.syscalln |
| 35 |
//go:nosplit |
| 36 |
//go:uintptrkeepalive |
| 37 |
func syscall_syscalln(fn uintptr, args ...uintptr) (r1, r2, err uintptr) { |
| 38 |
entersyscall() |
| 39 |
r1, r2, err = syscall_rawsyscalln(fn, args...) |
| 40 |
exitsyscall() |
| 41 |
return r1, r2, err |
| 42 |
} |
| 43 |
|
| 44 |
// syscall_rawsyscalln is a wrapper around the libc call with variable arguments. |
| 45 |
// The scheduler is not notified about the system call. |
| 46 |
// The syscall is executed on the current goroutine thread rather than on a |
| 47 |
// dedicated syscall thread. |
| 48 |
// |
| 49 |
//go:linkname syscall_rawsyscalln syscall.rawsyscalln |
| 50 |
//go:nosplit |
| 51 |
//go:uintptrkeepalive |
| 52 |
func syscall_rawsyscalln(fn uintptr, args ...uintptr) (r1, r2, err uintptr) { |
| 53 |
c := &libcCallInfo{ |
| 54 |
fn: fn, |
| 55 |
n: uintptr(len(args)), |
| 56 |
} |
| 57 |
if c.n != 0 { |
| 58 |
c.args = uintptr(noescape(unsafe.Pointer(&args[0]))) |
| 59 |
} |
| 60 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(syscallN_trampoline)), unsafe.Pointer(c)) |
| 61 |
if gp := getg(); gp != nil && gp.m != nil && gp.m.errnoAddr != nil { |
| 62 |
err = uintptr(*gp.m.errnoAddr) |
| 63 |
} else { |
| 64 |
var errnoAddr *int32 |
| 65 |
libc_error_addr(&errnoAddr) |
| 66 |
err = uintptr(*errnoAddr) |
| 67 |
} |
| 68 |
return c.r1, c.r2, err |
| 69 |
} |
| 70 |
|
| 71 |
func syscallN_trampoline() |
| 72 |
|
| 73 |
// crypto_x509_syscall is used in crypto/x509/internal/macos to call into Security.framework and CF. |
| 74 |
|
| 75 |
//go:linkname crypto_x509_syscall crypto/x509/internal/macos.syscall |
| 76 |
//go:nosplit |
| 77 |
func crypto_x509_syscall(fn, a1, a2, a3, a4, a5 uintptr, f1 float64) (r1 uintptr) { |
| 78 |
args := struct { |
| 79 |
fn, a1, a2, a3, a4, a5 uintptr |
| 80 |
f1 float64 |
| 81 |
r1 uintptr |
| 82 |
}{fn, a1, a2, a3, a4, a5, f1, r1} |
| 83 |
entersyscall() |
| 84 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall_x509)), unsafe.Pointer(&args)) |
| 85 |
exitsyscall() |
| 86 |
return args.r1 |
| 87 |
} |
| 88 |
func syscall_x509() |
| 89 |
|
| 90 |
// The *_trampoline functions convert from the Go calling convention to the C calling convention |
| 91 |
// and then call the underlying libc function. They are defined in sys_darwin_$ARCH.s. |
| 92 |
|
| 93 |
//go:nosplit |
| 94 |
//go:cgo_unsafe_args |
| 95 |
func pthread_attr_init(attr *pthreadattr) int32 { |
| 96 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_init_trampoline)), unsafe.Pointer(&attr)) |
| 97 |
KeepAlive(attr) |
| 98 |
return ret |
| 99 |
} |
| 100 |
func pthread_attr_init_trampoline() |
| 101 |
|
| 102 |
//go:nosplit |
| 103 |
//go:cgo_unsafe_args |
| 104 |
func pthread_attr_getstacksize(attr *pthreadattr, size *uintptr) int32 { |
| 105 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_getstacksize_trampoline)), unsafe.Pointer(&attr)) |
| 106 |
KeepAlive(attr) |
| 107 |
KeepAlive(size) |
| 108 |
return ret |
| 109 |
} |
| 110 |
func pthread_attr_getstacksize_trampoline() |
| 111 |
|
| 112 |
//go:nosplit |
| 113 |
//go:cgo_unsafe_args |
| 114 |
func pthread_attr_setdetachstate(attr *pthreadattr, state int) int32 { |
| 115 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_setdetachstate_trampoline)), unsafe.Pointer(&attr)) |
| 116 |
KeepAlive(attr) |
| 117 |
return ret |
| 118 |
} |
| 119 |
func pthread_attr_setdetachstate_trampoline() |
| 120 |
|
| 121 |
//go:nosplit |
| 122 |
//go:cgo_unsafe_args |
| 123 |
func pthread_create(attr *pthreadattr, start uintptr, arg unsafe.Pointer) int32 { |
| 124 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_create_trampoline)), unsafe.Pointer(&attr)) |
| 125 |
KeepAlive(attr) |
| 126 |
KeepAlive(arg) // Just for consistency. Arg of course needs to be kept alive for the start function. |
| 127 |
return ret |
| 128 |
} |
| 129 |
func pthread_create_trampoline() |
| 130 |
|
| 131 |
//go:nosplit |
| 132 |
//go:cgo_unsafe_args |
| 133 |
func raise(sig uint32) { |
| 134 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(raise_trampoline)), unsafe.Pointer(&sig)) |
| 135 |
} |
| 136 |
func raise_trampoline() |
| 137 |
|
| 138 |
//go:nosplit |
| 139 |
//go:cgo_unsafe_args |
| 140 |
func pthread_self() (t pthread) { |
| 141 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_self_trampoline)), unsafe.Pointer(&t)) |
| 142 |
return |
| 143 |
} |
| 144 |
func pthread_self_trampoline() |
| 145 |
|
| 146 |
//go:nosplit |
| 147 |
//go:cgo_unsafe_args |
| 148 |
func pthread_kill(t pthread, sig uint32) { |
| 149 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_kill_trampoline)), unsafe.Pointer(&t)) |
| 150 |
return |
| 151 |
} |
| 152 |
func pthread_kill_trampoline() |
| 153 |
|
| 154 |
// osinit_hack is a clumsy hack to work around Apple libc bugs |
| 155 |
// causing fork+exec to hang in the child process intermittently. |
| 156 |
// See go.dev/issue/33565 and go.dev/issue/56784 for a few reports. |
| 157 |
// |
| 158 |
// The stacks obtained from the hung child processes are in |
| 159 |
// libSystem_atfork_child, which is supposed to reinitialize various |
| 160 |
// parts of the C library in the new process. |
| 161 |
// |
| 162 |
// One common stack dies in _notify_fork_child calling _notify_globals |
| 163 |
// (inlined) calling _os_alloc_once, because _os_alloc_once detects that |
| 164 |
// the once lock is held by the parent process and then calls |
| 165 |
// _os_once_gate_corruption_abort. The allocation is setting up the |
| 166 |
// globals for the notification subsystem. See the source code at [1]. |
| 167 |
// To work around this, we can allocate the globals earlier in the Go |
| 168 |
// program's lifetime, before any execs are involved, by calling any |
| 169 |
// notify routine that is exported, calls _notify_globals, and doesn't do |
| 170 |
// anything too expensive otherwise. notify_is_valid_token(0) fits the bill. |
| 171 |
// |
| 172 |
// The other common stack dies in xpc_atfork_child calling |
| 173 |
// _objc_msgSend_uncached which ends up in |
| 174 |
// WAITING_FOR_ANOTHER_THREAD_TO_FINISH_CALLING_+initialize. Of course, |
| 175 |
// whatever thread the child is waiting for is in the parent process and |
| 176 |
// is not going to finish anything in the child process. There is no |
| 177 |
// public source code for these routines, so it is unclear exactly what |
| 178 |
// the problem is. An Apple engineer suggests using xpc_date_create_from_current, |
| 179 |
// which empirically does fix the problem. |
| 180 |
// |
| 181 |
// So osinit_hack_trampoline (in sys_darwin_$GOARCH.s) calls |
| 182 |
// notify_is_valid_token(0) and xpc_date_create_from_current(), which makes the |
| 183 |
// fork+exec hangs stop happening. If Apple fixes the libc bug in |
| 184 |
// some future version of macOS, then we can remove this awful code. |
| 185 |
// |
| 186 |
//go:nosplit |
| 187 |
func osinit_hack() { |
| 188 |
if GOOS == "darwin" { // not ios |
| 189 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(osinit_hack_trampoline)), nil) |
| 190 |
} |
| 191 |
return |
| 192 |
} |
| 193 |
func osinit_hack_trampoline() |
| 194 |
|
| 195 |
// mmap is used to do low-level memory allocation via mmap. Don't allow stack |
| 196 |
// splits, since this function (used by sysAlloc) is called in a lot of low-level |
| 197 |
// parts of the runtime and callers often assume it won't acquire any locks. |
| 198 |
// |
| 199 |
//go:nosplit |
| 200 |
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) { |
| 201 |
args := struct { |
| 202 |
addr unsafe.Pointer |
| 203 |
n uintptr |
| 204 |
prot, flags, fd int32 |
| 205 |
off uint32 |
| 206 |
ret1 unsafe.Pointer |
| 207 |
ret2 int |
| 208 |
}{addr, n, prot, flags, fd, off, nil, 0} |
| 209 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(mmap_trampoline)), unsafe.Pointer(&args)) |
| 210 |
return args.ret1, args.ret2 |
| 211 |
} |
| 212 |
func mmap_trampoline() |
| 213 |
|
| 214 |
//go:nosplit |
| 215 |
//go:cgo_unsafe_args |
| 216 |
func munmap(addr unsafe.Pointer, n uintptr) { |
| 217 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(munmap_trampoline)), unsafe.Pointer(&addr)) |
| 218 |
KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address. |
| 219 |
} |
| 220 |
func munmap_trampoline() |
| 221 |
|
| 222 |
//go:nosplit |
| 223 |
//go:cgo_unsafe_args |
| 224 |
func madvise(addr unsafe.Pointer, n uintptr, flags int32) { |
| 225 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(madvise_trampoline)), unsafe.Pointer(&addr)) |
| 226 |
KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address. |
| 227 |
} |
| 228 |
func madvise_trampoline() |
| 229 |
|
| 230 |
//go:nosplit |
| 231 |
//go:cgo_unsafe_args |
| 232 |
func mlock(addr unsafe.Pointer, n uintptr) { |
| 233 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(mlock_trampoline)), unsafe.Pointer(&addr)) |
| 234 |
KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address. |
| 235 |
} |
| 236 |
func mlock_trampoline() |
| 237 |
|
| 238 |
//go:nosplit |
| 239 |
//go:cgo_unsafe_args |
| 240 |
func read(fd int32, p unsafe.Pointer, n int32) int32 { |
| 241 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(read_trampoline)), unsafe.Pointer(&fd)) |
| 242 |
KeepAlive(p) |
| 243 |
return ret |
| 244 |
} |
| 245 |
func read_trampoline() |
| 246 |
|
| 247 |
func pipe() (r, w int32, errno int32) { |
| 248 |
var p [2]int32 |
| 249 |
errno = libcCall(unsafe.Pointer(abi.FuncPCABI0(pipe_trampoline)), noescape(unsafe.Pointer(&p))) |
| 250 |
return p[0], p[1], errno |
| 251 |
} |
| 252 |
func pipe_trampoline() |
| 253 |
|
| 254 |
//go:nosplit |
| 255 |
//go:cgo_unsafe_args |
| 256 |
func closefd(fd int32) int32 { |
| 257 |
return libcCall(unsafe.Pointer(abi.FuncPCABI0(close_trampoline)), unsafe.Pointer(&fd)) |
| 258 |
} |
| 259 |
func close_trampoline() |
| 260 |
|
| 261 |
// This is exported via linkname to assembly in runtime/cgo. |
| 262 |
// |
| 263 |
//go:nosplit |
| 264 |
//go:cgo_unsafe_args |
| 265 |
//go:linkname exit |
| 266 |
func exit(code int32) { |
| 267 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(exit_trampoline)), unsafe.Pointer(&code)) |
| 268 |
} |
| 269 |
func exit_trampoline() |
| 270 |
|
| 271 |
//go:nosplit |
| 272 |
//go:cgo_unsafe_args |
| 273 |
func usleep(usec uint32) { |
| 274 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec)) |
| 275 |
} |
| 276 |
func usleep_trampoline() |
| 277 |
|
| 278 |
//go:nosplit |
| 279 |
//go:cgo_unsafe_args |
| 280 |
func usleep_no_g(usec uint32) { |
| 281 |
asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec)) |
| 282 |
} |
| 283 |
|
| 284 |
//go:nosplit |
| 285 |
//go:cgo_unsafe_args |
| 286 |
func write1(fd uintptr, p unsafe.Pointer, n int32) int32 { |
| 287 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(write_trampoline)), unsafe.Pointer(&fd)) |
| 288 |
KeepAlive(p) |
| 289 |
return ret |
| 290 |
} |
| 291 |
func write_trampoline() |
| 292 |
|
| 293 |
//go:nosplit |
| 294 |
//go:cgo_unsafe_args |
| 295 |
func open(name *byte, mode, perm int32) (ret int32) { |
| 296 |
ret = libcCall(unsafe.Pointer(abi.FuncPCABI0(open_trampoline)), unsafe.Pointer(&name)) |
| 297 |
KeepAlive(name) |
| 298 |
return |
| 299 |
} |
| 300 |
func open_trampoline() |
| 301 |
|
| 302 |
//go:nosplit |
| 303 |
//go:cgo_unsafe_args |
| 304 |
func nanotime1() int64 { |
| 305 |
var r struct { |
| 306 |
t int64 // raw timer |
| 307 |
numer, denom uint32 // conversion factors. nanoseconds = t * numer / denom. |
| 308 |
} |
| 309 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(nanotime_trampoline)), unsafe.Pointer(&r)) |
| 310 |
// Note: Apple seems unconcerned about overflow here. See |
| 311 |
// https://developer.apple.com/library/content/qa/qa1398/_index.html |
| 312 |
// Note also, numer == denom == 1 is common. |
| 313 |
t := r.t |
| 314 |
if r.numer != 1 { |
| 315 |
t *= int64(r.numer) |
| 316 |
} |
| 317 |
if r.denom != 1 { |
| 318 |
t /= int64(r.denom) |
| 319 |
} |
| 320 |
return t |
| 321 |
} |
| 322 |
func nanotime_trampoline() |
| 323 |
|
| 324 |
// walltime should be an internal detail, |
| 325 |
// but widely used packages access it using linkname. |
| 326 |
// Notable members of the hall of shame include: |
| 327 |
// - gitee.com/quant1x/gox |
| 328 |
// |
| 329 |
// Do not remove or change the type signature. |
| 330 |
// See go.dev/issue/67401. |
| 331 |
// |
| 332 |
//go:linkname walltime |
| 333 |
//go:nosplit |
| 334 |
//go:cgo_unsafe_args |
| 335 |
func walltime() (int64, int32) { |
| 336 |
var t timespec |
| 337 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(walltime_trampoline)), unsafe.Pointer(&t)) |
| 338 |
return t.tv_sec, int32(t.tv_nsec) |
| 339 |
} |
| 340 |
func walltime_trampoline() |
| 341 |
|
| 342 |
//go:nosplit |
| 343 |
//go:cgo_unsafe_args |
| 344 |
func sigaction(sig uint32, new *usigactiont, old *usigactiont) { |
| 345 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaction_trampoline)), unsafe.Pointer(&sig)) |
| 346 |
KeepAlive(new) |
| 347 |
KeepAlive(old) |
| 348 |
} |
| 349 |
func sigaction_trampoline() |
| 350 |
|
| 351 |
//go:nosplit |
| 352 |
//go:cgo_unsafe_args |
| 353 |
func sigprocmask(how uint32, new *sigset, old *sigset) { |
| 354 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(sigprocmask_trampoline)), unsafe.Pointer(&how)) |
| 355 |
KeepAlive(new) |
| 356 |
KeepAlive(old) |
| 357 |
} |
| 358 |
func sigprocmask_trampoline() |
| 359 |
|
| 360 |
//go:nosplit |
| 361 |
//go:cgo_unsafe_args |
| 362 |
func sigaltstack(new *stackt, old *stackt) { |
| 363 |
if new != nil && new.ss_flags&_SS_DISABLE != 0 && new.ss_size == 0 { |
| 364 |
// Despite the fact that Darwin's sigaltstack man page says it ignores the size |
| 365 |
// when SS_DISABLE is set, it doesn't. sigaltstack returns ENOMEM |
| 366 |
// if we don't give it a reasonable size. |
| 367 |
// ref: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20140421/214296.html |
| 368 |
new.ss_size = 32768 |
| 369 |
} |
| 370 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaltstack_trampoline)), unsafe.Pointer(&new)) |
| 371 |
KeepAlive(new) |
| 372 |
KeepAlive(old) |
| 373 |
} |
| 374 |
func sigaltstack_trampoline() |
| 375 |
|
| 376 |
//go:nosplit |
| 377 |
//go:cgo_unsafe_args |
| 378 |
func raiseproc(sig uint32) { |
| 379 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(raiseproc_trampoline)), unsafe.Pointer(&sig)) |
| 380 |
} |
| 381 |
func raiseproc_trampoline() |
| 382 |
|
| 383 |
//go:nosplit |
| 384 |
//go:cgo_unsafe_args |
| 385 |
func setitimer(mode int32, new, old *itimerval) { |
| 386 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(setitimer_trampoline)), unsafe.Pointer(&mode)) |
| 387 |
KeepAlive(new) |
| 388 |
KeepAlive(old) |
| 389 |
} |
| 390 |
func setitimer_trampoline() |
| 391 |
|
| 392 |
//go:nosplit |
| 393 |
//go:cgo_unsafe_args |
| 394 |
func sysctl(mib *uint32, miblen uint32, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 { |
| 395 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(sysctl_trampoline)), unsafe.Pointer(&mib)) |
| 396 |
KeepAlive(mib) |
| 397 |
KeepAlive(oldp) |
| 398 |
KeepAlive(oldlenp) |
| 399 |
KeepAlive(newp) |
| 400 |
return ret |
| 401 |
} |
| 402 |
func sysctl_trampoline() |
| 403 |
|
| 404 |
//go:nosplit |
| 405 |
//go:cgo_unsafe_args |
| 406 |
func sysctlbyname(name *byte, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 { |
| 407 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(sysctlbyname_trampoline)), unsafe.Pointer(&name)) |
| 408 |
KeepAlive(name) |
| 409 |
KeepAlive(oldp) |
| 410 |
KeepAlive(oldlenp) |
| 411 |
KeepAlive(newp) |
| 412 |
return ret |
| 413 |
} |
| 414 |
func sysctlbyname_trampoline() |
| 415 |
|
| 416 |
//go:nosplit |
| 417 |
//go:cgo_unsafe_args |
| 418 |
func fcntl(fd, cmd, arg int32) (ret int32, errno int32) { |
| 419 |
args := struct { |
| 420 |
fd, cmd, arg int32 |
| 421 |
ret, errno int32 |
| 422 |
}{fd, cmd, arg, 0, 0} |
| 423 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&args)) |
| 424 |
return args.ret, args.errno |
| 425 |
} |
| 426 |
func fcntl_trampoline() |
| 427 |
|
| 428 |
//go:nosplit |
| 429 |
//go:cgo_unsafe_args |
| 430 |
func kqueue() int32 { |
| 431 |
v := libcCall(unsafe.Pointer(abi.FuncPCABI0(kqueue_trampoline)), nil) |
| 432 |
return v |
| 433 |
} |
| 434 |
func kqueue_trampoline() |
| 435 |
|
| 436 |
//go:nosplit |
| 437 |
//go:cgo_unsafe_args |
| 438 |
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 { |
| 439 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(kevent_trampoline)), unsafe.Pointer(&kq)) |
| 440 |
KeepAlive(ch) |
| 441 |
KeepAlive(ev) |
| 442 |
KeepAlive(ts) |
| 443 |
return ret |
| 444 |
} |
| 445 |
func kevent_trampoline() |
| 446 |
|
| 447 |
//go:nosplit |
| 448 |
//go:cgo_unsafe_args |
| 449 |
func pthread_mutex_init(m *pthreadmutex, attr *pthreadmutexattr) int32 { |
| 450 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_init_trampoline)), unsafe.Pointer(&m)) |
| 451 |
KeepAlive(m) |
| 452 |
KeepAlive(attr) |
| 453 |
return ret |
| 454 |
} |
| 455 |
func pthread_mutex_init_trampoline() |
| 456 |
|
| 457 |
//go:nosplit |
| 458 |
//go:cgo_unsafe_args |
| 459 |
func pthread_mutex_lock(m *pthreadmutex) int32 { |
| 460 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_lock_trampoline)), unsafe.Pointer(&m)) |
| 461 |
KeepAlive(m) |
| 462 |
return ret |
| 463 |
} |
| 464 |
func pthread_mutex_lock_trampoline() |
| 465 |
|
| 466 |
//go:nosplit |
| 467 |
//go:cgo_unsafe_args |
| 468 |
func pthread_mutex_unlock(m *pthreadmutex) int32 { |
| 469 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_unlock_trampoline)), unsafe.Pointer(&m)) |
| 470 |
KeepAlive(m) |
| 471 |
return ret |
| 472 |
} |
| 473 |
func pthread_mutex_unlock_trampoline() |
| 474 |
|
| 475 |
//go:nosplit |
| 476 |
//go:cgo_unsafe_args |
| 477 |
func pthread_cond_init(c *pthreadcond, attr *pthreadcondattr) int32 { |
| 478 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_init_trampoline)), unsafe.Pointer(&c)) |
| 479 |
KeepAlive(c) |
| 480 |
KeepAlive(attr) |
| 481 |
return ret |
| 482 |
} |
| 483 |
func pthread_cond_init_trampoline() |
| 484 |
|
| 485 |
//go:nosplit |
| 486 |
//go:cgo_unsafe_args |
| 487 |
func pthread_cond_wait(c *pthreadcond, m *pthreadmutex) int32 { |
| 488 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_wait_trampoline)), unsafe.Pointer(&c)) |
| 489 |
KeepAlive(c) |
| 490 |
KeepAlive(m) |
| 491 |
return ret |
| 492 |
} |
| 493 |
func pthread_cond_wait_trampoline() |
| 494 |
|
| 495 |
//go:nosplit |
| 496 |
//go:cgo_unsafe_args |
| 497 |
func pthread_cond_timedwait_relative_np(c *pthreadcond, m *pthreadmutex, t *timespec) int32 { |
| 498 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_timedwait_relative_np_trampoline)), unsafe.Pointer(&c)) |
| 499 |
KeepAlive(c) |
| 500 |
KeepAlive(m) |
| 501 |
KeepAlive(t) |
| 502 |
return ret |
| 503 |
} |
| 504 |
func pthread_cond_timedwait_relative_np_trampoline() |
| 505 |
|
| 506 |
//go:nosplit |
| 507 |
//go:cgo_unsafe_args |
| 508 |
func pthread_cond_signal(c *pthreadcond) int32 { |
| 509 |
ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_signal_trampoline)), unsafe.Pointer(&c)) |
| 510 |
KeepAlive(c) |
| 511 |
return ret |
| 512 |
} |
| 513 |
func pthread_cond_signal_trampoline() |
| 514 |
|
| 515 |
//go:nosplit |
| 516 |
//go:cgo_unsafe_args |
| 517 |
func arc4random_buf(p unsafe.Pointer, n int32) { |
| 518 |
// arc4random_buf() never fails, per its man page, so it's safe to ignore the return value. |
| 519 |
libcCall(unsafe.Pointer(abi.FuncPCABI0(arc4random_buf_trampoline)), unsafe.Pointer(&p)) |
| 520 |
KeepAlive(p) |
| 521 |
} |
| 522 |
func arc4random_buf_trampoline() |
| 523 |
|
| 524 |
// Not used on Darwin, but must be defined. |
| 525 |
func exitThread(wait *atomic.Uint32) { |
| 526 |
throw("exitThread") |
| 527 |
} |
| 528 |
|
| 529 |
//go:nosplit |
| 530 |
func setNonblock(fd int32) { |
| 531 |
flags, _ := fcntl(fd, _F_GETFL, 0) |
| 532 |
if flags != -1 { |
| 533 |
fcntl(fd, _F_SETFL, flags|_O_NONBLOCK) |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
func issetugid() int32 { |
| 538 |
return libcCall(unsafe.Pointer(abi.FuncPCABI0(issetugid_trampoline)), nil) |
| 539 |
} |
| 540 |
func issetugid_trampoline() |
| 541 |
|
| 542 |
// mach_vm_region is used to obtain virtual memory mappings for use by the |
| 543 |
// profiling system and is only exported to runtime/pprof. It is restricted |
| 544 |
// to obtaining mappings for the current process. |
| 545 |
// |
| 546 |
//go:linkname mach_vm_region runtime/pprof.mach_vm_region |
| 547 |
func mach_vm_region(address, region_size *uint64, info unsafe.Pointer) int32 { |
| 548 |
// kern_return_t mach_vm_region( |
| 549 |
// vm_map_read_t target_task, |
| 550 |
// mach_vm_address_t *address, |
| 551 |
// mach_vm_size_t *size, |
| 552 |
// vm_region_flavor_t flavor, |
| 553 |
// vm_region_info_t info, |
| 554 |
// mach_msg_type_number_t *infoCnt, |
| 555 |
// mach_port_t *object_name); |
| 556 |
var count machMsgTypeNumber = _VM_REGION_BASIC_INFO_COUNT_64 |
| 557 |
var object_name machPort |
| 558 |
args := struct { |
| 559 |
address *uint64 |
| 560 |
size *uint64 |
| 561 |
flavor machVMRegionFlavour |
| 562 |
info unsafe.Pointer |
| 563 |
count *machMsgTypeNumber |
| 564 |
object_name *machPort |
| 565 |
}{ |
| 566 |
address: address, |
| 567 |
size: region_size, |
| 568 |
flavor: _VM_REGION_BASIC_INFO_64, |
| 569 |
info: info, |
| 570 |
count: &count, |
| 571 |
object_name: &object_name, |
| 572 |
} |
| 573 |
return libcCall(unsafe.Pointer(abi.FuncPCABI0(mach_vm_region_trampoline)), unsafe.Pointer(&args)) |
| 574 |
} |
| 575 |
func mach_vm_region_trampoline() |
| 576 |
|
| 577 |
//go:linkname proc_regionfilename runtime/pprof.proc_regionfilename |
| 578 |
func proc_regionfilename(pid int, address uint64, buf *byte, buflen int64) int32 { |
| 579 |
args := struct { |
| 580 |
pid int |
| 581 |
address uint64 |
| 582 |
buf *byte |
| 583 |
bufSize int64 |
| 584 |
}{ |
| 585 |
pid: pid, |
| 586 |
address: address, |
| 587 |
buf: buf, |
| 588 |
bufSize: buflen, |
| 589 |
} |
| 590 |
return libcCall(unsafe.Pointer(abi.FuncPCABI0(proc_regionfilename_trampoline)), unsafe.Pointer(&args)) |
| 591 |
} |
| 592 |
func proc_regionfilename_trampoline() |
| 593 |
|
| 594 |
// Tell the linker that the libc_* functions are to be found |
| 595 |
// in a system library, with the libc_ prefix missing. |
| 596 |
|
| 597 |
//go:cgo_import_dynamic libc_pthread_attr_init pthread_attr_init "/usr/lib/libSystem.B.dylib" |
| 598 |
//go:cgo_import_dynamic libc_pthread_attr_getstacksize pthread_attr_getstacksize "/usr/lib/libSystem.B.dylib" |
| 599 |
//go:cgo_import_dynamic libc_pthread_attr_setdetachstate pthread_attr_setdetachstate "/usr/lib/libSystem.B.dylib" |
| 600 |
//go:cgo_import_dynamic libc_pthread_create pthread_create "/usr/lib/libSystem.B.dylib" |
| 601 |
//go:cgo_import_dynamic libc_pthread_self pthread_self "/usr/lib/libSystem.B.dylib" |
| 602 |
//go:cgo_import_dynamic libc_pthread_kill pthread_kill "/usr/lib/libSystem.B.dylib" |
| 603 |
//go:cgo_import_dynamic libc_exit _exit "/usr/lib/libSystem.B.dylib" |
| 604 |
//go:cgo_import_dynamic libc_raise raise "/usr/lib/libSystem.B.dylib" |
| 605 |
|
| 606 |
//go:cgo_import_dynamic libc_open open "/usr/lib/libSystem.B.dylib" |
| 607 |
//go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib" |
| 608 |
//go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib" |
| 609 |
//go:cgo_import_dynamic libc_write write "/usr/lib/libSystem.B.dylib" |
| 610 |
//go:cgo_import_dynamic libc_pipe pipe "/usr/lib/libSystem.B.dylib" |
| 611 |
|
| 612 |
//go:cgo_import_dynamic libc_mmap mmap "/usr/lib/libSystem.B.dylib" |
| 613 |
//go:cgo_import_dynamic libc_munmap munmap "/usr/lib/libSystem.B.dylib" |
| 614 |
//go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib" |
| 615 |
//go:cgo_import_dynamic libc_mlock mlock "/usr/lib/libSystem.B.dylib" |
| 616 |
//go:cgo_import_dynamic libc_error __error "/usr/lib/libSystem.B.dylib" |
| 617 |
//go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib" |
| 618 |
|
| 619 |
//go:cgo_import_dynamic libc_proc_regionfilename proc_regionfilename "/usr/lib/libSystem.B.dylib" |
| 620 |
//go:cgo_import_dynamic libc_mach_task_self_ mach_task_self_ "/usr/lib/libSystem.B.dylib"" |
| 621 |
//go:cgo_import_dynamic libc_mach_vm_region mach_vm_region "/usr/lib/libSystem.B.dylib"" |
| 622 |
//go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib" |
| 623 |
//go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib" |
| 624 |
//go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib" |
| 625 |
//go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib" |
| 626 |
//go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib" |
| 627 |
//go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib" |
| 628 |
//go:cgo_import_dynamic libc_getpid getpid "/usr/lib/libSystem.B.dylib" |
| 629 |
//go:cgo_import_dynamic libc_kill kill "/usr/lib/libSystem.B.dylib" |
| 630 |
//go:cgo_import_dynamic libc_setitimer setitimer "/usr/lib/libSystem.B.dylib" |
| 631 |
//go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib" |
| 632 |
//go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib" |
| 633 |
//go:cgo_import_dynamic libc_fcntl fcntl "/usr/lib/libSystem.B.dylib" |
| 634 |
//go:cgo_import_dynamic libc_kqueue kqueue "/usr/lib/libSystem.B.dylib" |
| 635 |
//go:cgo_import_dynamic libc_kevent kevent "/usr/lib/libSystem.B.dylib" |
| 636 |
|
| 637 |
//go:cgo_import_dynamic libc_pthread_mutex_init pthread_mutex_init "/usr/lib/libSystem.B.dylib" |
| 638 |
//go:cgo_import_dynamic libc_pthread_mutex_lock pthread_mutex_lock "/usr/lib/libSystem.B.dylib" |
| 639 |
//go:cgo_import_dynamic libc_pthread_mutex_unlock pthread_mutex_unlock "/usr/lib/libSystem.B.dylib" |
| 640 |
//go:cgo_import_dynamic libc_pthread_cond_init pthread_cond_init "/usr/lib/libSystem.B.dylib" |
| 641 |
//go:cgo_import_dynamic libc_pthread_cond_wait pthread_cond_wait "/usr/lib/libSystem.B.dylib" |
| 642 |
//go:cgo_import_dynamic libc_pthread_cond_timedwait_relative_np pthread_cond_timedwait_relative_np "/usr/lib/libSystem.B.dylib" |
| 643 |
//go:cgo_import_dynamic libc_pthread_cond_signal pthread_cond_signal "/usr/lib/libSystem.B.dylib" |
| 644 |
//go:cgo_import_dynamic libc_arc4random_buf arc4random_buf "/usr/lib/libSystem.B.dylib" |
| 645 |
|
| 646 |
//go:cgo_import_dynamic libc_notify_is_valid_token notify_is_valid_token "/usr/lib/libSystem.B.dylib" |
| 647 |
//go:cgo_import_dynamic libc_xpc_date_create_from_current xpc_date_create_from_current "/usr/lib/libSystem.B.dylib" |
| 648 |
|
| 649 |
//go:cgo_import_dynamic libc_issetugid issetugid "/usr/lib/libSystem.B.dylib" |