pub fn adjust_heap(&mut self, amount: isize) -> Result<(), Error> {
        if amount < 0 && self.heap_length < -amount as usize {
            return Err(Error::Overflow);
        }

        if amount > 0 && usize::MAX - self.heap_length < amount as usize {
            return Err(Error::Overflow);
        }

        let new_heap_length = self.heap_length.wrapping_add(amount as usize);

        let page_size = <Pageset as GenericPageset>::page_size();

        fn divup(dividend: usize, divisor: usize) -> usize {
            if dividend % divisor == 0 { dividend / divisor }
            else                       { dividend / divisor + 1 }
        }

        let old_heap_pages = divup(self.heap_length, page_size);
        let new_heap_pages = divup(new_heap_length,  page_size);

        if new_heap_pages > old_heap_pages {
            let base = self.heap_base + old_heap_pages * page_size;
            let size = (new_heap_pages - old_heap_pages) * page_size;

            self.map_allocate(base, size, PageType::default().writable())?;
        } else if new_heap_pages < old_heap_pages {
            let base = self.heap_base + new_heap_pages * page_size;
            let size = (old_heap_pages - new_heap_pages) * page_size;

            self.unmap_deallocate(base, size)?;
        }

        self.heap_length = new_heap_length;

        Ok(())
    }
/// Adjusts the process's heap by the requested amount.
Adjusts the process's heap by the requested amount.
Adjusts the process ' s heap by the requested amount .
pub fn adjust_heap(&mut self, amount: isize) -> Result<(), Error> {
        if amount < 0 && self.heap_length < -amount as usize {
            return Err(Error::Overflow);
        }
        if amount > 0 && usize::MAX - self.heap_length < amount as usize {
            return Err(Error::Overflow);
        }
        let new_heap_length = self.heap_length.wrapping_add(amount as usize);
        let page_size = <Pageset as GenericPageset>::page_size();
        fn divup(dividend: usize, divisor: usize) -> usize {
            if dividend % divisor == 0 { dividend / divisor }
            else                       { dividend / divisor + 1 }
        }
        let old_heap_pages = divup(self.heap_length, page_size);
        let new_heap_pages = divup(new_heap_length,  page_size);
        if new_heap_pages > old_heap_pages {
            let base = self.heap_base + old_heap_pages * page_size;
            let size = (new_heap_pages - old_heap_pages) * page_size;
            self.map_allocate(base, size, PageType::default().writable())?;
        } else if new_heap_pages < old_heap_pages {
            let base = self.heap_base + new_heap_pages * page_size;
            let size = (old_heap_pages - new_heap_pages) * page_size;
            self.unmap_deallocate(base, size)?;
        }
        self.heap_length = new_heap_length;
        Ok(())
    }
pub fn adjust_heap ( & mut self , amount : isize ) -> Result < ( ) , Error > { if amount < 0 && self . heap_length < - amount as usize { return Err ( Error :: Overflow ) ; } if amount > 0 && usize :: MAX - self . heap_length < amount as usize { return Err ( Error :: Overflow ) ; } let new_heap_length = self . heap_length . wrapping_add ( amount as usize ) ; let page_size = < Pageset as GenericPageset > :: page_size ( ) ; fn divup ( dividend : usize , divisor : usize ) -> usize { if dividend % divisor == 0 { dividend / divisor } else { dividend / divisor + 1 } } let old_heap_pages = divup ( self . heap_length , page_size ) ; let new_heap_pages = divup ( new_heap_length , page_size ) ; if new_heap_pages > old_heap_pages { let base = self . heap_base + old_heap_pages * page_size ; let size = ( new_heap_pages - old_heap_pages ) * page_size ; self . map_allocate ( base , size , PageType :: default ( ) . writable ( ) ) ? ; } else if new_heap_pages < old_heap_pages { let base = self . heap_base + new_heap_pages * page_size ; let size = ( old_heap_pages - new_heap_pages ) * page_size ; self . unmap_deallocate ( base , size ) ? ; } self . heap_length = new_heap_length ; Ok ( ( ) ) }
Adjusts the process's heap by the requested amount.
Adjusts the process ' s heap by the requested amount .
&mut self
amount
isize