1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Dmitry Kozlyuk
7 #include <rte_compat.h>
13 * Wrappers for OS facilities related to memory paging, used across DPDK.
16 /** Memory protection flags. */
18 RTE_PROT_READ = 1 << 0, /**< Read access. */
19 RTE_PROT_WRITE = 1 << 1, /**< Write access. */
20 RTE_PROT_EXECUTE = 1 << 2 /**< Code execution. */
23 /** Additional flags for memory mapping. */
25 /** Changes to the mapped memory are visible to other processes. */
26 RTE_MAP_SHARED = 1 << 0,
27 /** Mapping is not backed by a regular file. */
28 RTE_MAP_ANONYMOUS = 1 << 1,
29 /** Copy-on-write mapping, changes are invisible to other processes. */
30 RTE_MAP_PRIVATE = 1 << 2,
32 * Force mapping to the requested address. This flag should be used
33 * with caution, because to fulfill the request implementation
34 * may remove all other mappings in the requested region. However,
35 * it is not required to do so, thus mapping with this flag may fail.
37 RTE_MAP_FORCE_ADDRESS = 1 << 3
41 * Map a portion of an opened file or the page file into memory.
43 * This function is similar to POSIX mmap(3) with common MAP_ANONYMOUS
44 * extension, except for the return value.
46 * @param requested_addr
47 * Desired virtual address for mapping. Can be NULL to let OS choose.
49 * Size of the mapping in bytes.
51 * Protection flags, a combination of rte_mem_prot values.
53 * Additional mapping flags, a combination of rte_map_flags.
55 * Mapped file descriptor. Can be negative for anonymous mapping.
57 * Offset of the mapped region in fd. Must be 0 for anonymous mappings.
59 * Mapped address or NULL on failure and rte_errno is set to OS error.
63 rte_mem_map(void *requested_addr, size_t size, int prot, int flags,
64 int fd, size_t offset);
67 * OS-independent implementation of POSIX munmap(3).
71 rte_mem_unmap(void *virt, size_t size);
74 * Get system page size. This function never fails.
81 rte_mem_page_size(void);
84 * Lock in physical memory all pages crossed by the address region.
87 * Base virtual address of the region.
91 * 0 on success, negative on error.
93 * @see rte_mem_page_size() to retrieve the page size.
94 * @see rte_mem_lock_page() to lock an entire single page.
98 rte_mem_lock(const void *virt, size_t size);