fox32: fix stack overflow when initializing memory
This commit is contained in:
parent
fb3d681f55
commit
a8ff66c3a0
|
@ -23,8 +23,10 @@ struct MemoryInner {
|
||||||
impl MemoryInner {
|
impl MemoryInner {
|
||||||
pub fn new(rom: &[u8]) -> Self {
|
pub fn new(rom: &[u8]) -> Self {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
ram: Box::new([0u8; MEMORY_RAM_SIZE]),
|
// HACK: allocate directly on the heap to avoid a stack overflow
|
||||||
rom: Box::new([0u8; MEMORY_ROM_SIZE]),
|
// at runtime while trying to move around a 64MB array
|
||||||
|
ram: unsafe { Box::from_raw(Box::into_raw(vec![0u8; MEMORY_RAM_SIZE].into_boxed_slice()) as *mut MemoryRam) },
|
||||||
|
rom: unsafe { Box::from_raw(Box::into_raw(vec![0u8; MEMORY_ROM_SIZE].into_boxed_slice()) as *mut MemoryRom) },
|
||||||
};
|
};
|
||||||
this.rom.as_mut_slice().write(rom).expect("failed to copy ROM to memory");
|
this.rom.as_mut_slice().write(rom).expect("failed to copy ROM to memory");
|
||||||
this
|
this
|
||||||
|
@ -107,4 +109,4 @@ impl Memory {
|
||||||
self.write_8(address + 2, ((word & 0x00FF0000) >> 16) as u8);
|
self.write_8(address + 2, ((word & 0x00FF0000) >> 16) as u8);
|
||||||
self.write_8(address + 3, ((word & 0xFF000000) >> 24) as u8);
|
self.write_8(address + 3, ((word & 0xFF000000) >> 24) as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user