Skip to content

Commit 262a297

Browse files
simongdaviesludfjig
authored andcommitted
Add Linux and Windows implementations for dirty page tracking
- Implemented `LinuxDirtyPageTracker` for tracking dirty pages in Linux. - Utilizes SIGSEGV to detect writes and marks pages as dirty. - Supports concurrent access and ensures memory protection. - Includes comprehensive tests for various scenarios including overlap detection and concurrent writes. - Added `WindowsDirtyPageTracker` as a placeholder for Windows dirty page tracking. - Currently marks all pages as dirty until further implementation is completed. - Includes basic structure and initialization logic. Signed-off-by: Simon Davies <[email protected]>
1 parent a01a0a4 commit 262a297

File tree

3 files changed

+1404
-0
lines changed

3 files changed

+1404
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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) -> 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) -> Vec<usize> {
47+
self.inner.get_dirty_pages()
48+
}
49+
}

0 commit comments

Comments
 (0)