1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libexec/include/exec/elf.h Wed May 11 17:23:11 2022 +0200
1.3 @@ -0,0 +1,95 @@
1.4 +/*
1.5 + * ELF payload decoding support.
1.6 + *
1.7 + * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <exec/segment.h>
1.26 +
1.27 +
1.28 +
1.29 +/* Generic program segment interface. */
1.30 +
1.31 +class ProgramSegment
1.32 +{
1.33 +public:
1.34 + virtual bool loadable() = 0;
1.35 + virtual offset_t file_contents() = 0;
1.36 + virtual offset_t file_offset() = 0;
1.37 + virtual l4_addr_t region_address() = 0;
1.38 + virtual offset_t region_size() = 0;
1.39 + virtual l4re_rm_flags_t region_flags() = 0;
1.40 +
1.41 + Segment *segment();
1.42 +};
1.43 +
1.44 +template <typename PROGRAM_HEADER>
1.45 +class ProgramSegmentVariant : public ProgramSegment
1.46 +{
1.47 +protected:
1.48 + PROGRAM_HEADER *_header;
1.49 +
1.50 +public:
1.51 + explicit ProgramSegmentVariant(PROGRAM_HEADER *header);
1.52 +
1.53 + bool loadable();
1.54 + offset_t file_contents();
1.55 + offset_t file_offset();
1.56 + l4_addr_t region_address();
1.57 + offset_t region_size();
1.58 + l4re_rm_flags_t region_flags();
1.59 +};
1.60 +
1.61 +
1.62 +
1.63 +/* Generic interface for an ELF payload. */
1.64 +
1.65 +class Payload
1.66 +{
1.67 +public:
1.68 + virtual l4_addr_t entry_point() = 0;
1.69 + virtual offset_t header_extent() = 0;
1.70 + virtual offset_t program_header_extent() = 0;
1.71 + virtual unsigned int segments() = 0;
1.72 + virtual ProgramSegment *segment(unsigned int i) = 0;
1.73 +};
1.74 +
1.75 +template <typename HEADER, typename PROGRAM_HEADER>
1.76 +class PayloadVariant : public Payload
1.77 +{
1.78 +protected:
1.79 + HEADER *_header;
1.80 +
1.81 +public:
1.82 + explicit PayloadVariant(HEADER *header);
1.83 +
1.84 + l4_addr_t entry_point();
1.85 + offset_t header_extent();
1.86 + offset_t program_header_extent();
1.87 + unsigned int segments();
1.88 + ProgramSegment *segment(unsigned int i);
1.89 +};
1.90 +
1.91 +
1.92 +
1.93 +/* Return the appropriate payload object. */
1.94 +
1.95 +Payload *get_payload(char *buf);
1.96 +
1.97 +/* vim: tabstop=2 expandtab shiftwidth=2
1.98 +*/