github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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  // +build arm64
    16  
    17  package fpu
    18  
    19  const (
    20  	// fpsimdMagic is the magic number which is used in fpsimd_context.
    21  	fpsimdMagic = 0x46508001
    22  
    23  	// fpsimdContextSize is the size of fpsimd_context.
    24  	fpsimdContextSize = 0x210
    25  )
    26  
    27  // initAarch64FPState sets up initial state.
    28  //
    29  // Related code in Linux kernel: fpsimd_flush_thread().
    30  // FPCR = FPCR_RM_RN (0x0 << 22).
    31  //
    32  // Currently, aarch64FPState is only a space of 0x210 length for fpstate.
    33  // The fp head is useless in sentry/ptrace/kvm.
    34  //
    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  }