| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 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 <assert.h> | 7 #include <assert.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include "native_client/src/include/elf32.h" | 10 #include "native_client/src/include/elf32.h" |
| 11 #include "native_client/src/include/elf_auxv.h" | 11 #include "native_client/src/include/elf_auxv.h" |
| 12 #include "native_client/src/shared/platform/nacl_log.h" |
| 13 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 12 #include "native_client/src/untrusted/irt/irt_interfaces.h" | 14 #include "native_client/src/untrusted/irt/irt_interfaces.h" |
| 13 #include "native_client/src/untrusted/nacl/nacl_irt.h" | 15 #include "native_client/src/untrusted/nacl/nacl_irt.h" |
| 14 #include "native_client/src/untrusted/nacl/nacl_startup.h" | 16 #include "native_client/src/untrusted/nacl/nacl_startup.h" |
| 15 #include "native_client/src/untrusted/nacl/tls.h" | 17 #include "native_client/src/untrusted/nacl/tls.h" |
| 16 | 18 |
| 17 void __libc_init_array(void); | 19 void __libc_init_array(void); |
| 18 | 20 |
| 19 /* | 21 /* |
| 22 * This is declared as weak because plugin_main_nacl.cc on the |
| 23 * Chromium side has a copy of IrtInit(). |
| 24 * TODO(mseaborn): Remove IrtInit() from there and use this copy. |
| 25 */ |
| 26 __attribute__((weak)) |
| 27 int IrtInit(void) { |
| 28 static int initialized = 0; |
| 29 if (initialized) { |
| 30 return 0; |
| 31 } |
| 32 if (!NaClSrpcModuleInit()) { |
| 33 return 1; |
| 34 } |
| 35 NaClLogModuleInit(); /* Enable NaClLog'ing used by CHECK(). */ |
| 36 initialized = 1; |
| 37 return 0; |
| 38 } |
| 39 |
| 40 /* |
| 20 * This is the true entry point for untrusted code. | 41 * This is the true entry point for untrusted code. |
| 21 * See nacl_startup.h for the layout at the argument pointer. | 42 * See nacl_startup.h for the layout at the argument pointer. |
| 22 */ | 43 */ |
| 23 void _start(uint32_t *info) { | 44 void _start(uint32_t *info) { |
| 24 void (*fini)(void) = nacl_startup_fini(info); | 45 void (*fini)(void) = nacl_startup_fini(info); |
| 25 char **envp = nacl_startup_envp(info); | 46 char **envp = nacl_startup_envp(info); |
| 26 Elf32_auxv_t *auxv = nacl_startup_auxv(info); | 47 Elf32_auxv_t *auxv = nacl_startup_auxv(info); |
| 27 | 48 |
| 28 environ = envp; | 49 environ = envp; |
| 29 | 50 |
| 30 /* | 51 /* |
| 31 * We are the true entry point, never called by a dynamic linker. | 52 * We are the true entry point, never called by a dynamic linker. |
| 32 * So the finalizer function pointer is always NULL. | 53 * So the finalizer function pointer is always NULL. |
| 33 * We don't bother registering anything with atexit anyway, | 54 * We don't bother registering anything with atexit anyway, |
| 34 * since we do not expect our own exit function ever to be called. | 55 * since we do not expect our own exit function ever to be called. |
| 35 * Any cleanup we might need done must happen in nacl_irt_exit (irt_basic.c). | 56 * Any cleanup we might need done must happen in nacl_irt_exit (irt_basic.c). |
| 36 */ | 57 */ |
| 37 assert(fini == NULL); | 58 assert(fini == NULL); |
| 38 | 59 |
| 39 __pthread_initialize(); | 60 __pthread_initialize(); |
| 40 | 61 |
| 41 __libc_init_array(); | 62 __libc_init_array(); |
| 42 | 63 |
| 64 if (IrtInit()) { |
| 65 static const char fatal_msg[] = "IrtInit() failed\n"; |
| 66 write(2, fatal_msg, sizeof(fatal_msg) - 1); |
| 67 _exit(-1); |
| 68 } |
| 69 |
| 43 Elf32_auxv_t *entry = NULL; | 70 Elf32_auxv_t *entry = NULL; |
| 44 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) { | 71 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) { |
| 45 if (av->a_type == AT_ENTRY) { | 72 if (av->a_type == AT_ENTRY) { |
| 46 entry = av; | 73 entry = av; |
| 47 break; | 74 break; |
| 48 } | 75 } |
| 49 } | 76 } |
| 50 if (entry == NULL) { | 77 if (entry == NULL) { |
| 51 static const char fatal_msg[] = | 78 static const char fatal_msg[] = |
| 52 "irt_entry: No AT_ENTRY item found in auxv. " | 79 "irt_entry: No AT_ENTRY item found in auxv. " |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 */ | 100 */ |
| 74 _exit(0); | 101 _exit(0); |
| 75 } | 102 } |
| 76 | 103 |
| 77 /* | 104 /* |
| 78 * This is never actually called, but there is an artificial undefined | 105 * This is never actually called, but there is an artificial undefined |
| 79 * reference to it. | 106 * reference to it. |
| 80 */ | 107 */ |
| 81 int main(void) { | 108 int main(void) { |
| 82 } | 109 } |
| OLD | NEW |