...
1 package sysfs
2
3 import (
4 "syscall"
5 "time"
6 "unsafe"
7
8 "github.com/tetratelabs/wazero/experimental/sys"
9 )
10
11
12 type pollFd struct {
13
14 fd int32
15
16 events int16
17
18 revents int16
19 }
20
21
22 func newPollFd(fd uintptr, events, revents int16) pollFd {
23 return pollFd{fd: int32(fd), events: events, revents: revents}
24 }
25
26
27 const _POLLIN = 0x0001
28
29
30 func _poll(fds []pollFd, timeoutMillis int32) (n int, errno sys.Errno) {
31 var ts syscall.Timespec
32 if timeoutMillis >= 0 {
33 ts = syscall.NsecToTimespec(int64(time.Duration(timeoutMillis) * time.Millisecond))
34 }
35 return ppoll(fds, &ts)
36 }
37
38
39
40 func ppoll(fds []pollFd, timespec *syscall.Timespec) (n int, err sys.Errno) {
41 var fdptr *pollFd
42 nfd := len(fds)
43 if nfd != 0 {
44 fdptr = &fds[0]
45 }
46
47 n1, _, errno := syscall.Syscall6(
48 uintptr(syscall.SYS_PPOLL),
49 uintptr(unsafe.Pointer(fdptr)),
50 uintptr(nfd),
51 uintptr(unsafe.Pointer(timespec)),
52 uintptr(unsafe.Pointer(nil)),
53 uintptr(unsafe.Pointer(nil)),
54 uintptr(unsafe.Pointer(nil)))
55
56 return int(n1), sys.UnwrapOSError(errno)
57 }
58
View as plain text