<!-- description --> @brief Validates the provided ELF file. <!-- inputs/outputs --> @param file the elf file to validate
| 273 | /// @param file the elf file to validate |
| 274 | /// |
| 275 | static constexpr void |
| 276 | validate(loader::ext_elf_file_t const *const file) noexcept |
| 277 | { |
| 278 | /// NOTE: |
| 279 | /// - The point of this function is to provide some sanity checks |
| 280 | /// in debug mode which is why everything uses bsl::expects. |
| 281 | /// None of these are needed in a release build because it |
| 282 | /// will have gone through testing to ensure they all pass. |
| 283 | /// - Removing this logic in a release build helps to keep the |
| 284 | /// binary size smaller. |
| 285 | /// |
| 286 | |
| 287 | bsl::expects(nullptr != file); |
| 288 | validate_elf64_ehdr(file); |
| 289 | |
| 290 | auto const phdrtab{get_phdrtab(file)}; |
| 291 | for (bsl::safe_idx mut_i{}; mut_i < phdrtab.size(); ++mut_i) { |
| 292 | auto const *const phdr{phdrtab.at_if(mut_i)}; |
| 293 | |
| 294 | switch (phdr->p_type) { |
| 295 | case bfelf::PT_LOAD.get(): { |
| 296 | validate_pt_load(phdr); |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | case bfelf::PT_GNU_STACK.get(): { |
| 301 | validate_pt_gnu_stack(phdr); |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | case bfelf::PT_TLS.get(): { |
| 306 | validate_pt_tls(phdr); |
| 307 | break; |
| 308 | } |
| 309 | |
| 310 | default: { |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /// <!-- description --> |
| 318 | /// @brief Allocate the a page of RW or RW memory for the segment |