Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/cper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl Cper {
cper.append_section(section);
}

for extra_cper_section in crashlog.metadata.extra_cper_sections.iter() {
cper.append_section(CperSection::from_body(extra_cper_section.clone()));
}

cper
}

Expand Down
1 change: 1 addition & 0 deletions lib/src/cper/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod guids {
}

/// One of the CPER section bodies defined in the UEFI 2.10 Specifications (N.2)
#[derive(Clone)]
pub enum CperSectionBody {
FirmwareErrorRecord(FirmwareErrorRecord),
Unknown(Guid, Vec<u8>),
Expand Down
5 changes: 5 additions & 0 deletions lib/src/cper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ fn cl_from_cper() {
}
}

assert_eq!(crashlog.metadata.extra_cper_sections.len(), 2);
assert_eq!(records.len(), 3);

let cper_bytes = crashlog.to_bytes();
let cper = Cper::from_slice(&cper_bytes).unwrap();
assert_eq!(cper.record_header.section_count, 5);
}

#[test]
Expand Down
21 changes: 14 additions & 7 deletions lib/src/crashlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::Error;
use crate::bert::{Berr, Bert};
#[cfg(feature = "collateral_manager")]
use crate::collateral::{CollateralManager, CollateralTree};
use crate::cper::Cper;
use crate::cper::{Cper, CperSectionBody};
use crate::metadata::Metadata;
use crate::node::Node;
use crate::region::Region;
Expand Down Expand Up @@ -90,17 +90,24 @@ impl CrashLog {

/// Extracts the Crash Log records from [Cper] record.
pub(crate) fn from_cper(cper: Cper) -> Result<Self, Error> {
let regions: Vec<Region> = cper
.sections
.iter()
.filter_map(|section| Region::from_cper_section(&section.body))
.collect();
let mut regions: Vec<Region> = Vec::new();
let mut extra_cper_sections: Vec<CperSectionBody> = Vec::new();

for section in cper.sections {
if let Some(region) = Region::from_cper_section(&section.body) {
regions.push(region);
} else {
extra_cper_sections.push(section.body);
}
}

if regions.is_empty() {
return Err(Error::NoCrashLogFound);
}

CrashLog::from_regions(regions)
let mut crashlog = CrashLog::from_regions(regions)?;
crashlog.metadata.extra_cper_sections = extra_cper_sections;
Ok(crashlog)
}

/// Decodes a raw Crash Log binary.
Expand Down
1 change: 1 addition & 0 deletions lib/src/extract/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl CrashLog {
})
.inspect_err(|err| log::warn!("Cannot get time: {err}"))
.ok(),
..Default::default()
};

Ok(crashlog)
Expand Down
1 change: 1 addition & 0 deletions lib/src/extract/event_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn metadata_from_evt_values(
minute: time.wMinute as u8,
}),
computer: unsafe { computer.Anonymous.StringVal.to_string().ok() },
..Default::default()
})
}

Expand Down
9 changes: 9 additions & 0 deletions lib/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

//! Information extracted alongside the Crash Log records.

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use alloc::{fmt, string::String};
#[cfg(feature = "std")]
use std::fmt;

use crate::cper::CperSectionBody;

/// Crash Log Metadata
#[derive(Default)]
pub struct Metadata {
/// Name of the computer where the Crash Log has been extracted from.
pub computer: Option<String>,
/// Time of the extraction
pub time: Option<Time>,
/// When the Crash Log is extracted from a CPER, this field stores the extra CPER sections that
/// could be read from the CPER structure.
pub extra_cper_sections: Vec<CperSectionBody>,
}

/// Crash Log Extraction Time
Expand Down
Loading