fpu

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package fpu provides basic floating point helpers.

Index

Constants

View Source
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.

View Source
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

func InitHostState

func InitHostState()

InitHostState initializes host parameters.

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

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

func (s *State) BytePointer() *byte

BytePointer returns a pointer to the first byte of the state.

func (*State) Fork

func (s *State) Fork() State

Fork creates and returns an identical copy of the x86 floating point state.

func (*State) GetMXCSR

func (s *State) GetMXCSR() uint32

GetMXCSR gets the MXCSR control/status register in 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

func (s *State) PtraceGetFPRegs(dst io.Writer, maxlen int) (int, error)

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

func (s *State) PtraceSetFPRegs(src io.Reader, maxlen int) (int, error)

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) Reset

func (s *State) Reset()

Reset resets s to its initial state.

func (*State) SanitizeUser

func (s *State) SanitizeUser(featureSet cpuid.FeatureSet)

SanitizeUser mutates s to ensure that restoring it is safe.

func (*State) SetMXCSR

func (s *State) SetMXCSR(mxcsr uint32)

SetMXCSR sets the MXCSR control/status register in the state.

func (State) Slice

func (s State) Slice() []byte

Slice returns the byte array that contains only the fpu state. `s` has the fpu state and FP_XSTATE_MAGIC2.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL