1 /* 2 * Support for executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/re/env.h> 23 #include <l4/sys/err.h> 24 #include <l4/sys/factory.h> 25 #include <l4/sys/task.h> 26 #include <l4/sys/thread.h> 27 #include <l4/util/elf.h> 28 #include <l4/util/util.h> 29 30 #include <l4/libloader/adjust_stack> 31 32 #include <fsclient/client.h> 33 #include <ipc/cap_alloc.h> 34 #include <ipc/mem_ipc.h> 35 #include <ipc/server.h> 36 #include <mem/memory_utils.h> 37 #include <systypes/fcntl.h> 38 39 #include <map> 40 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <string.h> 44 45 #include <pthread-l4.h> 46 #include <pthread.h> 47 48 #include "pager_object_interface.h" 49 #include "pager_object_server.h" 50 51 52 53 /* Region data structures. */ 54 55 class Region 56 { 57 public: 58 l4_addr_t start; 59 unsigned int log2size; 60 l4_umword_t flags; 61 l4_addr_t map_start; 62 63 explicit Region() 64 : start(0), log2size(0), flags(0), map_start(0) 65 { 66 } 67 68 explicit Region(l4_addr_t start, unsigned int log2size, l4_umword_t flags, 69 l4_addr_t map_start) 70 : start(start), log2size(log2size), flags(flags), map_start(map_start) 71 { 72 } 73 }; 74 75 76 77 /* Program segment abstraction. */ 78 79 class Segment 80 { 81 protected: 82 Region _region; 83 84 public: 85 /* Allocated memory. */ 86 87 char *buf; 88 l4re_ds_t ds; 89 90 /* Segment base and corresponding region base. */ 91 92 l4_addr_t base, region_base; 93 94 /* Segment size and corresponding region size. */ 95 96 offset_t size, region_size; 97 98 /* Offset of segment content within the region. */ 99 100 offset_t region_offset; 101 102 /* Access flags. */ 103 104 l4re_rm_flags_t flags; 105 106 /* File access details. */ 107 108 offset_t file_offset, file_contents; 109 110 explicit Segment(offset_t base, offset_t size, l4re_rm_flags_t flags, 111 offset_t file_offset = 0, offset_t file_contents = 0) 112 : base(base), size(size), flags(flags), file_offset(file_offset), file_contents(file_contents) 113 { 114 region_base = trunc(base, L4_PAGESIZE); 115 region_offset = base - region_base; 116 region_size = round(size, L4_PAGESIZE); 117 } 118 119 long allocate(); 120 121 long fill(file_t *file); 122 123 Region ®ion(); 124 125 l4_addr_t region_address(char *address); 126 127 l4_addr_t region_address(l4_addr_t address); 128 }; 129 130 long Segment::allocate() 131 { 132 return ipc_allocate_align(size, L4RE_RM_F_SEARCH_ADDR | flags, 133 L4_PAGESHIFT, (void **) &buf, &ds); 134 } 135 136 long Segment::fill(file_t *file) 137 { 138 if (!file_contents) 139 return L4_EOK; 140 141 memset(buf, 0, region_size); 142 client_seek(file, file_offset, SEEK_SET); 143 offset_t nread = client_read(file, buf + region_offset, file_contents); 144 145 if (nread < file_contents) 146 return -L4_EIO; 147 else 148 return L4_EOK; 149 } 150 151 Region &Segment::region() 152 { 153 _region = Region((l4_addr_t) buf, page_order(region_size), flags, region_base); 154 return _region; 155 } 156 157 l4_addr_t Segment::region_address(char *address) 158 { 159 return (l4_addr_t) ((address - buf) + (char *) region_base); 160 } 161 162 l4_addr_t Segment::region_address(l4_addr_t address) 163 { 164 return (address - (l4_addr_t) buf) + region_base; 165 } 166 167 168 169 /* A simple system pager also acting as a region mapper. */ 170 171 typedef std::map<l4_addr_t, Region> Regions; 172 173 class ExecPager : public PagerObject 174 { 175 protected: 176 Regions _regions; 177 178 public: 179 virtual void add(Region region) 180 { 181 _regions[region.map_start] = region; 182 } 183 184 /* Notification methods. */ 185 186 virtual long exception(l4_exc_regs_t regs, 187 l4_snd_fpage_t *region); 188 189 virtual long page_fault(l4_umword_t pfa, l4_umword_t pc, 190 l4_snd_fpage_t *region); 191 192 /* Region manager/mapper methods. */ 193 194 virtual long attach(address_t *start, offset_t size, map_flags_t flags, 195 l4_cap_idx_t ds, address_t offset, unsigned char align); 196 197 }; 198 199 /* Handle a general exception. */ 200 201 long ExecPager::exception(l4_exc_regs_t regs, l4_snd_fpage_t *region) 202 { 203 (void) region; 204 205 printf("exception(...) -> pfa = %lx, pc = %lx\n", l4_utcb_exc_pfa(®s), l4_utcb_exc_pc(®s)); 206 207 printf("r15 = %lx\n", regs.r15); 208 printf("r14 = %lx\n", regs.r14); 209 printf("r13 = %lx\n", regs.r13); 210 printf("r12 = %lx\n", regs.r12); 211 printf("r11 = %lx\n", regs.r11); 212 printf("r10 = %lx\n", regs.r10); 213 printf("r9 = %lx\n", regs.r9); 214 printf("r8 = %lx\n", regs.r8); 215 printf("rdi = %lx\n", regs.rdi); 216 printf("rsi = %lx\n", regs.rsi); 217 printf("rbp = %lx\n", regs.rbp); 218 printf("pfa = %lx\n", regs.pfa); 219 printf("rbx = %lx\n", regs.rbx); 220 printf("rdx = %lx\n", regs.rdx); 221 printf("rcx = %lx\n", regs.rcx); 222 printf("rax = %lx\n", regs.rax); 223 printf("trapno = %lx\n", regs.trapno); 224 printf("err = %lx\n", regs.err); 225 printf("ip = %lx\n", regs.ip); 226 printf("flags = %lx\n", regs.flags); 227 printf("sp = %lx\n", regs.sp); 228 printf("ss = %lx\n", regs.ss); 229 printf("fs_base = %lx\n", regs.fs_base); 230 printf("gs_base = %lx\n", regs.gs_base); 231 232 return L4_EOK; 233 } 234 235 #define DEBUG 0 236 237 /* Handle a page fault using any configured regions. */ 238 239 long ExecPager::page_fault(l4_umword_t pfa, l4_umword_t pc, l4_snd_fpage_t *region) 240 { 241 l4_umword_t addr = pfa & ~7UL, flags = pfa & 7; 242 243 #if DEBUG 244 printf("page_fault(%lx, %lx) -> %lx (%lx) -> ", pfa, pc, addr, flags); 245 #endif 246 247 Regions::iterator it = _regions.upper_bound(addr); 248 249 if (it != _regions.begin()) 250 it--; 251 else 252 { 253 printf("not mapped!\n"); 254 return -L4_ENOMEM; 255 } 256 257 Region &r = it->second; 258 259 if ((addr >= r.map_start) && (addr < r.map_start + (1UL << r.log2size))) 260 { 261 l4_addr_t page_addr = trunc(addr, L4_PAGESIZE); 262 263 region->fpage = l4_fpage(r.start + (page_addr - r.map_start), L4_PAGESHIFT, r.flags); 264 region->snd_base = page_addr; 265 266 #if DEBUG 267 printf("%lx...%lx from %lx...%lx size %d rights %x\n", 268 r.map_start, region->snd_base, 269 r.start, l4_fpage_memaddr(region->fpage), 270 l4_fpage_size(region->fpage), 271 l4_fpage_rights(region->fpage)); 272 printf("%lx -> ", addr); 273 274 for (unsigned int i = 0; i < sizeof(l4_umword_t); i++) 275 printf("%02x", *((unsigned char *)(r.start + (addr - r.map_start) + i))); 276 277 printf("\n"); 278 #endif 279 280 return L4_EOK; 281 } 282 283 #if DEBUG 284 printf("not mapped!\n"); 285 #endif 286 287 return -L4_ENOMEM; 288 } 289 290 /* Attach a region for provision when page faults occur. This is required in 291 the initialisation of a program by the C library which requires a region 292 mapper. */ 293 294 long ExecPager::attach(address_t *start, offset_t size, map_flags_t flags, 295 l4_cap_idx_t ds, address_t offset, unsigned char align) 296 { 297 #if DEBUG 298 printf("attach(%lx, %ld, %lx, ..., %lx, %d)\n", *start, size, flags, offset, align); 299 #endif 300 301 if (align < L4_PAGESHIFT) 302 align = L4_PAGESHIFT; 303 304 offset_t increment = 1UL << align; 305 offset_t region_size = round(size, increment); 306 307 /* Either attempt to find an address for the specified region, starting from 308 any indicated address. */ 309 310 if (flags & L4RE_RM_F_SEARCH_ADDR) 311 { 312 address_t region_start = trunc(*start, increment); 313 Regions::iterator it = _regions.upper_bound(*start); 314 315 if (!region_start) 316 region_start += increment; 317 318 #if DEBUG 319 printf("-> search from %lx -> %lx...\n", *start, region_start); 320 #endif 321 322 /* Before last known region. */ 323 324 while (it != _regions.end()) 325 { 326 Regions::iterator next = it; 327 Region &r = it->second; 328 address_t start_limit; 329 address_t end_limit = r.map_start; 330 331 /* Consider any preceding region. If no such region exists, choose an 332 address at the start of memory. */ 333 334 if (it == _regions.begin()) 335 start_limit = L4_PAGESIZE; 336 else 337 { 338 it--; 339 Region &pr = it->second; 340 start_limit = pr.map_start + (1UL << pr.log2size); 341 it = next; 342 } 343 344 /* Test against the limits. */ 345 346 if (region_start < start_limit) 347 region_start = round(start_limit, increment); 348 349 /* Investigate subsequent regions if not enough space exists between the 350 preceding region (or start of memory) and the current region. */ 351 352 if ((region_start + region_size) > end_limit) 353 { 354 it++; 355 if (it == _regions.end()) 356 return -L4_ENOMEM; 357 } 358 else 359 break; 360 } 361 362 /* Attach the provided dataspace. 363 NOTE: This is only done in this implementation to support the paging 364 mechanism. In a region mapper residing within the actual task, the 365 dataspace's map operation would be invoked to obtain mappings. */ 366 367 l4_addr_t ds_start; 368 369 long err = ipc_attach_dataspace(ds, size, (void **) &ds_start); 370 371 if (err) 372 return err; 373 374 l4_touch_rw((const void *) ds_start, size); 375 376 #if DEBUG 377 printf("-> added region for %lx size %ld (%d)\n", region_start, region_size, page_order(region_size)); 378 #endif 379 380 add(Region(ds_start, page_order(region_size), flags & L4RE_DS_F_RIGHTS_MASK, region_start)); 381 382 *start = region_start; 383 return L4_EOK; 384 } 385 386 /* Or attempt to add the specified region at a specific address. */ 387 388 else 389 { 390 // NOTE: To be implemented. 391 392 return -L4_ENOMEM; 393 } 394 } 395 396 397 398 static l4_addr_t populate_stack(Segment &stack, int argc, char *argv[], l4_fpage_t utcb_fpage) 399 { 400 /* Populate stack with additional capabilities. */ 401 402 l4re_env_cap_entry_t *stack_env_cap = (l4re_env_cap_entry_t *) (stack.buf + stack.size); 403 404 /* Special invalid/terminating environment capability entry. */ 405 406 *(--stack_env_cap) = l4re_env_cap_entry_t(); 407 408 printf("Stack region end: %p\n", stack_env_cap); 409 410 l4_addr_t caps_start = (l4_addr_t) stack_env_cap; 411 l4_umword_t *stack_element = (l4_umword_t *) stack_env_cap; 412 413 /* Populate stack with argument values. */ 414 415 char *stack_arg = (char *) stack_element; 416 417 stack_arg = (char *) trunc((offset_t) stack_arg - strlen(argv[0]) - 1, sizeof(l4_umword_t)); 418 419 memset(stack_arg, 0, (char *) stack_element - stack_arg); 420 memcpy(stack_arg, argv[0], strlen(argv[0])); 421 422 printf("Stack L4 program argument: %p / %lx\n", stack_arg, stack.region_address(stack_arg)); 423 424 stack_element = (l4_umword_t *) stack_arg; 425 426 /* Loader flags, debugging flags, and the KIP capability index. 427 See: generate_l4aux in Remote_app_model */ 428 429 *(--stack_element) = 0; 430 *(--stack_element) = 0; 431 *(--stack_element) = 0x14 << L4_CAP_SHIFT; 432 433 printf("Stack L4 aux elements: %p / %lx\n", stack_element, stack.region_address((char *) stack_element)); 434 435 /* Populate stack with standard capabilities. */ 436 437 l4re_env_t *env = (l4re_env_t *) stack_element; 438 439 env--; 440 env->factory = L4_BASE_FACTORY_CAP; 441 env->main_thread = L4_BASE_THREAD_CAP; 442 env->log = L4_BASE_LOG_CAP; 443 env->scheduler = L4_BASE_SCHEDULER_CAP; 444 env->rm = 0x11 << L4_CAP_SHIFT; 445 env->mem_alloc = 0x12 << L4_CAP_SHIFT; 446 env->first_free_cap = 0x15; 447 env->caps = (l4re_env_cap_entry_t *) (stack.region_address(caps_start)); 448 env->utcb_area = utcb_fpage; 449 env->first_free_utcb = l4_fpage_memaddr(utcb_fpage) + L4_UTCB_OFFSET; 450 451 stack_element = (l4_umword_t *) env; 452 453 /* Populate stack with AUXV. */ 454 455 /* AUXV NULL. */ 456 457 *(--stack_element) = 0; 458 *(--stack_element) = 0; 459 460 /* L4Re global environment pointer. */ 461 462 *(--stack_element) = stack.region_address((char *) env); 463 *(--stack_element) = 0xf1; 464 465 /* Apparently required entries. */ 466 467 *(--stack_element) = L4_PAGESIZE; 468 *(--stack_element) = AT_PAGESZ; 469 470 *(--stack_element) = 0; 471 *(--stack_element) = AT_UID; 472 473 *(--stack_element) = 0; 474 *(--stack_element) = AT_EUID; 475 476 *(--stack_element) = 0; 477 *(--stack_element) = AT_GID; 478 479 *(--stack_element) = 0; 480 *(--stack_element) = AT_EGID; 481 482 l4_addr_t stack_data_end = (l4_addr_t) stack_element; 483 484 printf("Stack L4 data: %lx / %lx\n", stack_data_end, stack.region_address(stack_data_end)); 485 486 /* No environment pointers. */ 487 488 *(--stack_element) = 0; 489 490 /* Populate stack with argument pointers and count. */ 491 /* NOTE: Just one argument currently. */ 492 493 *(--stack_element) = 0; 494 *(--stack_element) = (l4_umword_t) (stack.region_address(stack_arg)); 495 *(--stack_element) = argc; 496 497 char *stack_adjusted = Ldr::adjust_sp((char *) stack_element, NULL); 498 499 /* Adjust the stack alignment. */ 500 501 if (stack_adjusted != (char *) stack_element) 502 memmove(stack_adjusted, (const void *) stack_element, stack_data_end - (l4_addr_t) stack_element); 503 504 l4_umword_t *stack_adjusted_element = (l4_umword_t *) stack_adjusted; 505 506 printf("%ld %lx %lx\n", stack_adjusted_element[0], stack_adjusted_element[1], stack_adjusted_element[2]); 507 508 l4_addr_t stack_start = stack.region_address(stack_adjusted); 509 510 printf("Stack L4 start: %p / %lx\n", stack_adjusted, stack.region_address(stack_adjusted)); 511 512 return stack_start; 513 } 514 515 516 517 static ExecPager exec_pager; 518 519 static void init_pager(ipc_server_config_type *config) 520 { 521 ipc_server_init_config(config); 522 523 config->expected_items = PagerObject_expected_items; 524 config->handler = (ipc_server_handler_type) handle_PagerObject; 525 config->handler_obj = static_cast<PagerObject *>(&exec_pager); 526 } 527 528 static long start_pager(ipc_server_config_type *config, pthread_t thread) 529 { 530 config->config_thread = 1; 531 config->thread = pthread_l4_cap(thread); 532 533 printf("Starting pager thread...\n"); 534 return ipc_server_start_config(config); 535 } 536 537 538 539 /* UTCB properties. 540 See: moe/server/src/loader.cc */ 541 542 enum ipc_exec_utcb 543 { 544 Default_max_threads = 16, 545 #ifdef ARCH_mips 546 Utcb_area_start = 0x73000000, 547 #else 548 Utcb_area_start = 0xb3000000, 549 #endif 550 }; 551 552 553 554 /* Capability mapping definitions for the new task. */ 555 556 struct mapped_cap 557 { 558 l4_cap_idx_t cap; 559 unsigned char rights; 560 l4_umword_t spot; 561 }; 562 563 static long map_capabilities(l4_cap_idx_t task, struct mapped_cap mapped_caps[]) 564 { 565 long err = L4_EOK; 566 int i = 0; 567 568 while (l4_is_valid_cap(mapped_caps[i].cap) && !err) 569 { 570 err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP, 571 l4_obj_fpage(mapped_caps[i].cap, 0, mapped_caps[i].rights), 572 l4_map_obj_control(mapped_caps[i].spot, L4_MAP_ITEM_MAP))); 573 i++; 574 } 575 576 return err; 577 } 578 579 580 581 int main(int argc, char *argv[]) 582 { 583 long err; 584 585 if (argc < 2) 586 { 587 printf("Need a program to run.\n"); 588 return 1; 589 } 590 591 /* Allocate capabilities for the task and thread. */ 592 593 l4_cap_idx_t caps[2]; 594 595 err = ipc_cap_alloc_many(caps, 2); 596 597 if (err) 598 { 599 printf("Could not allocate capabilities.\n"); 600 return 1; 601 } 602 603 l4_cap_idx_t &task = caps[0]; 604 l4_cap_idx_t &thread = caps[1]; 605 606 /* Obtain the payload as a dataspace. */ 607 608 file_t *file = client_open(argv[1], O_RDONLY); 609 610 if (file == NULL) 611 { 612 printf("Could not read file: %s\n", argv[1]); 613 return 1; 614 } 615 616 /* Copy the payload regions to new dataspaces. 617 NOTE: This should be directed by the ELF metadata. */ 618 619 address_t program_start = 0x1000af3; 620 621 Segment program(0x1000000, 0x282ae, L4_FPAGE_RWX, 0, 0x282ae); 622 Segment data(0x1029360, 0x8068, L4_FPAGE_RW, 0x28360, 0x2058); 623 Segment stack(0x80000000, 16 * L4_PAGESIZE, L4_FPAGE_RW); 624 Segment *segments[] = {&program, &data, &stack, NULL}; 625 Segment **segment; 626 627 for (segment = segments; *segment != NULL; segment++) 628 { 629 err = (*segment)->allocate(); 630 631 if (err) 632 { 633 printf("Could not reserve memory.\n"); 634 return 1; 635 } 636 637 err = (*segment)->fill(file); 638 639 if (err) 640 { 641 printf("Could not fill segment from file.\n"); 642 return 1; 643 } 644 } 645 646 if (memcmp(program.buf + program_start - program.region_base, "\x31\xed", 2)) 647 { 648 printf("Did not find expected instructions at start.\n"); 649 return 1; 650 } 651 652 /* UTCB location and size. */ 653 654 l4_addr_t utcb_start = Utcb_area_start; 655 int utcb_log2size = page_order(Default_max_threads * L4_UTCB_OFFSET); 656 657 /* Round up to at least one page. */ 658 659 if (utcb_log2size < L4_PAGESHIFT) 660 utcb_log2size = L4_PAGESHIFT; 661 662 l4_fpage_t utcb_fpage = l4_fpage(utcb_start, utcb_log2size, 0); 663 664 /* KIP allocation. */ 665 666 l4_addr_t kip_start = (l4_addr_t) l4re_kip(); 667 668 printf("KIP at %lx.\n", kip_start); 669 670 /* Populate the stack with argument and environment details. */ 671 672 l4_addr_t stack_start = populate_stack(stack, argc - 1, argv + 1, utcb_fpage); 673 674 /* Create a new task and thread. */ 675 676 err = l4_error(l4_factory_create_task(l4re_env()->factory, task, utcb_fpage)); 677 678 if (err) 679 { 680 printf("Could not create task.\n"); 681 return 1; 682 } 683 684 err = l4_error(l4_factory_create_thread(l4re_env()->factory, thread)); 685 686 if (err) 687 { 688 printf("Could not create thread.\n"); 689 return 1; 690 } 691 692 /* Start the pager. */ 693 694 ipc_server_config_type config; 695 pthread_t pager_thread; 696 pthread_attr_t attr; 697 698 pthread_attr_init(&attr); 699 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 700 701 init_pager(&config); 702 703 for (segment = segments; *segment != NULL; segment++) 704 exec_pager.add((*segment)->region()); 705 706 err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config); 707 708 if (err) 709 { 710 printf("Could not start pager thread.\n"); 711 return 1; 712 } 713 714 err = start_pager(&config, pager_thread); 715 716 if (err) 717 { 718 printf("Could not start pager.\n"); 719 return 1; 720 } 721 722 /* Define capability mappings for the new task. */ 723 724 struct mapped_cap mapped_caps[] = { 725 {config.server, L4_CAP_FPAGE_RWS, 0x10 << L4_CAP_SHIFT}, 726 {config.server, L4_CAP_FPAGE_RWS, 0x11 << L4_CAP_SHIFT}, 727 {task, L4_CAP_FPAGE_RWS, L4_BASE_TASK_CAP}, 728 {thread, L4_CAP_FPAGE_RWS, L4_BASE_THREAD_CAP}, 729 {l4re_env()->factory, L4_CAP_FPAGE_RWS, L4_BASE_FACTORY_CAP}, 730 {l4re_env()->log, L4_CAP_FPAGE_RWS, L4_BASE_LOG_CAP}, 731 {l4re_env()->scheduler, L4_CAP_FPAGE_RWS, L4_BASE_SCHEDULER_CAP}, 732 {l4re_env()->mem_alloc, L4_CAP_FPAGE_RWS, 0x12 << L4_CAP_SHIFT}, 733 {L4_INVALID_CAP, 0, 0}, 734 }; 735 736 err = map_capabilities(task, mapped_caps); 737 738 if (err) 739 { 740 printf("Could not capabilities into task.\n"); 741 return 1; 742 } 743 744 /* Map the KIP into the task. */ 745 746 err = l4_error(l4_task_map(task, L4RE_THIS_TASK_CAP, 747 l4_fpage(kip_start, L4_PAGESHIFT, L4_FPAGE_RX), 748 kip_start)); 749 750 if (err) 751 { 752 printf("Could not map KIP into task.\n"); 753 return 1; 754 } 755 756 /* Configure the thread with the region manager acting as pager and exception 757 handler. The UTCB will be situated at an address supported by a dataspace 758 attached to the new task. */ 759 760 printf("Configure thread...\n"); 761 762 l4_thread_control_start(); 763 l4_thread_control_pager(0x10 << L4_CAP_SHIFT); 764 l4_thread_control_exc_handler(0x10 << L4_CAP_SHIFT); 765 l4_thread_control_bind((l4_utcb_t *) utcb_start, task); 766 err = l4_error(l4_thread_control_commit(thread)); 767 768 if (err) 769 { 770 printf("Could not configure thread.\n"); 771 return 1; 772 } 773 774 /* Start the new thread. */ 775 776 printf("Schedule thread...\n"); 777 778 printf("Stack at 0x%lx mapped to region at 0x%lx.\n", stack_start, stack.region_base); 779 780 err = l4_error(l4_thread_ex_regs(thread, program_start, stack_start, 0)); 781 782 if (err) 783 { 784 printf("Could not set thread registers.\n"); 785 return 1; 786 } 787 788 printf("Run thread...\n"); 789 790 l4_sched_param_t sp = l4_sched_param(L4RE_MAIN_THREAD_PRIO); 791 792 err = l4_error(l4_scheduler_run_thread(l4re_env()->scheduler, thread, &sp)); 793 794 if (err) 795 { 796 printf("Could not run thread.\n"); 797 return 1; 798 } 799 800 printf("Finished.\n"); 801 while (1); 802 803 return 0; 804 } 805 806 /* vim: tabstop=2 expandtab shiftwidth=2 807 */