1.1 --- a/tests/dstest_exec.cc Mon May 09 01:00:51 2022 +0200
1.2 +++ b/tests/dstest_exec.cc Tue May 10 16:50:21 2022 +0200
1.3 @@ -884,6 +884,51 @@
1.4
1.5
1.6
1.7 +class PayloadBase
1.8 +{
1.9 +public:
1.10 + virtual l4_addr_t entry_point() = 0;
1.11 + virtual offset_t header_size() = 0;
1.12 +};
1.13 +
1.14 +template <typename HEADER>
1.15 +class Payload : public PayloadBase
1.16 +{
1.17 +protected:
1.18 + HEADER *_header;
1.19 +
1.20 +public:
1.21 + explicit Payload(HEADER *header)
1.22 + : _header(header)
1.23 + {
1.24 + }
1.25 +
1.26 + l4_addr_t entry_point()
1.27 + {
1.28 + return _header->e_entry;
1.29 + }
1.30 +
1.31 + offset_t header_size()
1.32 + {
1.33 + return sizeof(HEADER);
1.34 + }
1.35 +};
1.36 +
1.37 +static PayloadBase *get_payload(char *buf)
1.38 +{
1.39 + switch (buf[EI_CLASS])
1.40 + {
1.41 + case (char) 1:
1.42 + return new Payload<Elf32_Ehdr>((Elf32_Ehdr *) buf);
1.43 + case (char) 2:
1.44 + return new Payload<Elf64_Ehdr>((Elf64_Ehdr *) buf);
1.45 + default:
1.46 + return NULL;
1.47 + }
1.48 +}
1.49 +
1.50 +
1.51 +
1.52 static ExecPager exec_pager;
1.53
1.54 static void init_pager(ipc_server_config_type *config)
1.55 @@ -926,10 +971,41 @@
1.56 return 1;
1.57 }
1.58
1.59 + /* Obtain metadata from the file. */
1.60 +
1.61 + char buf[4096];
1.62 + offset_t nread;
1.63 +
1.64 + nread = client_read(file, buf, EI_NIDENT);
1.65 + if ((nread < EI_NIDENT) || memcmp(buf, "\x7f" "ELF", 4))
1.66 + {
1.67 + printf("Not an ELF payload: %s\n", argv[1]);
1.68 + return 1;
1.69 + }
1.70 +
1.71 + PayloadBase *payload = get_payload(buf);
1.72 +
1.73 + if (payload == NULL)
1.74 + {
1.75 + printf("Unrecognised object size.\n");
1.76 + return 1;
1.77 + }
1.78 +
1.79 + client_seek(file, 0, SEEK_SET);
1.80 + nread = client_read(file, buf, payload->header_size());
1.81 +
1.82 + if (nread < payload->header_size())
1.83 + {
1.84 + printf("Header incomplete.\n");
1.85 + return 1;
1.86 + }
1.87 +
1.88 + printf("Program start: %lx\n", payload->entry_point());
1.89 +
1.90 /* Copy the payload regions to new dataspaces.
1.91 NOTE: This should be directed by the ELF metadata. */
1.92
1.93 - address_t program_start = 0x1000b43;
1.94 + address_t program_start = payload->entry_point();
1.95 offset_t initial_stack_size = 16 * L4_PAGESIZE;
1.96
1.97 Segment program(0x1000000, 0x28326, L4_FPAGE_RWX, 0, 0x28326);