github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/sysfs/poll_darwin.go (about) 1 package sysfs 2 3 import ( 4 "unsafe" 5 6 "github.com/bananabytelabs/wazero/experimental/sys" 7 ) 8 9 // pollFd is the struct to query for file descriptor events using poll. 10 type pollFd struct { 11 // fd is the file descriptor. 12 fd int32 13 // events is a bitmap containing the requested events. 14 events int16 15 // revents is a bitmap containing the returned events. 16 revents int16 17 } 18 19 // newPollFd is a constructor for pollFd that abstracts the platform-specific type of file descriptors. 20 func newPollFd(fd uintptr, events, revents int16) pollFd { 21 return pollFd{fd: int32(fd), events: events, revents: revents} 22 } 23 24 // _POLLIN subscribes a notification when any readable data is available. 25 const _POLLIN = 0x0001 26 27 // _poll implements poll on Darwin via the corresponding libc function. 28 func _poll(fds []pollFd, timeoutMillis int32) (n int, errno sys.Errno) { 29 var fdptr *pollFd 30 nfds := len(fds) 31 if nfds > 0 { 32 fdptr = &fds[0] 33 } 34 n1, _, err := syscall_syscall6( 35 libc_poll_trampoline_addr, 36 uintptr(unsafe.Pointer(fdptr)), 37 uintptr(nfds), 38 uintptr(int(timeoutMillis)), 39 uintptr(unsafe.Pointer(nil)), 40 uintptr(unsafe.Pointer(nil)), 41 uintptr(unsafe.Pointer(nil))) 42 return int(n1), sys.UnwrapOSError(err) 43 } 44 45 // libc_poll_trampoline_addr is the address of the 46 // `libc_poll_trampoline` symbol, defined in `poll_darwin.s`. 47 // 48 // We use this to invoke the syscall through syscall_syscall6 imported below. 49 var libc_poll_trampoline_addr uintptr 50 51 // Imports the select symbol from libc as `libc_poll`. 52 // 53 // Note: CGO mechanisms are used in darwin regardless of the CGO_ENABLED value 54 // or the "cgo" build flag. See /RATIONALE.md for why. 55 //go:cgo_import_dynamic libc_poll poll "/usr/lib/libSystem.B.dylib"