Skip to content

Commit

Permalink
fix: page fault access and set x32 regs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvladco committed Feb 17, 2025
1 parent 294a657 commit b8b5743
Show file tree
Hide file tree
Showing 65 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/polkavm/interpreter/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (i *Instance) store(address uint32, v any) error {
}

func (i *Instance) setAndSkip32(dst polkavm.Reg, value uint32) {
i.regs[dst] = uint64(value)
i.regs[dst] = sext64(value)
i.skip()
}

Expand Down
7 changes: 6 additions & 1 deletion internal/polkavm/interpreter/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (i *Instance) step() (uint32, error) {
if err := jam.Unmarshal(i.code[i.instructionCounter+2+lenX:i.instructionCounter+2+lenX+lenY], &valueY); err != nil {
return 0, err
}
valueY = i.instructionCounter + sext(valueY, lenX)
valueY = i.instructionCounter + sext(valueY, lenY)

switch opcode {
case polkavm.LoadImmAndJump:
Expand Down Expand Up @@ -608,3 +608,8 @@ func sext(value uint32, length uint32) uint32 {
panic("unreachable")
}
}

// Xn∈{8}∶ N^28n → N_R
func sext64(value uint32) uint64 {
return uint64(int64(int32(value)))
}
6 changes: 6 additions & 0 deletions tests/integration/pvm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ func Test_PVM_Vectors(t *testing.T) {
mem := getMemoryMap(tc.InitialPageMap)

for _, initialMem := range tc.InitialMemory {
pageIndex := initialMem.Address / polkavm.PageSize
access := mem.GetAccess(pageIndex)
err = mem.SetAccess(pageIndex, polkavm.ReadWrite)
assert.NoError(t, err)
err := mem.Write(initialMem.Address, initialMem.Contents)
if err != nil {
t.Fatal(err)
}
err = mem.SetAccess(pageIndex, access)
assert.NoError(t, err)
}
i, err := interpreter.Instantiate(tc.Program, tc.InitialPc, tc.InitialGas, tc.InitialRegs, mem)
require.NoError(t, err)
Expand Down

0 comments on commit b8b5743

Please sign in to comment.