sandlock_core/checkpoint/
mod.rs1use serde::{Serialize, Deserialize};
2use std::path::PathBuf;
3use crate::sandbox::Sandbox;
4
5pub(crate) mod capture;
6mod image;
7mod inject;
8mod regs;
9pub(crate) mod resume;
10#[allow(dead_code)]
16pub(crate) mod restore_blob;
17#[allow(dead_code)]
18pub(crate) mod pager;
19
20#[allow(dead_code)]
22pub(crate) const CTRL_FD: i32 = 3; #[allow(dead_code)]
24pub(crate) const READY_FD: i32 = 4; #[allow(dead_code)]
26pub(crate) const GO_FD: i32 = 5; #[allow(dead_code)]
28pub(crate) const UFFD_SLOT: i32 = 6; pub(crate) use capture::capture;
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct Checkpoint {
35 pub name: String,
36 pub policy: Sandbox,
37 pub process_state: ProcessState,
38 pub fd_table: Vec<FdInfo>,
39 pub cow_snapshot: Option<PathBuf>,
40 pub app_state: Option<Vec<u8>>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct ProcessState {
46 pub pid: i32,
47 pub cwd: String,
48 pub exe: String,
49 pub regs: Vec<u64>,
50 pub fpregs: Vec<u8>,
51 pub memory_maps: Vec<MemoryMap>,
52 pub memory_data: Vec<MemorySegment>,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct MemorySegment {
57 pub start: u64,
58 pub data: Vec<u8>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct MemoryMap {
63 pub start: u64,
64 pub end: u64,
65 pub perms: String,
66 pub offset: u64,
67 pub path: Option<String>,
68}
69
70impl MemoryMap {
71 pub fn writable(&self) -> bool {
72 self.perms.starts_with("rw")
73 }
74
75 pub fn private(&self) -> bool {
76 self.perms.contains('p')
77 }
78
79 pub fn is_special(&self) -> bool {
80 self.path.as_ref().map_or(false, |p| {
81 p.starts_with("[vdso]")
84 || p.starts_with("[vvar]")
85 || p.starts_with("[vvar_vclock]")
86 || p.starts_with("[vsyscall]")
87 })
88 }
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct FdInfo {
93 pub fd: i32,
94 pub path: String,
95 pub flags: i32,
96 pub offset: u64,
97}
98
99#[derive(Debug, Clone, PartialEq, Eq)]
103pub struct SkippedFd {
104 pub fd: i32,
106 pub path: String,
108}