LCOV - code coverage report
Current view: top level - src/elf/note - note_abi.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 80.0 % 35 28
Test Date: 2026-04-12:00:00:00 Functions: 70.0 % 10 7

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : use std::marker::PhantomData;
       3              : 
       4              : use super::NoteBase;
       5              : use crate::common::FromFFI;
       6              : 
       7              : #[allow(non_camel_case_types)]
       8          156 : #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
       9              : /// ABI type for the note
      10              : pub enum Abi {
      11              :     LINUX,
      12              :     GNU,
      13              :     SOLARIS2,
      14              :     FREEBSD,
      15              :     NETBSD,
      16              :     SYLLABLE,
      17              :     NACL,
      18              :     UNKNOWN(u32),
      19              : }
      20              : 
      21              : impl From<u32> for Abi {
      22          169 :     fn from(value: u32) -> Self {
      23          169 :         match value {
      24          169 :             0 => Abi::LINUX,
      25            0 :             1 => Abi::GNU,
      26            0 :             2 => Abi::SOLARIS2,
      27            0 :             3 => Abi::FREEBSD,
      28            0 :             4 => Abi::NETBSD,
      29            0 :             5 => Abi::SYLLABLE,
      30            0 :             6 => Abi::NACL,
      31            0 :             _ => Abi::UNKNOWN(value),
      32              :         }
      33          169 :     }
      34              : }
      35              : 
      36              : /// Note representing an ABI tag (e.g. `NT_GNU_ABI_TAG`)
      37              : pub struct NoteAbi<'a> {
      38              :     ptr: cxx::UniquePtr<ffi::ELF_NoteAbi>,
      39              :     _owner: PhantomData<&'a ffi::ELF_Binary>,
      40              : }
      41              : 
      42              : impl NoteAbi<'_> {
      43              :     /// Return the ABI
      44          169 :     pub fn abi(&self) -> Abi {
      45          169 :         Abi::from(self.ptr.abi())
      46          169 :     }
      47              : 
      48              :     /// Return the version as `[major, minor, patch]`
      49          169 :     pub fn version(&self) -> Vec<u64> {
      50          169 :         Vec::from(self.ptr.version().as_slice())
      51          169 :     }
      52              : }
      53              : 
      54              : impl NoteBase for NoteAbi<'_> {
      55          494 :     fn get_base(&self) -> &ffi::ELF_Note {
      56          494 :         self.ptr.as_ref().unwrap().as_ref()
      57          494 :     }
      58              : }
      59              : 
      60              : impl FromFFI<ffi::ELF_NoteAbi> for NoteAbi<'_> {
      61          195 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_NoteAbi>) -> Self {
      62          195 :         Self {
      63          195 :             ptr,
      64          195 :             _owner: PhantomData,
      65          195 :         }
      66          195 :     }
      67              : }
      68              : 
      69              : impl std::fmt::Debug for NoteAbi<'_> {
      70          156 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      71          156 :         let base = self as &dyn NoteBase;
      72          156 :         f.debug_struct("NoteAbi")
      73          156 :             .field("base", &base)
      74          156 :             .field("abi", &self.abi())
      75          156 :             .field("version", &self.version())
      76          156 :             .finish()
      77          156 :     }
      78              : }
        

Generated by: LCOV version 2.1-1