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. |
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> | |
Mark Seaborn
2012/08/28 16:04:51
I don't think you actually need stddef.h below, do
Robert Muth (chromium)
2012/08/28 19:11:24
irt.h depends on it.
Mark Seaborn
2012/08/28 19:38:41
But irt.h contains "#include <stddef.h>". So I do
| |
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 static const char prefix_search[] = "nacl-irt-ppapihook"; | |
23 static const char prefix_replace[] = "nacl-irt-ppapihook-shimmed"; | |
24 | |
25 /* do not make assumptions about stcmp being available */ | |
Mark Seaborn
2012/08/28 16:04:51
'stcmp' -> 'strcmp'. Also capitalise the first le
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
| |
26 static int my_strcmp(const char* s1, const char* s2) { | |
Mark Seaborn
2012/08/28 16:04:51
This should use the " *" spacing style (as elsewhe
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
| |
27 while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2) { | |
Mark Seaborn
2012/08/28 16:04:51
"while( " -> "while ("
Robert Muth (chromium)
2012/08/28 19:11:24
Done.
| |
28 s1++; | |
29 s2++; | |
30 } | |
31 return *s1 - *s2; | |
32 } | |
33 | |
34 /* do not make assumptions about strcpy being available */ | |
35 static void my_strcpy(char* s1, const char* s2) { | |
36 while(*s2 != '\0') { | |
37 *s1 = *s2; | |
38 s1++; | |
39 s2++; | |
40 } | |
41 *s1 = '\0'; | |
42 } | |
43 | |
44 static size_t pnacl_irt_interface_interceptor(const char *interface_ident, | |
45 void *table, size_t tablesize) { | |
46 /* make this big enough to hold prefix_replace + version suffix */ | |
47 char buffer[2 * sizeof(prefix_replace)]; | |
48 | |
49 const char* ident = interface_ident; | |
50 /* rewrite: "nacl-irt-ppapihook-XXX" -> "nacl-irt-ppapihook-shimmed-XXX" */ | |
51 if (0 == my_strcmp(interface_ident, prefix_search)) { | |
Mark Seaborn
2012/08/28 16:04:51
When is this check going to return true, if interf
Robert Muth (chromium)
2012/08/28 19:11:24
Thanks this was a bug.
As I mention in the initial
Mark Seaborn
2012/08/28 19:38:41
Why don't you combine this change into your IRT ch
| |
52 /* but not if it is already "nacl-irt-ppapihook-shimmed-XXX" */ | |
53 if (0 != my_strcmp(interface_ident, prefix_replace)) { | |
54 my_strcpy(buffer, prefix_replace); | |
55 my_strcpy(buffer + sizeof(prefix_replace) - 1, | |
56 interface_ident + sizeof(prefix_search) - 1); | |
57 ident = buffer; | |
58 } | |
59 } | |
60 return real_irt_interface(ident, table, tablesize); | |
61 } | |
13 | 62 |
14 /* | 63 /* |
15 * This is the true entry point for untrusted code. | 64 * This is the true entry point for untrusted code. |
16 * See nacl_startup.h for the layout at the argument pointer. | 65 * See nacl_startup.h for the layout at the argument pointer. |
17 */ | 66 */ |
18 void _pnacl_wrapper_start(uint32_t *info) { | 67 void _pnacl_wrapper_start(uint32_t *info) { |
19 Elf32_auxv_t *auxv = nacl_startup_auxv(info); | 68 Elf32_auxv_t *auxv = nacl_startup_auxv(info); |
20 | 69 |
21 Elf32_auxv_t *entry = NULL; | 70 Elf32_auxv_t *entry = NULL; |
22 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) { |
23 if (av->a_type == AT_SYSINFO) { | 72 if (av->a_type == AT_SYSINFO) { |
24 entry = av; | 73 entry = av; |
25 break; | 74 break; |
26 } | 75 } |
27 } | 76 } |
28 | 77 |
29 if (entry != NULL) { | 78 if (entry != NULL) { |
30 /* | 79 /* |
31 * Save the real irt interface. | 80 * Save the real irt interface. |
32 */ | 81 */ |
33 __pnacl_real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; | 82 real_irt_interface = (TYPE_nacl_irt_query) entry->a_un.a_val; |
34 | 83 |
35 /* | 84 /* |
36 * Overwrite the auxv slot with the pnacl IRT shim query function. | 85 * Overwrite the auxv slot with the pnacl IRT shim query function. |
37 */ | 86 */ |
38 entry->a_type = AT_SYSINFO; | 87 entry->a_type = AT_SYSINFO; |
39 entry->a_un.a_val = (uintptr_t) __pnacl_irt_interface_wrapper; | 88 entry->a_un.a_val = (uintptr_t) pnacl_irt_interface_interceptor; |
40 } | 89 } |
41 | 90 |
42 /* If entry is NULL still allow startup to continue. It may be the case | 91 /* 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). | 92 * 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 | 93 * 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 | 94 * 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 | 95 * 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 | 96 * in the bitcode link line, but looking at the bitcode link line |
48 * seems brittle (what if the bitcode link was separated from translation). | 97 * 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. | 98 * Thus we always wrap _start, even if there is no IRT auxv entry. |
50 */ | 99 */ |
51 | 100 |
52 /* | 101 /* |
53 * Call the user entry point function. It should not return. | 102 * 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. | 103 * TODO(sehr): Find a way to ensure this is invoked via a tail call. |
55 */ | 104 */ |
56 _start(info); | 105 _start(info); |
57 } | 106 } |
OLD | NEW |