MCPcopy Create free account
hub / github.com/Bareflank/hypervisor / platform_alloc_contiguous

Function platform_alloc_contiguous

loader/tests/src/platform.c:171–197  ·  view source on GitHub ↗

* <!-- 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

Source from the content-addressed store, hash-verified

169 * Returns a nullptr on failure.
170 */
171NODISCARD void *
172platform_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 -->

Callers 1

test_platform.cppFile · 0.70

Calls 3

bf_touchFunction · 0.85
bf_is_page_alignedFunction · 0.70
bf_page_alignedFunction · 0.70

Tested by

no test coverage detected