Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 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/shared/ppapi_proxy/ppruntime.h" | 7 #include "native_client/src/shared/ppapi_proxy/ppruntime.h" |
| 8 #include "native_client/src/untrusted/irt/irt.h" | 8 #include "native_client/src/untrusted/irt/irt.h" |
| 9 #include "native_client/src/untrusted/irt/irt_interfaces.h" | |
| 9 #include "native_client/src/untrusted/irt/irt_ppapi.h" | 10 #include "native_client/src/untrusted/irt/irt_ppapi.h" |
| 10 #include "native_client/src/untrusted/irt/irt_private.h" | 11 #include "native_client/src/untrusted/irt/irt_private.h" |
| 11 | 12 |
| 13 #include "ppapi/generators/pnacl_shim.h" | |
| 14 | |
| 12 struct PP_StartFunctions g_pp_functions; | 15 struct PP_StartFunctions g_pp_functions; |
| 13 | 16 |
| 17 /* | |
| 18 * PNaCl Shimming magic | |
| 19 * ==================== | |
| 20 * Note: this could be simplified by changing the actual | |
| 21 * GetInterface functions for now we rely on some autogenerated files. | |
| 22 * | |
| 23 * Some background: | |
| 24 * pnacl has calling conventions which are slightly different from nacl-gcc. | |
| 25 * This only affect structure passing on x86-64 which is only used by Ppapi | |
| 26 * functions. | |
| 27 * There are two functions which are relevant: | |
| 28 * PPP_GetInterface and PPB_GetInterface. | |
| 29 * We interecept those functions, store the old version and then redirect | |
| 30 * to __Pnacl_PPPGetInterface and __Pnacl_PPBGetInterface. | |
| 31 */ | |
| 32 | |
| 33 /* Holds the orginial PP_StartFunctions if shimming is enabled. */ | |
| 34 struct PP_StartFunctions g_pp_functions_non_shim; | |
| 35 | |
| 36 static int32_t PPPInitializeModule_cc_shim(PP_Module module_id, | |
| 37 PPB_GetInterface get_browser_intf) { | |
| 38 /* save old version of PPB_GetInterface */ | |
| 39 __set_real_Pnacl_PPBGetInterface(get_browser_intf); | |
|
Roland McGrath
2012/08/06 23:32:24
There's no reason to use __ names in any of this.
Robert Muth (chromium)
2012/08/07 14:45:40
I agree but the "__" code is generated by python s
| |
| 40 /* redirect to new version of PPB_GetInterface */ | |
| 41 return g_pp_functions_non_shim.PPP_InitializeModule( | |
| 42 module_id, &__Pnacl_PPBGetInterface); | |
| 43 } | |
| 44 | |
| 45 static void PPP_ShutdownModule_cc_shim() { | |
| 46 /* redirect to non-shimed version */ | |
| 47 g_pp_functions_non_shim.PPP_ShutdownModule(); | |
| 48 } | |
| 49 | |
| 50 static const void *PPP_GetInterface_cc_shim(const char *interface_name) { | |
| 51 /* redirect to new version of PPP_GetInterface */ | |
| 52 return __Pnacl_PPPGetInterface(interface_name); | |
| 53 } | |
| 54 | |
| 55 struct PP_StartFunctions g_pp_functions_cc_shim = { | |
| 56 &PPPInitializeModule_cc_shim, | |
| 57 &PPP_ShutdownModule_cc_shim, | |
| 58 &PPP_GetInterface_cc_shim | |
| 59 }; | |
| 60 | |
| 61 /* register entry points to untrusted pepper plugin */ | |
| 14 static int irt_ppapi_start(const struct PP_StartFunctions *funcs) { | 62 static int irt_ppapi_start(const struct PP_StartFunctions *funcs) { |
| 15 g_pp_functions = *funcs; | 63 if (g_use_cc_shim) { |
| 64 /* save old version of PPP_GetInterface */ | |
| 65 __set_real_Pnacl_PPPGetInterface(funcs->PPP_GetInterface); | |
| 66 g_pp_functions_non_shim = *funcs; | |
| 67 g_pp_functions = g_pp_functions_cc_shim; | |
| 68 } else { | |
| 69 g_pp_functions = *funcs; | |
| 70 } | |
| 16 g_is_main_thread = 1; | 71 g_is_main_thread = 1; |
| 17 return PpapiPluginMain(); | 72 return PpapiPluginMain(); |
| 18 } | 73 } |
| 19 | 74 |
| 20 int32_t PPP_InitializeModule(PP_Module module_id, | 75 int32_t PPP_InitializeModule(PP_Module module_id, |
| 21 PPB_GetInterface get_browser_interface) { | 76 PPB_GetInterface get_browser_interface) { |
| 22 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); | 77 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); |
| 23 } | 78 } |
| 24 | 79 |
| 25 void PPP_ShutdownModule() { | 80 void PPP_ShutdownModule() { |
| 26 g_pp_functions.PPP_ShutdownModule(); | 81 g_pp_functions.PPP_ShutdownModule(); |
| 27 } | 82 } |
| 28 | 83 |
| 29 const void *PPP_GetInterface(const char *interface_name) { | 84 const void *PPP_GetInterface(const char *interface_name) { |
| 30 return g_pp_functions.PPP_GetInterface(interface_name); | 85 return g_pp_functions.PPP_GetInterface(interface_name); |
| 31 } | 86 } |
| 32 | 87 |
| 33 /* | 88 /* |
| 34 * This overrides the definition in ppapi_proxy/plugin_threading.cc. | 89 * This overrides the definition in ppapi_proxy/plugin_threading.cc. |
| 35 * TODO(mseaborn): Remove this when PPAPI is only supported via the IRT. | 90 * TODO(mseaborn): Remove this when PPAPI is only supported via the IRT. |
| 36 * See http://code.google.com/p/nativeclient/issues/detail?id=1691 | 91 * See http://code.google.com/p/nativeclient/issues/detail?id=1691 |
| 37 */ | 92 */ |
| 38 void PpapiPluginRegisterDefaultThreadCreator() { | 93 void PpapiPluginRegisterDefaultThreadCreator() { |
| 39 } | 94 } |
| 40 | 95 |
| 41 const struct nacl_irt_ppapihook nacl_irt_ppapihook = { | 96 const struct nacl_irt_ppapihook nacl_irt_ppapihook = { |
| 42 irt_ppapi_start, | 97 irt_ppapi_start, |
| 43 PpapiPluginRegisterThreadCreator, | 98 PpapiPluginRegisterThreadCreator, |
| 44 }; | 99 }; |
| OLD | NEW |