memscope_rs/analysis/unknown/
types.rs1use crate::capture::types::ImplementationDifficulty;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct UnknownMemoryRegionAnalysis {
6 pub total_unknown_bytes: usize,
7 pub unknown_percentage: f64,
8 pub unknown_categories: Vec<UnknownMemoryCategory>,
9 pub potential_causes: Vec<UnknownMemoryCause>,
10 pub reduction_strategies: Vec<UnknownRegionReductionStrategy>,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct UnknownMemoryCategory {
15 pub category_type: UnknownRegionType,
16 pub description: String,
17 pub estimated_size: usize,
18 pub confidence_level: f64,
19 pub examples: Vec<UnknownMemoryExample>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub enum UnknownRegionType {
24 MemoryMappedRegions,
25 ThreadLocalStorage,
26 DynamicLibraryRegions,
27 SystemReservedRegions,
28 JitCodeRegions,
29 ExternalLibraryAllocations,
30 GuardPages,
31 VdsoRegions,
32 AnonymousMappings,
33 SharedMemorySegments,
34 PreTrackingAllocations,
35 CorruptedMetadata,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct UnknownMemoryExample {
40 pub address_range: (usize, usize),
41 pub size: usize,
42 pub suspected_origin: String,
43 pub access_pattern: MemoryAccessPattern,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub enum UnknownMemoryCause {
48 ForeignFunctionInterface {
49 library_name: String,
50 function_name: Option<String>,
51 },
52 MemoryMapping {
53 mapping_type: MappingType,
54 file_path: Option<String>,
55 },
56 SystemAllocations {
57 allocation_type: SystemAllocationType,
58 },
59 ThreadingMemory {
60 thread_id: Option<u64>,
61 memory_type: ThreadMemoryType,
62 },
63 DynamicLoading {
64 library_path: String,
65 load_time: u64,
66 },
67 InstrumentationGaps {
68 gap_type: InstrumentationGapType,
69 description: String,
70 },
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub enum MappingType {
75 FileMapping,
76 AnonymousMapping,
77 SharedMapping,
78 DeviceMapping,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub enum SystemAllocationType {
83 KernelBuffers,
84 DriverMemory,
85 SystemCaches,
86 HardwareReserved,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub enum ThreadMemoryType {
91 ThreadStack,
92 ThreadLocalStorage,
93 ThreadControlBlock,
94 ThreadSynchronization,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub enum InstrumentationGapType {
99 EarlyBootstrap,
100 SignalHandlers,
101 InterruptHandlers,
102 AtomicOperations,
103 CompilerOptimizations,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct UnknownRegionReductionStrategy {
108 pub strategy_type: ReductionStrategyType,
109 pub description: String,
110 pub implementation_steps: Vec<String>,
111 pub expected_improvement: f64,
112 pub implementation_difficulty: ImplementationDifficulty,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub enum ReductionStrategyType {
117 EnhancedInstrumentation,
118 BetterSymbolResolution,
119 MemoryMappingTracking,
120 FfiCallInterception,
121 SystemCallMonitoring,
122 ThreadAwareTracking,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub struct SystemRegionInfo {
127 pub region_type: String,
128 pub description: String,
129 pub read_only: bool,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct LibraryMappingInfo {
134 pub start_address: usize,
135 pub end_address: usize,
136 pub permissions: String,
137 pub file_path: String,
138}
139
140impl LibraryMappingInfo {
141 pub fn contains_address(&self, addr: usize) -> bool {
142 addr >= self.start_address && addr < self.end_address
143 }
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
147pub enum MemoryAccessPattern {
148 Sequential,
149 Random,
150 Sparse,
151 Unknown,
152}