| 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> | 5 #include <unistd.h> |
| 6 | 6 |
| 7 #include "build/build_config.h" |
| 7 #include "native_client/src/public/irt_core.h" | 8 #include "native_client/src/public/irt_core.h" |
| 8 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" | 9 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h" |
| 9 #include "native_client/src/untrusted/irt/irt.h" | 10 #include "native_client/src/untrusted/irt/irt.h" |
| 10 #include "native_client/src/untrusted/irt/irt_private.h" | 11 #include "native_client/src/untrusted/irt/irt_private.h" |
| 11 #include "ppapi/nacl_irt/irt_manifest.h" | 12 #include "ppapi/nacl_irt/irt_manifest.h" |
| 12 #include "ppapi/nacl_irt/irt_ppapi.h" | 13 #include "ppapi/nacl_irt/irt_ppapi.h" |
| 13 #include "ppapi/nacl_irt/plugin_main.h" | 14 #include "ppapi/nacl_irt/plugin_main.h" |
| 14 #include "ppapi/nacl_irt/public/irt_ppapi.h" | 15 #include "ppapi/nacl_irt/public/irt_ppapi.h" |
| 15 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/irt_shim_ppapi.h" | 16 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/irt_shim_ppapi.h" |
| 16 | 17 |
| 17 static struct PP_StartFunctions g_pp_functions; | 18 static struct PP_StartFunctions g_pp_functions; |
| 18 | 19 |
| 19 int irt_ppapi_start(const struct PP_StartFunctions* funcs) { | 20 int irt_ppapi_start(const struct PP_StartFunctions* funcs) { |
| 21 #if !defined(OS_NACL_NONSFI) |
| 20 // Disable NaCl's open_resource() interface on this thread. | 22 // Disable NaCl's open_resource() interface on this thread. |
| 23 // TODO(hidehiko): This flag is no longer used because, even in SFI mode, |
| 24 // we switched from SRPC to Chrome IPC for open_resource() implementation. |
| 25 // Remove this flag. |
| 21 g_is_main_thread = 1; | 26 g_is_main_thread = 1; |
| 27 #endif |
| 22 | 28 |
| 23 g_pp_functions = *funcs; | 29 g_pp_functions = *funcs; |
| 24 return PpapiPluginMain(); | 30 return PpapiPluginMain(); |
| 25 } | 31 } |
| 26 | 32 |
| 27 int32_t PPP_InitializeModule(PP_Module module_id, | 33 int32_t PPP_InitializeModule(PP_Module module_id, |
| 28 PPB_GetInterface get_browser_interface) { | 34 PPB_GetInterface get_browser_interface) { |
| 29 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); | 35 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface); |
| 30 } | 36 } |
| 31 | 37 |
| 32 void PPP_ShutdownModule(void) { | 38 void PPP_ShutdownModule(void) { |
| 33 g_pp_functions.PPP_ShutdownModule(); | 39 g_pp_functions.PPP_ShutdownModule(); |
| 34 } | 40 } |
| 35 | 41 |
| 36 const void* PPP_GetInterface(const char* interface_name) { | 42 const void* PPP_GetInterface(const char* interface_name) { |
| 37 return g_pp_functions.PPP_GetInterface(interface_name); | 43 return g_pp_functions.PPP_GetInterface(interface_name); |
| 38 } | 44 } |
| 39 | 45 |
| 40 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = { | 46 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = { |
| 41 irt_ppapi_start, | 47 irt_ppapi_start, |
| 42 PpapiPluginRegisterThreadCreator, | 48 PpapiPluginRegisterThreadCreator, |
| 43 }; | 49 }; |
| 44 | 50 |
| 51 #if defined(OS_NACL_SFI) |
| 45 static int ppapihook_pnacl_private_filter(void) { | 52 static int ppapihook_pnacl_private_filter(void) { |
| 46 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); | 53 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); |
| 47 if (pnacl_mode == -1) | 54 if (pnacl_mode == -1) |
| 48 return 0; | 55 return 0; |
| 49 return pnacl_mode; | 56 return pnacl_mode; |
| 50 } | 57 } |
| 58 #endif |
| 51 | 59 |
| 52 static const nacl_irt_resource_open kIrtResourceOpen = { | 60 static const nacl_irt_resource_open kIrtResourceOpen = { |
| 53 ppapi::IrtOpenResource, | 61 ppapi::IrtOpenResource, |
| 54 }; | 62 }; |
| 55 | 63 |
| 64 #if defined(OS_NACL_SFI) |
| 56 static int not_pnacl_filter(void) { | 65 static int not_pnacl_filter(void) { |
| 57 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); | 66 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE); |
| 58 if (pnacl_mode == -1) | 67 if (pnacl_mode == -1) |
| 59 return 0; | 68 return 0; |
| 60 return !pnacl_mode; | 69 return !pnacl_mode; |
| 61 } | 70 } |
| 71 #endif |
| 62 | 72 |
| 63 static const struct nacl_irt_interface irt_interfaces[] = { | 73 static const struct nacl_irt_interface irt_interfaces[] = { |
| 64 { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook), | 74 { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook), |
| 65 NULL }, | 75 NULL }, |
| 76 #if defined(OS_NACL_SFI) |
| 66 { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1, | 77 { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1, |
| 67 &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private), | 78 &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private), |
| 68 ppapihook_pnacl_private_filter }, | 79 ppapihook_pnacl_private_filter }, |
| 80 #endif |
| 69 { NACL_IRT_RESOURCE_OPEN_v0_1, &kIrtResourceOpen, | 81 { NACL_IRT_RESOURCE_OPEN_v0_1, &kIrtResourceOpen, |
| 70 sizeof(kIrtResourceOpen), not_pnacl_filter }, | 82 sizeof(kIrtResourceOpen), |
| 83 #if defined(OS_NACL_SFI) |
| 84 not_pnacl_filter, |
| 85 #else |
| 86 // If we change PNaCl to use Non-SFI Mode on the open web, |
| 87 // we should add a filter here. |
| 88 NULL, |
| 89 #endif |
| 90 }, |
| 71 }; | 91 }; |
| 72 | 92 |
| 73 size_t chrome_irt_query(const char* interface_ident, | 93 size_t chrome_irt_query(const char* interface_ident, |
| 74 void* table, size_t tablesize) { | 94 void* table, size_t tablesize) { |
| 75 size_t result = nacl_irt_query_list(interface_ident, | 95 size_t result = nacl_irt_query_list(interface_ident, |
| 76 table, | 96 table, |
| 77 tablesize, | 97 tablesize, |
| 78 irt_interfaces, | 98 irt_interfaces, |
| 79 sizeof(irt_interfaces)); | 99 sizeof(irt_interfaces)); |
| 80 if (result != 0) | 100 if (result != 0) |
| 81 return result; | 101 return result; |
| 82 return nacl_irt_query_core(interface_ident, table, tablesize); | 102 return nacl_irt_query_core(interface_ident, table, tablesize); |
| 83 } | 103 } |
| OLD | NEW |