Source file
src/runtime/os2_aix.go
1
2
3
4
5
6
7
8
9
10
11 package runtime
12
13 import (
14 "internal/runtime/sys"
15 "unsafe"
16 )
17
18
19
20
21
22
23
24
25 var (
26 libc___n_pthreads,
27 libc___mod_init libFunc
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
120 var (
121
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
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
170
171 var asmsyscall6 libFunc
172
173
174
175
176
177
178
179
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
188
189 mp.libcallsp = sys.GetCallerSP()
190 } else {
191 resetLibcall = false
192 }
193
194 c := libcall{
195 fn: uintptr(unsafe.Pointer(fn)),
196 n: 0,
197 args: uintptr(unsafe.Pointer(&fn)),
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
210
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
219
220 mp.libcallsp = sys.GetCallerSP()
221 } else {
222 resetLibcall = false
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
241
242
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
251
252 mp.libcallsp = sys.GetCallerSP()
253 } else {
254 resetLibcall = false
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
273
274
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
283
284 mp.libcallsp = sys.GetCallerSP()
285 } else {
286 resetLibcall = false
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
305
306
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
315
316 mp.libcallsp = sys.GetCallerSP()
317 } else {
318 resetLibcall = false
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
337
338
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
347
348 mp.libcallsp = sys.GetCallerSP()
349 } else {
350 resetLibcall = false
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
369
370
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
379
380 mp.libcallsp = sys.GetCallerSP()
381 } else {
382 resetLibcall = false
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
403 func exit(code int32) {
404 gp := getg()
405
406
407
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
418 func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
419 gp := getg()
420
421
422
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
431 return write2(fd, uintptr(p), n)
432 }
433
434
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
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
450 func closefd(fd int32) int32 {
451 r, _ := syscall1(&libc_close, uintptr(fd))
452 return int32(r)
453 }
454
455
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
463
464
465
466
467
468
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
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
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
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
507 func sigaction(sig uintptr, new, old *sigactiont) {
508 gp := getg()
509
510
511
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
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
534
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
543 func usleep_no_g(us uint32) {
544 usleep1(us)
545 }
546
547
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
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
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
572 func malloc(size uintptr) unsafe.Pointer {
573 r, _ := syscall1(&libc_malloc, size)
574 return unsafe.Pointer(r)
575 }
576
577
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
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
590 func sem_post(sem *semt) int32 {
591 r, _ := syscall1(&libc_sem_post, uintptr(unsafe.Pointer(sem)))
592 return int32(r)
593 }
594
595
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
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
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
624 func osyield_no_g() {
625 osyield1()
626 }
627
628
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
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
647
648
649
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
658 func pthread_attr_init(attr *pthread_attr) int32 {
659 gp := getg()
660
661
662
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
674 func pthread_attr_setdetachstate(attr *pthread_attr, state int32) int32 {
675 gp := getg()
676
677
678
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
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
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
702 func pthread_attr_setstacksize(attr *pthread_attr, size uint64) int32 {
703 gp := getg()
704
705
706
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
718 func pthread_create(tid *pthread, attr *pthread_attr, fn *funcDescriptor, arg unsafe.Pointer) int32 {
719 gp := getg()
720
721
722
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
732
733 func sigprocmask1(how, new, old uintptr)
734
735
736 func sigprocmask(how int32, new, old *sigset) {
737 gp := getg()
738
739
740
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
754 func pthread_self() pthread {
755 r, _ := syscall0(&libpthread_self)
756 return pthread(r)
757 }
758
759
760 func signalM(mp *m, sig int) {
761 syscall2(&libpthread_kill, uintptr(pthread(mp.procid)), uintptr(sig))
762 }
763
View as plain text