github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/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) int32 {
   438  	return libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&fd))
   439  }
   440  func fcntl_trampoline()
   441  
   442  //go:nosplit
   443  //go:cgo_unsafe_args
   444  func kqueue() int32 {
   445  	v := libcCall(unsafe.Pointer(abi.FuncPCABI0(kqueue_trampoline)), nil)
   446  	return v
   447  }
   448  func kqueue_trampoline()
   449  
   450  //go:nosplit
   451  //go:cgo_unsafe_args
   452  func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 {
   453  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(kevent_trampoline)), unsafe.Pointer(&kq))
   454  	KeepAlive(ch)
   455  	KeepAlive(ev)
   456  	KeepAlive(ts)
   457  	return ret
   458  }
   459  func kevent_trampoline()
   460  
   461  //go:nosplit
   462  //go:cgo_unsafe_args
   463  func pthread_mutex_init(m *pthreadmutex, attr *pthreadmutexattr) int32 {
   464  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_init_trampoline)), unsafe.Pointer(&m))
   465  	KeepAlive(m)
   466  	KeepAlive(attr)
   467  	return ret
   468  }
   469  func pthread_mutex_init_trampoline()
   470  
   471  //go:nosplit
   472  //go:cgo_unsafe_args
   473  func pthread_mutex_lock(m *pthreadmutex) int32 {
   474  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_lock_trampoline)), unsafe.Pointer(&m))
   475  	KeepAlive(m)
   476  	return ret
   477  }
   478  func pthread_mutex_lock_trampoline()
   479  
   480  //go:nosplit
   481  //go:cgo_unsafe_args
   482  func pthread_mutex_unlock(m *pthreadmutex) int32 {
   483  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_unlock_trampoline)), unsafe.Pointer(&m))
   484  	KeepAlive(m)
   485  	return ret
   486  }
   487  func pthread_mutex_unlock_trampoline()
   488  
   489  //go:nosplit
   490  //go:cgo_unsafe_args
   491  func pthread_cond_init(c *pthreadcond, attr *pthreadcondattr) int32 {
   492  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_init_trampoline)), unsafe.Pointer(&c))
   493  	KeepAlive(c)
   494  	KeepAlive(attr)
   495  	return ret
   496  }
   497  func pthread_cond_init_trampoline()
   498  
   499  //go:nosplit
   500  //go:cgo_unsafe_args
   501  func pthread_cond_wait(c *pthreadcond, m *pthreadmutex) int32 {
   502  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_wait_trampoline)), unsafe.Pointer(&c))
   503  	KeepAlive(c)
   504  	KeepAlive(m)
   505  	return ret
   506  }
   507  func pthread_cond_wait_trampoline()
   508  
   509  //go:nosplit
   510  //go:cgo_unsafe_args
   511  func pthread_cond_timedwait_relative_np(c *pthreadcond, m *pthreadmutex, t *timespec) int32 {
   512  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_timedwait_relative_np_trampoline)), unsafe.Pointer(&c))
   513  	KeepAlive(c)
   514  	KeepAlive(m)
   515  	KeepAlive(t)
   516  	return ret
   517  }
   518  func pthread_cond_timedwait_relative_np_trampoline()
   519  
   520  //go:nosplit
   521  //go:cgo_unsafe_args
   522  func pthread_cond_signal(c *pthreadcond) int32 {
   523  	ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_signal_trampoline)), unsafe.Pointer(&c))
   524  	KeepAlive(c)
   525  	return ret
   526  }
   527  func pthread_cond_signal_trampoline()
   528  
   529  // Not used on Darwin, but must be defined.
   530  func exitThread(wait *atomic.Uint32) {
   531  	throw("exitThread")
   532  }
   533  
   534  //go:nosplit
   535  func closeonexec(fd int32) {
   536  	fcntl(fd, _F_SETFD, _FD_CLOEXEC)
   537  }
   538  
   539  //go:nosplit
   540  func setNonblock(fd int32) {
   541  	flags := fcntl(fd, _F_GETFL, 0)
   542  	fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
   543  }
   544  
   545  // Tell the linker that the libc_* functions are to be found
   546  // in a system library, with the libc_ prefix missing.
   547  
   548  //go:cgo_import_dynamic libc_pthread_attr_init pthread_attr_init "/usr/lib/libSystem.B.dylib"
   549  //go:cgo_import_dynamic libc_pthread_attr_getstacksize pthread_attr_getstacksize "/usr/lib/libSystem.B.dylib"
   550  //go:cgo_import_dynamic libc_pthread_attr_setdetachstate pthread_attr_setdetachstate "/usr/lib/libSystem.B.dylib"
   551  //go:cgo_import_dynamic libc_pthread_create pthread_create "/usr/lib/libSystem.B.dylib"
   552  //go:cgo_import_dynamic libc_pthread_self pthread_self "/usr/lib/libSystem.B.dylib"
   553  //go:cgo_import_dynamic libc_pthread_kill pthread_kill "/usr/lib/libSystem.B.dylib"
   554  //go:cgo_import_dynamic libc_exit _exit "/usr/lib/libSystem.B.dylib"
   555  //go:cgo_import_dynamic libc_raise raise "/usr/lib/libSystem.B.dylib"
   556  
   557  //go:cgo_import_dynamic libc_open open "/usr/lib/libSystem.B.dylib"
   558  //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"
   559  //go:cgo_import_dynamic libc_read read "/usr/lib/libSystem.B.dylib"
   560  //go:cgo_import_dynamic libc_write write "/usr/lib/libSystem.B.dylib"
   561  //go:cgo_import_dynamic libc_pipe pipe "/usr/lib/libSystem.B.dylib"
   562  
   563  //go:cgo_import_dynamic libc_mmap mmap "/usr/lib/libSystem.B.dylib"
   564  //go:cgo_import_dynamic libc_munmap munmap "/usr/lib/libSystem.B.dylib"
   565  //go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib"
   566  //go:cgo_import_dynamic libc_mlock mlock "/usr/lib/libSystem.B.dylib"
   567  //go:cgo_import_dynamic libc_error __error "/usr/lib/libSystem.B.dylib"
   568  //go:cgo_import_dynamic libc_usleep usleep "/usr/lib/libSystem.B.dylib"
   569  
   570  //go:cgo_import_dynamic libc_mach_timebase_info mach_timebase_info "/usr/lib/libSystem.B.dylib"
   571  //go:cgo_import_dynamic libc_mach_absolute_time mach_absolute_time "/usr/lib/libSystem.B.dylib"
   572  //go:cgo_import_dynamic libc_clock_gettime clock_gettime "/usr/lib/libSystem.B.dylib"
   573  //go:cgo_import_dynamic libc_sigaction sigaction "/usr/lib/libSystem.B.dylib"
   574  //go:cgo_import_dynamic libc_pthread_sigmask pthread_sigmask "/usr/lib/libSystem.B.dylib"
   575  //go:cgo_import_dynamic libc_sigaltstack sigaltstack "/usr/lib/libSystem.B.dylib"
   576  //go:cgo_import_dynamic libc_getpid getpid "/usr/lib/libSystem.B.dylib"
   577  //go:cgo_import_dynamic libc_kill kill "/usr/lib/libSystem.B.dylib"
   578  //go:cgo_import_dynamic libc_setitimer setitimer "/usr/lib/libSystem.B.dylib"
   579  //go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib"
   580  //go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib"
   581  //go:cgo_import_dynamic libc_fcntl fcntl "/usr/lib/libSystem.B.dylib"
   582  //go:cgo_import_dynamic libc_kqueue kqueue "/usr/lib/libSystem.B.dylib"
   583  //go:cgo_import_dynamic libc_kevent kevent "/usr/lib/libSystem.B.dylib"
   584  
   585  //go:cgo_import_dynamic libc_pthread_mutex_init pthread_mutex_init "/usr/lib/libSystem.B.dylib"
   586  //go:cgo_import_dynamic libc_pthread_mutex_lock pthread_mutex_lock "/usr/lib/libSystem.B.dylib"
   587  //go:cgo_import_dynamic libc_pthread_mutex_unlock pthread_mutex_unlock "/usr/lib/libSystem.B.dylib"
   588  //go:cgo_import_dynamic libc_pthread_cond_init pthread_cond_init "/usr/lib/libSystem.B.dylib"
   589  //go:cgo_import_dynamic libc_pthread_cond_wait pthread_cond_wait "/usr/lib/libSystem.B.dylib"
   590  //go:cgo_import_dynamic libc_pthread_cond_timedwait_relative_np pthread_cond_timedwait_relative_np "/usr/lib/libSystem.B.dylib"
   591  //go:cgo_import_dynamic libc_pthread_cond_signal pthread_cond_signal "/usr/lib/libSystem.B.dylib"
   592  
   593  //go:cgo_import_dynamic libc_notify_is_valid_token notify_is_valid_token "/usr/lib/libSystem.B.dylib"
   594  //go:cgo_import_dynamic libc_xpc_date_create_from_current xpc_date_create_from_current "/usr/lib/libSystem.B.dylib"