github.com/tetratelabs/wazero@v1.2.1/internal/sysfs/select_darwin.go (about) 1 package sysfs 2 3 import ( 4 "syscall" 5 "time" 6 "unsafe" 7 8 "github.com/tetratelabs/wazero/internal/platform" 9 ) 10 11 // syscall_select invokes select on Darwin, with the given timeout Duration. 12 // We implement our own version instead of relying on syscall.Select because the latter 13 // only returns the error and discards the result. 14 func syscall_select(n int, r, w, e *platform.FdSet, timeout *time.Duration) (int, error) { 15 var t *syscall.Timeval 16 if timeout != nil { 17 tv := syscall.NsecToTimeval(timeout.Nanoseconds()) 18 t = &tv 19 } 20 result, _, errno := syscall_syscall6( 21 libc_select_trampoline_addr, 22 uintptr(n), 23 uintptr(unsafe.Pointer(r)), 24 uintptr(unsafe.Pointer(w)), 25 uintptr(unsafe.Pointer(e)), 26 uintptr(unsafe.Pointer(t)), 27 0) 28 res := int(result) 29 if errno == 0 { 30 return res, nil 31 } 32 return res, errno 33 } 34 35 // libc_select_trampoline_addr is the address of the 36 // `libc_select_trampoline` symbol, defined in `select_darwin.s`. 37 // 38 // We use this to invoke the syscall through syscall_syscall6 imported below. 39 var libc_select_trampoline_addr uintptr 40 41 // Imports the select symbol from libc as `libc_select`. 42 // 43 // Note: CGO mechanisms are used in darwin regardless of the CGO_ENABLED value 44 // or the "cgo" build flag. See /RATIONALE.md for why. 45 //go:cgo_import_dynamic libc_select select "/usr/lib/libSystem.B.dylib"