arch

package
v0.0.0-...-ff2c174 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: Apache-2.0, MIT Imports: 22 Imported by: 0

Documentation

Overview

Package arch provides abstractions around architecture-dependent details, such as syscall calling conventions, native types, etc.

Index

Constants

View Source
const (
	// SignalActDefault is SIG_DFL and specifies that the default behavior for
	// a signal should be taken.
	SignalActDefault = 0

	// SignalActIgnore is SIG_IGN and specifies that a signal should be
	// ignored.
	SignalActIgnore = 1
)

Special values for SignalAct.Handler.

View Source
const (
	SignalFlagNoCldStop    = 0x00000001
	SignalFlagNoCldWait    = 0x00000002
	SignalFlagSigInfo      = 0x00000004
	SignalFlagRestorer     = 0x04000000
	SignalFlagOnStack      = 0x08000000
	SignalFlagRestart      = 0x10000000
	SignalFlagInterrupt    = 0x20000000
	SignalFlagNoDefer      = 0x40000000
	SignalFlagResetHandler = 0x80000000
)

Available signal flags.

View Source
const (
	// SignalInfoUser (properly SI_USER) indicates that a signal was sent from
	// a kill() or raise() syscall.
	SignalInfoUser = 0

	// SignalInfoKernel (properly SI_KERNEL) indicates that the signal was sent
	// by the kernel.
	SignalInfoKernel = 0x80

	// SignalInfoTimer (properly SI_TIMER) indicates that the signal was sent
	// by an expired timer.
	SignalInfoTimer = -2

	// SignalInfoTkill (properly SI_TKILL) indicates that the signal was sent
	// from a tkill() or tgkill() syscall.
	SignalInfoTkill = -6

	// CLD_EXITED indicates that a task exited.
	CLD_EXITED = 1

	// CLD_KILLED indicates that a task was killed by a signal.
	CLD_KILLED = 2

	// CLD_DUMPED indicates that a task was killed by a signal and then dumped
	// core.
	CLD_DUMPED = 3

	// CLD_TRAPPED indicates that a task was stopped by ptrace.
	CLD_TRAPPED = 4

	// CLD_STOPPED indicates that a thread group completed a group stop.
	CLD_STOPPED = 5

	// CLD_CONTINUED indicates that a group-stopped thread group was continued.
	CLD_CONTINUED = 6

	// SYS_SECCOMP indicates that a signal originates from seccomp.
	SYS_SECCOMP = 1

	// TRAP_BRKPT indicates a breakpoint trap.
	TRAP_BRKPT = 1
)

Possible values for SignalInfo.Code. These values originate from the Linux kernel's include/uapi/asm-generic/siginfo.h.

View Source
const (
	// SignalStackFlagOnStack is possible set on return from getaltstack,
	// in order to indicate that the thread is currently on the alt stack.
	SignalStackFlagOnStack = 1

	// SignalStackFlagDisable is a flag to indicate the stack is disabled.
	SignalStackFlagDisable = 2
)
View Source
const Host = AMD64

Host specifies the host architecture.

View Source
const StackBottomMagic = ^hostarch.Addr(0) // hostarch.Addr(-1)

StackBottomMagic is the special address callers must past to all stack marshalling operations to cause the src/dst address to be computed based on the current end of the stack.

View Source
const (
	// SyscallWidth is the width of syscall, sysenter, and int 80 insturctions.
	SyscallWidth = 2
)

System-related constants for x86.

Variables

View Source
var (
	// TrapInstruction is the x86 trap instruction.
	TrapInstruction = [1]byte{0xcc}

	// CPUIDInstruction is the x86 CPUID instruction.
	CPUIDInstruction = [2]byte{0xf, 0xa2}

	// X86TrapFlag is an exported const for use by other packages.
	X86TrapFlag uint64 = (1 << 8)
)

Functions

This section is empty.

Types

type Arch

type Arch int

Arch describes an architecture.

const (
	// AMD64 is the x86-64 architecture.
	AMD64 Arch = iota
	// ARM64 is the aarch64 architecture.
	ARM64
)

func (Arch) String

func (a Arch) String() string

String implements fmt.Stringer.

type AuxEntry

type AuxEntry struct {
	Key   uint64
	Value hostarch.Addr
}

An AuxEntry represents an entry in an ELF auxiliary vector.

+stateify savable

func (*AuxEntry) StateFields

func (a *AuxEntry) StateFields() []string

func (*AuxEntry) StateLoad

func (a *AuxEntry) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*AuxEntry) StateSave

func (a *AuxEntry) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*AuxEntry) StateTypeName

