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

Function platform_alloc

loader/tests/src/platform.c:128–154  ·  view source on GitHub ↗

* <!-- description --> * @brief This function allocates read/write virtual memory from the * kernel. This memory is not 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() * to release this memory. * * @note This function must zero the allocated memory *

Source from the content-addressed store, hash-verified

126 * Returns a nullptr on failure.
127 */
128NODISCARD void *
129platform_alloc(uint64_t const size) NOEXCEPT
130{
131 uint64_t mut_size = size;
132 if (!bf_is_page_aligned(size)) {
133 mut_size = bf_page_aligned(size + HYPERVISOR_PAGE_SIZE);
134 }
135
136 if (g_mut_platform_alloc > 0) {
137 --g_mut_platform_alloc;
138
139 if (0 == g_mut_platform_alloc) {
140 return NULLPTR;
141 }
142
143 bf_touch();
144 }
145 else {
146 bf_touch();
147 }
148
149#ifdef _WIN32
150 return memset(_aligned_malloc(mut_size, HYPERVISOR_PAGE_SIZE), 0, mut_size); // NOLINT
151#else
152 return memset(aligned_alloc(HYPERVISOR_PAGE_SIZE, mut_size), 0, mut_size); // NOLINT
153#endif
154}
155
156/**
157 * <!-- description -->

Callers 5

alloc_mk_root_page_tableFunction · 0.70
alloc_and_copy_mk_stateFunction · 0.70
testsFunction · 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