github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/safecopy/safecopy_amd64_unsafe.go (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  //go:build amd64 || i386
    16  // +build amd64 i386
    17  
    18  package safecopy
    19  
    20  import (
    21  	"unsafe"
    22  )
    23  
    24  var (
    25  	checkXstateBegin uintptr
    26  	checkXstateEnd   uintptr
    27  )
    28  
    29  func initializeArchAddresses() {
    30  	checkXstateBegin = addrOfCheckXstate()
    31  	checkXstateEnd = FindEndAddress(checkXstateBegin)
    32  }
    33  
    34  //go:noescape
    35  func checkXstate(addr uintptr) (fault uintptr, sig int32, mxcsr uint32, cw uint16)
    36  func addrOfCheckXstate() uintptr
    37  
    38  // CheckXstate verifies that xstate can be restored by the xrstor instruction.
    39  func CheckXstate(state *byte) error {
    40  	_, sig, _, _ := checkXstate(uintptr(unsafe.Pointer(state)))
    41  	return errorFromFaultSignal(uintptr(unsafe.Pointer(state)), sig)
    42  }