github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/runtime/os2_aix.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  // This file contains main runtime AIX syscalls.
     6  // Pollset syscalls are in netpoll_aix.go.
     7  // The implementation is based on Solaris and Windows.
     8  // Each syscall is made by calling its libc symbol using asmcgocall and asmsyscall6
     9  // asssembly functions.
    10  
    11  package runtime
    12  
    13  import (
    14  	"unsafe"
    15  )
    16  
    17  // Symbols imported for __start function.
    18  
    19  //go:cgo_import_dynamic libc___n_pthreads __n_pthreads "libpthread.a/shr_xpg5_64.o"
    20  //go:cgo_import_dynamic libc___mod_init __mod_init "libc.a/shr_64.o"
    21  //go:linkname libc___n_pthreads libc___n_pthread
    22  //go:linkname libc___mod_init libc___mod_init
    23  
    24  var (
    25  	libc___n_pthread,
    26  	libc___mod_init libFunc
    27  )
    28  
    29  // Syscalls
    30  
    31  //go:cgo_import_dynamic libc__Errno _Errno "libc.a/shr_64.o"
    32  //go:cgo_import_dynamic libc_clock_gettime clock_gettime "libc.a/shr_64.o"
    33  //go:cgo_import_dynamic libc_close close "libc.a/shr_64.o"
    34  //go:cgo_import_dynamic libc_exit exit "libc.a/shr_64.o"
    35  //go:cgo_import_dynamic libc_getpid getpid "libc.a/shr_64.o"
    36  //go:cgo_import_dynamic libc_getsystemcfg getsystemcfg "libc.a/shr_64.o"
    37  //go:cgo_import_dynamic libc_kill kill "libc.a/shr_64.o"
    38  //go:cgo_import_dynamic libc_madvise madvise "libc.a/shr_64.o"
    39  //go:cgo_import_dynamic libc_malloc malloc "libc.a/shr_64.o"
    40  //go:cgo_import_dynamic libc_mmap mmap "libc.a/shr_64.o"
    41  //go:cgo_import_dynamic libc_munmap munmap "libc.a/shr_64.o"
    42  //go:cgo_import_dynamic libc_open open "libc.a/shr_64.o"
    43  //go:cgo_import_dynamic libc_pipe pipe "libc.a/shr_64.o"
    44  //go:cgo_import_dynamic libc_raise raise "libc.a/shr_64.o"
    45  //go:cgo_import_dynamic libc_read read "libc.a/shr_64.o"
    46  //go:cgo_import_dynamic libc_sched_yield sched_yield "libc.a/shr_64.o"
    47  //go:cgo_import_dynamic libc_sem_init sem_init "libc.a/shr_64.o"
    48  //go:cgo_import_dynamic libc_sem_post sem_post "libc.a/shr_64.o"
    49  //go:cgo_import_dynamic libc_sem_timedwait sem_timedwait "libc.a/shr_64.o"
    50  //go:cgo_import_dynamic libc_sem_wait sem_wait "libc.a/shr_64.o"
    51  //go:cgo_import_dynamic libc_setitimer setitimer "libc.a/shr_64.o"
    52  //go:cgo_import_dynamic libc_sigaction sigaction "libc.a/shr_64.o"
    53  //go:cgo_import_dynamic libc_sigaltstack sigaltstack "libc.a/shr_64.o"
    54  //go:cgo_import_dynamic libc_sysconf sysconf "libc.a/shr_64.o"
    55  //go:cgo_import_dynamic libc_usleep usleep "libc.a/shr_64.o"
    56  //go:cgo_import_dynamic libc_write write "libc.a/shr_64.o"
    57  
    58  //go:cgo_import_dynamic libpthread___pth_init __pth_init "libpthread.a/shr_xpg5_64.o"
    59  //go:cgo_import_dynamic libpthread_attr_destroy pthread_attr_destroy "libpthread.a/shr_xpg5_64.o"
    60  //go:cgo_import_dynamic libpthread_attr_init pthread_attr_init "libpthread.a/shr_xpg5_64.o"
    61  //go:cgo_import_dynamic libpthread_attr_getstacksize pthread_attr_getstacksize "libpthread.a/shr_xpg5_64.o"
    62  //go:cgo_import_dynamic libpthread_attr_setstacksize pthread_attr_setstacksize "libpthread.a/shr_xpg5_64.o"
    63  //go:cgo_import_dynamic libpthread_attr_setdetachstate pthread_attr_setdetachstate "libpthread.a/shr_xpg5_64.o"
    64  //go:cgo_import_dynamic libpthread_attr_setstackaddr pthread_attr_setstackaddr "libpthread.a/shr_xpg5_64.o"
    65  //go:cgo_import_dynamic libpthread_create pthread_create "libpthread.a/shr_xpg5_64.o"
    66  //go:cgo_import_dynamic libpthread_sigthreadmask sigthreadmask "libpthread.a/shr_xpg5_64.o"
    67  
    68  //go:linkname libc__Errno libc__Errno
    69  //go:linkname libc_clock_gettime libc_clock_gettime
    70  //go:linkname libc_close libc_close
    71  //go:linkname libc_exit libc_exit
    72  //go:linkname libc_getpid libc_getpid
    73  //go:linkname libc_getsystemcfg libc_getsystemcfg
    74  //go:linkname libc_kill libc_kill
    75  //go:linkname libc_madvise libc_madvise
    76  //go:linkname libc_malloc libc_malloc
    77  //go:linkname libc_mmap libc_mmap
    78  //go:linkname libc_munmap libc_munmap
    79  //go:linkname libc_open libc_open
    80  //go:linkname libc_pipe libc_pipe
    81  //go:linkname libc_raise libc_raise
    82  //go:linkname libc_read libc_read
    83  //go:linkname libc_sched_yield libc_sched_yield
    84  //go:linkname libc_sem_init libc_sem_init
    85  //go:linkname libc_sem_post libc_sem_post
    86  //go:linkname libc_sem_timedwait libc_sem_timedwait
    87  //go:linkname libc_sem_wait libc_sem_wait
    88  //go:linkname libc_setitimer libc_setitimer
    89  //go:linkname libc_sigaction libc_sigaction
    90  //go:linkname libc_sigaltstack libc_sigaltstack
    91  //go:linkname libc_sysconf libc_sysconf
    92  //go:linkname libc_usleep libc_usleep
    93  //go:linkname libc_write libc_write
    94  
    95  //go:linkname libpthread___pth_init libpthread___pth_init
    96  //go:linkname libpthread_attr_destroy libpthread_attr_destroy
    97  //go:linkname libpthread_attr_init libpthread_attr_init
    98  //go:linkname libpthread_attr_getstacksize libpthread_attr_getstacksize
    99  //go:linkname libpthread_attr_setstacksize libpthread_attr_setstacksize
   100  //go:linkname libpthread_attr_setdetachstate libpthread_attr_setdetachstate
   101  //go:linkname libpthread_attr_setstackaddr libpthread_attr_setstackaddr
   102  //go:linkname libpthread_create libpthread_create
   103  //go:linkname libpthread_sigthreadmask libpthread_sigthreadmask
   104  
   105  var (
   106  	//libc
   107  	libc__Errno,
   108  	libc_clock_gettime,
   109  	libc_close,
   110  	libc_exit,
   111  	libc_getpid,
   112  	libc_getsystemcfg,
   113  	libc_kill,
   114  	libc_madvise,
   115  	libc_malloc,
   116  	libc_mmap,
   117  	libc_munmap,
   118  	libc_open,
   119  	libc_pipe,
   120  	libc_raise,
   121  	libc_read,
   122  	libc_sched_yield,
   123  	libc_sem_init,
   124  	libc_sem_post,
   125  	libc_sem_timedwait,
   126  	libc_sem_wait,
   127  	libc_setitimer,
   128  	libc_sigaction,
   129  	libc_sigaltstack,
   130  	libc_sysconf,
   131  	libc_usleep,
   132  	libc_write,
   133  	//libpthread
   134  	libpthread___pth_init,
   135  	libpthread_attr_destroy,
   136  	libpthread_attr_init,
   137  	libpthread_attr_getstacksize,
   138  	libpthread_attr_setstacksize,
   139  	libpthread_attr_setdetachstate,
   140  	libpthread_attr_setstackaddr,
   141  	libpthread_create,
   142  	libpthread_sigthreadmask libFunc
   143  )
   144  
   145  type libFunc uintptr
   146  
   147  // asmsyscall6 calls the libc symbol using a C convention.
   148  // It's defined in sys_aix_ppc64.go.
   149  var asmsyscall6 libFunc
   150  
   151  //go:nowritebarrier
   152  //go:nosplit
   153  func syscall0(fn *libFunc) (r, err uintptr) {
   154  	gp := getg()
   155  	var mp *m
   156  	if gp != nil {
   157  		mp = gp.m
   158  	}
   159  	if mp != nil && mp.libcallsp == 0 {
   160  		mp.libcallg.set(gp)
   161  		mp.libcallpc = getcallerpc()
   162  		// sp must be the last, because once async cpu profiler finds
   163  		// all three values to be non-zero, it will use them
   164  		mp.libcallsp = getcallersp()
   165  	} else {
   166  		mp = nil // See comment in sys_darwin.go:libcCall
   167  	}
   168  
   169  	c := &gp.m.libcall
   170  	c.fn = uintptr(unsafe.Pointer(fn))
   171  	c.n = 0
   172  	c.args = uintptr(noescape(unsafe.Pointer(&fn))) // it's unused but must be non-nil, otherwise crashes
   173  
   174  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   175  
   176  	if mp != nil {
   177  		mp.libcallsp = 0
   178  	}
   179  
   180  	return c.r1, c.err
   181  }
   182  
   183  //go:nowritebarrier
   184  //go:nosplit
   185  func syscall1(fn *libFunc, a0 uintptr) (r, err uintptr) {
   186  	gp := getg()
   187  	var mp *m
   188  	if gp != nil {
   189  		mp = gp.m
   190  	}
   191  	if mp != nil && mp.libcallsp == 0 {
   192  		mp.libcallg.set(gp)
   193  		mp.libcallpc = getcallerpc()
   194  		// sp must be the last, because once async cpu profiler finds
   195  		// all three values to be non-zero, it will use them
   196  		mp.libcallsp = getcallersp()
   197  	} else {
   198  		mp = nil // See comment in sys_darwin.go:libcCall
   199  	}
   200  
   201  	c := &gp.m.libcall
   202  	c.fn = uintptr(unsafe.Pointer(fn))
   203  	c.n = 1
   204  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   205  
   206  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   207  
   208  	if mp != nil {
   209  		mp.libcallsp = 0
   210  	}
   211  
   212  	return c.r1, c.err
   213  }
   214  
   215  //go:nowritebarrier
   216  //go:nosplit
   217  func syscall2(fn *libFunc, a0, a1 uintptr) (r, err uintptr) {
   218  	gp := getg()
   219  	var mp *m
   220  	if gp != nil {
   221  		mp = gp.m
   222  	}
   223  	if mp != nil && mp.libcallsp == 0 {
   224  		mp.libcallg.set(gp)
   225  		mp.libcallpc = getcallerpc()
   226  		// sp must be the last, because once async cpu profiler finds
   227  		// all three values to be non-zero, it will use them
   228  		mp.libcallsp = getcallersp()
   229  	} else {
   230  		mp = nil // See comment in sys_darwin.go:libcCall
   231  	}
   232  
   233  	c := &gp.m.libcall
   234  	c.fn = uintptr(unsafe.Pointer(fn))
   235  	c.n = 2
   236  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   237  
   238  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   239  
   240  	if mp != nil {
   241  		mp.libcallsp = 0
   242  	}
   243  
   244  	return c.r1, c.err
   245  }
   246  
   247  //go:nowritebarrier
   248  //go:nosplit
   249  func syscall3(fn *libFunc, a0, a1, a2 uintptr) (r, err uintptr) {
   250  	gp := getg()
   251  	var mp *m
   252  	if gp != nil {
   253  		mp = gp.m
   254  	}
   255  	if mp != nil && mp.libcallsp == 0 {
   256  		mp.libcallg.set(gp)
   257  		mp.libcallpc = getcallerpc()
   258  		// sp must be the last, because once async cpu profiler finds
   259  		// all three values to be non-zero, it will use them
   260  		mp.libcallsp = getcallersp()
   261  	} else {
   262  		mp = nil // See comment in sys_darwin.go:libcCall
   263  	}
   264  
   265  	c := &gp.m.libcall
   266  	c.fn = uintptr(unsafe.Pointer(fn))
   267  	c.n = 3
   268  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   269  
   270  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   271  
   272  	if mp != nil {
   273  		mp.libcallsp = 0
   274  	}
   275  
   276  	return c.r1, c.err
   277  }
   278  
   279  //go:nowritebarrier
   280  //go:nosplit
   281  func syscall4(fn *libFunc, a0, a1, a2, a3 uintptr) (r, err uintptr) {
   282  	gp := getg()
   283  	var mp *m
   284  	if gp != nil {
   285  		mp = gp.m
   286  	}
   287  	if mp != nil && mp.libcallsp == 0 {
   288  		mp.libcallg.set(gp)
   289  		mp.libcallpc = getcallerpc()
   290  		// sp must be the last, because once async cpu profiler finds
   291  		// all three values to be non-zero, it will use them
   292  		mp.libcallsp = getcallersp()
   293  	} else {
   294  		mp = nil // See comment in sys_darwin.go:libcCall
   295  	}
   296  
   297  	c := &gp.m.libcall
   298  	c.fn = uintptr(unsafe.Pointer(fn))
   299  	c.n = 4
   300  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   301  
   302  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   303  
   304  	if mp != nil {
   305  		mp.libcallsp = 0
   306  	}
   307  
   308  	return c.r1, c.err
   309  }
   310  
   311  //go:nowritebarrier
   312  //go:nosplit
   313  func syscall5(fn *libFunc, a0, a1, a2, a3, a4 uintptr) (r, err uintptr) {
   314  	gp := getg()
   315  	var mp *m
   316  	if gp != nil {
   317  		mp = gp.m
   318  	}
   319  	if mp != nil && mp.libcallsp == 0 {
   320  		mp.libcallg.set(gp)
   321  		mp.libcallpc = getcallerpc()
   322  		// sp must be the last, because once async cpu profiler finds
   323  		// all three values to be non-zero, it will use them
   324  		mp.libcallsp = getcallersp()
   325  	} else {
   326  		mp = nil // See comment in sys_darwin.go:libcCall
   327  	}
   328  
   329  	c := &gp.m.libcall
   330  	c.fn = uintptr(unsafe.Pointer(fn))
   331  	c.n = 5
   332  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   333  
   334  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   335  
   336  	if mp != nil {
   337  		mp.libcallsp = 0
   338  	}
   339  
   340  	return c.r1, c.err
   341  }
   342  
   343  //go:nowritebarrier
   344  //go:nosplit
   345  func syscall6(fn *libFunc, a0, a1, a2, a3, a4, a5 uintptr) (r, err uintptr) {
   346  	gp := getg()
   347  	var mp *m
   348  	if gp != nil {
   349  		mp = gp.m
   350  	}
   351  	if mp != nil && mp.libcallsp == 0 {
   352  		mp.libcallg.set(gp)
   353  		mp.libcallpc = getcallerpc()
   354  		// sp must be the last, because once async cpu profiler finds
   355  		// all three values to be non-zero, it will use them
   356  		mp.libcallsp = getcallersp()
   357  	} else {
   358  		mp = nil // See comment in sys_darwin.go:libcCall
   359  	}
   360  
   361  	c := &gp.m.libcall
   362  	c.fn = uintptr(unsafe.Pointer(fn))
   363  	c.n = 6
   364  	c.args = uintptr(noescape(unsafe.Pointer(&a0)))
   365  
   366  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(c))
   367  
   368  	if mp != nil {
   369  		mp.libcallsp = 0
   370  	}
   371  
   372  	return c.r1, c.err
   373  }
   374  
   375  //go:nosplit
   376  func exit(code int32) {
   377  	syscall1(&libc_exit, uintptr(code))
   378  }
   379  
   380  //go:nosplit
   381  func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
   382  	r, _ := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
   383  	return int32(r)
   384  
   385  }
   386  
   387  //go:nosplit
   388  func read(fd int32, p unsafe.Pointer, n int32) int32 {
   389  	r, _ := syscall3(&libc_read, uintptr(fd), uintptr(p), uintptr(n))
   390  	return int32(r)
   391  }
   392  
   393  //go:nosplit
   394  func open(name *byte, mode, perm int32) int32 {
   395  	r, _ := syscall3(&libc_open, uintptr(unsafe.Pointer(name)), uintptr(mode), uintptr(perm))
   396  	return int32(r)
   397  }
   398  
   399  //go:nosplit
   400  func closefd(fd int32) int32 {
   401  	r, _ := syscall1(&libc_close, uintptr(fd))
   402  	return int32(r)
   403  }
   404  
   405  //go:nosplit
   406  func pipe(fd *int32) int32 {
   407  	r, _ := syscall1(&libc_pipe, uintptr(unsafe.Pointer(fd)))
   408  	return int32(r)
   409  }
   410  
   411  // mmap calls the mmap system call.
   412  // We only pass the lower 32 bits of file offset to the
   413  // assembly routine; the higher bits (if required), should be provided
   414  // by the assembly routine as 0.
   415  // The err result is an OS error code such as ENOMEM.
   416  //go:nosplit
   417  func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int) {
   418  	r, err0 := syscall6(&libc_mmap, uintptr(addr), uintptr(n), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off))
   419  	return unsafe.Pointer(r), int(err0)
   420  }
   421  
   422  //go:nosplit
   423  func munmap(addr unsafe.Pointer, n uintptr) {
   424  	r, err := syscall2(&libc_munmap, uintptr(addr), uintptr(n))
   425  	if int32(r) == -1 {
   426  		println("syscall munmap failed: ", hex(err))
   427  		throw("syscall munmap")
   428  	}
   429  }
   430  
   431  //go:nosplit
   432  func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
   433  	r, err := syscall3(&libc_madvise, uintptr(addr), uintptr(n), uintptr(flags))
   434  	if int32(r) == -1 {
   435  		println("syscall madvise failed: ", hex(err))
   436  		throw("syscall madvise")
   437  	}
   438  }
   439  
   440  //go:nosplit
   441  func sigaction(sig uintptr, new, old *sigactiont) {
   442  	r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   443  	if int32(r) == -1 {
   444  		println("Sigaction failed for sig: ", sig, " with error:", hex(err))
   445  		throw("syscall sigaction")
   446  	}
   447  }
   448  
   449  //go:nosplit
   450  func sigaltstack(new, old *stackt) {
   451  	r, err := syscall2(&libc_sigaltstack, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   452  	if int32(r) == -1 {
   453  		println("syscall sigaltstack failed: ", hex(err))
   454  		throw("syscall sigaltstack")
   455  	}
   456  }
   457  
   458  //go:nosplit
   459  func getsystemcfg(label uint) uintptr {
   460  	r, _ := syscall1(&libc_getsystemcfg, uintptr(label))
   461  	return r
   462  }
   463  
   464  //go:nosplit
   465  func usleep(us uint32) {
   466  	r, err := syscall1(&libc_usleep, uintptr(us))
   467  	if int32(r) == -1 {
   468  		println("syscall usleep failed: ", hex(err))
   469  		throw("syscall usleep")
   470  	}
   471  }
   472  
   473  //go:nosplit
   474  func clock_gettime(clockid int32, tp *timespec) int32 {
   475  	r, _ := syscall2(&libc_clock_gettime, uintptr(clockid), uintptr(unsafe.Pointer(tp)))
   476  	return int32(r)
   477  }
   478  
   479  //go:nosplit
   480  func setitimer(mode int32, new, old *itimerval) {
   481  	r, err := syscall3(&libc_setitimer, uintptr(mode), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   482  	if int32(r) == -1 {
   483  		println("syscall setitimer failed: ", hex(err))
   484  		throw("syscall setitimer")
   485  	}
   486  }
   487  
   488  //go:nosplit
   489  func malloc(size uintptr) unsafe.Pointer {
   490  	r, _ := syscall1(&libc_malloc, size)
   491  	return unsafe.Pointer(r)
   492  }
   493  
   494  //go:nosplit
   495  func sem_init(sem *semt, pshared int32, value uint32) int32 {
   496  	r, _ := syscall3(&libc_sem_init, uintptr(unsafe.Pointer(sem)), uintptr(pshared), uintptr(value))
   497  	return int32(r)
   498  }
   499  
   500  //go:nosplit
   501  func sem_wait(sem *semt) (int32, int32) {
   502  	r, err := syscall1(&libc_sem_wait, uintptr(unsafe.Pointer(sem)))
   503  	return int32(r), int32(err)
   504  }
   505  
   506  //go:nosplit
   507  func sem_post(sem *semt) int32 {
   508  	r, _ := syscall1(&libc_sem_post, uintptr(unsafe.Pointer(sem)))
   509  	return int32(r)
   510  }
   511  
   512  //go:nosplit
   513  func sem_timedwait(sem *semt, timeout *timespec) (int32, int32) {
   514  	r, err := syscall2(&libc_sem_timedwait, uintptr(unsafe.Pointer(sem)), uintptr(unsafe.Pointer(timeout)))
   515  	return int32(r), int32(err)
   516  }
   517  
   518  //go:nosplit
   519  func raise(sig uint32) {
   520  	r, err := syscall1(&libc_raise, uintptr(sig))
   521  	if int32(r) == -1 {
   522  		println("syscall raise failed: ", hex(err))
   523  		throw("syscall raise")
   524  	}
   525  }
   526  
   527  //go:nosplit
   528  func raiseproc(sig uint32) {
   529  	pid, err := syscall0(&libc_getpid)
   530  	if int32(pid) == -1 {
   531  		println("syscall getpid failed: ", hex(err))
   532  		throw("syscall raiseproc")
   533  	}
   534  
   535  	syscall2(&libc_kill, pid, uintptr(sig))
   536  }
   537  
   538  func osyield1()
   539  
   540  //go:nosplit
   541  func osyield() {
   542  	_g_ := getg()
   543  
   544  	// Check the validity of m because we might be called in cgo callback
   545  	// path early enough where there isn't a m available yet.
   546  	if _g_ != nil && _g_.m != nil {
   547  		r, err := syscall0(&libc_sched_yield)
   548  		if int32(r) == -1 {
   549  			println("syscall osyield failed: ", hex(err))
   550  			throw("syscall osyield")
   551  		}
   552  		return
   553  	}
   554  	osyield1()
   555  }
   556  
   557  //go:nosplit
   558  func sysconf(name int32) uintptr {
   559  	r, _ := syscall1(&libc_sysconf, uintptr(name))
   560  	if int32(r) == -1 {
   561  		throw("syscall sysconf")
   562  	}
   563  	return r
   564  
   565  }
   566  
   567  // pthread functions returns its error code in the main return value
   568  // Therefore, err returns by syscall means nothing and must not be used
   569  
   570  //go:nosplit
   571  func pthread_attr_destroy(attr *pthread_attr) int32 {
   572  	r, _ := syscall1(&libpthread_attr_destroy, uintptr(unsafe.Pointer(attr)))
   573  	return int32(r)
   574  }
   575  
   576  //go:nosplit
   577  func pthread_attr_init(attr *pthread_attr) int32 {
   578  	r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
   579  	return int32(r)
   580  }
   581  
   582  //go:nosplit
   583  func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
   584  	r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
   585  	return int32(r)
   586  }
   587  
   588  //go:nosplit
   589  func pthread_attr_setstackaddr(attr *pthread_attr, stk unsafe.Pointer) int32 {
   590  	r, _ := syscall2(&libpthread_attr_setstackaddr, uintptr(unsafe.Pointer(attr)), uintptr(stk))
   591  	return int32(r)
   592  }
   593  
   594  //go:nosplit
   595  func pthread_attr_getstacksize(attr *pthread_attr, size *uint64) int32 {
   596  	r, _ := syscall2(&libpthread_attr_getstacksize, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(size)))
   597  	return int32(r)
   598  }
   599  
   600  //go:nosplit
   601  func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
   602  	r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
   603  	return int32(r)
   604  }
   605  
   606  //go:nosplit
   607  func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
   608  	r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
   609  	return int32(r)
   610  }
   611  
   612  // On multi-thread program, sigprocmask must not be called.
   613  // It's replaced by sigthreadmask.
   614  //go:nosplit
   615  func sigprocmask(how int32, new, old *sigset) {
   616  	r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   617  	if int32(r) != 0 {
   618  		println("syscall sigthreadmask failed: ", hex(err))
   619  		throw("syscall sigthreadmask")
   620  	}
   621  }