* <!-- description --> * @brief This function allocates read/write virtual memory from the * kernel. This memory is physically contiguous. The resulting * pointer is at least 4k aligned, so use this function sparingly * as it will always allocate at least one page. Use * platform_free_contiguous() to release this memory. * * @note This function must zero the allocated me
| 169 | * Returns a nullptr on failure. |
| 170 | */ |
| 171 | NODISCARD void * |
| 172 | platform_alloc_contiguous(uint64_t const size) NOEXCEPT |
| 173 | { |
| 174 | uint64_t mut_size = size; |
| 175 | if (!bf_is_page_aligned(size)) { |
| 176 | mut_size = bf_page_aligned(size + HYPERVISOR_PAGE_SIZE); |
| 177 | } |
| 178 | |
| 179 | if (g_mut_platform_alloc_contiguous > 0) { |
| 180 | --g_mut_platform_alloc_contiguous; |
| 181 | |
| 182 | if (0 == g_mut_platform_alloc_contiguous) { |
| 183 | return NULLPTR; |
| 184 | } |
| 185 | |
| 186 | bf_touch(); |
| 187 | } |
| 188 | else { |
| 189 | bf_touch(); |
| 190 | } |
| 191 | |
| 192 | #ifdef _WIN32 |
| 193 | return memset(_aligned_malloc(mut_size, HYPERVISOR_PAGE_SIZE), 0, mut_size); // NOLINT |
| 194 | #else |
| 195 | return memset(aligned_alloc(HYPERVISOR_PAGE_SIZE, mut_size), 0, mut_size); // NOLINT |
| 196 | #endif |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * <!-- description --> |
no test coverage detected