|
| 1 | +/* |
| 2 | +Copyright 2025 The Hyperlight Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +use tracing::{Span, instrument}; |
| 18 | + |
| 19 | +#[cfg(target_os = "linux")] |
| 20 | +pub use super::linux_dirty_page_tracker::LinuxDirtyPageTracker as PlatformDirtyPageTracker; |
| 21 | +use super::shared_mem::SharedMemory; |
| 22 | +#[cfg(target_os = "windows")] |
| 23 | +pub use super::windows_dirty_page_tracker::WindowsDirtyPageTracker as PlatformDirtyPageTracker; |
| 24 | +use crate::Result; |
| 25 | + |
| 26 | +/// Trait defining the interface for dirty page tracking implementations |
| 27 | +pub trait DirtyPageTracking { |
| 28 | + fn get_dirty_pages(self) -> Result<Vec<usize>>; |
| 29 | +} |
| 30 | + |
| 31 | +/// Cross-platform dirty page tracker that delegates to platform-specific implementations |
| 32 | +pub struct DirtyPageTracker { |
| 33 | + inner: PlatformDirtyPageTracker, |
| 34 | +} |
| 35 | + |
| 36 | +impl DirtyPageTracker { |
| 37 | + /// Create a new dirty page tracker for the given shared memory |
| 38 | + #[instrument(skip_all, parent = Span::current(), level = "Trace")] |
| 39 | + pub fn new<T: SharedMemory>(shared_memory: &T) -> Result<Self> { |
| 40 | + let inner = PlatformDirtyPageTracker::new(shared_memory)?; |
| 41 | + Ok(Self { inner }) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl DirtyPageTracking for DirtyPageTracker { |
| 46 | + fn get_dirty_pages(self) -> Result<Vec<usize>> { |
| 47 | + self.inner.get_dirty_pages() |
| 48 | + } |
| 49 | +} |
0 commit comments