| // SPDX-License-Identifier: GPL-2.0 | |
| // Copyright 2022-2023 Google LLC | |
| // Author: Ard Biesheuvel <ardb@google.com> | |
| use core::alloc::GlobalAlloc; | |
| use crate::paging::PAGE_SIZE; | |
| use crate::ALLOCATOR; | |
| pub fn get_zeroed_page() -> u64 { | |
| let layout = core::alloc::Layout::from_size_align(PAGE_SIZE, PAGE_SIZE).unwrap(); | |
| let page = unsafe { ALLOCATOR.alloc(layout) }; | |
| if page.is_null() { | |
| panic!("Out of memory!"); | |
| } | |
| unsafe { core::ptr::write_bytes(page, 0u8, PAGE_SIZE) }; | |
| page as u64 | |
| } |