Fix error returned from set_mmap

This commit is contained in:
Mark 2020-09-21 13:59:23 +03:00
parent a3642f482a
commit 7be4052928
2 changed files with 4 additions and 4 deletions

View File

@ -23,6 +23,7 @@ pub const FLAG_UPPER: u32 = 1 << 2;
pub enum Error { pub enum Error {
BufferTooSmall, BufferTooSmall,
BadPointer,
Error Error
} }

View File

@ -30,13 +30,13 @@ impl LoadProtocol for ProtoV1 {
if self.memory_map.size == 0 || self.memory_map.address == 0 { if self.memory_map.size == 0 || self.memory_map.address == 0 {
// Memory map pointer is stored // Memory map pointer is stored
if ptr >= 0x100000000 as *const _ { if ptr >= 0x100000000 as *const _ {
panic!("Memory map pointer crosses 4GiB"); return Err(Error::BadPointer);
} }
self.memory_map.address = map.address; self.memory_map.address = map.address;
} else { } else {
if map.size > self.memory_map.size { if map.size > self.memory_map.size {
panic!("Can't fit memory map"); return Err(Error::BufferTooSmall);
} }
unsafe { unsafe {
extern "C" { extern "C" {
@ -48,8 +48,7 @@ impl LoadProtocol for ProtoV1 {
self.memory_map.size = map.size; self.memory_map.size = map.size;
self.memory_map.entsize = map.entsize; self.memory_map.entsize = map.entsize;
Ok(())
Err(Error::BufferTooSmall)
} }
fn set_initrd(&mut self, base: usize, size: usize) { fn set_initrd(&mut self, base: usize, size: usize) {
if self.initrd_base + self.initrd_size >= 0x100000000 { if self.initrd_base + self.initrd_size >= 0x100000000 {