Documentation ¶
Index ¶
- Constants
- func GetInstructionDetails(pc Word, memory *memory.Memory) (insn, opcode, fun uint32)
- func HandleBranch(cpu *mipsevm.CpuScalars, registers *[32]Word, opcode uint32, insn uint32, ...) error
- func HandleHiLo(cpu *mipsevm.CpuScalars, registers *[32]Word, fun uint32, rs Word, rt Word, ...) error
- func HandleJump(cpu *mipsevm.CpuScalars, registers *[32]Word, linkReg Word, dest Word) error
- func HandleRd(cpu *mipsevm.CpuScalars, registers *[32]Word, storeReg Word, val Word, ...) error
- func HandleSysRead(a0, a1, a2 Word, preimageKey [32]byte, preimageOffset Word, ...) (v0, v1, newPreimageOffset Word, memUpdated bool, memAddr Word)
- func HandleSysWrite(a0, a1, a2 Word, lastHint hexutil.Bytes, preimageKey [32]byte, ...) (v0, v1 Word, newLastHint hexutil.Bytes, newPreimageKey common.Hash, ...)
- func HandleSyscallUpdates(cpu *mipsevm.CpuScalars, registers *[32]Word, v0, v1 Word)
- func StoreSubWord(memory *memory.Memory, vaddr Word, byteLength Word, value Word, ...)
- type MemTracker
- type MemoryTrackerImpl
- type NoopMemoryTracker
- type NoopStackTracker
- type PreimageReader
- type StackTracker
- type StackTrackerImpl
- type TraceableStackTracker
- type TrackingPreimageOracleReader
- func (p *TrackingPreimageOracleReader) GetPreimage(k [32]byte) []byte
- func (p *TrackingPreimageOracleReader) Hint(v []byte)
- func (p *TrackingPreimageOracleReader) LastPreimage() ([32]byte, []byte, Word)
- func (p *TrackingPreimageOracleReader) NumPreimageRequests() int
- func (p *TrackingPreimageOracleReader) ReadPreimage(key [32]byte, offset Word) (dat [32]byte, datLen Word)
- func (p *TrackingPreimageOracleReader) Reset()
- func (p *TrackingPreimageOracleReader) TotalPreimageSize() int
- type Word
- func ExecMipsCoreStepLogic(cpu *mipsevm.CpuScalars, registers *[32]Word, memory *memory.Memory, ...) (memUpdated bool, effMemAddr Word, err error)
- func ExecuteMipsInstruction(insn uint32, opcode uint32, fun uint32, rs, rt, mem Word) Word
- func GetSyscallArgs(registers *[32]Word) (syscallNum, a0, a1, a2, a3 Word)
- func HandleSysFcntl(a0, a1 Word) (v0, v1 Word)
- func HandleSysMmap(a0, a1, heap Word) (v0, v1, newHeap Word)
- func LoadSubWord(memory *memory.Memory, vaddr Word, byteLength Word, signExtend bool, ...) Word
- func SelectSubWord(vaddr Word, memWord Word, byteLength Word, signExtend bool) Word
- func SignExtend(dat Word, idx Word) Word
- func SignExtendImmediate(insn uint32) Word
- func UpdateSubWord(vaddr Word, memWord Word, byteLength Word, value Word) Word
Constants ¶
const ( // syscall number; 1st return value RegV0 = 2 // syscall arguments; returned unmodified RegA0 = 4 RegA1 = 5 RegA2 = 6 // 4th syscall argument; set to 0/1 for success/error RegA3 = 7 )
FYI: https://en.wikibooks.org/wiki/MIPS_Assembly/Register_File
https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
const ( RegSyscallNum = RegV0 RegSyscallErrno = RegA3 RegSyscallRet1 = RegV0 RegSyscallParam1 = RegA0 RegSyscallParam2 = RegA1 RegSyscallParam3 = RegA2 RegSyscallParam4 = RegA3 )
const ( OpLoadLinked = 0x30 OpStoreConditional = 0x38 OpLoadLinked64 = 0x34 OpStoreConditional64 = 0x3c OpLoadDoubleLeft = 0x1A OpLoadDoubleRight = 0x1B // Return address register RegRA = 31 )
const ( FdStdin = 0 FdStdout = 1 FdStderr = 2 FdHintRead = 3 FdHintWrite = 4 FdPreimageRead = 5 FdPreimageWrite = 6 )
File descriptors
const ( SysErrorSignal = ^Word(0) MipsEBADF = 0x9 MipsEINVAL = 0x16 MipsEAGAIN = 0xb MipsETIMEDOUT = 0x91 )
Errors
const ( FutexWaitPrivate = 128 FutexWakePrivate = 129 FutexTimeoutSteps = 10_000 FutexNoTimeout = ^uint64(0) FutexEmptyAddr = ^Word(0) )
SysFutex-related constants
const ( CloneVm = 0x100 CloneFs = 0x200 CloneFiles = 0x400 CloneSighand = 0x800 ClonePtrace = 0x2000 CloneVfork = 0x4000 CloneParent = 0x8000 CloneThread = 0x10000 CloneNewns = 0x20000 CloneSysvsem = 0x40000 CloneSettls = 0x80000 CloneParentSettid = 0x100000 CloneChildCleartid = 0x200000 CloneUntraced = 0x800000 CloneChildSettid = 0x1000000 CloneStopped = 0x2000000 CloneNewuts = 0x4000000 CloneNewipc = 0x8000000 ValidCloneFlags = CloneVm | CloneFs | CloneFiles | CloneSighand | CloneSysvsem | CloneThread )
SysClone flags Handling is meant to support go runtime use cases Pulled from: https://github.com/golang/go/blob/go1.21.3/src/runtime/os_linux.go#L124-L158
const ( // SchedQuantum is the number of steps dedicated for a thread before it's preempted. Effectively used to emulate thread "time slices" SchedQuantum = 100_000 // HZ is the assumed clock rate of an emulated MIPS32 CPU. // The value of HZ is a rough estimate of the Cannon instruction count / second on a typical machine. // HZ is used to emulate the clock_gettime syscall used by guest programs that have a Go runtime. // The Go runtime consumes the system time to determine when to initiate gc assists and for goroutine scheduling. // A HZ value that is too low (i.e. lower than the emulation speed) results in the main goroutine attempting to assist with GC more often. // Adjust this value accordingly as the emulation speed changes. The HZ value should be within the same order of magnitude as the emulation speed. HZ = 10_000_000 // ClockGettimeRealtimeFlag is the clock_gettime clock id for Linux's realtime clock: https://github.com/torvalds/linux/blob/ad618736883b8970f66af799e34007475fe33a68/include/uapi/linux/time.h#L49 ClockGettimeRealtimeFlag = 0 // ClockGettimeMonotonicFlag is the clock_gettime clock id for Linux's monotonic clock: https://github.com/torvalds/linux/blob/ad618736883b8970f66af799e34007475fe33a68/include/uapi/linux/time.h#L50 ClockGettimeMonotonicFlag = 1 )
Other constants
const (
AddressMask = arch.AddressMask
)
Variables ¶
This section is empty.
Functions ¶
func GetInstructionDetails ¶
func HandleBranch ¶
func HandleBranch(cpu *mipsevm.CpuScalars, registers *[32]Word, opcode uint32, insn uint32, rtReg Word, rs Word, stackTracker StackTracker) error
func HandleHiLo ¶
func HandleHiLo(cpu *mipsevm.CpuScalars, registers *[32]Word, fun uint32, rs Word, rt Word, storeReg Word) error
HandleHiLo handles instructions that modify HI and LO registers. It also additionally handles doubleword variable shift operations
func HandleJump ¶
func HandleSysRead ¶
func HandleSysRead( a0, a1, a2 Word, preimageKey [32]byte, preimageOffset Word, preimageReader PreimageReader, memory *memory.Memory, memTracker MemTracker, ) (v0, v1, newPreimageOffset Word, memUpdated bool, memAddr Word)
func HandleSysWrite ¶
func HandleSysWrite(a0, a1, a2 Word, lastHint hexutil.Bytes, preimageKey [32]byte, preimageOffset Word, oracle mipsevm.PreimageOracle, memory *memory.Memory, memTracker MemTracker, stdOut, stdErr io.Writer, ) (v0, v1 Word, newLastHint hexutil.Bytes, newPreimageKey common.Hash, newPreimageOffset Word)
func HandleSyscallUpdates ¶
func HandleSyscallUpdates(cpu *mipsevm.CpuScalars, registers *[32]Word, v0, v1 Word)
func StoreSubWord ¶ added in v1.9.5
func StoreSubWord(memory *memory.Memory, vaddr Word, byteLength Word, value Word, memoryTracker MemTracker)
StoreSubWord stores a Word that has been updated by the specified value at bit positions determined by the vaddr
Types ¶
type MemTracker ¶
type MemTracker interface {
TrackMemAccess(addr Word)
}
type MemoryTrackerImpl ¶
type MemoryTrackerImpl struct {
// contains filtered or unexported fields
}
func NewMemoryTracker ¶
func NewMemoryTracker(memory *memory.Memory) *MemoryTrackerImpl
func (*MemoryTrackerImpl) MemProof ¶
func (m *MemoryTrackerImpl) MemProof() [memory.MemProofSize]byte
func (*MemoryTrackerImpl) MemProof2 ¶ added in v1.9.3
func (m *MemoryTrackerImpl) MemProof2() [memory.MemProofSize]byte
func (*MemoryTrackerImpl) Reset ¶
func (m *MemoryTrackerImpl) Reset(enableProof bool)
func (*MemoryTrackerImpl) TrackMemAccess ¶
func (m *MemoryTrackerImpl) TrackMemAccess(effAddr Word)
func (*MemoryTrackerImpl) TrackMemAccess2 ¶ added in v1.9.3
func (m *MemoryTrackerImpl) TrackMemAccess2(effAddr Word)
TrackMemAccess2 creates a proof for a memory access following a call to TrackMemAccess This is used to generate proofs for contiguous memory accesses within the same step
type NoopMemoryTracker ¶ added in v1.9.5
type NoopMemoryTracker struct{}
func (*NoopMemoryTracker) TrackMemAccess ¶ added in v1.9.5
func (n *NoopMemoryTracker) TrackMemAccess(Word)
type NoopStackTracker ¶
type NoopStackTracker struct{}
func (*NoopStackTracker) PopStack ¶
func (n *NoopStackTracker) PopStack()
func (*NoopStackTracker) PushStack ¶
func (n *NoopStackTracker) PushStack(caller Word, target Word)
func (*NoopStackTracker) Traceback ¶
func (n *NoopStackTracker) Traceback()
type PreimageReader ¶
type StackTracker ¶
type StackTrackerImpl ¶
type StackTrackerImpl struct {
// contains filtered or unexported fields
}
func NewStackTracker ¶
func NewStackTrackerUnsafe ¶
func NewStackTrackerUnsafe(state mipsevm.FPVMState, meta mipsevm.Metadata) *StackTrackerImpl
NewStackTrackerUnsafe creates a new TraceableStackTracker without verifying meta is not nil
func (*StackTrackerImpl) PopStack ¶
func (s *StackTrackerImpl) PopStack()
func (*StackTrackerImpl) PushStack ¶
func (s *StackTrackerImpl) PushStack(caller Word, target Word)
func (*StackTrackerImpl) Traceback ¶
func (s *StackTrackerImpl) Traceback()
type TraceableStackTracker ¶
type TraceableStackTracker interface { StackTracker Traceback() }
type TrackingPreimageOracleReader ¶
type TrackingPreimageOracleReader struct {
// contains filtered or unexported fields
}
TrackingPreimageOracleReader wraps around a PreimageOracle, implements the PreimageOracle interface, and adds tracking functionality. It also implements the PreimageReader interface
func NewTrackingPreimageOracleReader ¶
func NewTrackingPreimageOracleReader(po mipsevm.PreimageOracle) *TrackingPreimageOracleReader
func (*TrackingPreimageOracleReader) GetPreimage ¶
func (p *TrackingPreimageOracleReader) GetPreimage(k [32]byte) []byte
func (*TrackingPreimageOracleReader) Hint ¶
func (p *TrackingPreimageOracleReader) Hint(v []byte)
func (*TrackingPreimageOracleReader) LastPreimage ¶
func (p *TrackingPreimageOracleReader) LastPreimage() ([32]byte, []byte, Word)
func (*TrackingPreimageOracleReader) NumPreimageRequests ¶
func (p *TrackingPreimageOracleReader) NumPreimageRequests() int
func (*TrackingPreimageOracleReader) ReadPreimage ¶
func (p *TrackingPreimageOracleReader) ReadPreimage(key [32]byte, offset Word) (dat [32]byte, datLen Word)
func (*TrackingPreimageOracleReader) Reset ¶
func (p *TrackingPreimageOracleReader) Reset()
func (*TrackingPreimageOracleReader) TotalPreimageSize ¶
func (p *TrackingPreimageOracleReader) TotalPreimageSize() int
type Word ¶ added in v1.9.4
func ExecMipsCoreStepLogic ¶
func ExecMipsCoreStepLogic(cpu *mipsevm.CpuScalars, registers *[32]Word, memory *memory.Memory, insn, opcode, fun uint32, memTracker MemTracker, stackTracker StackTracker) (memUpdated bool, effMemAddr Word, err error)
ExecMipsCoreStepLogic executes a MIPS instruction that isn't a syscall nor a RMW operation If a store operation occurred, then it returns the effective address of the store memory location.
func ExecuteMipsInstruction ¶
func GetSyscallArgs ¶
func HandleSysFcntl ¶
func HandleSysMmap ¶
func LoadSubWord ¶ added in v1.9.5
func LoadSubWord(memory *memory.Memory, vaddr Word, byteLength Word, signExtend bool, memoryTracker MemTracker) Word
LoadSubWord loads a subword of byteLength size from memory based on the low-order bits of vaddr
func SelectSubWord ¶ added in v1.9.5
SelectSubWord selects a subword of byteLength size contained in memWord based on the low-order bits of vaddr This is the nearest subword that is naturally aligned by the specified byteLength