Debian Codegraph @

src/runtime/os2_aix.go

raw
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 // assembly functions.
10
11 package runtime
12
13 import (
14 "internal/runtime/sys"
15 "unsafe"
16 )
17
18 // Symbols imported for __start function.
19
20 //go:cgo_import_dynamic libc___n_pthreads __n_pthreads "libpthread.a/shr_xpg5_64.o"
21 //go:cgo_import_dynamic libc___mod_init __mod_init "libc.a/shr_64.o"
22 //go:linkname libc___n_pthreads libc___n_pthreads
23 //go:linkname libc___mod_init libc___mod_init
24
25 var (
26 libc___n_pthreads,
27 libc___mod_init libFunc
28 )
29
30 // Syscalls
31
32 //go:cgo_import_dynamic libc__Errno _Errno "libc.a/shr_64.o"
33 //go:cgo_import_dynamic libc_clock_gettime clock_gettime "libc.a/shr_64.o"
34 //go:cgo_import_dynamic libc_close close "libc.a/shr_64.o"
35 //go:cgo_import_dynamic libc_exit _exit "libc.a/shr_64.o"
36 //go:cgo_import_dynamic libc_getpid getpid "libc.a/shr_64.o"
37 //go:cgo_import_dynamic libc_getsystemcfg getsystemcfg "libc.a/shr_64.o"
38 //go:cgo_import_dynamic libc_kill kill "libc.a/shr_64.o"
39 //go:cgo_import_dynamic libc_madvise madvise "libc.a/shr_64.o"
40 //go:cgo_import_dynamic libc_malloc malloc "libc.a/shr_64.o"
41 //go:cgo_import_dynamic libc_mmap mmap "libc.a/shr_64.o"
42 //go:cgo_import_dynamic libc_mprotect mprotect "libc.a/shr_64.o"
43 //go:cgo_import_dynamic libc_munmap munmap "libc.a/shr_64.o"
44 //go:cgo_import_dynamic libc_open open "libc.a/shr_64.o"
45 //go:cgo_import_dynamic libc_pipe pipe "libc.a/shr_64.o"
46 //go:cgo_import_dynamic libc_raise raise "libc.a/shr_64.o"
47 //go:cgo_import_dynamic libc_read read "libc.a/shr_64.o"
48 //go:cgo_import_dynamic libc_sched_yield sched_yield "libc.a/shr_64.o"
49 //go:cgo_import_dynamic libc_sem_init sem_init "libc.a/shr_64.o"
50 //go:cgo_import_dynamic libc_sem_post sem_post "libc.a/shr_64.o"
51 //go:cgo_import_dynamic libc_sem_timedwait sem_timedwait "libc.a/shr_64.o"
52 //go:cgo_import_dynamic libc_sem_wait sem_wait "libc.a/shr_64.o"
53 //go:cgo_import_dynamic libc_setitimer setitimer "libc.a/shr_64.o"
54 //go:cgo_import_dynamic libc_sigaction sigaction "libc.a/shr_64.o"
55 //go:cgo_import_dynamic libc_sigaltstack sigaltstack "libc.a/shr_64.o"
56 //go:cgo_import_dynamic libc_sysconf sysconf "libc.a/shr_64.o"
57 //go:cgo_import_dynamic libc_usleep usleep "libc.a/shr_64.o"
58 //go:cgo_import_dynamic libc_write write "libc.a/shr_64.o"
59 //go:cgo_import_dynamic libc_getuid getuid "libc.a/shr_64.o"
60 //go:cgo_import_dynamic libc_geteuid geteuid "libc.a/shr_64.o"
61 //go:cgo_import_dynamic libc_getgid getgid "libc.a/shr_64.o"
62 //go:cgo_import_dynamic libc_getegid getegid "libc.a/shr_64.o"
63
64 //go:cgo_import_dynamic libpthread___pth_init __pth_init "libpthread.a/shr_xpg5_64.o"
65 //go:cgo_import_dynamic libpthread_attr_destroy pthread_attr_destroy "libpthread.a/shr_xpg5_64.o"
66 //go:cgo_import_dynamic libpthread_attr_init pthread_attr_init "libpthread.a/shr_xpg5_64.o"
67 //go:cgo_import_dynamic libpthread_attr_getstacksize pthread_attr_getstacksize "libpthread.a/shr_xpg5_64.o"
68 //go:cgo_import_dynamic libpthread_attr_setstacksize pthread_attr_setstacksize "libpthread.a/shr_xpg5_64.o"
69 //go:cgo_import_dynamic libpthread_attr_setdetachstate pthread_attr_setdetachstate "libpthread.a/shr_xpg5_64.o"
70 //go:cgo_import_dynamic libpthread_attr_setstackaddr pthread_attr_setstackaddr "libpthread.a/shr_xpg5_64.o"
71 //go:cgo_import_dynamic libpthread_create pthread_create "libpthread.a/shr_xpg5_64.o"
72 //go:cgo_import_dynamic libpthread_sigthreadmask sigthreadmask "libpthread.a/shr_xpg5_64.o"
73 //go:cgo_import_dynamic libpthread_self pthread_self "libpthread.a/shr_xpg5_64.o"
74 //go:cgo_import_dynamic libpthread_kill pthread_kill "libpthread.a/shr_xpg5_64.o"
75
76 //go:linkname libc__Errno libc__Errno
77 //go:linkname libc_clock_gettime libc_clock_gettime
78 //go:linkname libc_close libc_close
79 //go:linkname libc_exit libc_exit
80 //go:linkname libc_getpid libc_getpid
81 //go:linkname libc_getsystemcfg libc_getsystemcfg
82 //go:linkname libc_kill libc_kill
83 //go:linkname libc_madvise libc_madvise
84 //go:linkname libc_malloc libc_malloc
85 //go:linkname libc_mmap libc_mmap
86 //go:linkname libc_mprotect libc_mprotect
87 //go:linkname libc_munmap libc_munmap
88 //go:linkname libc_open libc_open
89 //go:linkname libc_pipe libc_pipe
90 //go:linkname libc_raise libc_raise
91 //go:linkname libc_read libc_read
92 //go:linkname libc_sched_yield libc_sched_yield
93 //go:linkname libc_sem_init libc_sem_init
94 //go:linkname libc_sem_post libc_sem_post
95 //go:linkname libc_sem_timedwait libc_sem_timedwait
96 //go:linkname libc_sem_wait libc_sem_wait
97 //go:linkname libc_setitimer libc_setitimer
98 //go:linkname libc_sigaction libc_sigaction
99 //go:linkname libc_sigaltstack libc_sigaltstack
100 //go:linkname libc_sysconf libc_sysconf
101 //go:linkname libc_usleep libc_usleep
102 //go:linkname libc_write libc_write
103 //go:linkname libc_getuid libc_getuid
104 //go:linkname libc_geteuid libc_geteuid
105 //go:linkname libc_getgid libc_getgid
106 //go:linkname libc_getegid libc_getegid
107
108 //go:linkname libpthread___pth_init libpthread___pth_init
109 //go:linkname libpthread_attr_destroy libpthread_attr_destroy
110 //go:linkname libpthread_attr_init libpthread_attr_init
111 //go:linkname libpthread_attr_getstacksize libpthread_attr_getstacksize
112 //go:linkname libpthread_attr_setstacksize libpthread_attr_setstacksize
113 //go:linkname libpthread_attr_setdetachstate libpthread_attr_setdetachstate
114 //go:linkname libpthread_attr_setstackaddr libpthread_attr_setstackaddr
115 //go:linkname libpthread_create libpthread_create
116 //go:linkname libpthread_sigthreadmask libpthread_sigthreadmask
117 //go:linkname libpthread_self libpthread_self
118 //go:linkname libpthread_kill libpthread_kill
119
120 var (
121 //libc
122 libc__Errno,
123 libc_clock_gettime,
124 libc_close,
125 libc_exit,
126 libc_getpid,
127 libc_getsystemcfg,
128 libc_kill,
129 libc_madvise,
130 libc_malloc,
131 libc_mmap,
132 libc_mprotect,
133 libc_munmap,
134 libc_open,
135 libc_pipe,
136 libc_raise,
137 libc_read,
138 libc_sched_yield,
139 libc_sem_init,
140 libc_sem_post,
141 libc_sem_timedwait,
142 libc_sem_wait,
143 libc_setitimer,
144 libc_sigaction,
145 libc_sigaltstack,
146 libc_sysconf,
147 libc_usleep,
148 libc_write,
149 libc_getuid,
150 libc_geteuid,
151 libc_getgid,
152 libc_getegid,
153 //libpthread
154 libpthread___pth_init,
155 libpthread_attr_destroy,
156 libpthread_attr_init,
157 libpthread_attr_getstacksize,
158 libpthread_attr_setstacksize,
159 libpthread_attr_setdetachstate,
160 libpthread_attr_setstackaddr,
161 libpthread_create,
162 libpthread_sigthreadmask,
163 libpthread_self,
164 libpthread_kill libFunc
165 )
166
167 type libFunc uintptr
168
169 // asmsyscall6 calls the libc symbol using a C convention.
170 // It's defined in sys_aix_ppc64.go.
171 var asmsyscall6 libFunc
172
173 // syscallX functions must always be called with g != nil and m != nil,
174 // as it relies on g.m.libcall to pass arguments to asmcgocall.
175 // The few cases where syscalls haven't a g or a m must call their equivalent
176 // function in sys_aix_ppc64.s to handle them.
177
178 //go:nowritebarrier
179 //go:nosplit
180 func syscall0(fn *libFunc) (r, err uintptr) {
181 gp := getg()
182 mp := gp.m
183 resetLibcall := true
184 if mp.libcallsp == 0 {
185 mp.libcallg.set(gp)
186 mp.libcallpc = sys.GetCallerPC()
187 // sp must be the last, because once async cpu profiler finds
188 // all three values to be non-zero, it will use them
189 mp.libcallsp = sys.GetCallerSP()
190 } else {
191 resetLibcall = false // See comment in sys_darwin.go:libcCall
192 }
193
194 c := libcall{
195 fn: uintptr(unsafe.Pointer(fn)),
196 n: 0,
197 args: uintptr(unsafe.Pointer(&fn)), // it's unused but must be non-nil, otherwise crashes
198 }
199
200 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
201
202 if resetLibcall {
203 mp.libcallsp = 0
204 }
205
206 return c.r1, c.err
207 }
208
209 //go:nowritebarrier
210 //go:nosplit
211 func syscall1(fn *libFunc, a0 uintptr) (r, err uintptr) {
212 gp := getg()
213 mp := gp.m
214 resetLibcall := true
215 if mp.libcallsp == 0 {
216 mp.libcallg.set(gp)
217 mp.libcallpc = sys.GetCallerPC()
218 // sp must be the last, because once async cpu profiler finds
219 // all three values to be non-zero, it will use them
220 mp.libcallsp = sys.GetCallerSP()
221 } else {
222 resetLibcall = false // See comment in sys_darwin.go:libcCall
223 }
224
225 c := libcall{
226 fn: uintptr(unsafe.Pointer(fn)),
227 n: 1,
228 args: uintptr(unsafe.Pointer(&a0)),
229 }
230
231 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
232
233 if resetLibcall {
234 mp.libcallsp = 0
235 }
236
237 return c.r1, c.err
238 }
239
240 //go:nowritebarrier
241 //go:nosplit
242 //go:cgo_unsafe_args
243 func syscall2(fn *libFunc, a0, a1 uintptr) (r, err uintptr) {
244 gp := getg()
245 mp := gp.m
246 resetLibcall := true
247 if mp.libcallsp == 0 {
248 mp.libcallg.set(gp)
249 mp.libcallpc = sys.GetCallerPC()
250 // sp must be the last, because once async cpu profiler finds
251 // all three values to be non-zero, it will use them
252 mp.libcallsp = sys.GetCallerSP()
253 } else {
254 resetLibcall = false // See comment in sys_darwin.go:libcCall
255 }
256
257 c := libcall{
258 fn: uintptr(unsafe.Pointer(fn)),
259 n: 2,
260 args: uintptr(unsafe.Pointer(&a0)),
261 }
262
263 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
264
265 if resetLibcall {
266 mp.libcallsp = 0
267 }
268
269 return c.r1, c.err
270 }
271
272 //go:nowritebarrier
273 //go:nosplit
274 //go:cgo_unsafe_args
275 func syscall3(fn *libFunc, a0, a1, a2 uintptr) (r, err uintptr) {
276 gp := getg()
277 mp := gp.m
278 resetLibcall := true
279 if mp.libcallsp == 0 {
280 mp.libcallg.set(gp)
281 mp.libcallpc = sys.GetCallerPC()
282 // sp must be the last, because once async cpu profiler finds
283 // all three values to be non-zero, it will use them
284 mp.libcallsp = sys.GetCallerSP()
285 } else {
286 resetLibcall = false // See comment in sys_darwin.go:libcCall
287 }
288
289 c := libcall{
290 fn: uintptr(unsafe.Pointer(fn)),
291 n: 3,
292 args: uintptr(unsafe.Pointer(&a0)),
293 }
294
295 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
296
297 if resetLibcall {
298 mp.libcallsp = 0
299 }
300
301 return c.r1, c.err
302 }
303
304 //go:nowritebarrier
305 //go:nosplit
306 //go:cgo_unsafe_args
307 func syscall4(fn *libFunc, a0, a1, a2, a3 uintptr) (r, err uintptr) {
308 gp := getg()
309 mp := gp.m
310 resetLibcall := true
311 if mp.libcallsp == 0 {
312 mp.libcallg.set(gp)
313 mp.libcallpc = sys.GetCallerPC()
314 // sp must be the last, because once async cpu profiler finds
315 // all three values to be non-zero, it will use them
316 mp.libcallsp = sys.GetCallerSP()
317 } else {
318 resetLibcall = false // See comment in sys_darwin.go:libcCall
319 }
320
321 c := libcall{
322 fn: uintptr(unsafe.Pointer(fn)),
323 n: 4,
324 args: uintptr(unsafe.Pointer(&a0)),
325 }
326
327 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
328
329 if resetLibcall {
330 mp.libcallsp = 0
331 }
332
333 return c.r1, c.err
334 }
335
336 //go:nowritebarrier
337 //go:nosplit
338 //go:cgo_unsafe_args
339 func syscall5(fn *libFunc, a0, a1, a2, a3, a4 uintptr) (r, err uintptr) {
340 gp := getg()
341 mp := gp.m
342 resetLibcall := true
343 if mp.libcallsp == 0 {
344 mp.libcallg.set(gp)
345 mp.libcallpc = sys.GetCallerPC()
346 // sp must be the last, because once async cpu profiler finds
347 // all three values to be non-zero, it will use them
348 mp.libcallsp = sys.GetCallerSP()
349 } else {
350 resetLibcall = false // See comment in sys_darwin.go:libcCall
351 }
352
353 c := libcall{
354 fn: uintptr(unsafe.Pointer(fn)),
355 n: 5,
356 args: uintptr(unsafe.Pointer(&a0)),
357 }
358
359 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
360
361 if resetLibcall {
362 mp.libcallsp = 0
363 }
364
365 return c.r1, c.err
366 }
367
368 //go:nowritebarrier
369 //go:nosplit
370 //go:cgo_unsafe_args
371 func syscall6(fn *libFunc, a0, a1, a2, a3, a4, a5 uintptr) (r, err uintptr) {
372 gp := getg()
373 mp := gp.m
374 resetLibcall := true
375 if mp.libcallsp == 0 {
376 mp.libcallg.set(gp)
377 mp.libcallpc = sys.GetCallerPC()
378 // sp must be the last, because once async cpu profiler finds
379 // all three values to be non-zero, it will use them
380 mp.libcallsp = sys.GetCallerSP()
381 } else {
382 resetLibcall = false // See comment in sys_darwin.go:libcCall
383 }
384
385 c := libcall{
386 fn: uintptr(unsafe.Pointer(fn)),
387 n: 6,
388 args: uintptr(unsafe.Pointer(&a0)),
389 }
390
391 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
392
393 if resetLibcall {
394 mp.libcallsp = 0
395 }
396
397 return c.r1, c.err
398 }
399
400 func exit1(code int32)
401
402 //go:nosplit
403 func exit(code int32) {
404 gp := getg()
405
406 // Check the validity of g because without a g during
407 // newosproc0.
408 if gp != nil {
409 syscall1(&libc_exit, uintptr(code))
410 return
411 }
412 exit1(code)
413 }
414
415 func write2(fd, p uintptr, n int32) int32
416
417 //go:nosplit
418 func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
419 gp := getg()
420
421 // Check the validity of g because without a g during
422 // newosproc0.
423 if gp != nil {
424 r, errno := syscall3(&libc_write, uintptr(fd), uintptr(p), uintptr(n))
425 if int32(r) < 0 {
426 return -int32(errno)
427 }
428 return int32(r)
429 }
430 // Note that in this case we can't return a valid errno value.
431 return write2(fd, uintptr(p), n)
432 }
433
434 //go:nosplit
435 func read(fd int32, p unsafe.Pointer, n int32) int32 {
436 r, errno := syscall3(&libc_read, uintptr(fd), uintptr(p), uintptr(n))
437 if int32(r) < 0 {
438 return -int32(errno)
439 }
440 return int32(r)
441 }
442
443 //go:nosplit
444 func open(name *byte, mode, perm int32) int32 {
445 r, _ := syscall3(&libc_open, uintptr(unsafe.Pointer(name)), uintptr(mode), uintptr(perm))
446 return int32(r)
447 }
448
449 //go:nosplit
450 func closefd(fd int32) int32 {
451 r, _ := syscall1(&libc_close, uintptr(fd))
452 return int32(r)
453 }
454
455 //go:nosplit
456 func pipe() (r, w int32, errno int32) {
457 var p [2]int32
458 _, err := syscall1(&libc_pipe, uintptr(noescape(unsafe.Pointer(&p[0]))))
459 return p[0], p[1], int32(err)
460 }
461
462 // mmap calls the mmap system call.
463 // We only pass the lower 32 bits of file offset to the
464 // assembly routine; the higher bits (if required), should be provided
465 // by the assembly routine as 0.
466 // The err result is an OS error code such as ENOMEM.
467 //
468 //go:nosplit
469 func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
470 r, err0 := syscall6(&libc_mmap, uintptr(addr), uintptr(n), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(off))
471 if r == ^uintptr(0) {
472 return nil, int(err0)
473 }
474 return unsafe.Pointer(r), int(err0)
475 }
476
477 //go:nosplit
478 func mprotect(addr unsafe.Pointer, n uintptr, prot int32) (unsafe.Pointer, int) {
479 r, err0 := syscall3(&libc_mprotect, uintptr(addr), uintptr(n), uintptr(prot))
480 if r == ^uintptr(0) {
481 return nil, int(err0)
482 }
483 return unsafe.Pointer(r), int(err0)
484 }
485
486 //go:nosplit
487 func munmap(addr unsafe.Pointer, n uintptr) {
488 r, err := syscall2(&libc_munmap, uintptr(addr), uintptr(n))
489 if int32(r) == -1 {
490 println("syscall munmap failed: ", hex(err))
491 throw("syscall munmap")
492 }
493 }
494
495 //go:nosplit
496 func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
497 r, err := syscall3(&libc_madvise, uintptr(addr), uintptr(n), uintptr(flags))
498 if int32(r) == -1 {
499 println("syscall madvise failed: ", hex(err))
500 throw("syscall madvise")
501 }
502 }
503
504 func sigaction1(sig, new, old uintptr)
505
506 //go:nosplit
507 func sigaction(sig uintptr, new, old *sigactiont) {
508 gp := getg()
509
510 // Check the validity of g because without a g during
511 // runtime.libpreinit.
512 if gp != nil {
513 r, err := syscall3(&libc_sigaction, sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
514 if int32(r) == -1 {
515 println("Sigaction failed for sig: ", sig, " with error:", hex(err))
516 throw("syscall sigaction")
517 }
518 return
519 }
520
521 sigaction1(sig, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
522 }
523
524 //go:nosplit
525 func sigaltstack(new, old *stackt) {
526 r, err := syscall2(&libc_sigaltstack, uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
527 if int32(r) == -1 {
528 println("syscall sigaltstack failed: ", hex(err))
529 throw("syscall sigaltstack")
530 }
531 }
532
533 //go:nosplit
534 //go:linkname internal_cpu_getsystemcfg internal/cpu.getsystemcfg
535 func internal_cpu_getsystemcfg(label uint) uint {
536 r, _ := syscall1(&libc_getsystemcfg, uintptr(label))
537 return uint(r)
538 }
539
540 func usleep1(us uint32)
541
542 //go:nosplit
543 func usleep_no_g(us uint32) {
544 usleep1(us)
545 }
546
547 //go:nosplit
548 func usleep(us uint32) {
549 r, err := syscall1(&libc_usleep, uintptr(us))
550 if int32(r) == -1 {
551 println("syscall usleep failed: ", hex(err))
552 throw("syscall usleep")
553 }
554 }
555
556 //go:nosplit
557 func clock_gettime(clockid int32, tp *timespec) int32 {
558 r, _ := syscall2(&libc_clock_gettime, uintptr(clockid), uintptr(unsafe.Pointer(tp)))
559 return int32(r)
560 }
561
562 //go:nosplit
563 func setitimer(mode int32, new, old *itimerval) {
564 r, err := syscall3(&libc_setitimer, uintptr(mode), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
565 if int32(r) == -1 {
566 println("syscall setitimer failed: ", hex(err))
567 throw("syscall setitimer")
568 }
569 }
570
571 //go:nosplit
572 func malloc(size uintptr) unsafe.Pointer {
573 r, _ := syscall1(&libc_malloc, size)
574 return unsafe.Pointer(r)
575 }
576
577 //go:nosplit
578 func sem_init(sem *semt, pshared int32, value uint32) int32 {
579 r, _ := syscall3(&libc_sem_init, uintptr(unsafe.Pointer(sem)), uintptr(pshared), uintptr(value))
580 return int32(r)
581 }
582
583 //go:nosplit
584 func sem_wait(sem *semt) (int32, int32) {
585 r, err := syscall1(&libc_sem_wait, uintptr(unsafe.Pointer(sem)))
586 return int32(r), int32(err)
587 }
588
589 //go:nosplit
590 func sem_post(sem *semt) int32 {
591 r, _ := syscall1(&libc_sem_post, uintptr(unsafe.Pointer(sem)))
592 return int32(r)
593 }
594
595 //go:nosplit
596 func sem_timedwait(sem *semt, timeout *timespec) (int32, int32) {
597 r, err := syscall2(&libc_sem_timedwait, uintptr(unsafe.Pointer(sem)), uintptr(unsafe.Pointer(timeout)))
598 return int32(r), int32(err)
599 }
600
601 //go:nosplit
602 func raise(sig uint32) {
603 r, err := syscall1(&libc_raise, uintptr(sig))
604 if int32(r) == -1 {
605 println("syscall raise failed: ", hex(err))
606 throw("syscall raise")
607 }
608 }
609
610 //go:nosplit
611 func raiseproc(sig uint32) {
612 pid, err := syscall0(&libc_getpid)
613 if int32(pid) == -1 {
614 println("syscall getpid failed: ", hex(err))
615 throw("syscall raiseproc")
616 }
617
618 syscall2(&libc_kill, pid, uintptr(sig))
619 }
620
621 func osyield1()
622
623 //go:nosplit
624 func osyield_no_g() {
625 osyield1()
626 }
627
628 //go:nosplit
629 func osyield() {
630 r, err := syscall0(&libc_sched_yield)
631 if int32(r) == -1 {
632 println("syscall osyield failed: ", hex(err))
633 throw("syscall osyield")
634 }
635 }
636
637 //go:nosplit
638 func sysconf(name int32) uintptr {
639 r, _ := syscall1(&libc_sysconf, uintptr(name))
640 if int32(r) == -1 {
641 throw("syscall sysconf")
642 }
643 return r
644 }
645
646 // pthread functions returns its error code in the main return value
647 // Therefore, err returns by syscall means nothing and must not be used
648
649 //go:nosplit
650 func pthread_attr_destroy(attr *pthread_attr) int32 {
651 r, _ := syscall1(&libpthread_attr_destroy, uintptr(unsafe.Pointer(attr)))
652 return int32(r)
653 }
654
655 func pthread_attr_init1(attr uintptr) int32
656
657 //go:nosplit
658 func pthread_attr_init(attr *pthread_attr) int32 {
659 gp := getg()
660
661 // Check the validity of g because without a g during
662 // newosproc0.
663 if gp != nil {
664 r, _ := syscall1(&libpthread_attr_init, uintptr(unsafe.Pointer(attr)))
665 return int32(r)
666 }
667
668 return pthread_attr_init1(uintptr(unsafe.Pointer(attr)))
669 }
670
671 func pthread_attr_setdetachstate1(attr uintptr, state int32) int32
672
673 //go:nosplit
674 func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
675 gp := getg()
676
677 // Check the validity of g because without a g during
678 // newosproc0.
679 if gp != nil {
680 r, _ := syscall2(&libpthread_attr_setdetachstate, uintptr(unsafe.Pointer(attr)), uintptr(state))
681 return int32(r)
682 }
683
684 return pthread_attr_setdetachstate1(uintptr(unsafe.Pointer(attr)), state)
685 }
686
687 //go:nosplit
688 func pthread_attr_setstackaddr(attr *pthread_attr, stk unsafe.Pointer) int32 {
689 r, _ := syscall2(&libpthread_attr_setstackaddr, uintptr(unsafe.Pointer(attr)), uintptr(stk))
690 return int32(r)
691 }
692
693 //go:nosplit
694 func pthread_attr_getstacksize(attr *pthread_attr, size *uint64) int32 {
695 r, _ := syscall2(&libpthread_attr_getstacksize, uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(size)))
696 return int32(r)
697 }
698
699 func pthread_attr_setstacksize1(attr uintptr, size uint64) int32
700
701 //go:nosplit
702 func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
703 gp := getg()
704
705 // Check the validity of g because without a g during
706 // newosproc0.
707 if gp != nil {
708 r, _ := syscall2(&libpthread_attr_setstacksize, uintptr(unsafe.Pointer(attr)), uintptr(size))
709 return int32(r)
710 }
711
712 return pthread_attr_setstacksize1(uintptr(unsafe.Pointer(attr)), size)
713 }
714
715 func pthread_create1(tid, attr, fn, arg uintptr) int32
716
717 //go:nosplit
718 func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
719 gp := getg()
720
721 // Check the validity of g because without a g during
722 // newosproc0.
723 if gp != nil {
724 r, _ := syscall4(&libpthread_create, uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
725 return int32(r)
726 }
727
728 return pthread_create1(uintptr(unsafe.Pointer(tid)), uintptr(unsafe.Pointer(attr)), uintptr(unsafe.Pointer(fn)), uintptr(arg))
729 }
730
731 // On multi-thread program, sigprocmask must not be called.
732 // It's replaced by sigthreadmask.
733 func sigprocmask1(how, new, old uintptr)
734
735 //go:nosplit
736 func sigprocmask(how int32, new, old *sigset) {
737 gp := getg()
738
739 // Check the validity of m because it might be called during a cgo
740 // callback early enough where m isn't available yet.
741 if gp != nil && gp.m != nil {
742 r, err := syscall3(&libpthread_sigthreadmask, uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
743 if int32(r) != 0 {
744 println("syscall sigthreadmask failed: ", hex(err))
745 throw("syscall sigthreadmask")
746 }
747 return
748 }
749 sigprocmask1(uintptr(how), uintptr(unsafe.Pointer(new)), uintptr(unsafe.Pointer(old)))
750
751 }
752
753 //go:nosplit
754 func pthread_self() pthread {
755 r, _ := syscall0(&libpthread_self)
756 return pthread(r)
757 }
758
759 //go:nosplit
760 func signalM(mp *m, sig int) {
761 syscall2(&libpthread_kill, uintptr(pthread(mp.procid)), uintptr(sig))
762 }