MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / find_acpi_table

Function find_acpi_table

dstack-mr/src/acpi.rs:426–456  ·  view source on GitHub ↗

Searches for an ACPI table with the given signature and returns its offset, checksum offset, and length.

(tables: &[u8], signature: &str)

Source from the content-addressed store, hash-verified

424/// Searches for an ACPI table with the given signature and returns its offset,
425/// checksum offset, and length.
426fn find_acpi_table(tables: &[u8], signature: &str) -> Result<(u32, u32, u32)> {
427 let sig_bytes = signature.as_bytes();
428 if sig_bytes.len() != 4 {
429 bail!("Signature must be 4 bytes long, but got '{signature}'");
430 }
431
432 let mut offset = 0;
433 while offset < tables.len() {
434 // Ensure there's enough space for a table header
435 if offset + 8 > tables.len() {
436 bail!("Table not found: {signature}");
437 }
438
439 let header = AcpiTableHeader::decode(&mut &tables[offset..])
440 .context("failed to decode ACPI table header")?;
441
442 if header.signature == sig_bytes {
443 // Found the table
444 return Ok((offset as u32, (offset + 9) as u32, header.length));
445 }
446
447 if header.length == 0 {
448 // Invalid table length, stop searching
449 bail!("found table with zero length at offset {offset}");
450 }
451 // Move to the next table
452 offset += header.length as usize;
453 }
454
455 bail!("table not found: {signature}");
456}

Callers 1

build_tablesMethod · 0.85

Calls 2

decodeFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected