Chromium Code Reviews| Index: src/untrusted/irt/irt_ppapi.c |
| =================================================================== |
| --- src/untrusted/irt/irt_ppapi.c (revision 9381) |
| +++ src/untrusted/irt/irt_ppapi.c (working copy) |
| @@ -6,13 +6,68 @@ |
| #include "native_client/src/shared/ppapi_proxy/ppruntime.h" |
| #include "native_client/src/untrusted/irt/irt.h" |
| +#include "native_client/src/untrusted/irt/irt_interfaces.h" |
| #include "native_client/src/untrusted/irt/irt_ppapi.h" |
| #include "native_client/src/untrusted/irt/irt_private.h" |
| +#include "ppapi/generators/pnacl_shim.h" |
| + |
| struct PP_StartFunctions g_pp_functions; |
| +/* |
| + * PNaCl Shimming magic |
| + * ==================== |
| + * Note: this could be simplified by changing the actual |
| + * GetInterface functions for now we rely on some autogenerated files. |
| + * |
| + * Some background: |
| + * pnacl has calling conventions which are slightly different from nacl-gcc. |
| + * This only affect structure passing on x86-64 which is only used by Ppapi |
| + * functions. |
| + * There are two functions which are relevant: |
| + * PPP_GetInterface and PPB_GetInterface. |
| + * We interecept those functions, store the old version and then redirect |
| + * to __Pnacl_PPPGetInterface and __Pnacl_PPBGetInterface. |
| + */ |
| + |
| +/* Holds the orginial PP_StartFunctions if shimming is enabled. */ |
| +struct PP_StartFunctions g_pp_functions_non_shim; |
| + |
| +static int32_t PPPInitializeModule_cc_shim(PP_Module module_id, |
| + PPB_GetInterface get_browser_intf) { |
| + /* save old version of PPB_GetInterface */ |
| + __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
|
| + /* redirect to new version of PPB_GetInterface */ |
| + return g_pp_functions_non_shim.PPP_InitializeModule( |
| + module_id, &__Pnacl_PPBGetInterface); |
| +} |
| + |
| +static void PPP_ShutdownModule_cc_shim() { |
| + /* redirect to non-shimed version */ |
| + g_pp_functions_non_shim.PPP_ShutdownModule(); |
| +} |
| + |
| +static const void *PPP_GetInterface_cc_shim(const char *interface_name) { |
| + /* redirect to new version of PPP_GetInterface */ |
| + return __Pnacl_PPPGetInterface(interface_name); |
| +} |
| + |
| +struct PP_StartFunctions g_pp_functions_cc_shim = { |
| + &PPPInitializeModule_cc_shim, |
| + &PPP_ShutdownModule_cc_shim, |
| + &PPP_GetInterface_cc_shim |
| +}; |
| + |
| +/* register entry points to untrusted pepper plugin */ |
| static int irt_ppapi_start(const struct PP_StartFunctions *funcs) { |
| - g_pp_functions = *funcs; |
| + if (g_use_cc_shim) { |
| + /* save old version of PPP_GetInterface */ |
| + __set_real_Pnacl_PPPGetInterface(funcs->PPP_GetInterface); |
| + g_pp_functions_non_shim = *funcs; |
| + g_pp_functions = g_pp_functions_cc_shim; |
| + } else { |
| + g_pp_functions = *funcs; |
| + } |
| g_is_main_thread = 1; |
| return PpapiPluginMain(); |
| } |