blob: 0a32832e349c1c41f468b161a7b8a47ee73c1544 [file] [log] [blame]
Pierre-Clément Tosida4440a2022-08-22 18:06:32 +01001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Miscellaneous helper functions.
16
Srivatsa Vaddagiric25d68e2023-04-19 22:56:33 -070017use core::ops::Range;
Alice Wangeacb7382023-06-05 12:53:54 +000018use vmbase::memory::SIZE_4KB;
Pierre-Clément Tosia0934c12022-11-25 20:54:11 +000019
Pierre-Clément Tosi4f4f5eb2022-12-08 14:31:42 +000020pub const GUEST_PAGE_SIZE: usize = SIZE_4KB;
Pierre-Clément Tosi23aba522023-04-21 17:03:50 +010021pub const PVMFW_PAGE_SIZE: usize = SIZE_4KB;
Pierre-Clément Tosi4f4f5eb2022-12-08 14:31:42 +000022
Srivatsa Vaddagiric25d68e2023-04-19 22:56:33 -070023/// Trait to check containment of one range within another.
24pub(crate) trait RangeExt {
25 /// Returns true if `self` is contained within the `other` range.
26 fn is_within(&self, other: &Self) -> bool;
27}
28
29impl<T: PartialOrd> RangeExt for Range<T> {
30 fn is_within(&self, other: &Self) -> bool {
31 self.start >= other.start && self.end <= other.end
32 }
33}
34
Jiyong Parkb87f3302023-03-21 10:03:11 +090035/// Create &CStr out of &str literal
36#[macro_export]
37macro_rules! cstr {
38 ($str:literal) => {{
Pierre-Clément Tosi7c5df042023-05-12 12:06:44 +000039 core::ffi::CStr::from_bytes_with_nul(concat!($str, "\0").as_bytes()).unwrap()
Jiyong Parkb87f3302023-03-21 10:03:11 +090040 }};
41}