* <!-- 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
| 127 | * Returns a nullptr on failure. |
| 128 | */ |
| 129 | NODISCARD void * |
| 130 | platform_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 --> |