github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/safecopy/xrstor_amd64.s (about)

     1  // Copyright 2023 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  // handleCheckXstateFault returns (the value stored in AX, the value stored in DI).
    18  // Control is transferred to it when checkXstate below receives SIGSEGV or SIGBUS,
    19  // with the faulting address stored in AX and the signal number stored in DI.
    20  //
    21  // It must have the same frame configuration as memcpy so that it can undo any
    22  // potential call frame set up by the assembler.
    23  TEXT handleCheckXstateFault(SB), NOSPLIT|NOFRAME, $0-26
    24  	MOVQ	AX, addr+8(FP)
    25  	MOVL	DI, sig+16(FP)
    26  
    27  	LDMXCSR	mxcsr+20(FP)
    28  	BYTE $0xDB; BYTE $0xE2; // FNCLEX
    29  	FLDCW cw+24(FP)
    30  	RET
    31  
    32  
    33  // ·checkXstate verifies that the specified floating point state can be loaded.
    34  TEXT ·checkXstate(SB),NOSPLIT|NOFRAME,$0-26
    35  	// Store 0 as the returned signal number. If we run to completion,
    36  	// this is the value the caller will see; if a signal is received,
    37  	// handleMemcpyFault will store a different value in this address.
    38  	MOVL	$0, sig+16(FP)
    39  	// MXCSR and the x87 control word are the only floating point state
    40  	// that is callee-save and thus we must save.
    41  	STMXCSR mxcsr+20(FP)
    42  	FSTCW	cw+24(FP)
    43  
    44  	MOVQ addr+0(FP), DI
    45  	MOVL $0xffffffff, AX
    46  	MOVL $0xffffffff, DX
    47  	XRSTOR (DI)
    48  
    49  	// Restore MXCSR and the x87 control word.
    50  	LDMXCSR	mxcsr+20(FP)
    51  	BYTE $0xDB; BYTE $0xE2; // FNCLEX
    52  	FLDCW cw+24(FP)
    53  	RET
    54  
    55  // func addrOfCheckXstate() uintptr
    56  TEXT ·addrOfCheckXstate(SB), $0-8
    57  	MOVQ	$·checkXstate(SB), AX
    58  	MOVQ	AX, ret+0(FP)
    59  	RET