OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "components/nacl/common/nacl_messages.h" | 19 #include "components/nacl/common/nacl_messages.h" |
20 #include "components/nacl/loader/nacl_ipc_adapter.h" | 20 #include "components/nacl/loader/nacl_ipc_adapter.h" |
| 21 #include "components/nacl/loader/nacl_trusted_listener.h" |
21 #include "components/nacl/loader/nacl_validation_db.h" | 22 #include "components/nacl/loader/nacl_validation_db.h" |
22 #include "components/nacl/loader/nacl_validation_query.h" | 23 #include "components/nacl/loader/nacl_validation_query.h" |
23 #include "ipc/ipc_channel_handle.h" | 24 #include "ipc/ipc_channel_handle.h" |
24 #include "ipc/ipc_switches.h" | 25 #include "ipc/ipc_switches.h" |
25 #include "ipc/ipc_sync_channel.h" | 26 #include "ipc/ipc_sync_channel.h" |
26 #include "ipc/ipc_sync_message_filter.h" | 27 #include "ipc/ipc_sync_message_filter.h" |
27 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" | 28 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" |
28 #include "native_client/src/trusted/validator/nacl_file_info.h" | 29 #include "native_client/src/trusted/validator/nacl_file_info.h" |
29 | 30 |
30 #if defined(OS_POSIX) | 31 #if defined(OS_POSIX) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 170 } |
170 | 171 |
171 private: | 172 private: |
172 // The listener never dies, otherwise this might be a dangling reference. | 173 // The listener never dies, otherwise this might be a dangling reference. |
173 NaClListener* listener_; | 174 NaClListener* listener_; |
174 }; | 175 }; |
175 | 176 |
176 | 177 |
177 NaClListener::NaClListener() : shutdown_event_(true, false), | 178 NaClListener::NaClListener() : shutdown_event_(true, false), |
178 io_thread_("NaCl_IOThread"), | 179 io_thread_("NaCl_IOThread"), |
| 180 chrome_main_thread_("NaCl_ChromeMainThread"), |
179 #if defined(OS_LINUX) | 181 #if defined(OS_LINUX) |
180 prereserved_sandbox_size_(0), | 182 prereserved_sandbox_size_(0), |
181 #endif | 183 #endif |
182 #if defined(OS_POSIX) | 184 #if defined(OS_POSIX) |
183 number_of_cores_(-1), // unknown/error | 185 number_of_cores_(-1), // unknown/error |
184 #endif | 186 #endif |
185 main_loop_(NULL) { | 187 main_loop_(NULL) { |
186 io_thread_.StartWithOptions( | 188 io_thread_.StartWithOptions( |
187 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 189 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 190 chrome_main_thread_.StartWithOptions( |
| 191 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
188 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
189 DCHECK(g_listener == NULL); | 193 DCHECK(g_listener == NULL); |
190 g_listener = this; | 194 g_listener = this; |
191 #endif | 195 #endif |
192 } | 196 } |
193 | 197 |
194 NaClListener::~NaClListener() { | 198 NaClListener::~NaClListener() { |
195 NOTREACHED(); | 199 NOTREACHED(); |
196 shutdown_event_.Signal(); | 200 shutdown_event_.Signal(); |
197 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
(...skipping 28 matching lines...) Expand all Loading... |
226 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 230 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
227 bool handled = true; | 231 bool handled = true; |
228 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 232 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
229 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 233 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
230 IPC_MESSAGE_UNHANDLED(handled = false) | 234 IPC_MESSAGE_UNHANDLED(handled = false) |
231 IPC_END_MESSAGE_MAP() | 235 IPC_END_MESSAGE_MAP() |
232 return handled; | 236 return handled; |
233 } | 237 } |
234 | 238 |
235 void NaClListener::OnStart(const nacl::NaClStartParams& params) { | 239 void NaClListener::OnStart(const nacl::NaClStartParams& params) { |
| 240 // DCHECK(trusted_plugin_channel_created_); |
236 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); | 241 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); |
237 if (args == NULL) { | 242 if (args == NULL) { |
238 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 243 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
239 return; | 244 return; |
240 } | 245 } |
241 | 246 |
242 if (params.enable_ipc_proxy) { | 247 if (params.enable_ipc_proxy) { |
243 // Create the initial PPAPI IPC channel between the NaCl IRT and the | 248 // Create the initial PPAPI IPC channel between the NaCl IRT and the |
244 // browser process. The IRT uses this channel to communicate with the | 249 // browser process. The IRT uses this channel to communicate with the |
245 // browser and to create additional IPC channels to renderer processes. | 250 // browser and to create additional IPC channels to renderer processes. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 params.debug_stub_server_bound_socket); | 331 params.debug_stub_server_bound_socket); |
327 #endif | 332 #endif |
328 #if defined(OS_WIN) | 333 #if defined(OS_WIN) |
329 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 334 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
330 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 335 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
331 #endif | 336 #endif |
332 #if defined(OS_LINUX) | 337 #if defined(OS_LINUX) |
333 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 338 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
334 #endif | 339 #endif |
335 | 340 |
| 341 // FIXME: Handle nonsfi. |
336 #if defined(OS_LINUX) | 342 #if defined(OS_LINUX) |
337 if (params.enable_nonsfi_mode) { | 343 if (params.enable_nonsfi_mode) { |
338 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); | 344 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); |
339 NOTREACHED(); | 345 NOTREACHED(); |
340 return; | 346 return; |
341 } | 347 } |
342 #endif | 348 #endif |
343 NaClChromeMainStart(args); | 349 |
344 NOTREACHED(); | 350 int irt_fd = args->irt_fd; |
| 351 struct NaClApp* nap = NaClChromeMainCreateApp(args); |
| 352 CreateTrustedPluginChannel(nap, irt_fd); |
345 } | 353 } |
| 354 |
| 355 void NaClListener::CreateTrustedPluginChannel(struct NaClApp* nap, int irt_fd) { |
| 356 fprintf(stderr, "NaClListener::OnCreateTrustedPluginChannel\n"); |
| 357 IPC::ChannelHandle handle = |
| 358 IPC::Channel::GenerateVerifiedChannelID("nacl_trusted"); |
| 359 trusted_listener_ = new NaClTrustedListener( |
| 360 handle, nap, irt_fd, io_thread_.message_loop_proxy().get(), |
| 361 &shutdown_event_); |
| 362 #if defined(OS_POSIX) |
| 363 handle.socket = base::FileDescriptor( |
| 364 trusted_listener_->TakeClientFileDescriptor(), true); |
| 365 #endif |
| 366 if (!Send(new NaClProcessHostMsg_TrustedPluginChannelCreated(handle))) |
| 367 LOG(ERROR) << "Failed to send trusted plugin IPC channel handle " |
| 368 << "to NaClProcessHost."; |
| 369 } |
OLD | NEW |