OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium 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 "ppapi/native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" | 7 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.h" |
8 | 8 |
9 #include <string.h> | 9 #include <string.h> |
10 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" |
11 #include "native_client/src/untrusted/irt/irt.h" | 11 #include "native_client/src/untrusted/irt/irt.h" |
12 #include "native_client/src/untrusted/irt/irt_dev.h" | 12 #include "native_client/src/untrusted/irt/irt_dev.h" |
13 #include "ppapi/nacl_irt/irt_ppapi.h" | 13 #include "ppapi/nacl_irt/irt_ppapi.h" |
14 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" | 14 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
15 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.h" | 15 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.h" |
16 #include "ppapi/proxy/irt_shim_ppapi.h" | |
16 | 17 |
17 /* | 18 /* |
18 * This is a whitelist of NaCl IRT interfaces that are exposed under | 19 * This is a whitelist of NaCl IRT interfaces that are exposed under |
19 * PNaCl. This list omits the following: | 20 * PNaCl. This list omits the following: |
20 * | 21 * |
21 * * The old versions of "irt-memory", v0.1 and v0.2, which contain | 22 * * The old versions of "irt-memory", v0.1 and v0.2, which contain |
22 * the deprecated sysbrk() function. See: | 23 * the deprecated sysbrk() function. See: |
23 * https://code.google.com/p/nativeclient/issues/detail?id=3542 | 24 * https://code.google.com/p/nativeclient/issues/detail?id=3542 |
24 * | 25 * |
25 * * "irt-mutex", "irt-cond" and "irt-sem", which are deprecated and | 26 * * "irt-mutex", "irt-cond" and "irt-sem", which are deprecated and |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 static int is_irt_interface_whitelisted(const char *interface_name) { | 83 static int is_irt_interface_whitelisted(const char *interface_name) { |
83 int i; | 84 int i; |
84 for (i = 0; i < NACL_ARRAY_SIZE(irt_interface_whitelist); i++) { | 85 for (i = 0; i < NACL_ARRAY_SIZE(irt_interface_whitelist); i++) { |
85 if (mystrcmp(interface_name, irt_interface_whitelist[i]) == 0) { | 86 if (mystrcmp(interface_name, irt_interface_whitelist[i]) == 0) { |
86 return 1; | 87 return 1; |
87 } | 88 } |
88 } | 89 } |
89 return 0; | 90 return 0; |
90 } | 91 } |
91 | 92 |
92 TYPE_nacl_irt_query __pnacl_real_irt_interface = NULL; | 93 TYPE_nacl_irt_query __pnacl_real_irt_query_func = NULL; |
93 | 94 |
94 /* | 95 size_t __pnacl_wrap_irt_query_func(const char *interface_ident, |
95 * These remember the interface pointers the user registers by calling the | |
96 * IRT entry point. | |
97 */ | |
98 static struct PP_StartFunctions user_start_functions; | |
99 | |
100 static int32_t wrap_PPPInitializeModule(PP_Module module_id, | |
101 PPB_GetInterface get_browser_intf) { | |
102 __set_real_Pnacl_PPBGetInterface(get_browser_intf); | |
103 /* | |
104 * Calls from user code to the PPB interfaces pass through here and may | |
105 * require shims to convert the ABI. | |
106 */ | |
107 return (*user_start_functions.PPP_InitializeModule)(module_id, | |
108 &__Pnacl_PPBGetInterface); | |
109 } | |
110 | |
111 static void wrap_PPPShutdownModule() { | |
112 (*user_start_functions.PPP_ShutdownModule)(); | |
113 } | |
114 | |
115 static const struct PP_StartFunctions wrapped_ppapi_methods = { | |
116 wrap_PPPInitializeModule, | |
117 wrap_PPPShutdownModule, | |
118 /* | |
119 * Calls from the IRT to the user plugin pass through here and may require | |
120 * shims to convert the ABI. | |
121 */ | |
122 __Pnacl_PPPGetInterface | |
123 }; | |
124 | |
125 static struct nacl_irt_ppapihook real_irt_ppapi_hook; | |
126 | |
127 static int wrap_ppapi_start(const struct PP_StartFunctions *funcs) { | |
128 /* | |
129 * Save the user's real bindings for the start functions. | |
130 */ | |
131 user_start_functions = *funcs; | |
132 __set_real_Pnacl_PPPGetInterface(user_start_functions.PPP_GetInterface); | |
133 | |
134 /* | |
135 * Invoke the IRT's ppapi_start interface with the wrapped interface. | |
136 */ | |
137 return (*real_irt_ppapi_hook.ppapi_start)(&wrapped_ppapi_methods); | |
138 } | |
139 | |
140 size_t __pnacl_irt_interface_wrapper(const char *interface_ident, | |
141 void *table, size_t tablesize) { | 96 void *table, size_t tablesize) { |
142 if (!is_irt_interface_whitelisted(interface_ident)) | 97 if (!is_irt_interface_whitelisted(interface_ident)) |
143 return 0; | 98 return 0; |
144 | 99 |
145 /* | 100 /* |
146 * Note there is a benign race in initializing the wrapper. | 101 * Note there is a benign race in initializing the wrapper. |
147 * We build the "hook" structure by copying from the IRT's hook and then | 102 * We build the "hook" structure by copying from the IRT's hook and then |
148 * writing our wrapper for the ppapi method. Two threads may end up | 103 * writing our wrapper for the ppapi method. Two threads may end up |
149 * attempting to do this simultaneously, which should not be a problem, | 104 * attempting to do this simultaneously, which should not be a problem, |
150 * as they are writing the same values. | 105 * as they are writing the same values. |
151 */ | 106 */ |
152 if (0 != mystrcmp(interface_ident, NACL_IRT_PPAPIHOOK_v0_1)) { | 107 if (0 != mystrcmp(interface_ident, NACL_IRT_PPAPIHOOK_v0_1)) { |
153 /* | 108 /* |
154 * The interface is not wrapped, so use the real interface. | 109 * The interface is not wrapped, so use the real interface. |
155 */ | 110 */ |
156 return (*__pnacl_real_irt_interface)(interface_ident, table, tablesize); | 111 return (*__pnacl_real_irt_query_func)(interface_ident, table, tablesize); |
157 } | 112 } |
158 if ((*__pnacl_real_irt_interface)(NACL_IRT_PPAPIHOOK_v0_1, | 113 #if !PNACL_SHIM_AOT |
159 &real_irt_ppapi_hook, | 114 /* |
160 sizeof real_irt_ppapi_hook) != | 115 * For the PNaCl in-the-browser, redirect to using |
Mark Seaborn
2014/02/26 22:11:03
Nit: drop "the"?
jvoung (off chromium)
2014/02/27 01:39:55
Done.
| |
116 * NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1 instead of NACL_IRT_PPAPIHOOK_v0_1. | |
117 */ | |
118 return (*__pnacl_real_irt_query_func)(NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1, | |
119 table, tablesize); | |
120 #else | |
121 /* | |
122 * For offline generated nexes, avoid depending on the private | |
123 * NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1 interface, and just do the | |
124 * overriding here manually. | |
125 */ | |
126 struct nacl_irt_ppapihook real_irt_ppapi_hook; | |
127 if ((*__pnacl_real_irt_query_func)(NACL_IRT_PPAPIHOOK_v0_1, | |
128 &real_irt_ppapi_hook, | |
129 sizeof real_irt_ppapi_hook) != | |
161 sizeof real_irt_ppapi_hook) { | 130 sizeof real_irt_ppapi_hook) { |
162 return 0; | 131 return 0; |
163 } | 132 } |
133 real_irt_ppapi_start = real_irt_ppapi_hook.ppapi_start; | |
164 /* | 134 /* |
165 * Copy the interface structure into the client. | 135 * Copy the interface structure into the client. |
166 */ | 136 */ |
167 struct nacl_irt_ppapihook *dest = table; | 137 struct nacl_irt_ppapihook *dest = table; |
168 if (sizeof *dest <= tablesize) { | 138 if (sizeof *dest <= tablesize) { |
169 dest->ppapi_start = wrap_ppapi_start; | 139 dest->ppapi_start = irt_shim_ppapi_start; |
170 dest->ppapi_register_thread_creator = | 140 dest->ppapi_register_thread_creator = |
171 real_irt_ppapi_hook.ppapi_register_thread_creator; | 141 real_irt_ppapi_hook.ppapi_register_thread_creator; |
172 return sizeof *dest; | 142 return sizeof *dest; |
173 } | 143 } |
174 return 0; | 144 return 0; |
145 #endif | |
175 } | 146 } |
OLD | NEW |