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

Unified Diff: src/untrusted/irt/irt_ppapi.c

Issue 10826171: Incorporate shimming into the irt (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: src/untrusted/irt/irt_ppapi.c
===================================================================
--- src/untrusted/irt/irt_ppapi.c (revision 9574)
+++ src/untrusted/irt/irt_ppapi.c (working copy)
@@ -6,11 +6,15 @@
#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;
+/* register entry points to untrusted pepper plugin */
Mark Seaborn 2012/08/28 20:41:00 Please capitalise the first letter, or otherwise d
static int irt_ppapi_start(const struct PP_StartFunctions *funcs) {
g_pp_functions = *funcs;
g_is_main_thread = 1;
@@ -42,3 +46,68 @@
irt_ppapi_start,
PpapiPluginRegisterThreadCreator,
};
+
+
+/*
+ * PNaCl Shimming magic
Mark Seaborn 2012/08/28 20:41:00 Please capitalise consistently, i.e. "PNaCl Shimmi
+ * ====================
+ * Note: this could be simplified by changing the actual
+ * GetInterface functions but for now we rely on some autogenerated files.
+ *
+ * Some background:
+ * PNaCl has calling conventions which are slightly different from nacl-gcc.
+ * This affects 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 intercept those functions, store the old version and then redirect
+ * to __Pnacl_PPPGetInterface and __Pnacl_PPBGetInterface.
+ */
+
+/* Holds the orginial PP_StartFunctions data if shimming is enabled. */
+static struct PP_StartFunctions g_pp_functions_non_shim;
+
+static int32_t PPP_InitializeModule_cc_shim(
+ PP_Module module_id,
Mark Seaborn 2012/08/28 20:41:00 These arguments should be indented by 4 spaces not
+ PPB_GetInterface get_browser_intface) {
Mark Seaborn 2012/08/28 20:41:00 "intface" -> "interface"
+ /* Save old version of PPB_GetInterface. */
+ __set_real_Pnacl_PPBGetInterface(get_browser_intface);
+ /* 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-shimmed 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);
+}
+
+static struct PP_StartFunctions g_pp_functions_cc_shim = {
+ PPP_InitializeModule_cc_shim,
+ PPP_ShutdownModule_cc_shim,
+ PPP_GetInterface_cc_shim
+};
+
+/*
+ * This function is called by nexe module to advertise its API
+ * to Chrome.
+ * We need to shim all these functions and *also* do some extra bookeeping
Mark Seaborn 2012/08/28 20:41:00 "bookkeeping"
+ * work so we sneak in our own replacements g_pp_functions_cc_shim
+ * which in turn call the original functions.
+ */
+static int irt_ppapi_start_shimmed(const struct PP_StartFunctions *funcs) {
+ /* Save old version of PPP_GetInterface. */
+ __set_real_Pnacl_PPPGetInterface(funcs->PPP_GetInterface);
+ g_pp_functions_non_shim = *funcs;
+ return irt_ppapi_start(&g_pp_functions_cc_shim);
+}
+
+const struct nacl_irt_ppapihook nacl_irt_ppapihook_shimmed = {
+ irt_ppapi_start_shimmed,
+ PpapiPluginRegisterThreadCreator,
+};

Powered by Google App Engine
This is Rietveld 408576698