-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: define the Error
type
#70
Open
toku-sa-n
wants to merge
21
commits into
nrc:master
Choose a base branch
from
toku-sa-n:custom_error_type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b55e08a
chore: add `error.rs`
toku-sa-n b9fbcff
feat: define `Error`
toku-sa-n b49e400
chore(parse_header): return `Error` as `Err`
toku-sa-n d6a4bc2
chore(section_header): return `Error` as `Err`
toku-sa-n ed4c02e
chore(program_header): return `Error` as `Err`
toku-sa-n 8cd87db
chore: return `Error` as `Err`
toku-sa-n ee5cbd2
chore: statically check the size of `HeaderPt1`
toku-sa-n 293f91b
chore(get_binding): return `Error` as `Err`
toku-sa-n e645fad
chore(get_type): return `Error` as `Err`
toku-sa-n 27871f5
chore: return `Error` as `Err`
toku-sa-n 0a1410d
chore: return `Error` as `Err`
toku-sa-n adfcd62
chore: return `Error` as `Err`
toku-sa-n c585123
chore: remove `is` from error types
toku-sa-n 69fdd04
fix: forgot to remove `is`
toku-sa-n baaae0b
fix: forgot to remove `is`
toku-sa-n 085ba60
docs: use `the` instead of `this`
toku-sa-n ed45cd9
chore(get_string): use `assert_eq!`
toku-sa-n dcea4ec
chore: add a panic message
toku-sa-n 121da95
chore(Error): implement `PartialOrd` and `Ord`
toku-sa-n 18d0c74
chore(sections): return `Error` as `Err`
toku-sa-n 1a74804
chore(error): add `The`
toku-sa-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use core::fmt; | ||
|
||
/// Errors returned by the methods and functions of this crate. | ||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub enum Error { | ||
/// The magic number of the given ELF file is invalid. | ||
InvalidMagic, | ||
/// The class of the given ELF file is invalid. | ||
InvalidClass, | ||
/// The section type is invalid. | ||
InvalidSectionType, | ||
/// The segment type is invalid. | ||
InvalidSegmentType, | ||
/// The version of the given ELF file is invalid. | ||
InvalidVersion, | ||
/// The data format of the given ELF file is invalid. | ||
InvalidDataFormat, | ||
/// The symbol's binding is invalid. | ||
InvalidSymbolBinding, | ||
/// The symbol's type is invalid. | ||
InvalidSymbolType, | ||
/// The compression type is invalid. | ||
InvalidCompressionType, | ||
/// The tag of the dynamic link information is invalid. | ||
InvalidTag, | ||
/// The length of the given ELF file is too short. | ||
FileTooShort, | ||
/// The length of the section is too short. | ||
SectionTooShort, | ||
/// Program header is not found. | ||
ProgramHeaderNotFound, | ||
/// The `.symtab_shndx` section is not found. | ||
SymtabShndxNotFound, | ||
/// The `.strtab` section is not found. | ||
StrtabNotFound, | ||
/// The `.dynstr` section is not found. | ||
DynstrNotFound, | ||
/// The section type is `NULL`. | ||
NullSection, | ||
/// The section header index is one of the followings: | ||
/// - `SHN_UNDEF` | ||
/// - `SHN_ABS` | ||
/// - `SHN_COMMON` | ||
ReservedSectionHeaderIndex, | ||
/// The size of each program header recorded in the file header is different from the actual | ||
/// size. | ||
ProgramHeaderSizeMismatch, | ||
/// The class specified in the file header is different from the actual class. | ||
ClassMismatch, | ||
/// The segment whose type is `PT_SHLIB` should not be used. | ||
UseOfShLib, | ||
/// The alignments of the virtual address, offset, and align recorded in the program header are | ||
/// the invalid combination. | ||
MisalignedAddressAndOffset, | ||
/// Failed to decompress the section. | ||
DecompressionError, | ||
/// The dynamic link information does not contain a value, but a pointer. | ||
ValueNotContained, | ||
/// The dynamic link information does not contain a pointer, but a value. | ||
PointerNotContained, | ||
/// The 32-bit binaries are not supported. | ||
Binary32BitNotSupported, | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
match self { | ||
Self::InvalidMagic => "The magic number of the given ELF file is invalid.", | ||
Self::InvalidClass => "The class of the given ELF file is invalid.", | ||
Self::InvalidSectionType => "The section type is invalid.", | ||
Self::InvalidSegmentType => "The segment type is invalid.", | ||
Self::InvalidVersion => "The version of the given ELF file is invalid.", | ||
Self::InvalidDataFormat => "The data format of the given ELF file is invalid.", | ||
Self::InvalidSymbolBinding => "The symbol's binding is invalid.", | ||
Self::InvalidSymbolType => "The symbol's type is invalid.", | ||
Self::InvalidCompressionType => "The compression type is invalid.", | ||
Self::InvalidTag => "The tag of the dynamic link information is invalid.", | ||
Self::FileTooShort => "The length of the given ELF file is too short.", | ||
Self::SectionTooShort => "The length of the section is too short.", | ||
Self::ProgramHeaderNotFound => "The program header is not found.", | ||
Self::SymtabShndxNotFound => "The `.symtab_shndx` section is not found.", | ||
Self::StrtabNotFound => "The `.strtab` section is not found.", | ||
Self::DynstrNotFound => "The `.dynstr` section is not found.", | ||
Self::NullSection => "The section type is `NULL`.", | ||
Self::ReservedSectionHeaderIndex => "The section header index is reserved.", | ||
Self::ProgramHeaderSizeMismatch => "The size of each program header recorded in the file header is different from the actual size.", | ||
Self::ClassMismatch => "The class specified in the file header is different from the actual class.", | ||
Self::UseOfShLib => "The segment whose type is `PT_SHLIB` should not be used.", | ||
Self::MisalignedAddressAndOffset => "The alignments of the virtual address, offset, and align recorded in the program header are the invalid combination.", | ||
Self::DecompressionError => "Failed to decompress the section.", | ||
Self::ValueNotContained => "The dynamic link information does not contain a value, but a pointer.", | ||
Self::PointerNotContained => "The dynamic link information does not contain a pointer, but a value.", | ||
Self::Binary32BitNotSupported => "The 32-bit binaries are not supported.", | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the size check of
HeaderPt1
fromsanity_check
as it can be done in a const expression.