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

Side by Side Diff: ppapi/native_client/src/untrusted/pnacl_irt_shim/shim_ppapi.c

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

Powered by Google App Engine
This is Rietveld 408576698