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

Function platform_alloc

loader/windows/src/platform.c:94–112  ·  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

92 * Returns a nullptr on failure.
93 */
94NODISCARD void *
95platform_alloc(uint64_t const size) NOEXCEPT
96{
97 void *ret;
98
99 if (0 == size) {
100 bferror("invalid number of bytes (i.e., size)");
101 return NULLPTR;
102 }
103
104 ret = ExAllocatePoolWithTag(NonPagedPool, size, BF_TAG);
105 if (NULLPTR == ret) {
106 bferror("vmalloc failed");
107 return NULLPTR;
108 }
109
110 RtlFillMemory(ret, size, 0);
111 return ret;
112}
113
114/**
115 * <!-- description -->

Callers

nothing calls this directly

Calls 1

bferrorFunction · 0.50

Tested by

no test coverage detected