OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright 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 /* register entry points to untrusted pepper plugin */ | |
14 static int irt_ppapi_start(const struct PP_StartFunctions *funcs) { | 18 static int irt_ppapi_start(const struct PP_StartFunctions *funcs) { |
15 g_pp_functions = *funcs; | 19 g_pp_functions = *funcs; |
16 g_is_main_thread = 1; | 20 g_is_main_thread = 1; |
17 return PpapiPluginMain(); | 21 return PpapiPluginMain(); |
18 } | 22 } |
19 | 23 |
20 int32_t PPP_InitializeModule(PP_Module module_id, | 24 int32_t PPP_InitializeModule(PP_Module module_id, |
21 PPB_GetInterface get_browser_interface) { | 25 PPB_GetInterface get_browser_interface) { |
22 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); | 26 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); |
23 } | 27 } |
(...skipping 11 matching lines...) Expand all Loading... | |
35 * TODO(mseaborn): Remove this when PPAPI is only supported via the IRT. | 39 * TODO(mseaborn): Remove this when PPAPI is only supported via the IRT. |
36 * See http://code.google.com/p/nativeclient/issues/detail?id=1691 | 40 * See http://code.google.com/p/nativeclient/issues/detail?id=1691 |
37 */ | 41 */ |
38 void PpapiPluginRegisterDefaultThreadCreator() { | 42 void PpapiPluginRegisterDefaultThreadCreator() { |
39 } | 43 } |
40 | 44 |
41 const struct nacl_irt_ppapihook nacl_irt_ppapihook = { | 45 const struct nacl_irt_ppapihook nacl_irt_ppapihook = { |
42 irt_ppapi_start, | 46 irt_ppapi_start, |
43 PpapiPluginRegisterThreadCreator, | 47 PpapiPluginRegisterThreadCreator, |
44 }; | 48 }; |
49 | |
50 | |
51 /* | |
52 * PNaCl Shimming magic | |
53 * ==================== | |
54 * Note: this could be simplified by changing the actual | |
55 * GetInterface functions but for now we rely on some autogenerated files. | |
56 * | |
57 * Some background: | |
58 * pnacl has calling conventions which are slightly different from nacl-gcc. | |
Mark Seaborn
2012/08/28 15:51:20
'pnacl' -> 'PNaCl'
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
59 * This affects structure passing on x86-64 which is only used by Ppapi | |
Mark Seaborn
2012/08/28 15:51:20
'Ppapi' -> 'PPAPI'
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
60 * functions. | |
61 * There are two functions which are relevant: | |
62 * PPP_GetInterface and PPB_GetInterface. | |
63 * We interecept those functions, store the old version and then redirect | |
Mark Seaborn
2012/08/28 15:51:20
"intercept"
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
64 * to __Pnacl_PPPGetInterface and __Pnacl_PPBGetInterface. | |
65 */ | |
66 | |
67 /* Holds the orginial PP_StartFunctions data if shimming is enabled. */ | |
68 struct PP_StartFunctions g_pp_functions_non_shim; | |
Mark Seaborn
2012/08/28 15:51:20
This should be static, because it's only used with
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
69 | |
70 static int32_t PPP_InitializeModule_cc_shim(PP_Module module_id, | |
71 PPB_GetInterface get_browser_intf) { | |
Mark Seaborn
2012/08/28 15:51:20
Please use the full name: "get_browser_interface",
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
72 /* save old version of PPB_GetInterface */ | |
73 __set_real_Pnacl_PPBGetInterface(get_browser_intf); | |
74 /* redirect to new version of PPB_GetInterface */ | |
75 return g_pp_functions_non_shim.PPP_InitializeModule( | |
76 module_id, &__Pnacl_PPBGetInterface); | |
Mark Seaborn
2012/08/28 15:51:20
Nit: the usual style is to indent arguments by 4 s
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
77 } | |
78 | |
79 static void PPP_ShutdownModule_cc_shim() { | |
80 /* redirect to non-shimed version */ | |
Mark Seaborn
2012/08/28 15:51:20
"shimmed"
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
81 g_pp_functions_non_shim.PPP_ShutdownModule(); | |
82 } | |
83 | |
84 static const void *PPP_GetInterface_cc_shim(const char *interface_name) { | |
85 /* redirect to new version of PPP_GetInterface */ | |
86 return __Pnacl_PPPGetInterface(interface_name); | |
87 } | |
88 | |
89 static struct PP_StartFunctions g_pp_functions_cc_shim = { | |
90 &PPP_InitializeModule_cc_shim, | |
Mark Seaborn
2012/08/28 15:51:20
We don't use the redundant "&" for getting functio
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
91 &PPP_ShutdownModule_cc_shim, | |
92 &PPP_GetInterface_cc_shim | |
93 }; | |
94 | |
95 /* | |
96 * This function is called by nexe module to advertise its API | |
97 * to chrome. | |
Mark Seaborn
2012/08/28 15:51:20
'chrome' -> 'Chrome'
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
98 * We need to shim all these functions and also do some extra bookeeping | |
Mark Seaborn
2012/08/28 15:51:20
Isn't this repeating what you said in the earlier
Robert Muth (chromium)
2012/08/28 18:13:30
emphasized the word *also*
On 2012/08/28 15:51:20
| |
99 * work so we sneak in our own replacements g_pp_functions_cc_shim | |
100 * which in turn call the original functions. | |
101 */ | |
102 static int irt_ppapi_start_shimmed(const struct PP_StartFunctions *funcs) { | |
103 /* save old version of PPP_GetInterface */ | |
104 __set_real_Pnacl_PPPGetInterface(funcs->PPP_GetInterface); | |
105 g_pp_functions_non_shim = *funcs; | |
106 g_pp_functions = g_pp_functions_cc_shim; | |
107 g_is_main_thread = 1; | |
108 return PpapiPluginMain(); | |
Mark Seaborn
2012/08/28 15:51:20
Rather than duplicating code from irt_ppapi_start(
Robert Muth (chromium)
2012/08/28 18:13:30
Done.
| |
109 } | |
110 | |
111 const struct nacl_irt_ppapihook nacl_irt_ppapihook_shimmed = { | |
112 irt_ppapi_start_shimmed, | |
113 PpapiPluginRegisterThreadCreator, | |
114 }; | |
OLD | NEW |