1.1 --- a/tests/dstest_exec.cc Thu Jun 02 01:09:30 2022 +0200
1.2 +++ b/tests/dstest_exec.cc Fri Jun 03 00:21:10 2022 +0200
1.3 @@ -20,18 +20,15 @@
1.4 */
1.5
1.6 #include <l4/re/env.h>
1.7 -#include <l4/re/l4aux.h>
1.8 #include <l4/sys/err.h>
1.9 -#include <l4/util/elf.h>
1.10 #include <l4/util/util.h>
1.11
1.12 #include <exec/elf.h>
1.13 +#include <exec/memory.h>
1.14 #include <exec/process.h>
1.15 -#include <fsclient/client.h>
1.16 #include <ipc/mem_ipc.h>
1.17 #include <ipc/server.h>
1.18 #include <mem/memory_utils.h>
1.19 -#include <systypes/fcntl.h>
1.20
1.21 #include <map>
1.22
1.23 @@ -319,115 +316,22 @@
1.24 return 1;
1.25 }
1.26
1.27 - /* Obtain the payload as a dataspace. */
1.28 -
1.29 - file_t *file = client_open(argv[1], O_RDONLY);
1.30 -
1.31 - if (file == NULL)
1.32 - {
1.33 - printf("Could not read file: %s\n", argv[1]);
1.34 - return 1;
1.35 - }
1.36 -
1.37 - /* Obtain metadata from the file. */
1.38 -
1.39 - char *buf = (char *) client_mmap(file, 0, file->size, 0, 0, L4RE_DS_F_R);
1.40 -
1.41 - if ((file->size < EI_NIDENT) || memcmp(buf, "\x7f" "ELF", 4))
1.42 - {
1.43 - printf("Not an ELF payload: %s\n", argv[1]);
1.44 - return 1;
1.45 - }
1.46 + /* Initialise the memory of the new task. */
1.47
1.48 - Payload *payload = get_payload(buf);
1.49 + offset_t initial_stack_size = 16 * L4_PAGESIZE;
1.50 + ExplicitSegment stack(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW);
1.51 + Payload *payload;
1.52
1.53 - if (payload == NULL)
1.54 - {
1.55 - printf("Unrecognised object size.\n");
1.56 - return 1;
1.57 - }
1.58 -
1.59 - if (file->size < payload->header_extent())
1.60 + if (exec_get_payload(argv[1], &payload))
1.61 {
1.62 - printf("Header incomplete.\n");
1.63 - return 1;
1.64 - }
1.65 -
1.66 - printf("Program start: %lx\n", payload->entry_point());
1.67 -
1.68 - if (file->size < payload->program_header_extent())
1.69 - {
1.70 - printf("Program headers incomplete.\n");
1.71 + printf("Could not initialise program.\n");
1.72 return 1;
1.73 }
1.74
1.75 - /* Make appropriate segments, although program segments could be made
1.76 - interoperable with these. */
1.77 -
1.78 - Segment *segments[payload->segments() + 1];
1.79 -
1.80 - for (unsigned int i = 0; i < payload->segments(); i++)
1.81 - {
1.82 - ProgramSegment *ps = payload->segment(i);
1.83 -
1.84 - printf("Segment(0x%lx, 0x%lx, 0x%x, 0x%lx, 0x%lx): %s\n",
1.85 - ps->region_address(),
1.86 - ps->region_size(),
1.87 - ps->region_flags(),
1.88 - ps->file_offset(),
1.89 - ps->file_contents(),
1.90 - ps->loadable() ? "loadable" : "other");
1.91 -
1.92 - if (ps->loadable())
1.93 - segments[i] = ps->segment();
1.94 - else
1.95 - segments[i] = NULL;
1.96 - }
1.97 -
1.98 - /* Copy the payload regions to new dataspaces. */
1.99 -
1.100 - address_t program_start = payload->entry_point();
1.101 - offset_t initial_stack_size = 16 * L4_PAGESIZE;
1.102 -
1.103 - Segment stack(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW);
1.104 -
1.105 - segments[payload->segments()] = &stack;
1.106 -
1.107 - for (unsigned int i = 0; i < payload->segments() + 1; i++)
1.108 + if (stack.allocate())
1.109 {
1.110 - Segment *segment = segments[i];
1.111 -
1.112 - if (segment == NULL)
1.113 - continue;
1.114 -
1.115 - if (segment->file_contents())
1.116 - {
1.117 - file_t *file = client_open(argv[1], file_opening_flags(segment->region_flags()));
1.118 -
1.119 - if (file == NULL)
1.120 - {
1.121 - printf("Could not open file for segment.\n");
1.122 - return 1;
1.123 - }
1.124 -
1.125 - err = segment->fill(file);
1.126 -
1.127 - if (err)
1.128 - {
1.129 - printf("Could not fill segment from file.\n");
1.130 - return 1;
1.131 - }
1.132 - }
1.133 - else
1.134 - {
1.135 - err = segment->allocate();
1.136 -
1.137 - if (err)
1.138 - {
1.139 - printf("Could not allocate segment.\n");
1.140 - return 1;
1.141 - }
1.142 - }
1.143 + printf("Could not allocate stack.\n");
1.144 + return 1;
1.145 }
1.146
1.147 /* Start the pager. */
1.148 @@ -441,15 +345,13 @@
1.149
1.150 init_pager(&config);
1.151
1.152 - for (unsigned int i = 0; i < payload->segments() + 1; i++)
1.153 + for (unsigned int i = 0; i < payload->segments(); i++)
1.154 {
1.155 - Segment *segment = segments[i];
1.156 + if (payload->segment(i)->loadable())
1.157 + exec_pager.add(payload->segment(i)->region());
1.158 + }
1.159
1.160 - if (segment == NULL)
1.161 - continue;
1.162 -
1.163 - exec_pager.add(segment->region());
1.164 - }
1.165 + exec_pager.add(stack.region());
1.166
1.167 err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config);
1.168
1.169 @@ -494,7 +396,7 @@
1.170
1.171 printf("Run thread...\n");
1.172
1.173 - err = process.thread_start(program_start, st);
1.174 + err = process.thread_start(payload->entry_point(), st);
1.175
1.176 if (err)
1.177 {