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