OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright 2011 The Native Client Authors. All rights reserved. |
jvoung (off chromium)
2012/08/27 21:57:39
Is the new copyright header not supposed to have a
Robert Muth (chromium)
2012/08/27 22:38:18
yes, "(c)" is meaningless I was told
| |
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 <stddef.h> | |
7 #include "native_client/src/include/elf32.h" | 8 #include "native_client/src/include/elf32.h" |
8 #include "native_client/src/include/elf_auxv.h" | 9 #include "native_client/src/include/elf_auxv.h" |
9 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" |
10 #include "native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" | 11 #include "native_client/src/untrusted/irt/irt.h" |
11 #include "native_client/src/untrusted/nacl/nacl_startup.h" | 12 #include "native_client/src/untrusted/nacl/nacl_startup.h" |
12 | 13 |
14 /* | |
15 * For more information about this hack cf. | |
16 * src/untrusted/irt/irt_ppapi.c | |
17 */ | |
18 | |
19 static TYPE_nacl_irt_query real_irt_interface; | |
20 | |
21 /* cf. src/untrusted/irt/irt.h NACL_IRT_PPAPIHOOK_(SHIMMED_)v0_1 */ | |
22 char prefix_search[] = "nacl-irt-ppapihook"; | |
jvoung (off chromium)
2012/08/27 21:57:39
static const ?
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
| |
23 char prefix_replace[] = "nacl-irt-ppapihook-shimmed"; | |
24 | |
25 int my_strcmp(const char* s1, const char* s2) { | |
jvoung (off chromium)
2012/08/27 21:57:39
Comments about why we provide a custom strcmp, str
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
| |
26 while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2) { | |
27 s1++; | |
28 s2++; | |
29 } | |
30 return *s1 - *s2; | |
31 } | |
32 | |
33 void my_strpy(char* s1, const char* s2) { | |
jvoung (off chromium)
2012/08/27 21:57:39
my_strcpy
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
| |
34 while( *s2 != '\0') { | |
jvoung (off chromium)
2012/08/27 21:57:39
"strcpy"
extra space in front of *s2.
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
| |
35 *s1 = *s2; | |
36 s1++; | |
37 s2++; | |
38 } | |
39 *s1 = '\0'; | |
40 } | |
41 | |
42 static size_t pnacl_irt_interface_interceptor(const char *interface_ident, | |
43 void *table, size_t tablesize) { | |
44 /* make this big enough to hold prefix_replace + version suffix */ | |
45 char buffer[2 * sizeof(prefix_replace)]; | |
46 | |
47 const char* ident = interface_ident; | |
48 /* rewrite: "nacl-irt-ppapihook-XXX" -> "nacl-irt-ppapihook-shimmed-XXX" */ | |
49 if (0 == my_strcmp(interface_ident, prefix_search)) { | |
50 /* but not if it is already "nacl-irt-ppapihook-shimmed-XXX" */ | |
jvoung (off chromium)
2012/08/27 21:57:39
extra space "but not"
Robert Muth (chromium)
2012/08/27 22:38:18
Done.
| |
51 if (0 != my_strcmp(interface_ident, prefix_replace)) { | |
52 my_strpy(buffer, prefix_replace); | |
53 my_strpy(buffer + sizeof(prefix_replace) - 1, | |
54 interface_ident + sizeof(prefix_search) - 1); | |
55 ident = buffer; | |
56 } | |
57 } | |
58 return real_irt_interface(ident, table, tablesize); | |
59 } | |
13 | 60 |
14 /* | 61 /* |
15 * This is the true entry point for untrusted code. | 62 * This is the true entry point for untrusted code. |
16 * See nacl_startup.h for the layout at the argument pointer. | 63 * See nacl_startup.h for the layout at the argument pointer. |
17 */ | 64 */ |
18 void _pnacl_wrapper_start(uint32_t *info) { | 65 void _pnacl_wrapper_start(uint32_t *info) { |
19 Elf32_auxv_t *auxv = nacl_startup_auxv(info); | 66 Elf32_auxv_t *auxv = nacl_startup_auxv(info); |
20 | 67 |
21 Elf32_auxv_t *entry = NULL; | 68 Elf32_auxv_t *entry = NULL; |
22 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) { | 69 for (Elf32_auxv_t *av = auxv; av->a_type != AT_NULL; ++av) { |
23 if (av->a_type == AT_SYSINFO) { | 70 if (av->a_type == AT_SYSINFO) { |
24 entry = av; | 71 entry = av; |
25 break; | 72 break; |
26 } | 73 } |
27 } | 74 } |
28 | 75 |
29 if (entry != NULL) { | 76 if (entry != NULL) { |
30 /* | 77 /* |
31 * Save the real irt interface. | 78 * Save the real irt interface. |
32 */ | 79 */ |
33 __pnacl_real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; | 80 real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; |
34 | 81 |
35 /* | 82 /* |
36 * Overwrite the auxv slot with the pnacl IRT shim query function. | 83 * Overwrite the auxv slot with the pnacl IRT shim query function. |
37 */ | 84 */ |
38 entry->a_type = AT_SYSINFO; | 85 entry->a_type = AT_SYSINFO; |
39 entry->a_un.a_val = (uintptr_t) __pnacl_irt_interface_wrapper; | 86 entry->a_un.a_val = (uintptr_t) pnacl_irt_interface_interceptor; |
40 } | 87 } |
41 | 88 |
42 /* If entry is NULL still allow startup to continue. It may be the case | 89 /* If entry is NULL still allow startup to continue. It may be the case |
43 * that the IRT was not actually used (e.g., for some commandline tests). | 90 * that the IRT was not actually used (e.g., for some commandline tests). |
44 * For newlib, we can tell that the IRT isn't used when libnacl_sys_private.a | 91 * For newlib, we can tell that the IRT isn't used when libnacl_sys_private.a |
45 * is in the bitcode link line. However, glibc does not use | 92 * is in the bitcode link line. However, glibc does not use |
46 * libnacl_sys_private, so that would not work. We could look for -lppapi | 93 * libnacl_sys_private, so that would not work. We could look for -lppapi |
47 * in the bitcode link line, but looking at the bitcode link line | 94 * in the bitcode link line, but looking at the bitcode link line |
48 * seems brittle (what if the bitcode link was separated from translation). | 95 * seems brittle (what if the bitcode link was separated from translation). |
49 * Thus we always wrap _start, even if there is no IRT auxv entry. | 96 * Thus we always wrap _start, even if there is no IRT auxv entry. |
50 */ | 97 */ |
51 | 98 |
52 /* | 99 /* |
53 * Call the user entry point function. It should not return. | 100 * Call the user entry point function. It should not return. |
54 * TODO(sehr): Find a way to ensure this is invoked via a tail call. | 101 * TODO(sehr): Find a way to ensure this is invoked via a tail call. |
55 */ | 102 */ |
56 _start(info); | 103 _start(info); |
57 } | 104 } |
OLD | NEW |