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