pub fn protect(&self, addr: usize, len: usize, flags: MMUFlags) -> ZxResult {
        if !page_aligned(addr) || !page_aligned(len) {
            return Err(ZxError::INVALID_ARGS);
        }
        let mut guard = self.inner.lock();
        let inner = guard.as_mut().ok_or(ZxError::BAD_STATE)?;
        let end_addr = addr + len;
        // check if there are overlapping subregion
        if inner
            .children
            .iter()
            .any(|child| child.end_addr() >= addr && child.addr() <= end_addr)
        {
            return Err(ZxError::INVALID_ARGS);
        }
        let length: usize = inner
            .mappings
            .iter()
            .filter_map(|map| {
                if map.end_addr() >= addr && map.addr() <= end_addr {
                    Some(end_addr.min(map.end_addr()) - addr.max(map.addr()))
                } else {
                    None
                }
            })
            .sum();
        if length != len {
            return Err(ZxError::NOT_FOUND);
        }
        // check if protect flags is valid
        if inner
            .mappings
            .iter()
            .filter(|map| map.end_addr() >= addr && map.addr() <= end_addr) // get mappings in range: [addr, end_addr]
            .any(|map| !map.is_valid_mapping_flags(flags))
        {
            return Err(ZxError::ACCESS_DENIED);
        }
        inner
            .mappings
            .iter()
            .filter(|map| map.end_addr() >= addr && map.addr() <= end_addr)
            .for_each(|map| {
                let start_index = pages(addr.max(map.addr()) - map.addr());
                let end_index = pages(end_addr.min(map.end_addr()) - map.addr());
                map.protect(flags, start_index, end_index);
            });
        Ok(())
    }
/// Change protections on a subset of the region of memory in the containing
/// address space.  If the requested range overlaps with a subregion,
/// protect() will fail.
Change protections on a subset of the region of memory in the containing
address space.  If the requested range overlaps with a subregion,
protect() will fail.
Change protections on a subset of the region of memory in the containing address space . If the requested range overlaps with a subregion protect () will fail .
pub fn protect(&self, addr: usize, len: usize, flags: MMUFlags) -> ZxResult {
        if !page_aligned(addr) || !page_aligned(len) {
            return Err(ZxError::INVALID_ARGS);
        }
        let mut guard = self.inner.lock();
        let inner = guard.as_mut().ok_or(ZxError::BAD_STATE)?;
        let end_addr = addr + len;
        // check if there are overlapping subregion
        if inner
            .children
            .iter()
            .any(|child| child.end_addr() >= addr && child.addr() <= end_addr)
        {
            return Err(ZxError::INVALID_ARGS);
        }
        let length: usize = inner
            .mappings
            .iter()
            .filter_map(|map| {
                if map.end_addr() >= addr && map.addr() <= end_addr {
                    Some(end_addr.min(map.end_addr()) - addr.max(map.addr()))
                } else {
                    None
                }
            })
            .sum();
        if length != len {
            return Err(ZxError::NOT_FOUND);
        }
        // check if protect flags is valid
        if inner
            .mappings
            .iter()
            .filter(|map| map.end_addr() >= addr && map.addr() <= end_addr) // get mappings in range: [addr, end_addr]
            .any(|map| !map.is_valid_mapping_flags(flags))
        {
            return Err(ZxError::ACCESS_DENIED);
        }
        inner
            .mappings
            .iter()
            .filter(|map| map.end_addr() >= addr && map.addr() <= end_addr)
            .for_each(|map| {
                let start_index = pages(addr.max(map.addr()) - map.addr());
                let end_index = pages(end_addr.min(map.end_addr()) - map.addr());
                map.protect(flags, start_index, end_index);
            });
        Ok(())
    }
pub fn protect ( & self , addr : usize , len : usize , flags : MMUFlags ) -> ZxResult { if ! page_aligned ( addr ) || ! page_aligned ( len ) { return Err ( ZxError :: INVALID_ARGS ) ; } let mut guard = self . inner . lock ( ) ; let inner = guard . as_mut ( ) . ok_or ( ZxError :: BAD_STATE ) ? ; let end_addr = addr + len ; // check if there are overlapping subregion if inner . children . iter ( ) . any ( | child | child . end_addr ( ) >= addr && child . addr ( ) <= end_addr ) { return Err ( ZxError :: INVALID_ARGS ) ; } let length : usize = inner . mappings . iter ( ) . filter_map ( | map | { if map . end_addr ( ) >= addr && map . addr ( ) <= end_addr { Some ( end_addr . min ( map . end_addr ( ) ) - addr . max ( map . addr ( ) ) ) } else { None } } ) . sum ( ) ; if length != len { return Err ( ZxError :: NOT_FOUND ) ; } // check if protect flags is valid if inner . mappings . iter ( ) . filter ( | map | map . end_addr ( ) >= addr && map . addr ( ) <= end_addr ) // get mappings in range: [addr, end_addr] . any ( | map | ! map . is_valid_mapping_flags ( flags ) ) { return Err ( ZxError :: ACCESS_DENIED ) ; } inner . mappings . iter ( ) . filter ( | map | map . end_addr ( ) >= addr && map . addr ( ) <= end_addr ) . for_each ( | map | { let start_index = pages ( addr . max ( map . addr ( ) ) - map . addr ( ) ) ; let end_index = pages ( end_addr . min ( map . end_addr ( ) ) - map . addr ( ) ) ; map . protect ( flags , start_index , end_index ) ; } ) ; Ok ( ( ) ) }
Change protections on a subset of the region of memory in the containing
address space.
Change protections on a subset of the region of memory in the containing address space .
&self
addr
usize
len
usize
flags
MMUFlags
&self
addr
usize
len
usize
flags
MMUFlags