Source file
src/runtime/sys_darwin.go
Documentation: runtime
1
2
3
4
5 package runtime
6
7 import (
8 "internal/abi"
9 "internal/runtime/atomic"
10 "unsafe"
11 )
12
13
14
15
16
17
18
19
20
21
22
23
24
25 func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
26 args := struct{ fn, a1, a2, a3, r1, r2, err uintptr }{fn, a1, a2, a3, r1, r2, err}
27 entersyscall()
28 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall)), unsafe.Pointer(&args))
29 exitsyscall()
30 return args.r1, args.r2, args.err
31 }
32 func syscall()
33
34
35
36 func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
37 args := struct{ fn, a1, a2, a3, r1, r2, err uintptr }{fn, a1, a2, a3, r1, r2, err}
38 entersyscall()
39 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscallX)), unsafe.Pointer(&args))
40 exitsyscall()
41 return args.r1, args.r2, args.err
42 }
43 func syscallX()
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
59 args := struct{ fn, a1, a2, a3, a4, a5, a6, r1, r2, err uintptr }{fn, a1, a2, a3, a4, a5, a6, r1, r2, err}
60 entersyscall()
61 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall6)), unsafe.Pointer(&args))
62 exitsyscall()
63 return args.r1, args.r2, args.err
64 }
65 func syscall6()
66
67
68
69
70
71
72
73
74 func syscall_syscall9(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) {
75 entersyscall()
76 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall9)), unsafe.Pointer(&fn))
77 exitsyscall()
78 return
79 }
80 func syscall9()
81
82
83
84 func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
85 args := struct{ fn, a1, a2, a3, a4, a5, a6, r1, r2, err uintptr }{fn, a1, a2, a3, a4, a5, a6, r1, r2, err}
86 entersyscall()
87 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall6X)), unsafe.Pointer(&args))
88 exitsyscall()
89 return args.r1, args.r2, args.err
90 }
91 func syscall6X()
92
93
94
95
96
97
98
99 func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
100 args := struct{ fn, a1, a2, a3, r1, r2, err uintptr }{fn, a1, a2, a3, r1, r2, err}
101 entersyscall()
102 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscallPtr)), unsafe.Pointer(&args))
103 exitsyscall()
104 return args.r1, args.r2, args.err
105 }
106 func syscallPtr()
107
108
109
110
111
112
113
114 func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
115 args := struct{ fn, a1, a2, a3, r1, r2, err uintptr }{fn, a1, a2, a3, r1, r2, err}
116 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall)), unsafe.Pointer(&args))
117 return args.r1, args.r2, args.err
118 }
119
120
121
122
123
124
125
126 func syscall_rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
127 args := struct{ fn, a1, a2, a3, a4, a5, a6, r1, r2, err uintptr }{fn, a1, a2, a3, a4, a5, a6, r1, r2, err}
128 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall6)), unsafe.Pointer(&args))
129 return args.r1, args.r2, args.err
130 }
131
132
133
134
135
136 func crypto_x509_syscall(fn, a1, a2, a3, a4, a5 uintptr, f1 float64) (r1 uintptr) {
137 args := struct {
138 fn, a1, a2, a3, a4, a5 uintptr
139 f1 float64
140 r1 uintptr
141 }{fn, a1, a2, a3, a4, a5, f1, r1}
142 entersyscall()
143 libcCall(unsafe.Pointer(abi.FuncPCABI0(syscall_x509)), unsafe.Pointer(&args))
144 exitsyscall()
145 return args.r1
146 }
147 func syscall_x509()
148
149
150
151
152
153
154 func pthread_attr_init(attr *pthreadattr) int32 {
155 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_init_trampoline)), unsafe.Pointer(&attr))
156 KeepAlive(attr)
157 return ret
158 }
159 func pthread_attr_init_trampoline()
160
161
162
163 func pthread_attr_getstacksize(attr *pthreadattr, size *uintptr) int32 {
164 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_getstacksize_trampoline)), unsafe.Pointer(&attr))
165 KeepAlive(attr)
166 KeepAlive(size)
167 return ret
168 }
169 func pthread_attr_getstacksize_trampoline()
170
171
172
173 func pthread_attr_setdetachstate(attr *pthreadattr, state int) int32 {
174 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_attr_setdetachstate_trampoline)), unsafe.Pointer(&attr))
175 KeepAlive(attr)
176 return ret
177 }
178 func pthread_attr_setdetachstate_trampoline()
179
180
181
182 func pthread_create(attr *pthreadattr, start uintptr, arg unsafe.Pointer) int32 {
183 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_create_trampoline)), unsafe.Pointer(&attr))
184 KeepAlive(attr)
185 KeepAlive(arg)
186 return ret
187 }
188 func pthread_create_trampoline()
189
190
191
192 func raise(sig uint32) {
193 libcCall(unsafe.Pointer(abi.FuncPCABI0(raise_trampoline)), unsafe.Pointer(&sig))
194 }
195 func raise_trampoline()
196
197
198
199 func pthread_self() (t pthread) {
200 libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_self_trampoline)), unsafe.Pointer(&t))
201 return
202 }
203 func pthread_self_trampoline()
204
205
206
207 func pthread_kill(t pthread, sig uint32) {
208 libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_kill_trampoline)), unsafe.Pointer(&t))
209 return
210 }
211 func pthread_kill_trampoline()
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 func osinit_hack() {
247 if GOOS == "darwin" {
248 libcCall(unsafe.Pointer(abi.FuncPCABI0(osinit_hack_trampoline)), nil)
249 }
250 return
251 }
252 func osinit_hack_trampoline()
253
254
255
256
257
258
259 func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
260 args := struct {
261 addr unsafe.Pointer
262 n uintptr
263 prot, flags, fd int32
264 off uint32
265 ret1 unsafe.Pointer
266 ret2 int
267 }{addr, n, prot, flags, fd, off, nil, 0}
268 libcCall(unsafe.Pointer(abi.FuncPCABI0(mmap_trampoline)), unsafe.Pointer(&args))
269 return args.ret1, args.ret2
270 }
271 func mmap_trampoline()
272
273
274
275 func munmap(addr unsafe.Pointer, n uintptr) {
276 libcCall(unsafe.Pointer(abi.FuncPCABI0(munmap_trampoline)), unsafe.Pointer(&addr))
277 KeepAlive(addr)
278 }
279 func munmap_trampoline()
280
281
282
283 func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
284 libcCall(unsafe.Pointer(abi.FuncPCABI0(madvise_trampoline)), unsafe.Pointer(&addr))
285 KeepAlive(addr)
286 }
287 func madvise_trampoline()
288
289
290
291 func mlock(addr unsafe.Pointer, n uintptr) {
292 libcCall(unsafe.Pointer(abi.FuncPCABI0(mlock_trampoline)), unsafe.Pointer(&addr))
293 KeepAlive(addr)
294 }
295 func mlock_trampoline()
296
297
298
299 func read(fd int32, p unsafe.Pointer, n int32) int32 {
300 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(read_trampoline)), unsafe.Pointer(&fd))
301 KeepAlive(p)
302 return ret
303 }
304 func read_trampoline()
305
306 func pipe() (r, w int32, errno int32) {
307 var p [2]int32
308 errno = libcCall(unsafe.Pointer(abi.FuncPCABI0(pipe_trampoline)), noescape(unsafe.Pointer(&p)))
309 return p[0], p[1], errno
310 }
311 func pipe_trampoline()
312
313
314
315 func closefd(fd int32) int32 {
316 return libcCall(unsafe.Pointer(abi.FuncPCABI0(close_trampoline)), unsafe.Pointer(&fd))
317 }
318 func close_trampoline()
319
320
321
322
323
324
325 func exit(code int32) {
326 libcCall(unsafe.Pointer(abi.FuncPCABI0(exit_trampoline)), unsafe.Pointer(&code))
327 }
328 func exit_trampoline()
329
330
331
332 func usleep(usec uint32) {
333 libcCall(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
334 }
335 func usleep_trampoline()
336
337
338
339 func usleep_no_g(usec uint32) {
340 asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
341 }
342
343
344
345 func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
346 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(write_trampoline)), unsafe.Pointer(&fd))
347 KeepAlive(p)
348 return ret
349 }
350 func write_trampoline()
351
352
353
354 func open(name *byte, mode, perm int32) (ret int32) {
355 ret = libcCall(unsafe.Pointer(abi.FuncPCABI0(open_trampoline)), unsafe.Pointer(&name))
356 KeepAlive(name)
357 return
358 }
359 func open_trampoline()
360
361
362
363 func nanotime1() int64 {
364 var r struct {
365 t int64
366 numer, denom uint32
367 }
368 libcCall(unsafe.Pointer(abi.FuncPCABI0(nanotime_trampoline)), unsafe.Pointer(&r))
369
370
371
372 t := r.t
373 if r.numer != 1 {
374 t *= int64(r.numer)
375 }
376 if r.denom != 1 {
377 t /= int64(r.denom)
378 }
379 return t
380 }
381 func nanotime_trampoline()
382
383
384
385
386
387
388
389
390
391
392
393
394 func walltime() (int64, int32) {
395 var t timespec
396 libcCall(unsafe.Pointer(abi.FuncPCABI0(walltime_trampoline)), unsafe.Pointer(&t))
397 return t.tv_sec, int32(t.tv_nsec)
398 }
399 func walltime_trampoline()
400
401
402
403 func sigaction(sig uint32, new *usigactiont, old *usigactiont) {
404 libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaction_trampoline)), unsafe.Pointer(&sig))
405 KeepAlive(new)
406 KeepAlive(old)
407 }
408 func sigaction_trampoline()
409
410
411
412 func sigprocmask(how uint32, new *sigset, old *sigset) {
413 libcCall(unsafe.Pointer(abi.FuncPCABI0(sigprocmask_trampoline)), unsafe.Pointer(&how))
414 KeepAlive(new)
415 KeepAlive(old)
416 }
417 func sigprocmask_trampoline()
418
419
420
421 func sigaltstack(new *stackt, old *stackt) {
422 if new != nil && new.ss_flags&_SS_DISABLE != 0 && new.ss_size == 0 {
423
424
425
426
427 new.ss_size = 32768
428 }
429 libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaltstack_trampoline)), unsafe.Pointer(&new))
430 KeepAlive(new)
431 KeepAlive(old)
432 }
433 func sigaltstack_trampoline()
434
435
436
437 func raiseproc(sig uint32) {
438 libcCall(unsafe.Pointer(abi.FuncPCABI0(raiseproc_trampoline)), unsafe.Pointer(&sig))
439 }
440 func raiseproc_trampoline()
441
442
443
444 func setitimer(mode int32, new, old *itimerval) {
445 libcCall(unsafe.Pointer(abi.FuncPCABI0(setitimer_trampoline)), unsafe.Pointer(&mode))
446 KeepAlive(new)
447 KeepAlive(old)
448 }
449 func setitimer_trampoline()
450
451
452
453 func sysctl(mib *uint32, miblen uint32, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 {
454 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(sysctl_trampoline)), unsafe.Pointer(&mib))
455 KeepAlive(mib)
456 KeepAlive(oldp)
457 KeepAlive(oldlenp)
458 KeepAlive(newp)
459 return ret
460 }
461 func sysctl_trampoline()
462
463
464
465 func sysctlbyname(name *byte, oldp *byte, oldlenp *uintptr, newp *byte, newlen uintptr) int32 {
466 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(sysctlbyname_trampoline)), unsafe.Pointer(&name))
467 KeepAlive(name)
468 KeepAlive(oldp)
469 KeepAlive(oldlenp)
470 KeepAlive(newp)
471 return ret
472 }
473 func sysctlbyname_trampoline()
474
475
476
477 func fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
478 args := struct {
479 fd, cmd, arg int32
480 ret, errno int32
481 }{fd, cmd, arg, 0, 0}
482 libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&args))
483 return args.ret, args.errno
484 }
485 func fcntl_trampoline()
486
487
488
489 func kqueue() int32 {
490 v := libcCall(unsafe.Pointer(abi.FuncPCABI0(kqueue_trampoline)), nil)
491 return v
492 }
493 func kqueue_trampoline()
494
495
496
497 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 {
498 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(kevent_trampoline)), unsafe.Pointer(&kq))
499 KeepAlive(ch)
500 KeepAlive(ev)
501 KeepAlive(ts)
502 return ret
503 }
504 func kevent_trampoline()
505
506
507
508 func pthread_mutex_init(m *pthreadmutex, attr *pthreadmutexattr) int32 {
509 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_init_trampoline)), unsafe.Pointer(&m))
510 KeepAlive(m)
511 KeepAlive(attr)
512 return ret
513 }
514 func pthread_mutex_init_trampoline()
515
516
517
518 func pthread_mutex_lock(m *pthreadmutex) int32 {
519 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_lock_trampoline)), unsafe.Pointer(&m))
520 KeepAlive(m)
521 return ret
522 }
523 func pthread_mutex_lock_trampoline()
524
525
526
527 func pthread_mutex_unlock(m *pthreadmutex) int32 {
528 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_mutex_unlock_trampoline)), unsafe.Pointer(&m))
529 KeepAlive(m)
530 return ret
531 }
532 func pthread_mutex_unlock_trampoline()
533
534
535
536 func pthread_cond_init(c *pthreadcond, attr *pthreadcondattr) int32 {
537 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_init_trampoline)), unsafe.Pointer(&c))
538 KeepAlive(c)
539 KeepAlive(attr)
540 return ret
541 }
542 func pthread_cond_init_trampoline()
543
544
545
546 func pthread_cond_wait(c *pthreadcond, m *pthreadmutex) int32 {
547 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_wait_trampoline)), unsafe.Pointer(&c))
548 KeepAlive(c)
549 KeepAlive(m)
550 return ret
551 }
552 func pthread_cond_wait_trampoline()
553
554
555
556 func pthread_cond_timedwait_relative_np(c *pthreadcond, m *pthreadmutex, t *timespec) int32 {
557 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_timedwait_relative_np_trampoline)), unsafe.Pointer(&c))
558 KeepAlive(c)
559 KeepAlive(m)
560 KeepAlive(t)
561 return ret
562 }
563 func pthread_cond_timedwait_relative_np_trampoline()
564
565
566
567 func pthread_cond_signal(c *pthreadcond) int32 {
568 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(pthread_cond_signal_trampoline)), unsafe.Pointer(&c))
569 KeepAlive(c)
570 return ret
571 }
572 func pthread_cond_signal_trampoline()
573
574
575 func exitThread(wait *atomic.Uint32) {
576 throw("exitThread")
577 }
578
579
580 func setNonblock(fd int32) {
581 flags, _ := fcntl(fd, _F_GETFL, 0)
582 if flags != -1 {
583 fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
584 }
585 }
586
587 func issetugid() int32 {
588 return libcCall(unsafe.Pointer(abi.FuncPCABI0(issetugid_trampoline)), nil)
589 }
590 func issetugid_trampoline()
591
592
593
594
595
596
597 func mach_vm_region(address, region_size *uint64, info unsafe.Pointer) int32 {
598
599
600
601
602
603
604
605
606 var count machMsgTypeNumber = _VM_REGION_BASIC_INFO_COUNT_64
607 var object_name machPort
608 args := struct {
609 address *uint64
610 size *uint64
611 flavor machVMRegionFlavour
612 info unsafe.Pointer
613 count *machMsgTypeNumber
614 object_name *machPort
615 }{
616 address: address,
617 size: region_size,
618 flavor: _VM_REGION_BASIC_INFO_64,
619 info: info,
620 count: &count,
621 object_name: &object_name,
622 }
623 return libcCall(unsafe.Pointer(abi.FuncPCABI0(mach_vm_region_trampoline)), unsafe.Pointer(&args))
624 }
625 func mach_vm_region_trampoline()
626
627
628 func proc_regionfilename(pid int, address uint64, buf *byte, buflen int64) int32 {
629 args := struct {
630 pid int
631 address uint64
632 buf *byte
633 bufSize int64
634 }{
635 pid: pid,
636 address: address,
637 buf: buf,
638 bufSize: buflen,
639 }
640 return libcCall(unsafe.Pointer(abi.FuncPCABI0(proc_regionfilename_trampoline)), unsafe.Pointer(&args))
641 }
642 func proc_regionfilename_trampoline()
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
View as plain text