gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/arch/fpu/fpu_arm64.go (about) 1 // Copyright 2020 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 arm64 16 // +build arm64 17 18 package fpu 19 20 const ( 21 // fpsimdMagic is the magic number which is used in fpsimd_context. 22 fpsimdMagic = 0x46508001 23 24 // fpsimdContextSize is the size of fpsimd_context. 25 fpsimdContextSize = 0x210 26 ) 27 28 // initAarch64FPState sets up initial state. 29 // 30 // Related code in Linux kernel: fpsimd_flush_thread(). 31 // FPCR = FPCR_RM_RN (0x0 << 22). 32 // 33 // Currently, aarch64FPState is only a space of 0x210 length for fpstate. 34 // The fp head is useless in sentry/ptrace/kvm. 35 func initAarch64FPState(data *State) { 36 } 37 38 func newAarch64FPStateSlice() []byte { 39 return alignedBytes(4096, 16)[:fpsimdContextSize] 40 } 41 42 // NewState returns an initialized floating point state. 43 // 44 // The returned state is large enough to store all floating point state 45 // supported by host, even if the app won't use much of it due to a restricted 46 // FeatureSet. 47 func NewState() State { 48 f := State(newAarch64FPStateSlice()) 49 initAarch64FPState(&f) 50 return f 51 } 52 53 // Fork creates and returns an identical copy of the aarch64 floating point state. 54 func (s *State) Fork() State { 55 n := State(newAarch64FPStateSlice()) 56 copy(n, *s) 57 return n 58 } 59 60 // BytePointer returns a pointer to the first byte of the state. 61 // 62 //go:nosplit 63 func (s *State) BytePointer() *byte { 64 return &(*s)[0] 65 }