Source file src/runtime/sys_darwin.go

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

View as plain text