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

Function platform_alloc

loader/efi/src/platform.c:95–117  ·  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

93 * Returns a nullptr on failure.
94 */
95NODISCARD void *
96platform_alloc(uint64_t size)
97{
98 EFI_STATUS status = EFI_SUCCESS;
99 EFI_PHYSICAL_ADDRESS ret = ((EFI_PHYSICAL_ADDRESS)0);
100
101 platform_expects(((uint64_t)0) != size);
102
103 if (((uint64_t)0) != (size & (HYPERVISOR_PAGE_SIZE - ((uint64_t)1)))) {
104 size += HYPERVISOR_PAGE_SIZE;
105 size &= ~(HYPERVISOR_PAGE_SIZE - ((uint64_t)1));
106 }
107
108 status = g_st->BootServices->AllocatePages(
109 AllocateAnyPages, EfiRuntimeServicesData, size / HYPERVISOR_PAGE_SIZE, &ret);
110 if (EFI_ERROR(status)) {
111 bferror_x64("AllocatePages failed", status);
112 return NULL;
113 }
114
115 g_st->BootServices->SetMem((void *)ret, size, ((UINT8)0));
116 return (void *)ret;
117}
118
119/**
120 * <!-- description -->

Callers 15

alloc_mk_page_poolFunction · 0.50
alloc_mk_debug_ringFunction · 0.50
alloc_mk_stackFunction · 0.50
alloc_mk_argsFunction · 0.50
alloc_mk_root_page_tableFunction · 0.50
alloc_pdptFunction · 0.50
alloc_and_copy_mk_stateFunction · 0.50
alloc_ptFunction · 0.50

Calls 2

platform_expectsFunction · 0.70
bferror_x64Function · 0.50

Tested by

no test coverage detected