Skip to main content

intel_crashlog/
record.rs

1// Copyright (C) 2025 Intel Corporation
2// SPDX-License-Identifier: MIT
3
4//! Provides access to the content of a Crash Log record.
5
6mod core;
7mod decode;
8
9use crate::header::Header;
10#[cfg(not(feature = "std"))]
11use alloc::vec::Vec;
12
13/// A single Crash Log record
14#[derive(Default)]
15pub struct Record {
16    /// Header of the record
17    pub header: Header,
18    /// Raw content of the record
19    pub data: Vec<u8>,
20    /// Additional information provided to the record
21    pub context: Context,
22}
23
24/// Additional data provided to a Crash Log record
25#[derive(Clone, Default)]
26pub struct Context {
27    /// Header of the parent record
28    pub parent_header: Option<Header>,
29}
30
31impl Record {
32    pub fn payload(&self) -> &[u8] {
33        let begin = self.header.header_size();
34        let end = if self.header.version.cldic {
35            // Checksum is present at the end of the record
36            self.data.len() - 4
37        } else {
38            self.data.len()
39        };
40        &self.data[begin..end]
41    }
42
43    pub fn checksum(&self) -> Option<bool> {
44        if !self.header.version.cldic {
45            return None;
46        }
47
48        let checksum = self
49            .data
50            .chunks(4)
51            .map(|dword_slice| u32::from_le_bytes(dword_slice.try_into().unwrap_or([0; 4])))
52            .fold(0, |acc: u32, dword| acc.wrapping_add(dword));
53
54        Some(checksum == 0)
55    }
56}