Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: src/untrusted/irt/irt_entry.c

Issue 19571003: IRT: Replace __attribute__((constructor)) with explicit call in _start() (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Fix + cleanup Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/untrusted/irt/irt_core_entry.c ('k') | src/untrusted/irt/nacl.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/untrusted/irt/irt_core_entry.c ('k') | src/untrusted/irt/nacl.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698