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/include/elf_auxv.h" | 7 #include "native_client/src/include/elf_auxv.h" |
8 #include "native_client/src/include/elf32.h" | 8 #include "native_client/src/include/elf32.h" |
9 #include "native_client/src/untrusted/nacl/nacl_irt.h" | 9 #include "native_client/src/untrusted/nacl/nacl_irt.h" |
10 | 10 |
11 static int __libnacl_irt_mprotect(void *addr, size_t len, int prot) { | 11 static int __libnacl_irt_mprotect(void *addr, size_t len, int prot) { |
12 return ENOSYS; | 12 return ENOSYS; |
13 } | 13 } |
14 | 14 |
| 15 #if 0 |
| 16 void __libnacl_irt_init_module(void) { |
| 17 size_t count; |
| 18 size_t i; |
| 19 |
| 20 count = 0; |
| 21 while (NULL != nacl_irt_array[count].module_init) { |
| 22 ++count; |
| 23 } |
| 24 |
| 25 for (i = 0; i < count; ++i) { |
| 26 if (NULL != nacl_irt_array[i].module_init) { |
| 27 nacl_irt_array[i].module_init(); |
| 28 } |
| 29 } |
| 30 } |
| 31 |
| 32 void __libnacl_irt_fini_module(void) { |
| 33 size_t count; |
| 34 size_t i; |
| 35 |
| 36 count = 0; |
| 37 while (NULL != nacl_irt_array[count].module_init) { |
| 38 ++count; |
| 39 } |
| 40 |
| 41 for (i = 0; i < count; ++i) { |
| 42 if (NULL != nacl_irt_array[i].module_fini) { |
| 43 nacl_irt_array[i].module_fini(); |
| 44 } |
| 45 } |
| 46 } |
| 47 |
| 48 int nacl_irt_module_register(TYPE_nacl_irt_module_ctor ctor) { |
| 49 TYPE_nacl_irt_query irt_query = NULL; |
| 50 if ((irt_query = ctor(__nacl_irt_query)) != NULL) { |
| 51 __nacl_irt_query = irt_query; |
| 52 return 1; |
| 53 } |
| 54 return 0; |
| 55 } |
| 56 #endif |
| 57 |
| 58 #if 0 |
| 59 extern void (*__libnacl_irt_init_array_start []) (void) __attribute__((weak)); |
| 60 extern void (*__libnacl_irt_init_array_end []) (void) __attribute__((weak)); |
| 61 |
| 62 /* Iterate over all the init routines. */ |
| 63 void __libnacl_irt_init_array(void) { |
| 64 size_t count; |
| 65 size_t i; |
| 66 |
| 67 _init(); |
| 68 |
| 69 count = __init_array_end - __init_array_start; |
| 70 for (i = 0; i < count; i++) { |
| 71 __init_array_start[i] (); |
| 72 } |
| 73 } |
| 74 #endif |
| 75 |
15 /* | 76 /* |
16 * Scan the auxv for AT_SYSINFO, which is the pointer to the IRT query function. | 77 * Scan the auxv for AT_SYSINFO, which is the pointer to the IRT query function. |
17 * Stash that for later use. | 78 * Stash that for later use. |
18 */ | 79 */ |
19 static void grok_auxv(const Elf32_auxv_t *auxv) { | 80 static void grok_auxv(const Elf32_auxv_t *auxv) { |
20 const Elf32_auxv_t *av; | 81 const Elf32_auxv_t *av; |
21 for (av = auxv; av->a_type != AT_NULL; ++av) { | 82 for (av = auxv; av->a_type != AT_NULL; ++av) { |
22 if (av->a_type == AT_SYSINFO) { | 83 if (av->a_type == AT_SYSINFO) { |
23 __nacl_irt_query = (TYPE_nacl_irt_query) av->a_un.a_val; | 84 __nacl_irt_query = (TYPE_nacl_irt_query) av->a_un.a_val; |
24 } | 85 } |
25 } | 86 } |
26 } | 87 } |
27 | 88 |
28 #define DO_QUERY(ident, name) \ | 89 #define DO_QUERY(ident, name) \ |
29 __libnacl_mandatory_irt_query(ident, &__libnacl_irt_##name, \ | 90 __libnacl_mandatory_irt_query(ident, &__libnacl_irt_##name, \ |
30 sizeof(__libnacl_irt_##name)) | 91 sizeof(__libnacl_irt_##name)) |
31 | 92 |
32 /* | 93 /* |
33 * Initialize all our IRT function tables using the query function. | 94 * Initialize all our IRT function tables using the query function. |
34 * The query function's address is passed via AT_SYSINFO in auxv. | 95 * The query function's address is passed via AT_SYSINFO in auxv. |
35 */ | 96 */ |
36 void __libnacl_irt_init(Elf32_auxv_t *auxv) { | 97 void __libnacl_irt_init(int argc, char **argv, Elf32_auxv_t *auxv) { |
37 grok_auxv(auxv); | 98 grok_auxv(auxv); |
38 | 99 |
| 100 #if 0 |
| 101 { |
| 102 struct nacl_irt *irt = nacl_irt_new(NULL, __nacl_irt_query, NULL); |
| 103 if (irt != NULL) { |
| 104 nacl_irt_layer_init(irt->layer); |
| 105 } |
| 106 } |
| 107 DO_QUERY(NACL_IRT_INSTANCE_v0_1, instance); |
| 108 |
| 109 atexit(__libnacl_irt_instance.destroy); |
| 110 __libnacl_irt_instance.init(); |
| 111 #endif |
| 112 |
39 /* | 113 /* |
40 * The "fdio" interface doesn't do anything useful in Chromium (with the | 114 * The "fdio" interface doesn't do anything useful in Chromium (with the |
41 * exception that write() sometimes produces useful debugging output for | 115 * exception that write() sometimes produces useful debugging output for |
42 * stdout/stderr), so don't abort if the it is not available. | 116 * stdout/stderr), so don't abort if the it is not available. |
43 * | 117 * |
44 * We query for "fdio" early on so that write() can produce a useful | 118 * We query for "fdio" early on so that write() can produce a useful |
45 * debugging message if any other IRT queries fail. | 119 * debugging message if any other IRT queries fail. |
46 */ | 120 */ |
47 if (!__libnacl_irt_query(NACL_IRT_FDIO_v0_1, &__libnacl_irt_fdio, | 121 if (!__libnacl_irt_query(NACL_IRT_FDIO_v0_1, &__libnacl_irt_fdio, |
48 sizeof(__libnacl_irt_fdio))) { | 122 sizeof(__libnacl_irt_fdio))) { |
(...skipping 16 matching lines...) Expand all Loading... |
65 &old_irt_memory, | 139 &old_irt_memory, |
66 sizeof(struct nacl_irt_memory_v0_1)); | 140 sizeof(struct nacl_irt_memory_v0_1)); |
67 __libnacl_irt_memory.mprotect = __libnacl_irt_mprotect; | 141 __libnacl_irt_memory.mprotect = __libnacl_irt_mprotect; |
68 } | 142 } |
69 __libnacl_irt_memory.mmap = old_irt_memory.mmap; | 143 __libnacl_irt_memory.mmap = old_irt_memory.mmap; |
70 __libnacl_irt_memory.munmap = old_irt_memory.munmap; | 144 __libnacl_irt_memory.munmap = old_irt_memory.munmap; |
71 } | 145 } |
72 | 146 |
73 DO_QUERY(NACL_IRT_TLS_v0_1, tls); | 147 DO_QUERY(NACL_IRT_TLS_v0_1, tls); |
74 } | 148 } |
OLD | NEW |