1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- //go:build !arm64 && !loong64
16- // +build !arm64,!loong64
15+ //go:build linux
16+ // +build linux
1717
1818package netpoll
1919
@@ -22,12 +22,11 @@ import (
2222 "unsafe"
2323)
2424
25- const EPOLLET = - syscall .EPOLLET
25+ //go:linkname entersyscallblock runtime.entersyscallblock
26+ func entersyscallblock ()
2627
27- type epollevent struct {
28- events uint32
29- data [8 ]byte // unaligned uintptr
30- }
28+ //go:linkname exitsyscall runtime.exitsyscall
29+ func exitsyscall ()
3130
3231// EpollCreate implements epoll_create1.
3332func EpollCreate (flag int ) (fd int , err error ) {
@@ -51,14 +50,36 @@ func EpollCtl(epfd int, op int, fd int, event *epollevent) (err error) {
5150// EpollWait implements epoll_wait.
5251func EpollWait (epfd int , events []epollevent , msec int ) (n int , err error ) {
5352 var r0 uintptr
54- var _p0 = unsafe .Pointer (& events [0 ])
55- if msec == 0 {
56- r0 , _ , err = syscall .RawSyscall6 (syscall .SYS_EPOLL_WAIT , uintptr (epfd ), uintptr (_p0 ), uintptr (len (events )), 0 , 0 , 0 )
57- } else {
58- r0 , _ , err = syscall .Syscall6 (syscall .SYS_EPOLL_WAIT , uintptr (epfd ), uintptr (_p0 ), uintptr (len (events )), uintptr (msec ), 0 , 0 )
53+ r0 , _ , err = syscall .Syscall6 (SYS_EPOLL_WAIT , uintptr (epfd ), uintptr (unsafe .Pointer (& events [0 ])), uintptr (len (events )), uintptr (msec ), 0 , 0 )
54+ if err == syscall .Errno (0 ) {
55+ err = nil
5956 }
57+ return int (r0 ), err
58+ }
59+
60+ func EpollWaitRaw (epfd int , events []epollevent , msec int ) (n int , err error ) {
61+ var r0 uintptr
62+ r0 , _ , err = syscall .RawSyscall6 (SYS_EPOLL_WAIT , uintptr (epfd ), uintptr (unsafe .Pointer (& events [0 ])), uintptr (len (events )), uintptr (msec ), 0 , 0 )
6063 if err == syscall .Errno (0 ) {
6164 err = nil
6265 }
6366 return int (r0 ), err
6467}
68+
69+ func EpollWaitBlock (epfd int , events []epollevent , msec int ) (n int , err error ) {
70+ r0 , _ , errno := BlockSyscall6 (SYS_EPOLL_WAIT , uintptr (epfd ), uintptr (unsafe .Pointer (& events [0 ])), uintptr (len (events )), uintptr (msec ), 0 , 0 )
71+ if errno == syscall .Errno (0 ) {
72+ err = nil
73+ } else {
74+ err = errno
75+ }
76+ return int (r0 ), err
77+ }
78+
79+ //go:nosplit
80+ func BlockSyscall6 (trap , a1 , a2 , a3 , a4 , a5 , a6 uintptr ) (r1 , r2 uintptr , err syscall.Errno ) {
81+ entersyscallblock ()
82+ r1 , r2 , err = syscall .RawSyscall6 (trap , a1 , a2 , a3 , a4 , a5 , a6 )
83+ exitsyscall ()
84+ return r1 , r2 , err
85+ }
0 commit comments