func (a *AuxEntry) StateTypeName() string

type Auxv

type Auxv []AuxEntry

An Auxv represents an ELF auxiliary vector.

type Context

type Context interface {
	// Arch returns the architecture for this Context.
	Arch() Arch

	// Native converts a generic type to a native value.
	//
	// Because the architecture is not specified here, we may be dealing
	// with return values of varying sizes (for example ARCH_GETFS). This
	// is a simple utility function to convert to the native size in these
	// cases, and then we can CopyOut.
	Native(val uintptr) marshal.Marshallable

	// Value converts a native type back to a generic value.
	// Once a value has been converted to native via the above call -- it
	// can be converted back here.
	Value(val marshal.Marshallable) uintptr

	// Width returns the number of bytes for a native value.
	Width() uint

	// Fork creates a clone of the context.
	Fork() Context

	// SyscallNo returns the syscall number.
	SyscallNo() uintptr

	// SyscallSaveOrig save orignal register value.
	SyscallSaveOrig()

	// SyscallArgs returns the syscall arguments in an array.
	SyscallArgs() SyscallArguments

	// Return returns the return value for a system call.
	Return() uintptr

	// SetReturn sets the return value for a system call.
	SetReturn(value uintptr)

	// RestartSyscall reverses over the current syscall instruction, such that
	// when the application resumes execution the syscall will be re-attempted.
	RestartSyscall()

	// RestartSyscallWithRestartBlock reverses over the current syscall
	// instraction and overwrites the current syscall number with that of
	// restart_syscall(2). This causes the application to restart the current
	// syscall with a custom function when execution resumes.
	RestartSyscallWithRestartBlock()

	// IP returns the current instruction pointer.
	IP() uintptr

	// SetIP sets the current instruction pointer.
	SetIP(value uintptr)

	// Stack returns the current stack pointer.
	Stack() uintptr

	// SetStack sets the current stack pointer.
	SetStack(value uintptr)

	// TLS returns the current TLS pointer.
	TLS() uintptr

	// SetTLS sets the current TLS pointer. Returns false if value is invalid.
	SetTLS(value uintptr) bool

	// SetOldRSeqInterruptedIP sets the register that contains the old IP
	// when an "old rseq" restartable sequence is interrupted.
	SetOldRSeqInterruptedIP(value uintptr)

	// StateData returns a pointer to underlying architecture state.
	StateData() *State

	// RegisterMap returns a map of all registers.
	RegisterMap() (map[string]uintptr, error)

	// NewSignalAct returns a new object that is equivalent to struct sigaction
	// in the guest architecture.
	NewSignalAct() NativeSignalAct

	// NewSignalStack returns a new object that is equivalent to stack_t in the
	// guest architecture.
	NewSignalStack() NativeSignalStack

	// SignalSetup modifies the context in preparation for handling the
	// given signal.
	//
	// st is the stack where the signal handler frame should be
	// constructed.
	//
	// act is the SignalAct that specifies how this signal is being
	// handled.
	//
	// info is the SignalInfo of the signal being delivered.
	//
	// alt is the alternate signal stack (even if the alternate signal
	// stack is not going to be used).
	//
	// sigset is the signal mask before entering the signal handler.
	SignalSetup(st *Stack, act *SignalAct, info *SignalInfo, alt *SignalStack, sigset linux.SignalSet) error

	// SignalRestore restores context after returning from a signal
	// handler.
	//
	// st is the current thread stack.
	//
	// rt is true if SignalRestore is being entered from rt_sigreturn and
	// false if SignalRestore is being entered from sigreturn.
	// SignalRestore returns the thread's new signal mask.
	SignalRestore(st *Stack, rt bool) (linux.SignalSet, SignalStack, error)

	// CPUIDEmulate emulates a CPUID instruction according to current register state.
	CPUIDEmulate(l log.Logger)

	// SingleStep returns true if single stepping is enabled.
	SingleStep() bool

	// SetSingleStep enables single stepping.
	SetSingleStep()

	// ClearSingleStep disables single stepping.
	ClearSingleStep()

	// FloatingPointData will be passed to underlying save routines.
	FloatingPointData() *fpu.State

	// NewMmapLayout returns a layout for a new MM, where MinAddr for the
	// returned layout must be no lower than min, and MaxAddr for the returned
	// layout must be no higher than max. Repeated calls to NewMmapLayout may
	// return different layouts.
	NewMmapLayout(min, max hostarch.Addr, limits *limits.LimitSet) (MmapLayout, error)

	// PIELoadAddress returns a preferred load address for a
	// position-independent executable within l.
	PIELoadAddress(l MmapLayout) hostarch.Addr

	// FeatureSet returns the FeatureSet in use in this context.
	FeatureSet() *cpuid.FeatureSet

	// PtracePeekUser implements ptrace(PTRACE_PEEKUSR).
	PtracePeekUser(addr uintptr) (marshal.Marshallable, error)

	// PtracePokeUser implements ptrace(PTRACE_POKEUSR).
	PtracePokeUser(addr, data uintptr) error

	// PtraceGetRegs implements ptrace(PTRACE_GETREGS) by writing the
	// general-purpose registers represented by this Context to dst and
	// returning the number of bytes written.
	PtraceGetRegs(dst io.Writer) (int, error)

	// PtraceSetRegs implements ptrace(PTRACE_SETREGS) by reading
	// general-purpose registers from src into this Context and returning the
	// number of bytes read.
	PtraceSetRegs(src io.Reader) (int, error)

	// PtraceGetRegSet implements ptrace(PTRACE_GETREGSET) by writing the
	// register set given by architecture-defined value regset from this
	// Context to dst and returning the number of bytes written, which must be
	// less than or equal to maxlen.
	PtraceGetRegSet(regset uintptr, dst io.Writer, maxlen int) (int, error)

	// PtraceSetRegSet implements ptrace(PTRACE_SETREGSET) by reading the
	// register set given by architecture-defined value regset from src and
	// returning the number of bytes read, which must be less than or equal to
	// maxlen.
	PtraceSetRegSet(regset uintptr, src io.Reader, maxlen int) (int, error)

	// FullRestore returns 'true' if all CPU registers must be restored
	// when switching to the untrusted application. Typically a task enters
	// and leaves the kernel via a system call. Platform.Switch() may
	// optimize for this by not saving/restoring all registers if allowed
	// by the ABI. For e.g. the amd64 ABI specifies that syscall clobbers
	// %rcx and %r11. If FullRestore returns true then these optimizations
	// must be disabled and all registers restored.
	FullRestore() bool
}

