Documentation ¶
Overview ¶
Package fpu provides basic floating point helpers.
Index ¶
- Constants
- func InitHostState()
- type ErrLoadingState
- type FPSoftwareFrame
- func (f *FPSoftwareFrame) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (f *FPSoftwareFrame) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (f *FPSoftwareFrame) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (f *FPSoftwareFrame) MarshalBytes(dst []byte) []byte
- func (f *FPSoftwareFrame) MarshalUnsafe(dst []byte) []byte
- func (f *FPSoftwareFrame) Packed() bool
- func (f *FPSoftwareFrame) SizeBytes() int
- func (f *FPSoftwareFrame) UnmarshalBytes(src []byte) []byte
- func (f *FPSoftwareFrame) UnmarshalUnsafe(src []byte) []byte
- func (f *FPSoftwareFrame) WriteTo(writer io.Writer) (int64, error)
- type State
- func (s *State) AfterLoad()
- func (s *State) BytePointer() *byte
- func (s *State) Fork() State
- func (s *State) GetMXCSR() uint32
- func (s State) PrepForHostSigframe()
- func (s *State) PtraceGetFPRegs(dst io.Writer, maxlen int) (int, error)
- func (s *State) PtraceGetXstateRegs(dst io.Writer, maxlen int, featureSet cpuid.FeatureSet) (int, error)
- func (s *State) PtraceSetFPRegs(src io.Reader, maxlen int) (int, error)
- func (s *State) PtraceSetXstateRegs(src io.Reader, maxlen int, featureSet cpuid.FeatureSet) (int, error)
- func (s *State) Reset()
- func (s *State) SanitizeUser(featureSet cpuid.FeatureSet)
- func (s *State) SetMXCSR(mxcsr uint32)
- func (s State) Slice() []byte
Constants ¶
const ( // FP_XSTATE_MAGIC1 is the value of FPSoftwareFrame.Magic1. FP_XSTATE_MAGIC1 = 0x46505853 // FP_SW_FRAME_OFFSET is the offset of FPSoftwareFrame in the // fxsave/xsave area. FP_SW_FRAME_OFFSET = 464 // FP_XSTATE_MAGIC2 is the value written to the 4 bytes inserted by // Linux after the fxsave/xsave area in the signal frame. FP_XSTATE_MAGIC2 = 0x46505845 // FP_XSTATE_MAGIC2_SIZE is the size of FP_XSTATE_MAGIC2. FP_XSTATE_MAGIC2_SIZE = 4 )
From Linux's arch/x86/include/uapi/asm/sigcontext.h.
const ( // XFEATURE_MASK_FPSSE is xsave features that are always enabled in // signal frame fpstate. XFEATURE_MASK_FPSSE = 0x3 // FXSAVE_AREA_SIZE is the size of the FXSAVE area. FXSAVE_AREA_SIZE = 512 )
From Linux's arch/x86/include/asm/fpu/types.h.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrLoadingState ¶
type ErrLoadingState struct {
// contains filtered or unexported fields
}
ErrLoadingState indicates a failed restore due to unusable floating point state.
func (ErrLoadingState) Error ¶
func (e ErrLoadingState) Error() string
Error returns a sensible description of the restore error.
type FPSoftwareFrame ¶
type FPSoftwareFrame struct { Magic1 uint32 ExtendedSize uint32 Xfeatures uint64 XstateSize uint32 Padding [7]uint32 }
FPSoftwareFrame is equivalent to struct _fpx_sw_bytes, the data stored by Linux in bytes 464:511 of the fxsave/xsave frame.
+marshal
func (*FPSoftwareFrame) CopyIn ¶
func (f *FPSoftwareFrame) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
CopyIn implements marshal.Marshallable.CopyIn.
func (*FPSoftwareFrame) CopyOut ¶
func (f *FPSoftwareFrame) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
CopyOut implements marshal.Marshallable.CopyOut.
func (*FPSoftwareFrame) CopyOutN ¶
func (f *FPSoftwareFrame) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
CopyOutN implements marshal.Marshallable.CopyOutN.
func (*FPSoftwareFrame) MarshalBytes ¶
func (f *FPSoftwareFrame) MarshalBytes(dst []byte) []byte
MarshalBytes implements marshal.Marshallable.MarshalBytes.
func (*FPSoftwareFrame) MarshalUnsafe ¶
func (f *FPSoftwareFrame) MarshalUnsafe(dst []byte) []byte
MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
func (*FPSoftwareFrame) Packed ¶
func (f *FPSoftwareFrame) Packed() bool
Packed implements marshal.Marshallable.Packed.
func (*FPSoftwareFrame) SizeBytes ¶
func (f *FPSoftwareFrame) SizeBytes() int
SizeBytes implements marshal.Marshallable.SizeBytes.
func (*FPSoftwareFrame) UnmarshalBytes ¶
func (f *FPSoftwareFrame) UnmarshalBytes(src []byte) []byte
UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
func (*FPSoftwareFrame) UnmarshalUnsafe ¶
func (f *FPSoftwareFrame) UnmarshalUnsafe(src []byte) []byte
UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
type State ¶
type State []byte
State represents floating point state.
This is a simple byte slice, but may have architecture-specific methods attached to it.
func NewState ¶
func NewState() State
NewState returns an initialized floating point state.
The returned state is large enough to store all floating point state supported by host, even if the app won't use much of it due to a restricted FeatureSet. Since they may still be able to see state not advertised by CPUID we must ensure it does not contain any sentry state.
func (*State) AfterLoad ¶
func (s *State) AfterLoad()
AfterLoad converts the loaded state to the format that compatible with the current processor.
func (*State) BytePointer ¶
BytePointer returns a pointer to the first byte of the state.
func (State) PrepForHostSigframe ¶
func (s State) PrepForHostSigframe()
PrepForHostSigframe prepare the SW reserved portion of the fxsave memory layout and adds FP_XSTATE_MAGIC2. It has to be called if the state is restored by rt_sigreturn.
Look at save_xstate_epilog in the kernel sources for more details.
func (*State) PtraceGetFPRegs ¶
PtraceGetFPRegs implements Context.PtraceGetFPRegs.
func (*State) PtraceGetXstateRegs ¶
func (s *State) PtraceGetXstateRegs(dst io.Writer, maxlen int, featureSet cpuid.FeatureSet) (int, error)
PtraceGetXstateRegs implements ptrace(PTRACE_GETREGS, NT_X86_XSTATE) by writing the floating point registers from this state to dst and returning the number of bytes written, which must be less than or equal to maxlen.
func (*State) PtraceSetFPRegs ¶
PtraceSetFPRegs implements Context.PtraceSetFPRegs.
func (*State) PtraceSetXstateRegs ¶
func (s *State) PtraceSetXstateRegs(src io.Reader, maxlen int, featureSet cpuid.FeatureSet) (int, error)
PtraceSetXstateRegs implements ptrace(PTRACE_SETREGS, NT_X86_XSTATE) by reading floating point registers from src and returning the number of bytes read, which must be less than or equal to maxlen.
func (*State) SanitizeUser ¶
func (s *State) SanitizeUser(featureSet cpuid.FeatureSet)
SanitizeUser mutates s to ensure that restoring it is safe.