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