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