Index: ppapi/proxy/irt_shim_ppapi.c |
diff --git a/ppapi/proxy/irt_shim_ppapi.c b/ppapi/proxy/irt_shim_ppapi.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..45087360697ed8412c6169edc66be73ae1b465ba |
--- /dev/null |
+++ b/ppapi/proxy/irt_shim_ppapi.c |
@@ -0,0 +1,74 @@ |
+/* |
+ * Copyright 2014 The Chromium Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "native_client/src/untrusted/irt/irt.h" |
+#include "ppapi/nacl_irt/irt_ppapi.h" |
+#include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
+#include "ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.h" |
+ |
+/* |
+ * Defines a version of the version irt_ppapi_start and of the irt_ppapihook |
+ * that returns a shimmed GetInterface for PNaCl. |
+ * |
+ * The hook will be linked into the IRT but it is considered unstable, |
+ * should not use that IRT hook. Instead PNaCl nexes should embed the |
+ * irt_shim_ppapi_start and the shim functions directly into the nexe |
+ * for stability. |
+ */ |
+ |
+static struct PP_StartFunctions user_start_functions; |
+ |
+static int32_t shim_PPPInitializeModule(PP_Module module_id, |
+ PPB_GetInterface get_browser_intf) { |
+ /* Record the original PPB_GetInterface and provide a shimmed one. */ |
+ __set_real_Pnacl_PPBGetInterface(get_browser_intf); |
+ return (*user_start_functions.PPP_InitializeModule)(module_id, |
+ &__Pnacl_PPBGetInterface); |
+} |
+ |
+static void shim_PPPShutdownModule() { |
+ (*user_start_functions.PPP_ShutdownModule)(); |
+} |
+ |
+#if PNACL_SHIM_AOT |
+ /* |
+ * This will be overridden by the shim. |
+ */ |
+int (*real_irt_ppapi_start)(const struct PP_StartFunctions *) = NULL; |
+#else |
+ /* |
+ * Otherwise, when linking directly into the IRT, we can refer to the |
+ * real irt_ppapi_start. |
+ */ |
+extern int irt_ppapi_start(const struct PP_StartFunctions *); |
+static int (* const real_irt_ppapi_start)(const struct PP_StartFunctions *) = |
+ &irt_ppapi_start; |
+#endif |
+ |
+int irt_shim_ppapi_start(const struct PP_StartFunctions *funcs) { |
+ user_start_functions = *funcs; |
+ /* |
+ * Record the original PPP_GetInterface and provide a shimmed one |
+ * via wrapped_ppapi_methods. |
+ */ |
+ const struct PP_StartFunctions wrapped_ppapi_methods = { |
+ shim_PPPInitializeModule, |
+ shim_PPPShutdownModule, |
+ __Pnacl_PPPGetInterface |
+ }; |
+ __set_real_Pnacl_PPPGetInterface(user_start_functions.PPP_GetInterface); |
+ /* |
+ * Invoke the IRT's ppapi_start interface with the wrapped interface. |
+ */ |
+ return (*real_irt_ppapi_start)(&wrapped_ppapi_methods); |
+} |
+ |
+#if !PNACL_SHIM_AOT |
+const struct nacl_irt_ppapihook nacl_irt_shim_ppapihook = { |
+ irt_shim_ppapi_start, |
+ PpapiPluginRegisterThreadCreator, |
+}; |
+#endif |