1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* Copyright (c) 2024 Google Inc. All rights reserved
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
use core::ffi::c_char;
use core::ffi::c_uint;
use core::ffi::c_void;
use core::ptr::addr_of_mut;
use crate::paddr_t;
use crate::status_t;
pub use crate::sys::vaddr_to_paddr;
pub use crate::sys::vmm_alloc_contiguous;
pub use crate::sys::vmm_alloc_physical_etc;
pub use crate::sys::vmm_aspace_t;
pub use crate::sys::vmm_free_region;
#[inline]
pub fn vmm_get_kernel_aspace() -> *mut vmm_aspace_t {
// SAFETY: The returned raw pointer holds the same safety invariants as accessing a `static mut`,
// so this `unsafe` is unconditionally sound, and may become safe in edition 2024:
// <https://github.com/rust-lang/rust/issues/114447>.
unsafe { addr_of_mut!(crate::sys::_kernel_aspace) }
}
#[inline]
pub unsafe fn vmm_alloc_physical(
aspace: *mut vmm_aspace_t,
name: *const c_char,
size: usize,
ptr: *const *mut c_void,
align_log2: u8,
paddr: *const paddr_t,
vmm_flags: c_uint,
arch_mmu_flags: c_uint,
) -> status_t {
vmm_alloc_physical_etc(
aspace,
name,
size,
ptr.cast_mut(),
align_log2,
paddr.cast_mut(),
1,
vmm_flags,
arch_mmu_flags,
)
}
|