gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/arch/fpu/fpu_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 fpu 19 20 import ( 21 "unsafe" 22 ) 23 24 // PrepForHostSigframe prepare the SW reserved portion of the fxsave memory 25 // layout and adds FP_XSTATE_MAGIC2. It has to be called if the state is 26 // restored by rt_sigreturn. 27 // 28 // Look at save_xstate_epilog in the kernel sources for more details. 29 // 30 //go:nosplit 31 func (s State) PrepForHostSigframe() { 32 fpsw := (*FPSoftwareFrame)(unsafe.Pointer(&s[FP_SW_FRAME_OFFSET])) 33 fpsw.Magic1 = FP_XSTATE_MAGIC1 34 fpsw.ExtendedSize = uint32(hostFPSize) + FP_XSTATE_MAGIC2_SIZE 35 fpsw.Xfeatures = XFEATURE_MASK_FPSSE | hostXCR0Mask 36 fpsw.XstateSize = uint32(hostFPSize) 37 38 if !hostUseXsave { 39 return 40 } 41 42 *(*uint32)(unsafe.Pointer(&s[hostFPSize])) = FP_XSTATE_MAGIC2 43 }