Skip to content

Commit

Permalink
Update memory access struct
Browse files Browse the repository at this point in the history
  • Loading branch information
pantrif committed Dec 3, 2024
1 parent 6631d1e commit d6e54a8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/polkavm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"github.com/eigerco/strawberry/internal/state"
)

type MemoryAccess bool
type MemoryAccess int

const (
ReadOnly MemoryAccess = false // (R)
ReadWrite MemoryAccess = true // (W)
Inaccessible MemoryAccess = iota // ∅ (Inaccessible)
ReadOnly // R (Read-Only)
ReadWrite // W (Read-Write)
)

// Memory Equation: 34 (M)
Expand All @@ -27,8 +28,8 @@ type memorySegment struct {
// Read reads from the set of readable indices (Vμ)
func (m *Memory) Read(address uint32, data []byte) error {
memSeg := m.inRange(address)
if memSeg == nil {
return &ErrPageFault{Reason: "address not in a valid range", Address: address}
if memSeg == nil || memSeg.access == Inaccessible {
return &ErrPageFault{Reason: "inaccessible memory", Address: address}
}

offset := int(address - memSeg.start)
Expand Down

0 comments on commit d6e54a8

Please sign in to comment.