* <!-- 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 *
| 92 | * Returns a nullptr on failure. |
| 93 | */ |
| 94 | NODISCARD void * |
| 95 | platform_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 --> |