[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / ppapi / nacl_irt / irt_ppapi.cc
blobce17f8a1ef5de9e33be84f49c61aa3e523b5d660
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
3 // found in the LICENSE file.
5 #include <unistd.h>
7 #include "build/build_config.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 "native_client/src/untrusted/irt/irt_private.h"
12 #include "ppapi/nacl_irt/irt_manifest.h"
13 #include "ppapi/nacl_irt/irt_ppapi.h"
14 #include "ppapi/nacl_irt/plugin_main.h"
15 #include "ppapi/nacl_irt/public/irt_ppapi.h"
16 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/irt_shim_ppapi.h"
18 static struct PP_StartFunctions g_pp_functions;
20 int irt_ppapi_start(const struct PP_StartFunctions* funcs) {
21 #if !defined(OS_NACL_NONSFI)
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.
26 g_is_main_thread = 1;
27 #endif
29 g_pp_functions = *funcs;
30 return PpapiPluginMain();
33 int32_t PPP_InitializeModule(PP_Module module_id,
34 PPB_GetInterface get_browser_interface) {
35 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface);
38 void PPP_ShutdownModule(void) {
39 g_pp_functions.PPP_ShutdownModule();
42 const void* PPP_GetInterface(const char* interface_name) {
43 return g_pp_functions.PPP_GetInterface(interface_name);
46 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = {
47 irt_ppapi_start,
48 PpapiPluginRegisterThreadCreator,
51 #if defined(OS_NACL_SFI)
52 static int ppapihook_pnacl_private_filter(void) {
53 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE);
54 if (pnacl_mode == -1)
55 return 0;
56 return pnacl_mode;
58 #endif
60 static const nacl_irt_resource_open kIrtResourceOpen = {
61 ppapi::IrtOpenResource,
64 #if defined(OS_NACL_SFI)
65 static int not_pnacl_filter(void) {
66 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE);
67 if (pnacl_mode == -1)
68 return 0;
69 return !pnacl_mode;
71 #endif
73 static const struct nacl_irt_interface irt_interfaces[] = {
74 { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook),
75 NULL },
76 #if defined(OS_NACL_SFI)
77 { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1,
78 &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private),
79 ppapihook_pnacl_private_filter },
80 #endif
81 { NACL_IRT_RESOURCE_OPEN_v0_1, &kIrtResourceOpen,
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
93 size_t chrome_irt_query(const char* interface_ident,
94 void* table, size_t tablesize) {
95 size_t result = nacl_irt_query_list(interface_ident,
96 table,
97 tablesize,
98 irt_interfaces,
99 sizeof(irt_interfaces));
100 if (result != 0)
101 return result;
102 return nacl_irt_query_core(interface_ident, table, tablesize);