OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <unistd.h> |
| 6 |
5 #include "build/build_config.h" | 7 #include "build/build_config.h" |
6 #include "ppapi/nacl_irt/irt_interfaces.h" | 8 #include "native_client/src/public/irt_core.h" |
| 9 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" |
| 10 #include "native_client/src/untrusted/irt/irt.h" |
| 11 #include "ppapi/nacl_irt/irt_manifest.h" |
7 #include "ppapi/nacl_irt/irt_ppapi.h" | 12 #include "ppapi/nacl_irt/irt_ppapi.h" |
8 #include "ppapi/nacl_irt/plugin_main.h" | 13 #include "ppapi/nacl_irt/plugin_main.h" |
9 #include "ppapi/nacl_irt/public/irt_ppapi.h" | 14 #include "ppapi/nacl_irt/public/irt_ppapi.h" |
| 15 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/irt_shim_ppapi.h" |
10 | 16 |
11 static struct PP_StartFunctions g_pp_functions; | 17 static struct PP_StartFunctions g_pp_functions; |
12 | 18 |
13 int irt_ppapi_start(const struct PP_StartFunctions* funcs) { | 19 int irt_ppapi_start(const struct PP_StartFunctions* funcs) { |
14 g_pp_functions = *funcs; | 20 g_pp_functions = *funcs; |
15 return PpapiPluginMain(); | 21 return PpapiPluginMain(); |
16 } | 22 } |
17 | 23 |
18 int32_t PPP_InitializeModule(PP_Module module_id, | 24 int32_t PPP_InitializeModule(PP_Module module_id, |
19 PPB_GetInterface get_browser_interface) { | 25 PPB_GetInterface get_browser_interface) { |
20 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); | 26 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); |
21 } | 27 } |
22 | 28 |
23 void PPP_ShutdownModule(void) { | 29 void PPP_ShutdownModule(void) { |
24 g_pp_functions.PPP_ShutdownModule(); | 30 g_pp_functions.PPP_ShutdownModule(); |
25 } | 31 } |
26 | 32 |
27 const void* PPP_GetInterface(const char* interface_name) { | 33 const void* PPP_GetInterface(const char* interface_name) { |
28 return g_pp_functions.PPP_GetInterface(interface_name); | 34 return g_pp_functions.PPP_GetInterface(interface_name); |
29 } | 35 } |
30 | 36 |
31 const struct nacl_irt_ppapihook nacl_irt_ppapihook = { | 37 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = { |
32 irt_ppapi_start, | 38 irt_ppapi_start, |
33 PpapiPluginRegisterThreadCreator, | 39 PpapiPluginRegisterThreadCreator, |
34 }; | 40 }; |
| 41 |
| 42 #if defined(OS_NACL_SFI) |
| 43 static int ppapihook_pnacl_private_filter(void) { |
| 44 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); |
| 45 if (pnacl_mode == -1) |
| 46 return 0; |
| 47 return pnacl_mode; |
| 48 } |
| 49 #endif |
| 50 |
| 51 static const nacl_irt_resource_open kIrtResourceOpen = { |
| 52 ppapi::IrtOpenResource, |
| 53 }; |
| 54 |
| 55 #if defined(OS_NACL_SFI) |
| 56 static int not_pnacl_filter(void) { |
| 57 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); |
| 58 if (pnacl_mode == -1) |
| 59 return 0; |
| 60 return !pnacl_mode; |
| 61 } |
| 62 #endif |
| 63 |
| 64 static const struct nacl_irt_interface irt_interfaces[] = { |
| 65 { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook), |
| 66 NULL }, |
| 67 #if defined(OS_NACL_SFI) |
| 68 { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1, |
| 69 &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private), |
| 70 ppapihook_pnacl_private_filter }, |
| 71 #endif |
| 72 { NACL_IRT_RESOURCE_OPEN_v0_1, &kIrtResourceOpen, |
| 73 sizeof(kIrtResourceOpen), |
| 74 #if defined(OS_NACL_SFI) |
| 75 not_pnacl_filter, |
| 76 #else |
| 77 // If we change PNaCl to use Non-SFI Mode on the open web, |
| 78 // we should add a filter here. |
| 79 NULL, |
| 80 #endif |
| 81 }, |
| 82 }; |
| 83 |
| 84 size_t chrome_irt_query(const char* interface_ident, |
| 85 void* table, size_t tablesize) { |
| 86 size_t result = nacl_irt_query_list(interface_ident, |
| 87 table, |
| 88 tablesize, |
| 89 irt_interfaces, |
| 90 sizeof(irt_interfaces)); |
| 91 if (result != 0) |
| 92 return result; |
| 93 |
| 94 return nacl_irt_query_core(interface_ident, table, tablesize); |
| 95 } |
OLD | NEW |