Context provides architecture-dependent information for a specific thread.

NOTE(b/34169503): Currently we use uintptr here to refer to a generic native register value. While this will work for the foreseeable future, it isn't strictly correct. We may want to create some abstraction that makes this more clear or enables us to store values of arbitrary widths. This is particularly true for RegisterMap().

func New

func New(arch Arch, fs *cpuid.FeatureSet) Context

New returns a new architecture context.

type MmapDirection

type MmapDirection int

MmapDirection is a search direction for mmaps.

const (
	// MmapBottomUp instructs mmap to prefer lower addresses.
	MmapBottomUp MmapDirection = iota

	// MmapTopDown instructs mmap to prefer higher addresses.
	MmapTopDown
)

type MmapLayout

type MmapLayout struct {
	// MinAddr is the lowest mappable address.
	MinAddr hostarch.Addr

	// MaxAddr is the highest mappable address.
	MaxAddr hostarch.Addr

	// BottomUpBase is the lowest address that may be returned for a
	// MmapBottomUp mmap.
	BottomUpBase hostarch.Addr

	// TopDownBase is the highest address that may be returned for a
	// MmapTopDown mmap.
	TopDownBase hostarch.Addr

	// DefaultDirection is the direction for most non-fixed mmaps in this
	// layout.
	DefaultDirection MmapDirection

	// MaxStackRand is the maximum randomization to apply to stack
	// allocations to maintain a proper gap between the stack and
	// TopDownBase.
	MaxStackRand uint64
}

MmapLayout defines the layout of the user address space for a particular MemoryManager.

Note that "highest address" below is always exclusive.

+stateify savable

func (*MmapLayout) StateFields

func (m *MmapLayout) StateFields() []string

func (*MmapLayout) StateLoad

func (m *MmapLayout) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*MmapLayout) StateSave

func (m *MmapLayout) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*MmapLayout) StateTypeName

func (m *MmapLayout) StateTypeName() string

func (*MmapLayout) Valid

func (m *MmapLayout) Valid() bool

Valid returns true if this layout is valid.

type NativeSignalAct

type NativeSignalAct interface {
	marshal.Marshallable

	// SerializeFrom copies the data in the host SignalAct s into this object.
	SerializeFrom(s *SignalAct)

	// DeserializeTo copies the data in this object into the host SignalAct s.
	DeserializeTo(s *SignalAct)
}

NativeSignalAct is a type that is equivalent to struct sigaction in the guest architecture.

type NativeSignalStack

