paul@308 | 1 | /* |
paul@308 | 2 | * Support for executing code in new tasks and threads. |
paul@308 | 3 | * |
paul@308 | 4 | * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> |
paul@308 | 5 | * |
paul@308 | 6 | * This program is free software; you can redistribute it and/or |
paul@308 | 7 | * modify it under the terms of the GNU General Public License as |
paul@308 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@308 | 9 | * the License, or (at your option) any later version. |
paul@308 | 10 | * |
paul@308 | 11 | * This program is distributed in the hope that it will be useful, |
paul@308 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@308 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@308 | 14 | * GNU General Public License for more details. |
paul@308 | 15 | * |
paul@308 | 16 | * You should have received a copy of the GNU General Public License |
paul@308 | 17 | * along with this program; if not, write to the Free Software |
paul@308 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@308 | 19 | * Boston, MA 02110-1301, USA |
paul@308 | 20 | */ |
paul@308 | 21 | |
paul@308 | 22 | #include <l4/re/env.h> |
paul@322 | 23 | #include <l4/re/l4aux.h> |
paul@308 | 24 | #include <l4/sys/err.h> |
paul@312 | 25 | #include <l4/util/elf.h> |
paul@312 | 26 | #include <l4/util/util.h> |
paul@308 | 27 | |
paul@327 | 28 | #include <exec/elf.h> |
paul@324 | 29 | #include <exec/process.h> |
paul@308 | 30 | #include <fsclient/client.h> |
paul@308 | 31 | #include <ipc/mem_ipc.h> |
paul@308 | 32 | #include <ipc/server.h> |
paul@311 | 33 | #include <mem/memory_utils.h> |
paul@308 | 34 | #include <systypes/fcntl.h> |
paul@308 | 35 | |
paul@312 | 36 | #include <map> |
paul@312 | 37 | |
paul@308 | 38 | #include <stdio.h> |
paul@308 | 39 | #include <stdlib.h> |
paul@308 | 40 | #include <string.h> |
paul@308 | 41 | |
paul@308 | 42 | #include <pthread-l4.h> |
paul@308 | 43 | #include <pthread.h> |
paul@308 | 44 | |
paul@312 | 45 | #include "pager_object_interface.h" |
paul@312 | 46 | #include "pager_object_server.h" |
paul@308 | 47 | |
paul@308 | 48 | |
paul@308 | 49 | |
paul@312 | 50 | /* A simple system pager also acting as a region mapper. */ |
paul@312 | 51 | |
paul@320 | 52 | typedef std::map<l4_addr_t, MappedRegion> MappedRegions; |
paul@316 | 53 | |
paul@312 | 54 | class ExecPager : public PagerObject |
paul@312 | 55 | { |
paul@312 | 56 | protected: |
paul@320 | 57 | MappedRegions _regions; |
paul@312 | 58 | |
paul@312 | 59 | public: |
paul@320 | 60 | virtual void add(MappedRegion region) |
paul@312 | 61 | { |
paul@312 | 62 | _regions[region.map_start] = region; |
paul@312 | 63 | } |
paul@312 | 64 | |
paul@312 | 65 | /* Notification methods. */ |
paul@308 | 66 | |
paul@308 | 67 | virtual long exception(l4_exc_regs_t regs, |
paul@308 | 68 | l4_snd_fpage_t *region); |
paul@308 | 69 | |
paul@308 | 70 | virtual long page_fault(l4_umword_t pfa, l4_umword_t pc, |
paul@308 | 71 | l4_snd_fpage_t *region); |
paul@312 | 72 | |
paul@312 | 73 | /* Region manager/mapper methods. */ |
paul@312 | 74 | |
paul@312 | 75 | virtual long attach(address_t *start, offset_t size, map_flags_t flags, |
paul@312 | 76 | l4_cap_idx_t ds, address_t offset, unsigned char align); |
paul@312 | 77 | |
paul@308 | 78 | }; |
paul@308 | 79 | |
paul@312 | 80 | /* Handle a general exception. */ |
paul@312 | 81 | |
paul@308 | 82 | long ExecPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region) |
paul@308 | 83 | { |
paul@308 | 84 | (void) region; |
paul@308 | 85 | |
paul@308 | 86 | printf("exception(...) -> pfa = %lx, pc = %lx\n", l4_utcb_exc_pfa(®s), l4_utcb_exc_pc(®s)); |
paul@312 | 87 | |
paul@312 | 88 | printf("r15 = %lx\n", regs.r15); |
paul@312 | 89 | printf("r14 = %lx\n", regs.r14); |
paul@312 | 90 | printf("r13 = %lx\n", regs.r13); |
paul@312 | 91 | printf("r12 = %lx\n", regs.r12); |
paul@312 | 92 | printf("r11 = %lx\n", regs.r11); |
paul@312 | 93 | printf("r10 = %lx\n", regs.r10); |
paul@312 | 94 | printf("r9 = %lx\n", regs.r9); |
paul@312 | 95 | printf("r8 = %lx\n", regs.r8); |
paul@312 | 96 | printf("rdi = %lx\n", regs.rdi); |
paul@312 | 97 | printf("rsi = %lx\n", regs.rsi); |
paul@312 | 98 | printf("rbp = %lx\n", regs.rbp); |
paul@312 | 99 | printf("pfa = %lx\n", regs.pfa); |
paul@312 | 100 | printf("rbx = %lx\n", regs.rbx); |
paul@312 | 101 | printf("rdx = %lx\n", regs.rdx); |
paul@312 | 102 | printf("rcx = %lx\n", regs.rcx); |
paul@312 | 103 | printf("rax = %lx\n", regs.rax); |
paul@312 | 104 | printf("trapno = %lx\n", regs.trapno); |
paul@312 | 105 | printf("err = %lx\n", regs.err); |
paul@312 | 106 | printf("ip = %lx\n", regs.ip); |
paul@312 | 107 | printf("flags = %lx\n", regs.flags); |
paul@312 | 108 | printf("sp = %lx\n", regs.sp); |
paul@312 | 109 | printf("ss = %lx\n", regs.ss); |
paul@312 | 110 | printf("fs_base = %lx\n", regs.fs_base); |
paul@312 | 111 | printf("gs_base = %lx\n", regs.gs_base); |
paul@312 | 112 | |
paul@308 | 113 | return L4_EOK; |
paul@308 | 114 | } |
paul@308 | 115 | |
paul@315 | 116 | #define DEBUG 0 |
paul@315 | 117 | |
paul@312 | 118 | /* Handle a page fault using any configured regions. */ |
paul@312 | 119 | |
paul@308 | 120 | long ExecPager::page_fault(l4_umword_t pfa, l4_umword_t pc, l4_snd_fpage_t *region) |
paul@308 | 121 | { |
paul@308 | 122 | l4_umword_t addr = pfa & ~7UL, flags = pfa & 7; |
paul@308 | 123 | |
paul@315 | 124 | #if DEBUG |
paul@312 | 125 | printf("page_fault(%lx, %lx) -> %lx (%lx) -> ", pfa, pc, addr, flags); |
paul@312 | 126 | #endif |
paul@312 | 127 | |
paul@320 | 128 | MappedRegions::iterator it = _regions.upper_bound(addr); |
paul@312 | 129 | |
paul@312 | 130 | if (it != _regions.begin()) |
paul@312 | 131 | it--; |
paul@312 | 132 | else |
paul@312 | 133 | { |
paul@312 | 134 | printf("not mapped!\n"); |
paul@312 | 135 | return -L4_ENOMEM; |
paul@312 | 136 | } |
paul@312 | 137 | |
paul@320 | 138 | MappedRegion &r = it->second; |
paul@308 | 139 | |
paul@329 | 140 | if ((addr >= r.map_start) && (addr < r.map_start + r.size)) |
paul@308 | 141 | { |
paul@312 | 142 | l4_addr_t page_addr = trunc(addr, L4_PAGESIZE); |
paul@312 | 143 | |
paul@312 | 144 | region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, r.flags); |
paul@312 | 145 | region->snd_base = page_addr; |
paul@312 | 146 | |
paul@315 | 147 | #if DEBUG |
paul@329 | 148 | printf("%lx...%lx from %lx...%lx offset %lx size %d rights %x\n", |
paul@312 | 149 | r.map_start, region->snd_base, |
paul@312 | 150 | r.start, l4_fpage_memaddr(region->fpage), |
paul@329 | 151 | addr - r.map_start, |
paul@312 | 152 | l4_fpage_size(region->fpage), |
paul@312 | 153 | l4_fpage_rights(region->fpage)); |
paul@312 | 154 | printf("%lx -> ", addr); |
paul@312 | 155 | |
paul@312 | 156 | for (unsigned int i = 0; i < sizeof(l4_umword_t); i++) |
paul@312 | 157 | printf("%02x", *((unsigned char *)(r.start + (addr - r.map_start) + i))); |
paul@312 | 158 | |
paul@312 | 159 | printf("\n"); |
paul@312 | 160 | #endif |
paul@308 | 161 | |
paul@329 | 162 | if (r.flags & L4RE_RM_F_W) |
paul@329 | 163 | l4_touch_rw((const void *) (r.start + (page_addr - r.map_start)), L4_PAGESIZE); |
paul@329 | 164 | else |
paul@329 | 165 | l4_touch_ro((const void *) (r.start + (page_addr - r.map_start)), L4_PAGESIZE); |
paul@329 | 166 | |
paul@308 | 167 | return L4_EOK; |
paul@308 | 168 | } |
paul@308 | 169 | |
paul@315 | 170 | #if DEBUG |
paul@312 | 171 | printf("not mapped!\n"); |
paul@312 | 172 | #endif |
paul@312 | 173 | |
paul@308 | 174 | return -L4_ENOMEM; |
paul@308 | 175 | } |
paul@308 | 176 | |
paul@312 | 177 | /* Attach a region for provision when page faults occur. This is required in |
paul@312 | 178 | the initialisation of a program by the C library which requires a region |
paul@312 | 179 | mapper. */ |
paul@312 | 180 | |
paul@312 | 181 | long ExecPager::attach(address_t *start, offset_t size, map_flags_t flags, |
paul@312 | 182 | l4_cap_idx_t ds, address_t offset, unsigned char align) |
paul@312 | 183 | { |
paul@315 | 184 | #if DEBUG |
paul@312 | 185 | printf("attach(%lx, %ld, %lx, ..., %lx, %d)\n", *start, size, flags, offset, align); |
paul@312 | 186 | #endif |
paul@312 | 187 | |
paul@312 | 188 | if (align < L4_PAGESHIFT) |
paul@312 | 189 | align = L4_PAGESHIFT; |
paul@312 | 190 | |
paul@312 | 191 | offset_t increment = 1UL << align; |
paul@312 | 192 | offset_t region_size = round(size, increment); |
paul@312 | 193 | |
paul@312 | 194 | /* Either attempt to find an address for the specified region, starting from |
paul@312 | 195 | any indicated address. */ |
paul@312 | 196 | |
paul@312 | 197 | if (flags & L4RE_RM_F_SEARCH_ADDR) |
paul@312 | 198 | { |
paul@312 | 199 | address_t region_start = trunc(*start, increment); |
paul@320 | 200 | MappedRegions::iterator it = _regions.upper_bound(*start); |
paul@312 | 201 | |
paul@312 | 202 | if (!region_start) |
paul@312 | 203 | region_start += increment; |
paul@312 | 204 | |
paul@315 | 205 | #if DEBUG |
paul@312 | 206 | printf("-> search from %lx -> %lx...\n", *start, region_start); |
paul@312 | 207 | #endif |
paul@312 | 208 | |
paul@312 | 209 | /* Before last known region. */ |
paul@312 | 210 | |
paul@312 | 211 | while (it != _regions.end()) |
paul@312 | 212 | { |
paul@320 | 213 | MappedRegions::iterator next = it; |
paul@320 | 214 | MappedRegion &r = it->second; |
paul@312 | 215 | address_t start_limit; |
paul@312 | 216 | address_t end_limit = r.map_start; |
paul@312 | 217 | |
paul@312 | 218 | /* Consider any preceding region. If no such region exists, choose an |
paul@312 | 219 | address at the start of memory. */ |
paul@312 | 220 | |
paul@312 | 221 | if (it == _regions.begin()) |
paul@312 | 222 | start_limit = L4_PAGESIZE; |
paul@312 | 223 | else |
paul@312 | 224 | { |
paul@312 | 225 | it--; |
paul@320 | 226 | MappedRegion &pr = it->second; |
paul@329 | 227 | start_limit = pr.map_start + pr.size; |
paul@312 | 228 | it = next; |
paul@312 | 229 | } |
paul@312 | 230 | |
paul@312 | 231 | /* Test against the limits. */ |
paul@312 | 232 | |
paul@312 | 233 | if (region_start < start_limit) |
paul@312 | 234 | region_start = round(start_limit, increment); |
paul@312 | 235 | |
paul@312 | 236 | /* Investigate subsequent regions if not enough space exists between the |
paul@312 | 237 | preceding region (or start of memory) and the current region. */ |
paul@312 | 238 | |
paul@312 | 239 | if ((region_start + region_size) > end_limit) |
paul@312 | 240 | { |
paul@312 | 241 | it++; |
paul@312 | 242 | if (it == _regions.end()) |
paul@312 | 243 | return -L4_ENOMEM; |
paul@312 | 244 | } |
paul@312 | 245 | else |
paul@312 | 246 | break; |
paul@312 | 247 | } |
paul@312 | 248 | |
paul@312 | 249 | /* Attach the provided dataspace. |
paul@312 | 250 | NOTE: This is only done in this implementation to support the paging |
paul@312 | 251 | mechanism. In a region mapper residing within the actual task, the |
paul@312 | 252 | dataspace's map operation would be invoked to obtain mappings. */ |
paul@312 | 253 | |
paul@312 | 254 | l4_addr_t ds_start; |
paul@312 | 255 | |
paul@312 | 256 | long err = ipc_attach_dataspace(ds, size, (void **) &ds_start); |
paul@312 | 257 | |
paul@312 | 258 | if (err) |
paul@312 | 259 | return err; |
paul@312 | 260 | |
paul@312 | 261 | l4_touch_rw((const void *) ds_start, size); |
paul@312 | 262 | |
paul@315 | 263 | #if DEBUG |
paul@312 | 264 | printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size)); |
paul@312 | 265 | #endif |
paul@312 | 266 | |
paul@329 | 267 | add(MappedRegion(ds_start, region_size, flags & L4RE_DS_F_RIGHTS_MASK, region_start)); |
paul@312 | 268 | |
paul@312 | 269 | *start = region_start; |
paul@312 | 270 | return L4_EOK; |
paul@312 | 271 | } |
paul@312 | 272 | |
paul@312 | 273 | /* Or attempt to add the specified region at a specific address. */ |
paul@312 | 274 | |
paul@312 | 275 | else |
paul@312 | 276 | { |
paul@312 | 277 | // NOTE: To be implemented. |
paul@312 | 278 | |
paul@312 | 279 | return -L4_ENOMEM; |
paul@312 | 280 | } |
paul@312 | 281 | } |
paul@312 | 282 | |
paul@308 | 283 | |
paul@308 | 284 | |
paul@308 | 285 | static ExecPager exec_pager; |
paul@308 | 286 | |
paul@312 | 287 | static void init_pager(ipc_server_config_type *config) |
paul@308 | 288 | { |
paul@308 | 289 | ipc_server_init_config(config); |
paul@308 | 290 | |
paul@312 | 291 | config->expected_items = PagerObject_expected_items; |
paul@312 | 292 | config->handler = (ipc_server_handler_type) handle_PagerObject; |
paul@312 | 293 | config->handler_obj = static_cast<PagerObject *>(&exec_pager); |
paul@308 | 294 | } |
paul@308 | 295 | |
paul@308 | 296 | static long start_pager(ipc_server_config_type *config, pthread_t thread) |
paul@308 | 297 | { |
paul@308 | 298 | config->config_thread = 1; |
paul@308 | 299 | config->thread = pthread_l4_cap(thread); |
paul@308 | 300 | |
paul@308 | 301 | printf("Starting pager thread...\n"); |
paul@308 | 302 | return ipc_server_start_config(config); |
paul@308 | 303 | } |
paul@308 | 304 | |
paul@308 | 305 | |
paul@308 | 306 | |
paul@308 | 307 | int main(int argc, char *argv[]) |
paul@308 | 308 | { |
paul@308 | 309 | long err; |
paul@308 | 310 | |
paul@308 | 311 | if (argc < 2) |
paul@308 | 312 | { |
paul@308 | 313 | printf("Need a program to run.\n"); |
paul@308 | 314 | return 1; |
paul@308 | 315 | } |
paul@308 | 316 | |
paul@308 | 317 | /* Obtain the payload as a dataspace. */ |
paul@308 | 318 | |
paul@308 | 319 | file_t *file = client_open(argv[1], O_RDONLY); |
paul@308 | 320 | |
paul@308 | 321 | if (file == NULL) |
paul@308 | 322 | { |
paul@308 | 323 | printf("Could not read file: %s\n", argv[1]); |
paul@308 | 324 | return 1; |
paul@308 | 325 | } |
paul@308 | 326 | |
paul@323 | 327 | /* Obtain metadata from the file. */ |
paul@323 | 328 | |
paul@323 | 329 | char buf[4096]; |
paul@323 | 330 | offset_t nread; |
paul@323 | 331 | |
paul@323 | 332 | nread = client_read(file, buf, EI_NIDENT); |
paul@323 | 333 | if ((nread < EI_NIDENT) || memcmp(buf, "\x7f" "ELF", 4)) |
paul@323 | 334 | { |
paul@323 | 335 | printf("Not an ELF payload: %s\n", argv[1]); |
paul@323 | 336 | return 1; |
paul@323 | 337 | } |
paul@323 | 338 | |
paul@325 | 339 | Payload *payload = get_payload(buf); |
paul@323 | 340 | |
paul@323 | 341 | if (payload == NULL) |
paul@323 | 342 | { |
paul@323 | 343 | printf("Unrecognised object size.\n"); |
paul@323 | 344 | return 1; |
paul@323 | 345 | } |
paul@323 | 346 | |
paul@323 | 347 | client_seek(file, 0, SEEK_SET); |
paul@325 | 348 | nread = client_read(file, buf, payload->header_extent()); |
paul@323 | 349 | |
paul@325 | 350 | if (nread < payload->header_extent()) |
paul@323 | 351 | { |
paul@323 | 352 | printf("Header incomplete.\n"); |
paul@323 | 353 | return 1; |
paul@323 | 354 | } |
paul@323 | 355 | |
paul@323 | 356 | printf("Program start: %lx\n", payload->entry_point()); |
paul@323 | 357 | |
paul@325 | 358 | client_seek(file, 0, SEEK_SET); |
paul@325 | 359 | nread = client_read(file, buf, payload->program_header_extent()); |
paul@325 | 360 | |
paul@325 | 361 | if (nread < payload->program_header_extent()) |
paul@325 | 362 | { |
paul@325 | 363 | printf("Program headers incomplete.\n"); |
paul@325 | 364 | return 1; |
paul@325 | 365 | } |
paul@325 | 366 | |
paul@325 | 367 | /* Make appropriate segments, although program segments could be made |
paul@325 | 368 | interoperable with these. */ |
paul@325 | 369 | |
paul@325 | 370 | Segment *segments[payload->segments() + 1]; |
paul@325 | 371 | |
paul@325 | 372 | for (unsigned int i = 0; i < payload->segments(); i++) |
paul@325 | 373 | { |
paul@325 | 374 | ProgramSegment *ps = payload->segment(i); |
paul@325 | 375 | |
paul@325 | 376 | printf("Segment(0x%lx, 0x%lx, 0x%x, 0x%lx, 0x%lx): %s\n", |
paul@325 | 377 | ps->region_address(), |
paul@325 | 378 | ps->region_size(), |
paul@325 | 379 | ps->region_flags(), |
paul@325 | 380 | ps->file_offset(), |
paul@325 | 381 | ps->file_contents(), |
paul@325 | 382 | ps->loadable() ? "loadable" : "other"); |
paul@325 | 383 | |
paul@325 | 384 | if (ps->loadable()) |
paul@325 | 385 | segments[i] = ps->segment(); |
paul@325 | 386 | else |
paul@325 | 387 | segments[i] = NULL; |
paul@325 | 388 | } |
paul@325 | 389 | |
paul@325 | 390 | /* Copy the payload regions to new dataspaces. */ |
paul@308 | 391 | |
paul@323 | 392 | address_t program_start = payload->entry_point(); |
paul@320 | 393 | offset_t initial_stack_size = 16 * L4_PAGESIZE; |
paul@315 | 394 | |
paul@320 | 395 | Segment stack(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW); |
paul@325 | 396 | |
paul@325 | 397 | segments[payload->segments()] = &stack; |
paul@316 | 398 | |
paul@325 | 399 | for (unsigned int i = 0; i < payload->segments() + 1; i++) |
paul@316 | 400 | { |
paul@325 | 401 | Segment *segment = segments[i]; |
paul@325 | 402 | |
paul@325 | 403 | if (segment == NULL) |
paul@325 | 404 | continue; |
paul@325 | 405 | |
paul@329 | 406 | if (segment->file_contents()) |
paul@329 | 407 | { |
paul@329 | 408 | flags_t flags; |
paul@329 | 409 | |
paul@329 | 410 | if ((segment->region_flags() & L4RE_RM_F_RW) == L4RE_RM_F_RW) |
paul@329 | 411 | flags = O_RDWR; |
paul@329 | 412 | else if (segment->region_flags() & L4RE_RM_F_W) |
paul@329 | 413 | flags = O_WRONLY; |
paul@329 | 414 | else |
paul@329 | 415 | flags = O_RDONLY; |
paul@329 | 416 | |
paul@329 | 417 | file_t *file = client_open(argv[1], flags); |
paul@308 | 418 | |
paul@329 | 419 | if (file == NULL) |
paul@329 | 420 | { |
paul@329 | 421 | printf("Could not open file for segment.\n"); |
paul@329 | 422 | return 1; |
paul@329 | 423 | } |
paul@329 | 424 | |
paul@329 | 425 | err = segment->fill(file); |
paul@329 | 426 | |
paul@329 | 427 | if (err) |
paul@329 | 428 | { |
paul@329 | 429 | printf("Could not fill segment from file.\n"); |
paul@329 | 430 | return 1; |
paul@329 | 431 | } |
paul@316 | 432 | } |
paul@329 | 433 | else |
paul@329 | 434 | { |
paul@329 | 435 | err = segment->allocate(); |
paul@316 | 436 | |
paul@329 | 437 | if (err) |
paul@329 | 438 | { |
paul@329 | 439 | printf("Could not allocate segment.\n"); |
paul@329 | 440 | return 1; |
paul@329 | 441 | } |
paul@316 | 442 | } |
paul@308 | 443 | } |
paul@308 | 444 | |
paul@308 | 445 | /* Start the pager. */ |
paul@308 | 446 | |
paul@308 | 447 | ipc_server_config_type config; |
paul@308 | 448 | pthread_t pager_thread; |
paul@308 | 449 | pthread_attr_t attr; |
paul@308 | 450 | |
paul@308 | 451 | pthread_attr_init(&attr); |
paul@308 | 452 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
paul@308 | 453 | |
paul@312 | 454 | init_pager(&config); |
paul@312 | 455 | |
paul@325 | 456 | for (unsigned int i = 0; i < payload->segments() + 1; i++) |
paul@325 | 457 | { |
paul@325 | 458 | Segment *segment = segments[i]; |
paul@325 | 459 | |
paul@325 | 460 | if (segment == NULL) |
paul@325 | 461 | continue; |
paul@325 | 462 | |
paul@325 | 463 | exec_pager.add(segment->region()); |
paul@325 | 464 | } |
paul@308 | 465 | |
paul@308 | 466 | err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config); |
paul@308 | 467 | |
paul@308 | 468 | if (err) |
paul@308 | 469 | { |
paul@308 | 470 | printf("Could not start pager thread.\n"); |
paul@308 | 471 | return 1; |
paul@308 | 472 | } |
paul@308 | 473 | |
paul@308 | 474 | err = start_pager(&config, pager_thread); |
paul@308 | 475 | |
paul@308 | 476 | if (err) |
paul@308 | 477 | { |
paul@308 | 478 | printf("Could not start pager.\n"); |
paul@308 | 479 | return 1; |
paul@308 | 480 | } |
paul@308 | 481 | |
paul@319 | 482 | /* Configure the environment for the task, specifying the pager (and exception |
paul@319 | 483 | handler plus region mapper). */ |
paul@308 | 484 | |
paul@321 | 485 | Process process; |
paul@321 | 486 | |
paul@321 | 487 | err = process.configure(config.server); |
paul@308 | 488 | |
paul@308 | 489 | if (err) |
paul@308 | 490 | { |
paul@321 | 491 | printf("Could not configure task.\n"); |
paul@308 | 492 | return 1; |
paul@308 | 493 | } |
paul@308 | 494 | |
paul@321 | 495 | /* Populate a thread stack with argument and environment details. */ |
paul@321 | 496 | |
paul@321 | 497 | Stack st(stack); |
paul@321 | 498 | |
paul@321 | 499 | /* NOTE: Environment vector is currently not defined. */ |
paul@321 | 500 | |
paul@321 | 501 | char *envp[] = {NULL}; |
paul@321 | 502 | |
paul@321 | 503 | st.populate(argc - 1, argv + 1, envp); |
paul@321 | 504 | |
paul@321 | 505 | /* Start the new thread in the given stack. */ |
paul@308 | 506 | |
paul@308 | 507 | printf("Run thread...\n"); |
paul@308 | 508 | |
paul@321 | 509 | err = process.thread_start(program_start, st); |
paul@308 | 510 | |
paul@308 | 511 | if (err) |
paul@308 | 512 | { |
paul@308 | 513 | printf("Could not run thread.\n"); |
paul@308 | 514 | return 1; |
paul@308 | 515 | } |
paul@308 | 516 | |
paul@308 | 517 | printf("Finished.\n"); |
paul@308 | 518 | while (1); |
paul@308 | 519 | |
paul@308 | 520 | return 0; |
paul@308 | 521 | } |
paul@308 | 522 | |
paul@308 | 523 | /* vim: tabstop=2 expandtab shiftwidth=2 |
paul@308 | 524 | */ |