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

Function platform_alloc_contiguous

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

127 * Returns a nullptr on failure.
128 */
129NODISCARD void *
130platform_alloc_contiguous(uint64_t const size) NOEXCEPT
131{
132 void *ret;
133
134 if (0 == size) {
135 bferror("invalid number of bytes (i.e., size)");
136 return NULLPTR;
137 }
138
139 PHYSICAL_ADDRESS addr;
140 addr.QuadPart = MAXULONG64;
141
142 ret = MmAllocateContiguousMemory(size, addr);
143 if (NULLPTR == ret) {
144 bferror("kmalloc failed");
145 return NULLPTR;
146 }
147
148 RtlFillMemory(ret, size, 0);
149 return ret;
150}
151
152/**
153 * <!-- description -->

Callers

nothing calls this directly

Calls 1

bferrorFunction · 0.50

Tested by

no test coverage detected