type NativeSignalStack interface {
	marshal.Marshallable

	// SerializeFrom copies the data in the host SignalStack s into this
	// object.
	SerializeFrom(s *SignalStack)

	// DeserializeTo copies the data in this object into the host SignalStack
	// s.
	DeserializeTo(s *SignalStack)
}

NativeSignalStack is a type that is equivalent to stack_t in the guest architecture.

type Registers

type Registers struct {
	linux.PtraceRegs
}

Registers represents the CPU registers for this architecture.

+stateify savable

func (*Registers) StateFields

func (r *Registers) StateFields() []string

func (*Registers) StateLoad

func (r *Registers) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*Registers) StateSave

func (r *Registers) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*Registers) StateTypeName

func (r *Registers) StateTypeName() string

type SignalAct

type SignalAct struct {
	Handler  uint64
	Flags    uint64
	Restorer uint64 // Only used on amd64.
	Mask     linux.SignalSet
}

SignalAct represents the action that should be taken when a signal is delivered, and is equivalent to struct sigaction.

+marshal +stateify savable

func (*SignalAct) CopyIn

func (s *SignalAct) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*SignalAct) CopyOut

func (s *SignalAct) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*SignalAct) CopyOutN

func (s *SignalAct) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*SignalAct) DeserializeTo

func (s *SignalAct) DeserializeTo(other *SignalAct)

DeserializeTo implements NativeSignalAct.DeserializeTo.

func (SignalAct) HasRestorer

func (s SignalAct) HasRestorer() bool

HasRestorer returns true iff this SignalAct has the Restorer flag set.

func (SignalAct) IsNoDefer

func (s SignalAct) IsNoDefer() bool

IsNoDefer returns true iff this SignalAct has the NoDefer flag set.

func (SignalAct) IsOnStack

func (s SignalAct) IsOnStack() bool

IsOnStack returns true iff this SignalAct has the OnStack flag set.

func (SignalAct) IsResetHandler

func (s SignalAct) IsResetHandler() bool

IsResetHandler returns true iff this SignalAct has the ResetHandler flag set.

func (SignalAct) IsRestart

func (s SignalAct) IsRestart() bool

IsRestart returns true iff this SignalAct has the Restart flag set.

func (SignalAct) IsSigInfo

func (s SignalAct) IsSigInfo() bool

IsSigInfo returns true iff this handle expects siginfo.

func (*SignalAct) MarshalBytes

func (s *SignalAct) MarshalBytes(dst []byte)

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*SignalAct) MarshalUnsafe

func (s *SignalAct) MarshalUnsafe(dst []byte)

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*SignalAct) Packed

func (s *SignalAct) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*SignalAct) SerializeFrom

func (s *SignalAct) SerializeFrom(other *SignalAct)

SerializeFrom implements NativeSignalAct.SerializeFrom.

func (*SignalAct) SizeBytes

func (s *SignalAct) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*SignalAct) StateFields

func (s *SignalAct) StateFields() []string

func (*SignalAct) StateLoad

func (s *SignalAct) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*SignalAct) StateSave

func (s *SignalAct) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SignalAct) StateTypeName

func (s *SignalAct) StateTypeName() string

func (*SignalAct) UnmarshalBytes

func (s *SignalAct) UnmarshalBytes(src []byte)

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*SignalAct) UnmarshalUnsafe

func (s *SignalAct) UnmarshalUnsafe(src []byte)

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*SignalAct) WriteTo

func (s *SignalAct) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type SignalContext64

type SignalContext64 struct {
	R8      uint64
	R9      uint64
	R10     uint64
	R11     uint64
	R12     uint64
	R13     uint64
	R14     uint64
	R15     uint64
	Rdi     uint64
	Rsi     uint64
	Rbp     uint64
	Rbx     uint64
	Rdx     uint64
	Rax     uint64
	Rcx     uint64
	Rsp     uint64
	Rip     uint64
	Eflags  uint64
	Cs      uint16
	Gs      uint16 // always 0 on amd64.
	Fs      uint16 // always 0 on amd64.
	Ss      uint16 // only restored if _UC_STRICT_RESTORE_SS (unsupported).
	Err     uint64
	Trapno  uint64
	Oldmask linux.SignalSet
	Cr2     uint64
	// Pointer to a struct _fpstate. See b/33003106#comment8.
	Fpstate  uint64
	Reserved [8]uint64
}

SignalContext64 is equivalent to struct sigcontext, the type passed as the second argument to signal handlers set by signal(2).

+marshal

func (*SignalContext64) CopyIn

func (s *SignalContext64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*SignalContext64) CopyOut

