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