Commit 8ed6612b authored by Inphi's avatar Inphi Committed by GitHub

cannon: Adjust initial heap (#10376)

* cannon: Adjust initial heap start

This gives the program more memory to work with; minimizing the chance
of heap/stack corruption.

* Update cannon/mipsevm/patch.go
Co-authored-by: default avatarcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------
Co-authored-by: default avatarclabby <ben@clab.by>
Co-authored-by: default avatarcoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
parent 4be7223a
...@@ -8,13 +8,15 @@ import ( ...@@ -8,13 +8,15 @@ import (
"io" "io"
) )
const HEAP_START = 0x05000000
func LoadELF(f *elf.File) (*State, error) { func LoadELF(f *elf.File) (*State, error) {
s := &State{ s := &State{
PC: uint32(f.Entry), PC: uint32(f.Entry),
NextPC: uint32(f.Entry + 4), NextPC: uint32(f.Entry + 4),
HI: 0, HI: 0,
LO: 0, LO: 0,
Heap: 0x20000000, Heap: HEAP_START,
Registers: [32]uint32{}, Registers: [32]uint32{},
Memory: NewMemory(), Memory: NewMemory(),
ExitCode: 0, ExitCode: 0,
...@@ -43,6 +45,9 @@ func LoadELF(f *elf.File) (*State, error) { ...@@ -43,6 +45,9 @@ func LoadELF(f *elf.File) (*State, error) {
if prog.Vaddr+prog.Memsz >= uint64(1<<32) { if prog.Vaddr+prog.Memsz >= uint64(1<<32) {
return nil, fmt.Errorf("program %d out of 32-bit mem range: %x - %x (size: %x)", i, prog.Vaddr, prog.Vaddr+prog.Memsz, prog.Memsz) return nil, fmt.Errorf("program %d out of 32-bit mem range: %x - %x (size: %x)", i, prog.Vaddr, prog.Vaddr+prog.Memsz, prog.Memsz)
} }
if prog.Vaddr+prog.Memsz >= HEAP_START {
return nil, fmt.Errorf("program %d overlaps with heap: %x - %x (size: %x). The heap start offset must be reconfigured", i, prog.Vaddr, prog.Vaddr+prog.Memsz, prog.Memsz)
}
if err := s.Memory.SetMemoryRange(uint32(prog.Vaddr), r); err != nil { if err := s.Memory.SetMemoryRange(uint32(prog.Vaddr), r); err != nil {
return nil, fmt.Errorf("failed to read program segment %d: %w", i, err) return nil, fmt.Errorf("failed to read program segment %d: %w", i, err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment