zephyr::raw

Function k_mem_map_phys_guard

Source
pub unsafe extern "C" fn k_mem_map_phys_guard(
    phys: usize,
    size: usize,
    flags: u32,
    is_anon: bool,
) -> *mut c_void
Expand description

Map memory into virtual address space with guard pages.

This maps memory into virtual address space with a preceding and a succeeding guard pages. The memory mapped via this function must be unmapped using k_mem_unmap_phys_guard().

This function maps a contiguous physical memory region into kernel’s virtual address space with a preceding and a succeeding guard pages. Given a physical address and a size, return a linear address representing the base of where the physical region is mapped in the virtual address space for the Zephyr kernel.

This function alters the active page tables in the area reserved for the kernel. This function will choose the virtual address and return it to the caller.

If user thread access control needs to be managed in any way, do not enable K_MEM_PERM_USER flags here; instead manage the region’s permissions with memory domain APIs after the mapping has been established. Setting K_MEM_PERM_USER here will allow all user threads to access this memory which is usually undesirable.

Unless K_MEM_MAP_UNINIT is used, the returned memory will be zeroed.

The returned virtual memory pointer will be page-aligned. The size parameter, and any base address for re-mapping purposes must be page- aligned.

Note that the allocation includes two guard pages immediately before and after the requested region. The total size of the allocation will be the requested size plus the size of these two guard pages.

Many K_MEM_MAP_* flags have been implemented to alter the behavior of this function, with details in the documentation for these flags.

@see k_mem_map() for additional information if called via that.

@param phys Physical address base of the memory region if not requesting anonymous memory. Must be page-aligned. @param size Size of the memory mapping. This must be page-aligned. @param flags K_MEM_PERM_, K_MEM_MAP_ control flags. @param is_anon True is requesting mapping with anonymous memory.

@return The mapped memory location, or NULL if insufficient virtual address space, insufficient physical memory to establish the mapping, or insufficient memory for paging structures.