func (s *SignalContext64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*SignalContext64) CopyOutN

func (s *SignalContext64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*SignalContext64) MarshalBytes

func (s *SignalContext64) MarshalBytes(dst []byte)

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*SignalContext64) MarshalUnsafe

func (s *SignalContext64) MarshalUnsafe(dst []byte)

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*SignalContext64) Packed

func (s *SignalContext64) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*SignalContext64) SizeBytes

func (s *SignalContext64) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*SignalContext64) UnmarshalBytes

func (s *SignalContext64) UnmarshalBytes(src []byte)

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*SignalContext64) UnmarshalUnsafe

func (s *SignalContext64) UnmarshalUnsafe(src []byte)

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*SignalContext64) WriteTo

func (s *SignalContext64) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type SignalInfo

type SignalInfo struct {
	Signo int32 // Signal number
	Errno int32 // Errno value
	Code  int32 // Signal code

	// struct siginfo::_sifields is a union. In SignalInfo, fields in the union
	// are accessed through methods.
	//
	// For reference, here is the definition of _sifields: (_sigfault._trapno,
	// which does not exist on x86, omitted for clarity)
	//
	// union {
	// 	int _pad[SI_PAD_SIZE];
	//
	// 	/* kill() */
	// 	struct {
	// 		__kernel_pid_t _pid;	/* sender's pid */
	// 		__ARCH_SI_UID_T _uid;	/* sender's uid */
	// 	} _kill;
	//
	// 	/* POSIX.1b timers */
	// 	struct {
	// 		__kernel_timer_t _tid;	/* timer id */
	// 		int _overrun;		/* overrun count */
	// 		char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
	// 		sigval_t _sigval;	/* same as below */
	// 		int _sys_private;       /* not to be passed to user */
	// 	} _timer;
	//
	// 	/* POSIX.1b signals */
	// 	struct {
	// 		__kernel_pid_t _pid;	/* sender's pid */
	// 		__ARCH_SI_UID_T _uid;	/* sender's uid */
	// 		sigval_t _sigval;
	// 	} _rt;
	//
	// 	/* SIGCHLD */
	// 	struct {
	// 		__kernel_pid_t _pid;	/* which child */
	// 		__ARCH_SI_UID_T _uid;	/* sender's uid */
	// 		int _status;		/* exit code */
	// 		__ARCH_SI_CLOCK_T _utime;
	// 		__ARCH_SI_CLOCK_T _stime;
	// 	} _sigchld;
	//
	// 	/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
	// 	struct {
	// 		void *_addr; /* faulting insn/memory ref. */
	// 		short _addr_lsb; /* LSB of the reported address */
	// 	} _sigfault;
	//
	// 	/* SIGPOLL */
	// 	struct {
	// 		__ARCH_SI_BAND_T _band;	/* POLL_IN, POLL_OUT, POLL_MSG */
	// 		int _fd;
	// 	} _sigpoll;
	//
	// 	/* SIGSYS */
	// 	struct {
	// 		void *_call_addr; /* calling user insn */
	// 		int _syscall;	/* triggering system call number */
	// 		unsigned int _arch;	/* AUDIT_ARCH_* of syscall */
	// 	} _sigsys;
	// } _sifields;
	//
	// _sifields is padded so that the size of siginfo is SI_MAX_SIZE = 128
	// bytes.
	Fields [128 - 16]byte
	// contains filtered or unexported fields
}

SignalInfo represents information about a signal being delivered, and is equivalent to struct siginfo in linux kernel(linux/include/uapi/asm-generic/siginfo.h).

+marshal +stateify savable

func (*SignalInfo) Addr

func (s *SignalInfo) Addr() uint64

Addr returns the si_addr field.

func (*SignalInfo) Arch

func (s *SignalInfo) Arch() uint32

Arch returns the si_arch field.

func (*SignalInfo) Band

func (s *SignalInfo) Band() int64

Band returns the si_band field.

func (*SignalInfo) CallAddr

func (s *SignalInfo) CallAddr() uint64

CallAddr returns the si_call_addr field.

func (*SignalInfo) CopyIn

func (s *SignalInfo) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*SignalInfo) CopyOut

func (s *SignalInfo) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*SignalInfo) CopyOutN

func (s *SignalInfo) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*SignalInfo) FD

func (s *SignalInfo) FD() uint32

FD returns the si_fd field.

func (*SignalInfo) FixSignalCodeForUser

func (s *SignalInfo) FixSignalCodeForUser()

FixSignalCodeForUser fixes up si_code.

