]> git.proxmox.com Git - rustc.git/blob - vendor/gimli/src/read/lists.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / vendor / gimli / src / read / lists.rs
1 use crate::common::{Encoding, Format};
2 use crate::read::{Error, Reader, Result};
3
4 #[derive(Debug, Clone, Copy)]
5 pub(crate) struct ListsHeader {
6 encoding: Encoding,
7 offset_entry_count: u32,
8 }
9
10 impl Default for ListsHeader {
11 fn default() -> Self {
12 ListsHeader {
13 encoding: Encoding {
14 format: Format::Dwarf32,
15 version: 5,
16 address_size: 0,
17 },
18 offset_entry_count: 0,
19 }
20 }
21 }
22
23 impl ListsHeader {
24 /// Return the serialized size of the table header.
25 #[allow(dead_code)]
26 #[inline]
27 fn size(self) -> u8 {
28 // initial_length + version + address_size + segment_selector_size + offset_entry_count
29 ListsHeader::size_for_encoding(self.encoding)
30 }
31
32 /// Return the serialized size of the table header.
33 #[inline]
34 pub(crate) fn size_for_encoding(encoding: Encoding) -> u8 {
35 // initial_length + version + address_size + segment_selector_size + offset_entry_count
36 encoding.format.initial_length_size() + 2 + 1 + 1 + 4
37 }
38 }
39
40 // TODO: add an iterator over headers in the appropriate sections section
41 #[allow(dead_code)]
42 fn parse_header<R: Reader>(input: &mut R) -> Result<ListsHeader> {
43 let (length, format) = input.read_initial_length()?;
44 input.truncate(length)?;
45
46 let version = input.read_u16()?;
47 if version != 5 {
48 return Err(Error::UnknownVersion(u64::from(version)));
49 }
50
51 let address_size = input.read_u8()?;
52 let segment_selector_size = input.read_u8()?;
53 if segment_selector_size != 0 {
54 return Err(Error::UnsupportedSegmentSize);
55 }
56 let offset_entry_count = input.read_u32()?;
57
58 let encoding = Encoding {
59 format,
60 version,
61 address_size,
62 };
63 Ok(ListsHeader {
64 encoding,
65 offset_entry_count,
66 })
67 }