github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/tcpip/link/rawfile/blockingpoll_amd64.s (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #include "textflag.h"
    16  
    17  // BlockingPoll makes the ppoll() syscall while calling the version of
    18  // entersyscall that relinquishes the P so that other Gs can run. This is meant
    19  // to be called in cases when the syscall is expected to block.
    20  //
    21  // func BlockingPoll(fds *PollEvent, nfds int, timeout *syscall.Timespec) (n int, err syscall.Errno)
    22  TEXT ·BlockingPoll(SB),NOSPLIT,$0-40
    23  	CALL	·callEntersyscallblock(SB)
    24  	MOVQ	fds+0(FP), DI
    25  	MOVQ	nfds+8(FP), SI
    26  	MOVQ	timeout+16(FP), DX
    27  	MOVQ	$0x0, R10  // sigmask parameter which isn't used here
    28  	MOVQ	$0x10f, AX // SYS_PPOLL
    29  	SYSCALL
    30  	CMPQ	AX, $0xfffffffffffff001
    31  	JLS	ok
    32  	MOVQ	$-1, n+24(FP)
    33  	NEGQ	AX
    34  	MOVQ	AX, err+32(FP)
    35  	CALL	·callExitsyscall(SB)
    36  	RET
    37  ok:
    38  	MOVQ	AX, n+24(FP)
    39  	MOVQ	$0, err+32(FP)
    40  	CALL	·callExitsyscall(SB)
    41  	RET