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