lib/tldr/src/formats/elf/layout/frame.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const elf = @import("../root.zig");
 2 
 3 const Rela = elf.format.Rela;
 4 
 5 pub const EhFramePieceLayout = struct {
 6     input_offset: u64 = 0,
 7     size: u64 = 0,
 8     output_offset: u64 = 0,
 9     patch_cie_pointer: bool = false,
10     cie_pointer: u32 = 0,
11 };
12 
13 pub const EhFrameCieLayout = struct {
14     input_offset: u64 = 0,
15     output_offset: u64 = 0,
16 };
17 
18 pub const EhFrameSectionLayout = struct {
19     present: bool = false,
20     pieces: []EhFramePieceLayout = &.{},
21     relocations: []Rela = &.{},
22 
23     pub fn deinit(self: *EhFrameSectionLayout, allocator: anytype) void {
24         if (self.pieces.len != 0) allocator.free(self.pieces);
25         if (self.relocations.len != 0) allocator.free(self.relocations);
26     }
27 
28     pub fn isPresent(self: EhFrameSectionLayout) bool {
29         return self.present;
30     }
31 };
32 
33 pub fn sectionAt(sections: []const EhFrameSectionLayout, section_index: usize) ?EhFrameSectionLayout {
34     if (section_index >= sections.len) return null;
35     const eh_frame_section = sections[section_index];
36     if (!eh_frame_section.isPresent()) return null;
37     return eh_frame_section;
38 }