Skip to content

Commit

Permalink
host_copy_to/from: remove redundant check
Browse files Browse the repository at this point in the history
Remove validate_address() calls where the check is also made
inside each granule api.

Signed-off-by: Bokdeuk Jeong <[email protected]>
  • Loading branch information
bokdeuk-jeong committed Dec 18, 2024
1 parent 19ce05a commit 03dde61
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions rmm/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::granule::validate_addr;
#[cfg(feature = "gst_page_table")]
use crate::granule::{is_not_in_realm, GRANULE_SIZE};
#[cfg(not(feature = "gst_page_table"))]
Expand All @@ -11,11 +10,11 @@ use vmsa::guard::Content;

pub fn copy_from<T: SafetyChecked + SafetyAssured + Copy>(addr: usize) -> Option<T> {
#[cfg(feature = "gst_page_table")]
if !validate_addr(addr) || !is_not_in_realm(addr) {
if !is_not_in_realm(addr) {
return None;
}
#[cfg(not(feature = "gst_page_table"))]
if !validate_addr(addr) || get_granule_if!(addr, GranuleState::Undelegated).is_err() {
if get_granule_if!(addr, GranuleState::Undelegated).is_err() {
return None;
}

Expand All @@ -31,11 +30,11 @@ pub fn copy_from<T: SafetyChecked + SafetyAssured + Copy>(addr: usize) -> Option

pub fn copy_to_obj<T: SafetyChecked + SafetyAssured + Copy>(src: usize, dst: &mut T) -> Option<()> {
#[cfg(feature = "gst_page_table")]
if !validate_addr(src) || !is_not_in_realm(src) {
if !is_not_in_realm(src) {
return None;
}
#[cfg(not(feature = "gst_page_table"))]
if !validate_addr(src) || get_granule_if!(src, GranuleState::Undelegated).is_err() {
if get_granule_if!(src, GranuleState::Undelegated).is_err() {
return None;
}

Expand All @@ -51,11 +50,11 @@ pub fn copy_to_obj<T: SafetyChecked + SafetyAssured + Copy>(src: usize, dst: &mu

pub fn copy_to_ptr<T: SafetyChecked + SafetyAssured + Copy>(src: &T, dst: usize) -> Option<()> {
#[cfg(feature = "gst_page_table")]
if !validate_addr(dst) || !is_not_in_realm(dst) {
if !is_not_in_realm(dst) {
return None;
}
#[cfg(not(feature = "gst_page_table"))]
if !validate_addr(dst) || get_granule_if!(dst, GranuleState::Undelegated).is_err() {
if get_granule_if!(dst, GranuleState::Undelegated).is_err() {
return None;
}

Expand Down

0 comments on commit 03dde61

Please sign in to comment.