pub unsafe extern "C" fn k_mem_map(
size: usize,
flags: u32,
) -> *mut c_void
Expand description
Map anonymous memory into Zephyr’s address space
This function effectively increases the data space available to Zephyr. The kernel will choose a base virtual address and return it to the caller. The memory will have access permissions for all contexts set per the provided flags argument.
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 mapped region is not guaranteed to be physically contiguous in memory. Physically contiguous buffers should be allocated statically and pinned at build time.
Pages mapped in this way have write-back cache settings.
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.
@param size Size of the memory mapping. This must be page-aligned. @param flags K_MEM_PERM_, K_MEM_MAP_ control flags. @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.