| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/nacl/nacl_listener.h" | 5 #include "chrome/nacl/nacl_listener.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "chrome/common/nacl_messages.h" | 14 #include "chrome/common/nacl_messages.h" |
| 15 #include "chrome/nacl/nacl_validation_db.h" | 15 #include "chrome/nacl/nacl_validation_db.h" |
| 16 #include "chrome/nacl/nacl_validation_query.h" | 16 #include "chrome/nacl/nacl_validation_query.h" |
| 17 #include "ipc/ipc_channel_handle.h" |
| 18 #include "ipc/ipc_switches.h" |
| 17 #include "ipc/ipc_sync_channel.h" | 19 #include "ipc/ipc_sync_channel.h" |
| 18 #include "ipc/ipc_sync_message_filter.h" | 20 #include "ipc/ipc_sync_message_filter.h" |
| 19 #include "ipc/ipc_switches.h" | |
| 20 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" | 21 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" |
| 21 | 22 |
| 22 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
| 23 #include "content/public/common/child_process_sandbox_support_linux.h" | 24 #include "content/public/common/child_process_sandbox_support_linux.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 #include <fcntl.h> | 28 #include <fcntl.h> |
| 28 #include <io.h> | 29 #include <io.h> |
| 29 | 30 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 136 |
| 136 private: | 137 private: |
| 137 // The listener never dies, otherwise this might be a dangling reference. | 138 // The listener never dies, otherwise this might be a dangling reference. |
| 138 NaClListener* listener_; | 139 NaClListener* listener_; |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 | 142 |
| 142 NaClListener::NaClListener() : shutdown_event_(true, false), | 143 NaClListener::NaClListener() : shutdown_event_(true, false), |
| 143 io_thread_("NaCl_IOThread"), | 144 io_thread_("NaCl_IOThread"), |
| 144 main_loop_(NULL), | 145 main_loop_(NULL), |
| 146 nacl_ppapi_channel_(NULL), |
| 145 debug_enabled_(false) { | 147 debug_enabled_(false) { |
| 146 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 148 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
| 149 nacl_ipc_manager_.Init(io_thread_.message_loop_proxy()); |
| 147 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
| 148 DCHECK(g_listener == NULL); | 151 DCHECK(g_listener == NULL); |
| 149 g_listener = this; | 152 g_listener = this; |
| 150 #endif | 153 #endif |
| 151 } | 154 } |
| 152 | 155 |
| 153 NaClListener::~NaClListener() { | 156 NaClListener::~NaClListener() { |
| 154 NOTREACHED(); | 157 NOTREACHED(); |
| 155 shutdown_event_.Signal(); | 158 shutdown_event_.Signal(); |
| 156 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return handled; | 194 return handled; |
| 192 } | 195 } |
| 193 | 196 |
| 194 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { | 197 void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { |
| 195 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); | 198 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); |
| 196 if (args == NULL) { | 199 if (args == NULL) { |
| 197 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 200 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
| 198 return; | 201 return; |
| 199 } | 202 } |
| 200 | 203 |
| 204 // Create the server side of the channel and notify the process host so it |
| 205 // can reply to the renderer, which will then try to connect as client. |
| 206 IPC::ChannelHandle channel_handle = |
| 207 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
| 208 nacl_ppapi_channel_ = nacl_ipc_manager_.CreateChannel(channel_handle); |
| 209 |
| 210 Send(new NaClProcessHostMsg_PpapiChannelCreated(channel_handle)); |
| 211 |
| 201 std::vector<nacl::FileDescriptor> handles = params.handles; | 212 std::vector<nacl::FileDescriptor> handles = params.handles; |
| 202 | 213 |
| 203 #if defined(OS_LINUX) || defined(OS_MACOSX) | 214 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 204 args->create_memory_object_func = CreateMemoryObject; | 215 args->create_memory_object_func = CreateMemoryObject; |
| 205 # if defined(OS_MACOSX) | 216 # if defined(OS_MACOSX) |
| 206 CHECK(handles.size() >= 1); | 217 CHECK(handles.size() >= 1); |
| 207 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); | 218 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); |
| 208 handles.pop_back(); | 219 handles.pop_back(); |
| 209 # endif | 220 # endif |
| 210 #endif | 221 #endif |
| (...skipping 25 matching lines...) Expand all Loading... |
| 236 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); | 247 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); |
| 237 args->enable_exception_handling = params.enable_exception_handling; | 248 args->enable_exception_handling = params.enable_exception_handling; |
| 238 args->enable_debug_stub = debug_enabled_; | 249 args->enable_debug_stub = debug_enabled_; |
| 239 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 240 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 251 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
| 241 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 252 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
| 242 #endif | 253 #endif |
| 243 NaClChromeMainStart(args); | 254 NaClChromeMainStart(args); |
| 244 NOTREACHED(); | 255 NOTREACHED(); |
| 245 } | 256 } |
| OLD | NEW |