Skip to main content

clear

Function clear 

Source
pub unsafe fn clear(
    location: NonNull<u8>,
    size: usize,
    protection: Protection,
) -> Result<()>
Expand description

Recommit a range of pages, such that they remain allocated and return zero when accessed.

§Errors

Returns Error::InvalidInput if:

§Safety

This must be a valid range of memory.

Undefined behavior if location + size overflows.

§Examples

unsafe {
    *ptr.as_ptr() = 1;
    pagealloc::clear(ptr, pagealloc::page_size(), pagealloc::Protection::ReadWrite)?;
    assert_eq!(*ptr.as_ptr(), 0);
}