Source file 
src/runtime/sys_darwin.go
     1  
     2  
     3  
     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  
    16  
    17  
    18  
    19  
    20  func libc_error_addr(addr **int32) {
    21  	libcCall(unsafe.Pointer(abi.FuncPCABI0(libc_error_trampoline)), unsafe.Pointer(&addr))
    22  }
    23  
    24  
    25  type libcCallInfo struct {
    26  	fn     uintptr
    27  	n      uintptr 
    28  	args   uintptr 
    29  	r1, r2 uintptr 
    30  }
    31  
    32  
    33  
    34  
    35  
    36  
    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  
    45  
    46  
    47  
    48  
    49  
    50  
    51  
    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  
    74  
    75  
    76  
    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  
    91  
    92  
    93  
    94  
    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  
   103  
   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  
   113  
   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  
   122  
   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) 
   127  	return ret
   128  }
   129  func pthread_create_trampoline()
   130  
   131  
   132  
   133  func raise(sig uint32) {
   134  	libcCall(unsafe.Pointer(abi.FuncPCABI0(raise_trampoline)), unsafe.Pointer(&sig))
   135  }
   136  func raise_trampoline()
   137  
   138  
   139  
   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  
   147  
   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  
   155  
   156  
   157  
   158  
   159  
   160  
   161  
   162  
   163  
   164  
   165  
   166  
   167  
   168  
   169  
   170  
   171  
   172  
   173  
   174  
   175  
   176  
   177  
   178  
   179  
   180  
   181  
   182  
   183  
   184  
   185  
   186  
   187  func osinit_hack() {
   188  	if GOOS == "darwin" { 
   189  		libcCall(unsafe.Pointer(abi.FuncPCABI0(osinit_hack_trampoline)), nil)
   190  	}
   191  	return
   192  }
   193  func osinit_hack_trampoline()
   194  
   195  
   196  
   197  
   198  
   199  
   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  
   215  
   216  func munmap(addr unsafe.Pointer, n uintptr) {
   217  	libcCall(unsafe.Pointer(abi.FuncPCABI0(munmap_trampoline)), unsafe.Pointer(&addr))
   218  	KeepAlive(addr) 
   219  }
   220  func munmap_trampoline()
   221  
   222  
   223  
   224  func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
   225  	libcCall(unsafe.Pointer(abi.FuncPCABI0(madvise_trampoline)), unsafe.Pointer(&addr))
   226  	KeepAlive(addr) 
   227  }
   228  func madvise_trampoline()
   229  
   230  
   231  
   232  func mlock(addr unsafe.Pointer, n uintptr) {
   233  	libcCall(unsafe.Pointer(abi.FuncPCABI0(mlock_trampoline)), unsafe.Pointer(&addr))
   234  	KeepAlive(addr) 
   235  }
   236  func mlock_trampoline()
   237  
   238  
   239  
   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  
   255  
   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  
   262  
   263  
   264  
   265  
   266  func exit(code int32) {
   267  	libcCall(unsafe.Pointer(abi.FuncPCABI0(exit_trampoline)), unsafe.Pointer(&code))
   268  }
   269  func exit_trampoline()
   270  
   271  
   272  
   273  func usleep(usec uint32) {
   274  	libcCall(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
   275  }
   276  func usleep_trampoline()
   277  
   278  
   279  
   280  func usleep_no_g(usec uint32) {
   281  	asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
   282  }
   283  
   284  
   285  
   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  
   294  
   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  
   303  
   304  func nanotime1() int64 {
   305  	var r struct {
   306  		t            int64  
   307  		numer, denom uint32 
   308  	}
   309  	libcCall(unsafe.Pointer(abi.FuncPCABI0(nanotime_trampoline)), unsafe.Pointer(&r))
   310  	
   311  	
   312  	
   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  
   325  
   326  
   327  
   328  
   329  
   330  
   331  
   332  
   333  
   334  
   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  
   343  
   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  
   352  
   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  
   361  
   362  func sigaltstack(new *stackt, old *stackt) {
   363  	if new != nil && new.ss_flags&_SS_DISABLE != 0 && new.ss_size == 0 {
   364  		
   365  		
   366  		
   367  		
   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  
   377  
   378  func raiseproc(sig uint32) {
   379  	libcCall(unsafe.Pointer(abi.FuncPCABI0(raiseproc_trampoline)), unsafe.Pointer(&sig))
   380  }
   381  func raiseproc_trampoline()
   382  
   383  
   384  
   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  
   393  
   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  
   405  
   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  
   417  
   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  
   429  
   430  func kqueue() int32 {
   431  	v := libcCall(unsafe.Pointer(abi.FuncPCABI0(kqueue_trampoline)), nil)
   432  	return v
   433  }
   434  func kqueue_trampoline()
   435  
   436  
   437  
   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  
   448  
   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  
   458  
   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  
   467  
   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  
   476  
   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  
   486  
   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  
   496  
   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  
   507  
   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  
   516  
   517  func arc4random_buf(p unsafe.Pointer, n int32) {
   518  	
   519  	libcCall(unsafe.Pointer(abi.FuncPCABI0(arc4random_buf_trampoline)), unsafe.Pointer(&p))
   520  	KeepAlive(p)
   521  }
   522  func arc4random_buf_trampoline()
   523  
   524  
   525  func exitThread(wait *atomic.Uint32) {
   526  	throw("exitThread")
   527  }
   528  
   529  
   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  
   543  
   544  
   545  
   546  
   547  func mach_vm_region(address, region_size *uint64, info unsafe.Pointer) int32 {
   548  	
   549  	
   550  	
   551  	
   552  	
   553  	
   554  	
   555  	
   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  
   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  
   595  
   596  
   597  
   598  
   599  
   600  
   601  
   602  
   603  
   604  
   605  
   606  
   607  
   608  
   609  
   610  
   611  
   612  
   613  
   614  
   615  
   616  
   617  
   618  
   619  
   620  
   621  
   622  
   623  
   624  
   625  
   626  
   627  
   628  
   629  
   630  
   631  
   632  
   633  
   634  
   635  
   636  
   637  
   638  
   639  
   640  
   641  
   642  
   643  
   644  
   645  
   646  
   647  
   648  
   649  
   650  
View as plain text