OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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. |
| 4 |
| 5 #include <sys/nacl_imc_api.h> |
| 6 #include <sys/nacl_syscalls.h> |
| 7 |
| 8 #include "native_client/src/shared/platform/nacl_check.h" |
| 9 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| 10 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_core.h" |
| 11 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" |
| 12 #include "native_client/src/shared/ppapi_proxy/ppruntime.h" |
| 13 #include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h" |
| 14 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 15 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 16 |
| 17 |
| 18 #define NACL_SEND_FD 6 |
| 19 |
| 20 namespace { |
| 21 |
| 22 NaClSrpcChannel* main_srpc_channel; |
| 23 NaClSrpcChannel* upcall_srpc_channel; |
| 24 PP_Module module_id_for_plugin; |
| 25 struct PP_ThreadFunctions thread_funcs; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace ppapi_proxy { |
| 30 |
| 31 const PP_Resource kInvalidResourceId = 0; |
| 32 |
| 33 NaClSrpcChannel* GetMainSrpcChannel() { |
| 34 return main_srpc_channel; |
| 35 } |
| 36 |
| 37 void SetMainSrpcChannel(NaClSrpcChannel* channel) { |
| 38 main_srpc_channel = channel; |
| 39 } |
| 40 |
| 41 NaClSrpcChannel* GetUpcallSrpcChannel() { |
| 42 return upcall_srpc_channel; |
| 43 } |
| 44 |
| 45 void SetUpcallSrpcChannel(NaClSrpcChannel* channel) { |
| 46 upcall_srpc_channel = channel; |
| 47 } |
| 48 |
| 49 void SetModuleIdForSrpcChannel(NaClSrpcChannel* channel, PP_Module module_id) { |
| 50 module_id_for_plugin = module_id; |
| 51 } |
| 52 |
| 53 void UnsetModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
| 54 const PP_Module kInvalidModuleId = 0; |
| 55 module_id_for_plugin = kInvalidModuleId; |
| 56 } |
| 57 |
| 58 PP_Module LookupModuleIdForSrpcChannel(NaClSrpcChannel* channel) { |
| 59 return module_id_for_plugin; |
| 60 } |
| 61 |
| 62 const struct PP_ThreadFunctions* GetThreadCreator() { |
| 63 return &thread_funcs; |
| 64 } |
| 65 |
| 66 // Browser interface helpers |
| 67 |
| 68 const void* GetBrowserInterfaceSafe(const char* interface_name) { |
| 69 const void* ppb_interface = GetBrowserInterface(interface_name); |
| 70 if (ppb_interface == NULL) |
| 71 DebugPrintf("PPB_GetInterface: %s not found\n", interface_name); |
| 72 CHECK(ppb_interface != NULL); |
| 73 return ppb_interface; |
| 74 } |
| 75 |
| 76 const PPB_Core* PPBCoreInterface() { |
| 77 return static_cast<const PPB_Core*>( |
| 78 GetBrowserInterfaceSafe(PPB_CORE_INTERFACE)); |
| 79 } |
| 80 |
| 81 const PPB_Memory_Dev* PPBMemoryInterface() { |
| 82 return static_cast<const PPB_Memory_Dev*>( |
| 83 GetBrowserInterfaceSafe(PPB_MEMORY_DEV_INTERFACE)); |
| 84 } |
| 85 |
| 86 const PPB_Var* PPBVarInterface() { |
| 87 return static_cast<const PPB_Var*>( |
| 88 GetBrowserInterfaceSafe(PPB_VAR_INTERFACE)); |
| 89 } |
| 90 |
| 91 // Plugin interface helpers |
| 92 |
| 93 const void* GetPluginInterface(const char* interface_name) { |
| 94 return ::PPP_GetInterface(interface_name); |
| 95 } |
| 96 |
| 97 const void* GetPluginInterfaceSafe(const char* interface_name) { |
| 98 const void* ppp_interface = GetPluginInterface(interface_name); |
| 99 if (ppp_interface == NULL) |
| 100 DebugPrintf("PPP_GetInterface: %s not found\n", interface_name); |
| 101 CHECK(ppp_interface != NULL); |
| 102 return ppp_interface; |
| 103 } |
| 104 |
| 105 const PPP_Find_Dev* PPPFindInterface() { |
| 106 static const void* ppp = GetPluginInterfaceSafe(PPP_FIND_DEV_INTERFACE); |
| 107 return static_cast<const PPP_Find_Dev*>(ppp); |
| 108 } |
| 109 |
| 110 const PPP_InputEvent* PPPInputEventInterface() { |
| 111 static const void* ppp = GetPluginInterfaceSafe(PPP_INPUT_EVENT_INTERFACE); |
| 112 return static_cast<const PPP_InputEvent*>(ppp); |
| 113 } |
| 114 |
| 115 const PPP_Instance* PPPInstanceInterface() { |
| 116 static const void* ppp = GetPluginInterfaceSafe(PPP_INSTANCE_INTERFACE); |
| 117 return static_cast<const PPP_Instance*>(ppp); |
| 118 } |
| 119 |
| 120 const PPP_Messaging* PPPMessagingInterface() { |
| 121 static const void* ppp = GetPluginInterfaceSafe(PPP_MESSAGING_INTERFACE); |
| 122 return static_cast<const PPP_Messaging*>(ppp); |
| 123 } |
| 124 |
| 125 const PPP_Printing_Dev* PPPPrintingInterface() { |
| 126 static const void* ppp = GetPluginInterfaceSafe(PPP_PRINTING_DEV_INTERFACE); |
| 127 return static_cast<const PPP_Printing_Dev*>(ppp); |
| 128 } |
| 129 |
| 130 const PPP_Scrollbar_Dev* PPPScrollbarInterface() { |
| 131 static const void* ppp = GetPluginInterfaceSafe(PPP_SCROLLBAR_DEV_INTERFACE); |
| 132 return static_cast<const PPP_Scrollbar_Dev*>(ppp); |
| 133 } |
| 134 |
| 135 const PPP_Selection_Dev* PPPSelectionInterface() { |
| 136 static const void* ppp = GetPluginInterfaceSafe(PPP_SELECTION_DEV_INTERFACE); |
| 137 return static_cast<const PPP_Selection_Dev*>(ppp); |
| 138 } |
| 139 |
| 140 const PPP_Widget_Dev* PPPWidgetInterface() { |
| 141 static const void* ppp = GetPluginInterfaceSafe(PPP_WIDGET_DEV_INTERFACE); |
| 142 return static_cast<const PPP_Widget_Dev*>(ppp); |
| 143 } |
| 144 |
| 145 const PPP_Zoom_Dev* PPPZoomInterface() { |
| 146 static const void* ppp = GetPluginInterfaceSafe(PPP_ZOOM_DEV_INTERFACE); |
| 147 return static_cast<const PPP_Zoom_Dev*>(ppp); |
| 148 } |
| 149 |
| 150 |
| 151 } // namespace ppapi_proxy |
| 152 |
| 153 void PpapiPluginRegisterThreadCreator( |
| 154 const struct PP_ThreadFunctions* new_funcs) { |
| 155 thread_funcs = *new_funcs; |
| 156 } |
| 157 |
| 158 int IrtInit() { |
| 159 // TODO(halyavin): this is needed for tests without IRT. They do not start |
| 160 // in irt_entry.c where IrtInit is called. |
| 161 static int initialized = 0; |
| 162 if (initialized) { |
| 163 return 0; |
| 164 } |
| 165 if (!NaClSrpcModuleInit()) { |
| 166 return 1; |
| 167 } |
| 168 NaClLogModuleInit(); // Enable NaClLog'ing used by CHECK(). |
| 169 initialized = 1; |
| 170 return 0; |
| 171 } |
| 172 |
| 173 int PpapiPluginMain() { |
| 174 IrtInit(); |
| 175 PpapiPluginRegisterDefaultThreadCreator(); |
| 176 // Designate this as the main thread for PPB_Core::IsMainThread(). |
| 177 ppapi_proxy::PluginCore::MarkMainThread(); |
| 178 if (!NaClSrpcAcceptClientConnection(PppRpcs::srpc_methods)) { |
| 179 return 1; |
| 180 } |
| 181 NaClSrpcModuleFini(); |
| 182 |
| 183 return 0; |
| 184 } |
OLD | NEW |