Move implementation of load methods to chromium layer
[chromium-blink-merge.git] / ppapi / nacl_irt / irt_ppapi.cc
bloba298a232b12c67a65413430850268f3097c08365
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 "mojo/nacl/mojo_irt.h"
9 #include "native_client/src/public/irt_core.h"
10 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
11 #include "native_client/src/untrusted/irt/irt.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 g_pp_functions = *funcs;
22 return PpapiPluginMain();
25 int32_t PPP_InitializeModule(PP_Module module_id,
26 PPB_GetInterface get_browser_interface) {
27 return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface);
30 void PPP_ShutdownModule(void) {
31 g_pp_functions.PPP_ShutdownModule();
34 const void* PPP_GetInterface(const char* interface_name) {
35 return g_pp_functions.PPP_GetInterface(interface_name);
38 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = {
39 irt_ppapi_start,
40 PpapiPluginRegisterThreadCreator,
43 #if defined(OS_NACL_SFI)
44 static int ppapihook_pnacl_private_filter(void) {
45 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE);
46 if (pnacl_mode == -1)
47 return 0;
48 return pnacl_mode;
50 #endif
52 static const nacl_irt_resource_open kIrtResourceOpen = {
53 ppapi::IrtOpenResource,
56 #if defined(OS_NACL_SFI)
57 static int not_pnacl_filter(void) {
58 int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE);
59 if (pnacl_mode == -1)
60 return 0;
61 return !pnacl_mode;
63 #endif
65 static const struct nacl_irt_interface irt_interfaces[] = {
66 { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook),
67 NULL },
68 #if defined(OS_NACL_SFI)
69 { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1,
70 &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private),
71 ppapihook_pnacl_private_filter },
72 #endif
73 { NACL_IRT_RESOURCE_OPEN_v0_1, &kIrtResourceOpen,
74 sizeof(kIrtResourceOpen),
75 #if defined(OS_NACL_SFI)
76 not_pnacl_filter,
77 #else
78 // If we change PNaCl to use Non-SFI Mode on the open web,
79 // we should add a filter here.
80 NULL,
81 #endif
85 size_t chrome_irt_query(const char* interface_ident,
86 void* table, size_t tablesize) {
87 size_t result = nacl_irt_query_list(interface_ident,
88 table,
89 tablesize,
90 irt_interfaces,
91 sizeof(irt_interfaces));
92 if (result != 0)
93 return result;
95 #if defined(OS_NACL_SFI)
96 result = mojo_irt_query(interface_ident, table, tablesize);
97 if (result != 0)
98 return result;
99 #endif
101 return nacl_irt_query_core(interface_ident, table, tablesize);