diff --git a/common/src/lib.rs b/common/src/lib.rs index 66f3686530..f90ed57454 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -126,6 +126,12 @@ pub unsafe fn physmap( ty: MemoryType, ) -> Result<*mut ()> { // TODO: arraystring? + + //Return an error rather than potentially crash the kernel. + if(base_phys == 0) { + return Err(Error::new(EINVAL)); + } + let path = format!( "/scheme/memory/physical@{}", match ty { diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 2900a1e68c..6055fc74be 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -373,6 +373,7 @@ impl PciFunctionHandle { Ok(mapped_bar) } else { let (bar, bar_size) = self.config.func.bars[bir as usize].expect_mem(); + let ptr = unsafe { common::physmap( bar,