Debian Codegraph @

third_party/rust/minidump-writer/src/linux/errors.rs

raw
1 use {
2 super::{ptrace_dumper::InitError, serializers::*},
3 crate::{
4 dir_section::FileWriterError, maps_reader::MappingInfo, mem_writer::MemoryWriterError,
5 serializers::*, Pid,
6 },
7 error_graph::ErrorList,
8 std::ffi::OsString,
9 thiserror::Error,
10 };
11
12 #[derive(Error, Debug, serde::Serialize)]
13 pub enum MapsReaderError {
14 #[error("Couldn't parse as ELF file")]
15 ELFParsingFailed(
16 #[from]
17 #[serde(serialize_with = "serialize_goblin_error")]
18 goblin::error::Error,
19 ),
20 #[error("No soname found (filename: {})", .0.to_string_lossy())]
21 NoSoName(OsString, #[source] ModuleReaderError),
22
23 // parse_from_line()
24 #[error("Map entry malformed: No {0} found")]
25 MapEntryMalformed(&'static str),
26 #[error("Couldn't parse address")]
27 UnparsableInteger(
28 #[from]
29 #[serde(skip)]
30 std::num::ParseIntError,
31 ),
32 #[error("Linux gate location doesn't fit in the required integer type")]
33 LinuxGateNotConvertable(
34 #[from]
35 #[serde(skip)]
36 std::num::TryFromIntError,
37 ),
38
39 // get_mmap()
40 #[error("Not safe to open mapping {}", .0.to_string_lossy())]
41 NotSafeToOpenMapping(OsString),
42 #[error("IO Error")]
43 FileError(
44 #[from]
45 #[serde(serialize_with = "serialize_io_error")]
46 std::io::Error,
47 ),
48 #[error("Mmapped file empty or not an ELF file")]
49 MmapSanityCheckFailed,
50 #[error("Symlink does not match ({0} vs. {1})")]
51 SymlinkError(std::path::PathBuf, std::path::PathBuf),
52 }
53
54 #[derive(Debug, Error, serde::Serialize)]
55 pub enum CpuInfoError {
56 #[error("IO error for file /proc/cpuinfo")]
57 IOError(
58 #[from]
59 #[serde(serialize_with = "serialize_io_error")]
60 std::io::Error,
61 ),
62 #[error("Not all entries of /proc/cpuinfo found!")]
63 NotAllProcEntriesFound,
64 #[error("Couldn't parse core from file")]
65 UnparsableInteger(
66 #[from]
67 #[serde(skip)]
68 std::num::ParseIntError,
69 ),
70 #[error("Couldn't parse cores: {0}")]
71 UnparsableCores(String),
72 }
73
74 #[derive(Error, Debug, serde::Serialize)]
75 pub enum ThreadInfoError {
76 #[error("Index out of bounds: Got {0}, only have {1}")]
77 IndexOutOfBounds(usize, usize),
78 #[error("Either ppid ({1}) or tgid ({2}) not found in {0}")]
79 InvalidPid(String, Pid, Pid),
80 #[error("IO error")]
81 IOError(
82 #[from]
83 #[serde(serialize_with = "serialize_io_error")]
84 std::io::Error,
85 ),
86 #[error("Couldn't parse address")]
87 UnparsableInteger(
88 #[from]
89 #[serde(skip)]
90 std::num::ParseIntError,
91 ),
92 #[error("nix::ptrace() error")]
93 PtraceError(
94 #[from]
95 #[serde(serialize_with = "serialize_nix_error")]
96 nix::Error,
97 ),
98 #[error("Invalid line in /proc/{0}/status: {1}")]
99 InvalidProcStatusFile(Pid, String),
100 }
101
102 #[derive(Debug, Error, serde::Serialize)]
103 pub enum AndroidError {
104 #[error("Failed to copy memory from process")]
105 CopyFromProcessError(#[from] DumperError),
106 #[error("Failed slice conversion")]
107 TryFromSliceError(
108 #[from]
109 #[serde(skip)]
110 std::array::TryFromSliceError,
111 ),
112 #[error("No Android rel found")]
113 NoRelFound,
114 }
115
116 #[derive(Debug, Error, serde::Serialize)]
117 #[error("Copy from process {child} failed (source {src}, offset: {offset}, length: {length})")]
118 pub struct CopyFromProcessError {
119 pub child: Pid,
120 pub src: usize,
121 pub offset: usize,
122 pub length: usize,
123 #[serde(serialize_with = "serialize_nix_error")]
124 pub source: nix::Error,
125 }
126
127 #[derive(Debug, Error, serde::Serialize)]
128 pub enum DumperError {
129 #[error("Failed to get PAGE_SIZE from system")]
130 SysConfError(
131 #[from]
132 #[serde(serialize_with = "serialize_nix_error")]
133 nix::Error,
134 ),
135 #[error("wait::waitpid(Pid={0}) failed")]
136 WaitPidError(
137 Pid,
138 #[source]
139 #[serde(serialize_with = "serialize_nix_error")]
140 nix::Error,
141 ),
142 #[error("nix::ptrace::attach(Pid={0}) failed")]
143 PtraceAttachError(
144 Pid,
145 #[source]
146 #[serde(serialize_with = "serialize_nix_error")]
147 nix::Error,
148 ),
149 #[error("nix::ptrace::detach(Pid={0}) failed")]
150 PtraceDetachError(
151 Pid,
152 #[source]
153 #[serde(serialize_with = "serialize_nix_error")]
154 nix::Error,
155 ),
156 #[error(transparent)]
157 CopyFromProcessError(#[from] CopyFromProcessError),
158 #[error("Skipped thread {0} due to it being part of the seccomp sandbox's trusted code")]
159 DetachSkippedThread(Pid),
160 #[error("No mapping for stack pointer found")]
161 NoStackPointerMapping,
162 #[error("Failed slice conversion")]
163 TryFromSliceError(
164 #[from]
165 #[serde(skip)]
166 std::array::TryFromSliceError,
167 ),
168 #[error("Couldn't parse as ELF file")]
169 ELFParsingFailed(
170 #[from]
171 #[serde(serialize_with = "serialize_goblin_error")]
172 goblin::error::Error,
173 ),
174 #[error("Could not read value from module")]
175 ModuleReaderError(#[from] ModuleReaderError),
176 #[error("Not safe to open mapping: {}", .0.to_string_lossy())]
177 NotSafeToOpenMapping(OsString),
178 #[error("Failed integer conversion")]
179 TryFromIntError(
180 #[from]
181 #[serde(skip)]
182 std::num::TryFromIntError,
183 ),
184 #[error("Maps reader error")]
185 MapsReaderError(#[from] MapsReaderError),
186 }
187
188 #[derive(Debug, Error, serde::Serialize)]
189 pub enum SectionAppMemoryError {
190 #[error("Failed to copy memory from process")]
191 CopyFromProcessError(#[from] DumperError),
192 #[error("Failed to write to memory")]
193 MemoryWriterError(#[from] MemoryWriterError),
194 }
195
196 #[derive(Debug, Error, serde::Serialize)]
197 pub enum SectionExceptionStreamError {
198 #[error("Failed to write to memory")]
199 MemoryWriterError(#[from] MemoryWriterError),
200 }
201
202 #[derive(Debug, Error, serde::Serialize)]
203 pub enum SectionHandleDataStreamError {
204 #[error("Failed to access file")]
205 IOError(
206 #[from]
207 #[serde(serialize_with = "serialize_io_error")]
208 std::io::Error,
209 ),
210 #[error("Failed to write to memory")]
211 MemoryWriterError(#[from] MemoryWriterError),
212 #[error("Failed integer conversion")]
213 TryFromIntError(
214 #[from]
215 #[serde(skip)]
216 std::num::TryFromIntError,
217 ),
218 }
219
220 #[derive(Debug, Error, serde::Serialize)]
221 pub enum SectionMappingsError {
222 #[error("Failed to write to memory")]
223 MemoryWriterError(#[from] MemoryWriterError),
224 #[error("Failed to get effective path of mapping ({0:?})")]
225 GetEffectivePathError(MappingInfo, #[source] MapsReaderError),
226 }
227
228 #[derive(Debug, Error, serde::Serialize)]
229 pub enum SectionMemInfoListError {
230 #[error("Failed to write to memory")]
231 MemoryWriterError(#[from] MemoryWriterError),
232 #[error("Failed to read from procfs")]
233 ProcfsError(
234 #[from]
235 #[serde(serialize_with = "serialize_proc_error")]
236 procfs_core::ProcError,
237 ),
238 }
239
240 #[derive(Debug, Error, serde::Serialize)]
241 pub enum SectionMemListError {
242 #[error("Failed to write to memory")]
243 MemoryWriterError(#[from] MemoryWriterError),
244 }
245
246 #[derive(Debug, Error, serde::Serialize)]
247 pub enum SectionSystemInfoError {
248 #[error("Failed to write to memory")]
249 MemoryWriterError(#[from] MemoryWriterError),
250 #[error("Failed to get CPU Info")]
251 CpuInfoError(#[from] CpuInfoError),
252 #[error("Failed trying to write CPU information")]
253 WriteCpuInformationFailed(#[source] CpuInfoError),
254 }
255
256 #[derive(Debug, Error, serde::Serialize)]
257 pub enum SectionThreadListError {
258 #[error("Failed to write to memory")]
259 MemoryWriterError(#[from] MemoryWriterError),
260 #[error("Failed integer conversion")]
261 TryFromIntError(
262 #[from]
263 #[serde(skip)]
264 std::num::TryFromIntError,
265 ),
266 #[error("Failed to copy memory from process")]
267 CopyFromProcessError(#[from] DumperError),
268 #[error("Failed to get thread info")]
269 ThreadInfoError(#[from] ThreadInfoError),
270 #[error("Failed to write to memory buffer")]
271 IOError(
272 #[from]
273 #[serde(serialize_with = "serialize_io_error")]
274 std::io::Error,
275 ),
276 }
277
278 #[derive(Debug, Error, serde::Serialize)]
279 pub enum SectionThreadNamesError {
280 #[error("Failed integer conversion")]
281 TryFromIntError(
282 #[from]
283 #[serde(skip)]
284 std::num::TryFromIntError,
285 ),
286 #[error("Failed to write to memory")]
287 MemoryWriterError(#[from] MemoryWriterError),
288 #[error("Failed to write to memory buffer")]
289 IOError(
290 #[from]
291 #[serde(serialize_with = "serialize_io_error")]
292 std::io::Error,
293 ),
294 }
295
296 #[derive(Debug, Error, serde::Serialize)]
297 pub enum SectionDsoDebugError {
298 #[error("Failed to write to memory")]
299 MemoryWriterError(#[from] MemoryWriterError),
300 #[error("Could not find: {0}")]
301 CouldNotFind(&'static str),
302 #[error("Failed to copy memory from process")]
303 CopyFromProcessError(#[from] DumperError),
304 #[error("Failed to copy memory from process")]
305 FromUTF8Error(
306 #[from]
307 #[serde(serialize_with = "serialize_from_utf8_error")]
308 std::string::FromUtf8Error,
309 ),
310 }
311
312 #[derive(Debug, Error, serde::Serialize)]
313 pub enum WriterError {
314 #[error("Error during init phase")]
315 InitError(#[from] InitError),
316 #[error(transparent)]
317 DumperError(#[from] DumperError),
318 #[error("Failed when writing section AppMemory")]
319 SectionAppMemoryError(#[from] SectionAppMemoryError),
320 #[error("Failed when writing section ExceptionStream")]
321 SectionExceptionStreamError(#[from] SectionExceptionStreamError),
322 #[error("Failed when writing section HandleDataStream")]
323 SectionHandleDataStreamError(#[from] SectionHandleDataStreamError),
324 #[error("Failed when writing section MappingsError")]
325 SectionMappingsError(#[from] SectionMappingsError),
326 #[error("Failed when writing section MemList")]
327 SectionMemListError(#[from] SectionMemListError),
328 #[error("Failed when writing section SystemInfo")]
329 SectionSystemInfoError(#[from] SectionSystemInfoError),
330 #[error("Failed when writing section MemoryInfoList")]
331 SectionMemoryInfoListError(#[from] SectionMemInfoListError),
332 #[error("Failed when writing section ThreadList")]
333 SectionThreadListError(#[from] SectionThreadListError),
334 #[error("Failed when writing section ThreadNameList")]
335 SectionThreadNamesError(#[from] SectionThreadNamesError),
336 #[error("Failed when writing section DsoDebug")]
337 SectionDsoDebugError(#[from] SectionDsoDebugError),
338 #[error("Failed to write to memory")]
339 MemoryWriterError(#[from] MemoryWriterError),
340 #[error("Failed to write to file")]
341 FileWriterError(#[from] FileWriterError),
342 #[error("Failed to get current timestamp when writing header of minidump")]
343 SystemTimeError(
344 #[from]
345 #[serde(serialize_with = "serialize_system_time_error")]
346 std::time::SystemTimeError,
347 ),
348 #[error("Errors occurred while initializing PTraceDumper")]
349 InitErrors(#[source] ErrorList<InitError>),
350 #[error("Errors occurred while suspending threads")]
351 SuspendThreadsErrors(#[source] ErrorList<DumperError>),
352 #[error("Errors occurred while resuming threads")]
353 ResumeThreadsErrors(#[source] ErrorList<DumperError>),
354 #[error("Crash thread does not reference principal mapping")]
355 PrincipalMappingNotReferenced,
356 #[error("Errors occurred while writing system info")]
357 WriteSystemInfoErrors(#[source] ErrorList<SectionSystemInfoError>),
358 #[error("Failed writing cpuinfo")]
359 WriteCpuInfoFailed(#[source] MemoryWriterError),
360 #[error("Failed writing thread proc status")]
361 WriteThreadProcStatusFailed(#[source] MemoryWriterError),
362 #[error("Failed writing OS Release Information")]
363 WriteOsReleaseInfoFailed(#[source] MemoryWriterError),
364 #[error("Failed writing process command line")]
365 WriteCommandLineFailed(#[source] MemoryWriterError),
366 #[error("Writing process environment failed")]
367 WriteEnvironmentFailed(#[source] MemoryWriterError),
368 #[error("Failed to write auxv file")]
369 WriteAuxvFailed(#[source] MemoryWriterError),
370 #[error("Failed to write maps file")]
371 WriteMapsFailed(#[source] MemoryWriterError),
372 #[error("Failed writing DSO Debug Stream")]
373 WriteDSODebugStreamFailed(#[source] SectionDsoDebugError),
374 #[error("Failed writing limits file")]
375 WriteLimitsFailed(#[source] MemoryWriterError),
376 #[error("Failed writing handle data stream")]
377 WriteHandleDataStreamFailed(#[source] SectionHandleDataStreamError),
378 #[error("Failed writing handle data stream direction entry")]
379 WriteHandleDataStreamDirentFailed(#[source] FileWriterError),
380 #[error("No threads left to suspend out of {0}")]
381 SuspendNoThreadsLeft(usize),
382 #[error("Failed to convert soft error list to JSON")]
383 ConvertToJsonFailed(
384 #[source]
385 #[serde(skip)]
386 serde_json::Error,
387 ),
388 }
389
390 #[derive(Debug, Error, serde::Serialize)]
391 pub enum ModuleReaderError {
392 #[error("failed to read module file ({path}): {error}")]
393 MapFile {
394 path: std::path::PathBuf,
395 #[source]
396 #[serde(serialize_with = "serialize_io_error")]
397 error: std::io::Error,
398 },
399 #[error("failed to read module memory: {length} bytes at {offset}{}: {error}", .start_address.map(|addr| format!(" (start address: {addr})")).unwrap_or_default())]
400 ReadModuleMemory {
401 offset: u64,
402 length: u64,
403 start_address: Option<u64>,
404 #[source]
405 #[serde(serialize_with = "serialize_nix_error")]
406 error: nix::Error,
407 },
408 #[error("failed to parse ELF memory: {0}")]
409 Parsing(
410 #[from]
411 #[serde(serialize_with = "serialize_goblin_error")]
412 goblin::error::Error,
413 ),
414 #[error("no build id notes in program headers")]
415 NoProgramHeaderNote,
416 #[error("no string table available to locate note sections")]
417 NoStrTab,
418 #[error("no build id note sections")]
419 NoSectionNote,
420 #[error("the ELF data contains no program headers")]
421 NoProgramHeaders,
422 #[error("the ELF data contains no sections")]
423 NoSections,
424 #[error("the ELF data does not have a .text section from which to generate a build id")]
425 NoTextSection,
426 #[error(
427 "failed to calculate build id\n\
428 ... from program headers: {program_headers}\n\
429 ... from sections: {section}\n\
430 ... from the text section: {section}"
431 )]
432 NoBuildId {
433 program_headers: Box<Self>,
434 section: Box<Self>,
435 generated: Box<Self>,
436 },
437 #[error("no dynamic string table section")]
438 NoDynStrSection,
439 #[error("a string in the strtab did not have a terminating nul byte")]
440 StrTabNoNulByte,
441 #[error("no SONAME found in dynamic linking information")]
442 NoSoNameEntry,
443 #[error("no dynamic linking information section")]
444 NoDynamicSection,
445 #[error(
446 "failed to retrieve soname\n\
447 ... from program headers: {program_headers}\n\
448 ... from sections: {section}"
449 )]
450 NoSoName {
451 program_headers: Box<Self>,
452 section: Box<Self>,
453 },
454 }