The si_code we get from Linux may contain the kernel-specific code in the top 16 bits if it's positive (e.g., from ptrace). Linux's copy_siginfo_to_user does

err |= __put_user((short)from->si_code, &to->si_code);

to mask out those bits and we need to do the same.

func (*SignalInfo) MarshalBytes

func (s *SignalInfo) MarshalBytes(dst []byte)

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*SignalInfo) MarshalUnsafe

func (s *SignalInfo) MarshalUnsafe(dst []byte)

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*SignalInfo) Overrun

func (s *SignalInfo) Overrun() int32

Overrun returns the si_overrun field.

func (*SignalInfo) PID

func (s *SignalInfo) PID() int32

PID returns the si_pid field.

func (*SignalInfo) Packed

func (s *SignalInfo) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*SignalInfo) SetAddr

func (s *SignalInfo) SetAddr(val uint64)

SetAddr sets the si_addr field.

func (*SignalInfo) SetArch

func (s *SignalInfo) SetArch(val uint32)

SetArch mutates the si_arch field.

func (*SignalInfo) SetBand

func (s *SignalInfo) SetBand(val int64)

SetBand mutates the si_band field.

func (*SignalInfo) SetCallAddr

func (s *SignalInfo) SetCallAddr(val uint64)

SetCallAddr mutates the si_call_addr field.

func (*SignalInfo) SetFD

func (s *SignalInfo) SetFD(val uint32)

SetFD mutates the si_fd field.

func (*SignalInfo) SetOverrun

func (s *SignalInfo) SetOverrun(val int32)

SetOverrun sets the si_overrun field.

func (*SignalInfo) SetPID

func (s *SignalInfo) SetPID(val int32)

SetPID mutates the si_pid field.

func (*SignalInfo) SetSigval

func (s *SignalInfo) SetSigval(val uint64)

SetSigval mutates the sigval field.

func (*SignalInfo) SetStatus

func (s *SignalInfo) SetStatus(val int32)

SetStatus mutates the si_status field.

func (*SignalInfo) SetSyscall

func (s *SignalInfo) SetSyscall(val int32)

SetSyscall mutates the si_syscall field.

func (*SignalInfo) SetTimerID

func (s *SignalInfo) SetTimerID(val linux.TimerID)

SetTimerID sets the si_timerid field.

func (*SignalInfo) SetUID

func (s *SignalInfo) SetUID(val int32)

SetUID mutates the si_uid field.

func (*SignalInfo) Sigval

func (s *SignalInfo) Sigval() uint64

Sigval returns the sigval field, which is aliased to both si_int and si_ptr.

func (*SignalInfo) SizeBytes

func (s *SignalInfo) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*SignalInfo) StateFields

func (s *SignalInfo) StateFields() []string

func (*SignalInfo) StateLoad

func (s *SignalInfo) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*SignalInfo) StateSave

func (s *SignalInfo) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SignalInfo) StateTypeName

func (s *SignalInfo) StateTypeName() string

func (*SignalInfo) Status

func (s *SignalInfo) Status() int32

Status returns the si_status field.

func (*SignalInfo) Syscall

func (s *SignalInfo) Syscall() int32

Syscall returns the si_syscall field.

func (*SignalInfo) TimerID

func (s *SignalInfo) TimerID() linux.TimerID

TimerID returns the si_timerid field.

func (*SignalInfo) UID

func (s *SignalInfo) UID() int32

UID returns the si_uid field.

func (*SignalInfo) UnmarshalBytes

func (s *SignalInfo) UnmarshalBytes(src []byte)

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*SignalInfo) UnmarshalUnsafe

func (s *SignalInfo) UnmarshalUnsafe(src []byte)

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*SignalInfo) WriteTo

func (s *SignalInfo) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type SignalStack

type SignalStack struct {
	Addr  uint64
	Flags uint32

	Size uint64
	// contains filtered or unexported fields
}

SignalStack represents information about a user stack, and is equivalent to stack_t.

+marshal +stateify savable

func (*SignalStack) Contains

func (s *SignalStack) Contains(sp hostarch.Addr) bool

Contains checks if the stack pointer is within this stack.

func (*SignalStack) CopyIn

func (s *SignalStack) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*SignalStack) CopyOut

func (s *SignalStack) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*SignalStack) CopyOutN

func (s *SignalStack) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*SignalStack) DeserializeTo

func (s *SignalStack) DeserializeTo(other *SignalStack)

DeserializeTo implements NativeSignalStack.DeserializeTo.

func (SignalStack) IsEnabled

func (s SignalStack) IsEnabled() bool

IsEnabled returns true iff this signal stack is marked as enabled.

