paul@327 | 1 | /* |
paul@327 | 2 | * ELF payload decoding support. |
paul@327 | 3 | * |
paul@327 | 4 | * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> |
paul@327 | 5 | * |
paul@327 | 6 | * This program is free software; you can redistribute it and/or |
paul@327 | 7 | * modify it under the terms of the GNU General Public License as |
paul@327 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@327 | 9 | * the License, or (at your option) any later version. |
paul@327 | 10 | * |
paul@327 | 11 | * This program is distributed in the hope that it will be useful, |
paul@327 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@327 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@327 | 14 | * GNU General Public License for more details. |
paul@327 | 15 | * |
paul@327 | 16 | * You should have received a copy of the GNU General Public License |
paul@327 | 17 | * along with this program; if not, write to the Free Software |
paul@327 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@327 | 19 | * Boston, MA 02110-1301, USA |
paul@327 | 20 | */ |
paul@327 | 21 | |
paul@349 | 22 | #pragma once |
paul@349 | 23 | |
paul@327 | 24 | #include <exec/segment.h> |
paul@327 | 25 | |
paul@327 | 26 | |
paul@327 | 27 | |
paul@327 | 28 | /* Generic program segment interface. */ |
paul@327 | 29 | |
paul@327 | 30 | template <typename PROGRAM_HEADER> |
paul@349 | 31 | class ProgramSegmentVariant : public Segment |
paul@327 | 32 | { |
paul@327 | 33 | protected: |
paul@327 | 34 | PROGRAM_HEADER *_header; |
paul@327 | 35 | |
paul@327 | 36 | public: |
paul@327 | 37 | explicit ProgramSegmentVariant(PROGRAM_HEADER *header); |
paul@327 | 38 | |
paul@327 | 39 | bool loadable(); |
paul@327 | 40 | offset_t file_contents(); |
paul@327 | 41 | offset_t file_offset(); |
paul@327 | 42 | l4_addr_t region_address(); |
paul@327 | 43 | offset_t region_size(); |
paul@327 | 44 | l4re_rm_flags_t region_flags(); |
paul@327 | 45 | }; |
paul@327 | 46 | |
paul@349 | 47 | |
paul@327 | 48 | |
paul@327 | 49 | /* Generic interface for an ELF payload. */ |
paul@327 | 50 | |
paul@327 | 51 | class Payload |
paul@327 | 52 | { |
paul@349 | 53 | protected: |
paul@349 | 54 | Segment **_segments = NULL; |
paul@349 | 55 | |
paul@327 | 56 | public: |
paul@349 | 57 | virtual ~Payload(); |
paul@349 | 58 | |
paul@327 | 59 | virtual l4_addr_t entry_point() = 0; |
paul@327 | 60 | virtual offset_t header_extent() = 0; |
paul@327 | 61 | virtual offset_t program_header_extent() = 0; |
paul@349 | 62 | virtual unsigned int segments(); |
paul@349 | 63 | virtual Segment *segment(unsigned int i) = 0; |
paul@327 | 64 | }; |
paul@327 | 65 | |
paul@327 | 66 | template <typename HEADER, typename PROGRAM_HEADER> |
paul@327 | 67 | class PayloadVariant : public Payload |
paul@327 | 68 | { |
paul@327 | 69 | protected: |
paul@327 | 70 | HEADER *_header; |
paul@327 | 71 | |
paul@327 | 72 | public: |
paul@327 | 73 | explicit PayloadVariant(HEADER *header); |
paul@327 | 74 | |
paul@327 | 75 | l4_addr_t entry_point(); |
paul@327 | 76 | offset_t header_extent(); |
paul@327 | 77 | offset_t program_header_extent(); |
paul@327 | 78 | unsigned int segments(); |
paul@349 | 79 | Segment *segment(unsigned int i); |
paul@327 | 80 | }; |
paul@327 | 81 | |
paul@327 | 82 | |
paul@327 | 83 | |
paul@327 | 84 | /* Return the appropriate payload object. */ |
paul@327 | 85 | |
paul@356 | 86 | Payload *exec_open_payload(char *buf); |
paul@327 | 87 | |
paul@327 | 88 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@327 | 89 | */ |