...

Source file src/runtime/os2_aix.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	// 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	// syscallX functions must always be called with g != nil and m != nil,
   152	// as it relies on g.m.libcall to pass arguments to asmcgocall.
   153	// The few cases where syscalls haven't a g or a m must call their equivalent
   154	// function in sys_aix_ppc64.s to handle them.
   155	
   156	//go:nowritebarrier
   157	//go:nosplit
   158	func syscall0(fn *libFunc) (r, err uintptr) {
   159		gp := getg()
   160		mp := gp.m
   161		resetLibcall := true
   162		if mp.libcallsp == 0 {
   163			mp.libcallg.set(gp)
   164			mp.libcallpc = getcallerpc()
   165			// sp must be the last, because once async cpu profiler finds
   166			// all three values to be non-zero, it will use them
   167			mp.libcallsp = getcallersp()
   168		} else {
   169			resetLibcall = false // See comment in sys_darwin.go:libcCall
   170		}
   171	
   172		c := libcall{
   173			fn:   uintptr(unsafe.Pointer(fn)),
   174			n:    0,
   175			args: uintptr(unsafe.Pointer(&fn)), // it's unused but must be non-nil, otherwise crashes
   176		}
   177	
   178		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   179	
   180		if resetLibcall {
   181			mp.libcallsp = 0
   182		}
   183	
   184		return c.r1, c.err
   185	}
   186	
   187	//go:nowritebarrier
   188	//go:nosplit
   189	func syscall1(fn *libFunc, a0 uintptr) (r, err uintptr) {
   190		gp := getg()
   191		mp := gp.m
   192		resetLibcall := true
   193		if mp.libcallsp == 0 {
   194			mp.libcallg.set(gp)
   195			mp.libcallpc = getcallerpc()
   196			// sp must be the last, because once async cpu profiler finds
   197			// all three values to be non-zero, it will use them
   198			mp.libcallsp = getcallersp()
   199		} else {
   200			resetLibcall = false // See comment in sys_darwin.go:libcCall
   201		}
   202	
   203		c := libcall{
   204			fn:   uintptr(unsafe.Pointer(fn)),
   205			n:    1,
   206			args: uintptr(unsafe.Pointer(&a0)),
   207		}
   208	
   209		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   210	
   211		if resetLibcall {
   212			mp.libcallsp = 0
   213		}
   214	
   215		return c.r1, c.err
   216	}
   217	
   218	//go:nowritebarrier
   219	//go:nosplit
   220	//go:cgo_unsafe_args
   221	func syscall2(fn *libFunc, a0, a1 uintptr) (r, err uintptr) {
   222		gp := getg()
   223		mp := gp.m
   224		resetLibcall := true
   225		if mp.libcallsp == 0 {
   226			mp.libcallg.set(gp)
   227			mp.libcallpc = getcallerpc()
   228			// sp must be the last, because once async cpu profiler finds
   229			// all three values to be non-zero, it will use them
   230			mp.libcallsp = getcallersp()
   231		} else {
   232			resetLibcall = false // See comment in sys_darwin.go:libcCall
   233		}
   234	
   235		c := libcall{
   236			fn:   uintptr(unsafe.Pointer(fn)),
   237			n:    2,
   238			args: uintptr(unsafe.Pointer(&a0)),
   239		}
   240	
   241		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   242	
   243		if resetLibcall {
   244			mp.libcallsp = 0
   245		}
   246	
   247		return c.r1, c.err
   248	}
   249	
   250	//go:nowritebarrier
   251	//go:nosplit
   252	//go:cgo_unsafe_args
   253	func syscall3(fn *libFunc, a0, a1, a2 uintptr) (r, err uintptr) {
   254		gp := getg()
   255		mp := gp.m
   256		resetLibcall := true
   257		if mp.libcallsp == 0 {
   258			mp.libcallg.set(gp)
   259			mp.libcallpc = getcallerpc()
   260			// sp must be the last, because once async cpu profiler finds
   261			// all three values to be non-zero, it will use them
   262			mp.libcallsp = getcallersp()
   263		} else {
   264			resetLibcall = false // See comment in sys_darwin.go:libcCall
   265		}
   266	
   267		c := libcall{
   268			fn:   uintptr(unsafe.Pointer(fn)),
   269			n:    3,
   270			args: uintptr(unsafe.Pointer(&a0)),
   271		}
   272	
   273		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   274	
   275		if resetLibcall {
   276			mp.libcallsp = 0
   277		}
   278	
   279		return c.r1, c.err
   280	}
   281	
   282	//go:nowritebarrier
   283	//go:nosplit
   284	//go:cgo_unsafe_args
   285	func syscall4(fn *libFunc, a0, a1, a2, a3 uintptr) (r, err uintptr) {
   286		gp := getg()
   287		mp := gp.m
   288		resetLibcall := true
   289		if mp.libcallsp == 0 {
   290			mp.libcallg.set(gp)
   291			mp.libcallpc = getcallerpc()
   292			// sp must be the last, because once async cpu profiler finds
   293			// all three values to be non-zero, it will use them
   294			mp.libcallsp = getcallersp()
   295		} else {
   296			resetLibcall = false // See comment in sys_darwin.go:libcCall
   297		}
   298	
   299		c := libcall{
   300			fn:   uintptr(unsafe.Pointer(fn)),
   301			n:    4,
   302			args: uintptr(unsafe.Pointer(&a0)),
   303		}
   304	
   305		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   306	
   307		if resetLibcall {
   308			mp.libcallsp = 0
   309		}
   310	
   311		return c.r1, c.err
   312	}
   313	
   314	//go:nowritebarrier
   315	//go:nosplit
   316	//go:cgo_unsafe_args
   317	func syscall5(fn *libFunc, a0, a1, a2, a3, a4 uintptr) (r, err uintptr) {
   318		gp := getg()
   319		mp := gp.m
   320		resetLibcall := true
   321		if mp.libcallsp == 0 {
   322			mp.libcallg.set(gp)
   323			mp.libcallpc = getcallerpc()
   324			// sp must be the last, because once async cpu profiler finds
   325			// all three values to be non-zero, it will use them
   326			mp.libcallsp = getcallersp()
   327		} else {
   328			resetLibcall = false // See comment in sys_darwin.go:libcCall
   329		}
   330	
   331		c := libcall{
   332			fn:   uintptr(unsafe.Pointer(fn)),
   333			n:    5,
   334			args: uintptr(unsafe.Pointer(&a0)),
   335		}
   336	
   337		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   338	
   339		if resetLibcall {
   340			mp.libcallsp = 0
   341		}
   342	
   343		return c.r1, c.err
   344	}
   345	
   346	//go:nowritebarrier
   347	//go:nosplit
   348	//go:cgo_unsafe_args
   349	func syscall6(fn *libFunc, a0, a1, a2, a3, a4, a5 uintptr) (r, err uintptr) {
   350		gp := getg()
   351		mp := gp.m
   352		resetLibcall := true
   353		if mp.libcallsp == 0 {
   354			mp.libcallg.set(gp)
   355			mp.libcallpc = getcallerpc()
   356			// sp must be the last, because once async cpu profiler finds
   357			// all three values to be non-zero, it will use them
   358			mp.libcallsp = getcallersp()
   359		} else {
   360			resetLibcall = false // See comment in sys_darwin.go:libcCall
   361		}
   362	
   363		c := libcall{
   364			fn:   uintptr(unsafe.Pointer(fn)),
   365			n:    6,
   366			args: uintptr(unsafe.Pointer(&a0)),
   367		}
   368	
   369		asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
   370	
   371		if resetLibcall {
   372			mp.libcallsp = 0
   373		}
   374	
   375		return c.r1, c.err
   376	}
   377	
   378	func exit1(code int32)
   379	
   380	//go:nosplit
   381	func exit(code int32) {
   382		_g_ := getg()
   383	
   384		// Check the validity of g because without a g during
   385		// newosproc0.
   386		if _g_ != nil {
   387			syscall1(&libc_exit, uintptr(code))
   388			return
   389		}
   390		exit1(code)
   391	}
   392	
   393	func write1(fd, p uintptr, n int32) int32
   394	
   395	//go:nosplit
   396	func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
   397		_g_ := getg()
   398	
   399		// Check the validity of g because without a g during
   400		// newosproc0.
   401		if _g_ != nil {
   402			r, _ := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
   403			return int32(r)
   404		}
   405		return write1(fd, uintptr(p), n)
   406	
   407	}
   408	
   409	//go:nosplit
   410	func read(fd int32, p unsafe.Pointer, n int32) int32 {
   411		r, _ := syscall3(&libc_read, uintptr(fd), uintptr(p), uintptr(n))
   412		return int32(r)
   413	}
   414	
   415	//go:nosplit
   416	func open(name *byte, mode, perm int32) int32 {
   417		r, _ := syscall3(&libc_open, uintptr(unsafe.Pointer(name)), uintptr(mode), uintptr(perm))
   418		return int32(r)
   419	}
   420	
   421	//go:nosplit
   422	func closefd(fd int32) int32 {
   423		r, _ := syscall1(&libc_close, uintptr(fd))
   424		return int32(r)
   425	}
   426	
   427	//go:nosplit
   428	func pipe(fd *int32) int32 {
   429		r, _ := syscall1(&libc_pipe, uintptr(unsafe.Pointer(fd)))
   430		return int32(r)
   431	}
   432	
   433	// mmap calls the mmap system call.
   434	// We only pass the lower 32 bits of file offset to the
   435	// assembly routine; the higher bits (if required), should be provided
   436	// by the assembly routine as 0.
   437	// The err result is an OS error code such as ENOMEM.
   438	//go:nosplit
   439	func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
   440		r, err0 := syscall6(&libc_mmap, uintptr(addr), uintptr(n), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off))
   441		if r == ^uintptr(0) {
   442			return nil, int(err0)
   443		}
   444		return unsafe.Pointer(r), int(err0)
   445	}
   446	
   447	//go:nosplit
   448	func munmap(addr unsafe.Pointer, n uintptr) {
   449		r, err := syscall2(&libc_munmap, uintptr(addr), uintptr(n))
   450		if int32(r) == -1 {
   451			println("syscall munmap failed: ", hex(err))
   452			throw("syscall munmap")
   453		}
   454	}
   455	
   456	//go:nosplit
   457	func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
   458		r, err := syscall3(&libc_madvise, uintptr(addr), uintptr(n), uintptr(flags))
   459		if int32(r) == -1 {
   460			println("syscall madvise failed: ", hex(err))
   461			throw("syscall madvise")
   462		}
   463	}
   464	
   465	func sigaction1(sig, new, old uintptr)
   466	
   467	//go:nosplit
   468	func sigaction(sig uintptr, new, old *sigactiont) {
   469		_g_ := getg()
   470	
   471		// Check the validity of g because without a g during
   472		// runtime.libpreinit.
   473		if _g_ != nil {
   474			r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   475			if int32(r) == -1 {
   476				println("Sigaction failed for sig: ", sig, " with error:", hex(err))
   477				throw("syscall sigaction")
   478			}
   479			return
   480		}
   481	
   482		sigaction1(sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   483	}
   484	
   485	//go:nosplit
   486	func sigaltstack(new, old *stackt) {
   487		r, err := syscall2(&libc_sigaltstack, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   488		if int32(r) == -1 {
   489			println("syscall sigaltstack failed: ", hex(err))
   490			throw("syscall sigaltstack")
   491		}
   492	}
   493	
   494	//go:nosplit
   495	func getsystemcfg(label uint) uintptr {
   496		r, _ := syscall1(&libc_getsystemcfg, uintptr(label))
   497		return r
   498	}
   499	
   500	func usleep1(us uint32)
   501	
   502	//go:nosplit
   503	func usleep(us uint32) {
   504		_g_ := getg()
   505	
   506		// Check the validity of m because we might be called in cgo callback
   507		// path early enough where there isn't a g or a m available yet.
   508		if _g_ != nil && _g_.m != nil {
   509			r, err := syscall1(&libc_usleep, uintptr(us))
   510			if int32(r) == -1 {
   511				println("syscall usleep failed: ", hex(err))
   512				throw("syscall usleep")
   513			}
   514			return
   515		}
   516		usleep1(us)
   517	}
   518	
   519	//go:nosplit
   520	func clock_gettime(clockid int32, tp *timespec) int32 {
   521		r, _ := syscall2(&libc_clock_gettime, uintptr(clockid), uintptr(unsafe.Pointer(tp)))
   522		return int32(r)
   523	}
   524	
   525	//go:nosplit
   526	func setitimer(mode int32, new, old *itimerval) {
   527		r, err := syscall3(&libc_setitimer, uintptr(mode), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   528		if int32(r) == -1 {
   529			println("syscall setitimer failed: ", hex(err))
   530			throw("syscall setitimer")
   531		}
   532	}
   533	
   534	//go:nosplit
   535	func malloc(size uintptr) unsafe.Pointer {
   536		r, _ := syscall1(&libc_malloc, size)
   537		return unsafe.Pointer(r)
   538	}
   539	
   540	//go:nosplit
   541	func sem_init(sem *semt, pshared int32, value uint32) int32 {
   542		r, _ := syscall3(&libc_sem_init, uintptr(unsafe.Pointer(sem)), uintptr(pshared), uintptr(value))
   543		return int32(r)
   544	}
   545	
   546	//go:nosplit
   547	func sem_wait(sem *semt) (int32, int32) {
   548		r, err := syscall1(&libc_sem_wait, uintptr(unsafe.Pointer(sem)))
   549		return int32(r), int32(err)
   550	}
   551	
   552	//go:nosplit
   553	func sem_post(sem *semt) int32 {
   554		r, _ := syscall1(&libc_sem_post, uintptr(unsafe.Pointer(sem)))
   555		return int32(r)
   556	}
   557	
   558	//go:nosplit
   559	func sem_timedwait(sem *semt, timeout *timespec) (int32, int32) {
   560		r, err := syscall2(&libc_sem_timedwait, uintptr(unsafe.Pointer(sem)), uintptr(unsafe.Pointer(timeout)))
   561		return int32(r), int32(err)
   562	}
   563	
   564	//go:nosplit
   565	func raise(sig uint32) {
   566		r, err := syscall1(&libc_raise, uintptr(sig))
   567		if int32(r) == -1 {
   568			println("syscall raise failed: ", hex(err))
   569			throw("syscall raise")
   570		}
   571	}
   572	
   573	//go:nosplit
   574	func raiseproc(sig uint32) {
   575		pid, err := syscall0(&libc_getpid)
   576		if int32(pid) == -1 {
   577			println("syscall getpid failed: ", hex(err))
   578			throw("syscall raiseproc")
   579		}
   580	
   581		syscall2(&libc_kill, pid, uintptr(sig))
   582	}
   583	
   584	func osyield1()
   585	
   586	//go:nosplit
   587	func osyield() {
   588		_g_ := getg()
   589	
   590		// Check the validity of m because it might be called during a cgo
   591		// callback early enough where m isn't available yet.
   592		if _g_ != nil && _g_.m != nil {
   593			r, err := syscall0(&libc_sched_yield)
   594			if int32(r) == -1 {
   595				println("syscall osyield failed: ", hex(err))
   596				throw("syscall osyield")
   597			}
   598			return
   599		}
   600		osyield1()
   601	}
   602	
   603	//go:nosplit
   604	func sysconf(name int32) uintptr {
   605		r, _ := syscall1(&libc_sysconf, uintptr(name))
   606		if int32(r) == -1 {
   607			throw("syscall sysconf")
   608		}
   609		return r
   610	
   611	}
   612	
   613	// pthread functions returns its error code in the main return value
   614	// Therefore, err returns by syscall means nothing and must not be used
   615	
   616	//go:nosplit
   617	func pthread_attr_destroy(attr *pthread_attr) int32 {
   618		r, _ := syscall1(&libpthread_attr_destroy, uintptr(unsafe.Pointer(attr)))
   619		return int32(r)
   620	}
   621	
   622	func pthread_attr_init1(attr uintptr) int32
   623	
   624	//go:nosplit
   625	func pthread_attr_init(attr *pthread_attr) int32 {
   626		_g_ := getg()
   627	
   628		// Check the validity of g because without a g during
   629		// newosproc0.
   630		if _g_ != nil {
   631			r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
   632			return int32(r)
   633		}
   634	
   635		return pthread_attr_init1(uintptr(unsafe.Pointer(attr)))
   636	}
   637	
   638	func pthread_attr_setdetachstate1(attr uintptr, state int32) int32
   639	
   640	//go:nosplit
   641	func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
   642		_g_ := getg()
   643	
   644		// Check the validity of g because without a g during
   645		// newosproc0.
   646		if _g_ != nil {
   647			r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
   648			return int32(r)
   649		}
   650	
   651		return pthread_attr_setdetachstate1(uintptr(unsafe.Pointer(attr)), state)
   652	}
   653	
   654	//go:nosplit
   655	func pthread_attr_setstackaddr(attr *pthread_attr, stk unsafe.Pointer) int32 {
   656		r, _ := syscall2(&libpthread_attr_setstackaddr, uintptr(unsafe.Pointer(attr)), uintptr(stk))
   657		return int32(r)
   658	}
   659	
   660	//go:nosplit
   661	func pthread_attr_getstacksize(attr *pthread_attr, size *uint64) int32 {
   662		r, _ := syscall2(&libpthread_attr_getstacksize, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(size)))
   663		return int32(r)
   664	}
   665	
   666	func pthread_attr_setstacksize1(attr uintptr, size uint64) int32
   667	
   668	//go:nosplit
   669	func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
   670		_g_ := getg()
   671	
   672		// Check the validity of g because without a g during
   673		// newosproc0.
   674		if _g_ != nil {
   675			r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
   676			return int32(r)
   677		}
   678	
   679		return pthread_attr_setstacksize1(uintptr(unsafe.Pointer(attr)), size)
   680	}
   681	
   682	func pthread_create1(tid, attr, fn, arg uintptr) int32
   683	
   684	//go:nosplit
   685	func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
   686		_g_ := getg()
   687	
   688		// Check the validity of g because without a g during
   689		// newosproc0.
   690		if _g_ != nil {
   691			r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
   692			return int32(r)
   693		}
   694	
   695		return pthread_create1(uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
   696	}
   697	
   698	// On multi-thread program, sigprocmask must not be called.
   699	// It's replaced by sigthreadmask.
   700	func sigprocmask1(how, new, old uintptr)
   701	
   702	//go:nosplit
   703	func sigprocmask(how int32, new, old *sigset) {
   704		_g_ := getg()
   705	
   706		// Check the validity of m because it might be called during a cgo
   707		// callback early enough where m isn't available yet.
   708		if _g_ != nil && _g_.m != nil {
   709			r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   710			if int32(r) != 0 {
   711				println("syscall sigthreadmask failed: ", hex(err))
   712				throw("syscall sigthreadmask")
   713			}
   714			return
   715		}
   716		sigprocmask1(uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
   717	
   718	}
   719	

View as plain text