1.1 --- a/tests/dstest_exec.cc Wed May 11 16:37:05 2022 +0200
1.2 +++ b/tests/dstest_exec.cc Wed May 11 17:23:11 2022 +0200
1.3 @@ -25,6 +25,7 @@
1.4 #include <l4/util/elf.h>
1.5 #include <l4/util/util.h>
1.6
1.7 +#include <exec/elf.h>
1.8 #include <exec/process.h>
1.9 #include <fsclient/client.h>
1.10 #include <ipc/mem_ipc.h>
1.11 @@ -275,153 +276,6 @@
1.12
1.13
1.14
1.15 -/* Generic program segment interface. */
1.16 -
1.17 -class ProgramSegment
1.18 -{
1.19 -public:
1.20 - virtual bool loadable() = 0;
1.21 - virtual offset_t file_contents() = 0;
1.22 - virtual offset_t file_offset() = 0;
1.23 - virtual l4_addr_t region_address() = 0;
1.24 - virtual offset_t region_size() = 0;
1.25 - virtual l4re_rm_flags_t region_flags() = 0;
1.26 -
1.27 - Segment *segment()
1.28 - {
1.29 - return new Segment(
1.30 - region_address(),
1.31 - region_size(),
1.32 - region_flags(),
1.33 - file_offset(),
1.34 - file_contents());
1.35 - }
1.36 -};
1.37 -
1.38 -template <typename PROGRAM_HEADER>
1.39 -class ProgramSegmentVariant : public ProgramSegment
1.40 -{
1.41 -protected:
1.42 - PROGRAM_HEADER *_header;
1.43 -
1.44 -public:
1.45 - explicit ProgramSegmentVariant(PROGRAM_HEADER *header)
1.46 - : _header(header)
1.47 - {
1.48 - }
1.49 -
1.50 - bool loadable()
1.51 - {
1.52 - return _header->p_type == PT_LOAD;
1.53 - }
1.54 -
1.55 - offset_t file_contents()
1.56 - {
1.57 - return _header->p_filesz;
1.58 - }
1.59 -
1.60 - offset_t file_offset()
1.61 - {
1.62 - return _header->p_offset;
1.63 - }
1.64 -
1.65 - l4_addr_t region_address()
1.66 - {
1.67 - return _header->p_vaddr;
1.68 - }
1.69 -
1.70 - offset_t region_size()
1.71 - {
1.72 - return _header->p_memsz;
1.73 - }
1.74 -
1.75 - l4re_rm_flags_t region_flags()
1.76 - {
1.77 - l4re_rm_flags_t flags = 0;
1.78 -
1.79 - if (_header->p_flags & PF_R)
1.80 - flags |= L4RE_RM_F_R;
1.81 - if (_header->p_flags & PF_W)
1.82 - flags |= L4RE_RM_F_W;
1.83 - if (_header->p_flags & PF_X)
1.84 - flags |= L4RE_RM_F_X;
1.85 -
1.86 - return flags;
1.87 - }
1.88 -};
1.89 -
1.90 -
1.91 -
1.92 -/* Generic interface for an ELF payload. */
1.93 -
1.94 -class Payload
1.95 -{
1.96 -public:
1.97 - virtual l4_addr_t entry_point() = 0;
1.98 - virtual offset_t header_extent() = 0;
1.99 - virtual offset_t program_header_extent() = 0;
1.100 - virtual unsigned int segments() = 0;
1.101 - virtual ProgramSegment *segment(unsigned int i) = 0;
1.102 -};
1.103 -
1.104 -template <typename HEADER, typename PROGRAM_HEADER>
1.105 -class PayloadVariant : public Payload
1.106 -{
1.107 -protected:
1.108 - HEADER *_header;
1.109 -
1.110 -public:
1.111 - explicit PayloadVariant(HEADER *header)
1.112 - : _header(header)
1.113 - {
1.114 - }
1.115 -
1.116 - l4_addr_t entry_point()
1.117 - {
1.118 - return _header->e_entry;
1.119 - }
1.120 -
1.121 - offset_t header_extent()
1.122 - {
1.123 - return sizeof(HEADER);
1.124 - }
1.125 -
1.126 - offset_t program_header_extent()
1.127 - {
1.128 - return _header->e_phoff + _header->e_phentsize * _header->e_phnum;
1.129 - }
1.130 -
1.131 - unsigned int segments()
1.132 - {
1.133 - return _header->e_phnum;
1.134 - }
1.135 -
1.136 - ProgramSegment *segment(unsigned int i)
1.137 - {
1.138 - if (i >= segments())
1.139 - return NULL;
1.140 -
1.141 - return new ProgramSegmentVariant<PROGRAM_HEADER>(
1.142 - (PROGRAM_HEADER *) ((char *) _header + _header->e_phoff +
1.143 - _header->e_phentsize * i));
1.144 - }
1.145 -};
1.146 -
1.147 -static Payload *get_payload(char *buf)
1.148 -{
1.149 - switch (buf[EI_CLASS])
1.150 - {
1.151 - case (char) 1:
1.152 - return new PayloadVariant<Elf32_Ehdr, Elf32_Phdr>((Elf32_Ehdr *) buf);
1.153 - case (char) 2:
1.154 - return new PayloadVariant<Elf64_Ehdr, Elf64_Phdr>((Elf64_Ehdr *) buf);
1.155 - default:
1.156 - return NULL;
1.157 - }
1.158 -}
1.159 -
1.160 -
1.161 -
1.162 static ExecPager exec_pager;
1.163
1.164 static void init_pager(ipc_server_config_type *config)