Pierre-Clément Tosi | da4440a | 2022-08-22 18:06:32 +0100 | [diff] [blame] | 1 | // 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 Vaddagiri | c25d68e | 2023-04-19 22:56:33 -0700 | [diff] [blame] | 17 | use core::ops::Range; |
Alice Wang | eacb738 | 2023-06-05 12:53:54 +0000 | [diff] [blame] | 18 | use vmbase::memory::SIZE_4KB; |
Pierre-Clément Tosi | a0934c1 | 2022-11-25 20:54:11 +0000 | [diff] [blame] | 19 | |
Pierre-Clément Tosi | 4f4f5eb | 2022-12-08 14:31:42 +0000 | [diff] [blame] | 20 | pub const GUEST_PAGE_SIZE: usize = SIZE_4KB; |
Pierre-Clément Tosi | 23aba52 | 2023-04-21 17:03:50 +0100 | [diff] [blame] | 21 | pub const PVMFW_PAGE_SIZE: usize = SIZE_4KB; |
Pierre-Clément Tosi | 4f4f5eb | 2022-12-08 14:31:42 +0000 | [diff] [blame] | 22 | |
Srivatsa Vaddagiri | c25d68e | 2023-04-19 22:56:33 -0700 | [diff] [blame] | 23 | /// Trait to check containment of one range within another. |
| 24 | pub(crate) trait RangeExt { |
| 25 | /// Returns true if `self` is contained within the `other` range. |
| 26 | fn is_within(&self, other: &Self) -> bool; |
| 27 | } |
| 28 | |
| 29 | impl<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 Park | b87f330 | 2023-03-21 10:03:11 +0900 | [diff] [blame] | 35 | /// Create &CStr out of &str literal |
| 36 | #[macro_export] |
| 37 | macro_rules! cstr { |
| 38 | ($str:literal) => {{ |
Pierre-Clément Tosi | 7c5df04 | 2023-05-12 12:06:44 +0000 | [diff] [blame] | 39 | core::ffi::CStr::from_bytes_with_nul(concat!($str, "\0").as_bytes()).unwrap() |
Jiyong Park | b87f330 | 2023-03-21 10:03:11 +0900 | [diff] [blame] | 40 | }}; |
| 41 | } |