OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
| 7 #include "native_client/src/nonsfi/irt/irt_interfaces.h" |
| 8 |
7 #include <assert.h> | 9 #include <assert.h> |
8 #include <errno.h> | 10 #include <errno.h> |
9 #include <fcntl.h> | 11 #include <fcntl.h> |
10 #include <limits.h> | 12 #include <limits.h> |
11 #include <pthread.h> | 13 #include <pthread.h> |
12 #include <stdio.h> | 14 #include <stdio.h> |
13 #include <stdlib.h> | 15 #include <stdlib.h> |
14 #include <string.h> | 16 #include <string.h> |
15 #include <sys/mman.h> | 17 #include <sys/mman.h> |
16 #include <sys/stat.h> | 18 #include <sys/stat.h> |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return 0; | 473 return 0; |
472 } | 474 } |
473 | 475 |
474 static void irt_stub_func(const char *name) { | 476 static void irt_stub_func(const char *name) { |
475 fprintf(stderr, "Error: Unimplemented IRT function: %s\n", name); | 477 fprintf(stderr, "Error: Unimplemented IRT function: %s\n", name); |
476 abort(); | 478 abort(); |
477 } | 479 } |
478 | 480 |
479 #define DEFINE_STUB(name) \ | 481 #define DEFINE_STUB(name) \ |
480 static void irt_stub_##name() { irt_stub_func(#name); } | 482 static void irt_stub_##name() { irt_stub_func(#name); } |
481 #define USE_STUB(s, name) (typeof(s.name)) irt_stub_##name | 483 #define USE_STUB(s, name) (__typeof__(s.name)) irt_stub_##name |
482 | 484 |
483 static const struct nacl_irt_basic irt_basic = { | 485 static const struct nacl_irt_basic irt_basic = { |
484 irt_exit, | 486 irt_exit, |
485 irt_gettod, | 487 irt_gettod, |
486 irt_clock_func, | 488 irt_clock_func, |
487 irt_nanosleep, | 489 irt_nanosleep, |
488 irt_sched_yield, | 490 irt_sched_yield, |
489 irt_sysconf, | 491 irt_sysconf, |
490 }; | 492 }; |
491 | 493 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return size; | 603 return size; |
602 } | 604 } |
603 break; | 605 break; |
604 } | 606 } |
605 } | 607 } |
606 fprintf(stderr, "Warning: unavailable IRT interface queried: %s\n", | 608 fprintf(stderr, "Warning: unavailable IRT interface queried: %s\n", |
607 interface_ident); | 609 interface_ident); |
608 return 0; | 610 return 0; |
609 } | 611 } |
610 | 612 |
611 int main(int argc, char **argv, char **environ) { | 613 int nacl_irt_nonsfi_entry(int argc, char **argv, char **environ, |
| 614 nacl_entry_func_t entry_func) { |
612 /* Find size of environ array. */ | 615 /* Find size of environ array. */ |
613 size_t env_count = 0; | 616 size_t env_count = 0; |
614 while (environ[env_count] != NULL) | 617 while (environ[env_count] != NULL) |
615 env_count++; | 618 env_count++; |
616 | 619 |
617 size_t count = | 620 size_t count = |
618 1 /* cleanup_func pointer */ | 621 1 /* cleanup_func pointer */ |
619 + 2 /* envc and argc counts */ | 622 + 2 /* envc and argc counts */ |
620 + argc + 1 /* argv array, with terminator */ | 623 + argc + 1 /* argv array, with terminator */ |
621 + env_count + 1 /* environ array, with terminator */ | 624 + env_count + 1 /* environ array, with terminator */ |
(...skipping 16 matching lines...) Expand all Loading... |
638 data[pos++] = (uintptr_t) environ[i]; | 641 data[pos++] = (uintptr_t) environ[i]; |
639 data[pos++] = 0; | 642 data[pos++] = 0; |
640 /* auxv[0] */ | 643 /* auxv[0] */ |
641 data[pos++] = AT_SYSINFO; | 644 data[pos++] = AT_SYSINFO; |
642 data[pos++] = (uintptr_t) irt_interface_query; | 645 data[pos++] = (uintptr_t) irt_interface_query; |
643 /* auxv[1] */ | 646 /* auxv[1] */ |
644 data[pos++] = 0; | 647 data[pos++] = 0; |
645 data[pos++] = 0; | 648 data[pos++] = 0; |
646 assert(pos == count); | 649 assert(pos == count); |
647 | 650 |
| 651 entry_func(data); |
| 652 return 1; |
| 653 } |
| 654 |
| 655 #if defined(DEFINE_MAIN) |
| 656 int main(int argc, char **argv, char **environ) { |
648 /* | 657 /* |
649 * On Linux, we rename _start() to _user_start() to avoid a clash | 658 * On Linux, we rename _start() to _user_start() to avoid a clash |
650 * with the "_start" routine in the host toolchain. On Mac OS X, | 659 * with the "_start" routine in the host toolchain. On Mac OS X, |
651 * lacking objcopy, doing the symbol renaming is trickier, but also | 660 * lacking objcopy, doing the symbol renaming is trickier, but also |
652 * unnecessary, because the host toolchain doesn't have a "_start" | 661 * unnecessary, because the host toolchain doesn't have a "_start" |
653 * routine. | 662 * routine. |
654 */ | 663 */ |
| 664 nacl_entry_func_t entry_func = |
655 #if defined(__APPLE__) | 665 #if defined(__APPLE__) |
656 _start(data); | 666 _start; |
657 #else | 667 #else |
658 _user_start(data); | 668 _user_start; |
659 #endif | 669 #endif |
660 return 1; | 670 |
| 671 return nacl_irt_nonsfi_entry(argc, argv, environ, entry_func); |
661 } | 672 } |
| 673 #endif |
OLD | NEW |