func (*SignalStack) MarshalBytes

func (s *SignalStack) MarshalBytes(dst []byte)

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*SignalStack) MarshalUnsafe

func (s *SignalStack) MarshalUnsafe(dst []byte)

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*SignalStack) Packed

func (s *SignalStack) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*SignalStack) SerializeFrom

func (s *SignalStack) SerializeFrom(other *SignalStack)

SerializeFrom implements NativeSignalStack.SerializeFrom.

func (*SignalStack) SetOnStack

func (s *SignalStack) SetOnStack()

SetOnStack marks this signal stack as in use.

Note that there is no corresponding ClearOnStack, and that this should only be called on copies that are serialized to userspace.

func (*SignalStack) SizeBytes

func (s *SignalStack) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*SignalStack) StateFields

func (s *SignalStack) StateFields() []string

func (*SignalStack) StateLoad

func (s *SignalStack) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*SignalStack) StateSave

func (s *SignalStack) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SignalStack) StateTypeName

func (s *SignalStack) StateTypeName() string

func (SignalStack) Top

func (s SignalStack) Top() hostarch.Addr

Top returns the stack's top address.

func (*SignalStack) UnmarshalBytes

func (s *SignalStack) UnmarshalBytes(src []byte)

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*SignalStack) UnmarshalUnsafe

func (s *SignalStack) UnmarshalUnsafe(src []byte)

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*SignalStack) WriteTo

func (s *SignalStack) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type Stack

type Stack struct {
	// Our arch info.
	// We use this for automatic Native conversion of hostarch.Addrs during
	// Push() and Pop().
	Arch Context

	// The interface used to actually copy user memory.
	IO usermem.IO

	// Our current stack bottom.
	Bottom hostarch.Addr
	// contains filtered or unexported fields
}

Stack is a simple wrapper around a hostarch.IO and an address. Stack implements marshal.CopyContext, and marshallable values can be pushed or popped from the stack through the marshal.Marshallable interface.

Stack is not thread-safe.

func (*Stack) Align

func (s *Stack) Align(offset int)

Align aligns the stack to the given offset.

func (*Stack) CopyInBytes

func (s *Stack) CopyInBytes(sentinel hostarch.Addr, b []byte) (int, error)

CopyInBytes implements marshal.CopyContext.CopyInBytes. CopyInBytes computes an appropriate address based on the current end of the stack. Callers must use the sentinel address StackBottomMagic to marshal methods to indicate this.

func (*Stack) CopyOutBytes

func (s *Stack) CopyOutBytes(sentinel hostarch.Addr, b []byte) (int, error)

CopyOutBytes implements marshal.CopyContext.CopyOutBytes. CopyOutBytes computes an appropriate address based on the current end of the stack. Callers use the sentinel address StackBottomMagic to marshal methods to indicate this.

func (*Stack) CopyScratchBuffer

func (s *Stack) CopyScratchBuffer(size int) []byte

CopyScratchBuffer implements marshal.CopyContext.CopyScratchBuffer.

func (*Stack) Load

func (s *Stack) Load(args []string, env []string, aux Auxv) (StackLayout, error)

Load pushes the given args, env and aux vector to the stack using the well-known format for a new executable. It returns the start and end of the argument and environment vectors.

func (*Stack) PushNullTerminatedByteSlice

func (s *Stack) PushNullTerminatedByteSlice(bs []byte) (int, error)

PushNullTerminatedByteSlice writes bs to the stack, followed by an extra null byte at the end. On error, the contents of the stack and the bottom cursor are undefined.

type StackLayout

type StackLayout struct {
	// ArgvStart is the beginning of the argument vector.
	ArgvStart hostarch.Addr

	// ArgvEnd is the end of the argument vector.
	ArgvEnd hostarch.Addr

	// EnvvStart is the beginning of the environment vector.
	EnvvStart hostarch.Addr

	// EnvvEnd is the end of the environment vector.
	EnvvEnd hostarch.Addr
}

StackLayout describes the location of the arguments and environment on the stack.

type State

type State struct {
	// The system registers.
	Regs Registers

	// FeatureSet is a pointer to the currently active feature set.
	FeatureSet *cpuid.FeatureSet
	// contains filtered or unexported fields
}

State contains the common architecture bits for X86 (the build tag of this file ensures it's only built on x86).

+stateify savable

func (*State) CPUIDEmulate

func (s *State) CPUIDEmulate(l log.Logger)

CPUIDEmulate emulates a cpuid instruction.

func (*State) ClearSingleStep

func (s *State) ClearSingleStep()

ClearSingleStep enables single stepping.

func (*State) Fork

func (s *State) Fork() State

Fork creates and returns an identical copy of the state.

func (*State) FullRestore

func (s *State) FullRestore() bool

FullRestore indicates whether a full restore is required.

func (State) Proto

func (s State) Proto() *rpb.Registers

Proto returns a protobuf representation of the system registers in State.

func (*State) PtraceGetRegSet

func (s *State) PtraceGetRegSet(regset uintptr, dst io.Writer, maxlen int) (int, error)

PtraceGetRegSet implements Context.PtraceGetRegSet.

func (*State) PtraceGetRegs

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

PtraceGetRegs implements Context.PtraceGetRegs.

func (*State) PtraceSetRegSet

func (s *State) PtraceSetRegSet(regset uintptr, src io.Reader, maxlen int) (int, error)

PtraceSetRegSet implements Context.PtraceSetRegSet.

func (*State) PtraceSetRegs

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

PtraceSetRegs implements Context.PtraceSetRegs.

func (*State) RegisterMap

func (s *State) RegisterMap() (map[string]uintptr, error)

RegisterMap returns a map of all registers.

func (*State) SetSingleStep

func (s *State) SetSingleStep()

SetSingleStep enables single stepping.

func (*State) SingleStep

func (s *State) SingleStep() bool

SingleStep implements Context.SingleStep.

func (*State) StateData

func (s *State) StateData() *State

StateData implements Context.StateData.

func (*State) StateFields

func (s *State) StateFields() []string

func (*State) StateLoad

func (s *State) StateLoad(stateSourceObject state.Source)

+checklocksignore

func (*State) StateSave

func (s *State) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*State) StateTypeName

func (s *State) StateTypeName() string

type SyscallArgument

type SyscallArgument struct {
	// Prefer to use accessor methods instead of 'Value' directly.
	Value uintptr
}

SyscallArgument is an argument supplied to a syscall implementation. The methods used to access the arguments are named after the ***C type name*** and they convert to the closest Go type available. For example, Int() refers to a 32-bit signed integer argument represented in Go as an int32.

Using the accessor methods guarantees that the conversion between types is correct, taking into account size and signedness (i.e., zero-extension vs signed-extension).

func (SyscallArgument) Int

func (a SyscallArgument) Int() int32

Int returns the int32 representation of a 32-bit signed integer argument.

func (SyscallArgument) Int64

func (a SyscallArgument) Int64() int64

Int64 returns the int64 representation of a 64-bit signed integer argument.

func (SyscallArgument) ModeT

func (a SyscallArgument) ModeT() uint

ModeT returns the int representation of a mode_t argument.

func (SyscallArgument) Pointer

func (a SyscallArgument) Pointer() hostarch.Addr

Pointer returns the hostarch.Addr representation of a pointer argument.

func (SyscallArgument) SizeT

func (a SyscallArgument) SizeT() uint

SizeT returns the uint representation of a size_t argument.

func (SyscallArgument) Uint

func (a SyscallArgument) Uint() uint32

Uint returns the uint32 representation of a 32-bit unsigned integer argument.

func (SyscallArgument) Uint64

func (a SyscallArgument) Uint64() uint64

Uint64 returns the uint64 representation of a 64-bit unsigned integer argument.

type SyscallArguments

type SyscallArguments [6]SyscallArgument

SyscallArguments represents the set of arguments passed to a syscall.

type UContext64

type UContext64 struct {
	Flags    uint64
	Link     uint64
	Stack    SignalStack
	MContext SignalContext64
	Sigset   linux.SignalSet
}

UContext64 is equivalent to ucontext_t on 64-bit x86.

+marshal

func (*UContext64) CopyIn

func (u *UContext64) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*UContext64) CopyOut

func (u *UContext64) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*UContext64) CopyOutN

func (u *UContext64) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*UContext64) MarshalBytes

func (u *UContext64) MarshalBytes(dst []byte)

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*UContext64) MarshalUnsafe

func (u *UContext64) MarshalUnsafe(dst []byte)

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*UContext64) Packed

func (u *UContext64) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*UContext64) SizeBytes

func (u *UContext64) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*UContext64) UnmarshalBytes

func (u *UContext64) UnmarshalBytes(src []byte)

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*UContext64) UnmarshalUnsafe

func (u *UContext64) UnmarshalUnsafe(src []byte)

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*UContext64) WriteTo

func (u *UContext64) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

Directories

Path Synopsis
Package fpu provides basic floating point helpers.
Package fpu provides basic floating point helpers.

Jump to

Keyboard shortcuts

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