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) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // Fall back to NaCl's default implementation. | 77 // Fall back to NaCl's default implementation. |
78 return -1; | 78 return -1; |
79 } | 79 } |
80 | 80 |
81 #elif defined(OS_LINUX) | 81 #elif defined(OS_LINUX) |
82 | 82 |
83 int CreateMemoryObject(size_t size, int executable) { | 83 int CreateMemoryObject(size_t size, int executable) { |
84 return content::MakeSharedMemorySegmentViaIPC(size, executable); | 84 return content::MakeSharedMemorySegmentViaIPC(size, executable); |
85 } | 85 } |
86 | 86 |
87 NaClListener* g_listener; | |
Mark Seaborn
2014/03/26 23:34:04
Shouldn't this be unconditional? Doesn't look lik
bradn
2014/05/05 18:46:07
Oops. Done. Not sure why it ended up like that.
| |
88 | |
87 #elif defined(OS_WIN) | 89 #elif defined(OS_WIN) |
88 | 90 |
89 NaClListener* g_listener; | |
90 | |
91 // We wrap the function to convert the bool return value to an int. | 91 // We wrap the function to convert the bool return value to an int. |
92 int BrokerDuplicateHandle(NaClHandle source_handle, | 92 int BrokerDuplicateHandle(NaClHandle source_handle, |
93 uint32_t process_id, | 93 uint32_t process_id, |
94 NaClHandle* target_handle, | 94 NaClHandle* target_handle, |
95 uint32_t desired_access, | 95 uint32_t desired_access, |
96 uint32_t options) { | 96 uint32_t options) { |
97 return content::BrokerDuplicateHandle(source_handle, process_id, | 97 return content::BrokerDuplicateHandle(source_handle, process_id, |
98 target_handle, desired_access, | 98 target_handle, desired_access, |
99 options); | 99 options); |
100 } | 100 } |
101 | 101 |
102 int AttachDebugExceptionHandler(const void* info, size_t info_size) { | 102 int AttachDebugExceptionHandler(const void* info, size_t info_size) { |
103 std::string info_string(reinterpret_cast<const char*>(info), info_size); | 103 std::string info_string(reinterpret_cast<const char*>(info), info_size); |
104 bool result = false; | 104 bool result = false; |
105 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( | 105 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( |
106 info_string, &result))) | 106 info_string, &result))) |
107 return false; | 107 return false; |
108 return result; | 108 return result; |
109 } | 109 } |
110 | 110 |
111 #endif | 111 #endif |
112 | 112 |
113 void DebugStubPortSelectedHandler(uint16_t port) { | |
114 g_listener->Send(new NaClProcessHostMsg_DebugStubPortSelected(port)); | |
115 } | |
116 | |
113 // Creates the PPAPI IPC channel between the NaCl IRT and the host | 117 // Creates the PPAPI IPC channel between the NaCl IRT and the host |
114 // (browser/renderer) process, and starts to listen it on the thread where | 118 // (browser/renderer) process, and starts to listen it on the thread where |
115 // the given message_loop_proxy runs. | 119 // the given message_loop_proxy runs. |
116 // Also, creates and sets the corresponding NaClDesc to the given nap with | 120 // Also, creates and sets the corresponding NaClDesc to the given nap with |
117 // the FD #. | 121 // the FD #. |
118 void SetUpIPCAdapter(IPC::ChannelHandle* handle, | 122 void SetUpIPCAdapter(IPC::ChannelHandle* handle, |
119 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 123 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
120 struct NaClApp* nap, | 124 struct NaClApp* nap, |
121 int nacl_fd) { | 125 int nacl_fd) { |
122 scoped_refptr<NaClIPCAdapter> ipc_adapter( | 126 scoped_refptr<NaClIPCAdapter> ipc_adapter( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 io_thread_("NaCl_IOThread"), | 206 io_thread_("NaCl_IOThread"), |
203 #if defined(OS_LINUX) | 207 #if defined(OS_LINUX) |
204 prereserved_sandbox_size_(0), | 208 prereserved_sandbox_size_(0), |
205 #endif | 209 #endif |
206 #if defined(OS_POSIX) | 210 #if defined(OS_POSIX) |
207 number_of_cores_(-1), // unknown/error | 211 number_of_cores_(-1), // unknown/error |
208 #endif | 212 #endif |
209 main_loop_(NULL) { | 213 main_loop_(NULL) { |
210 io_thread_.StartWithOptions( | 214 io_thread_.StartWithOptions( |
211 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 215 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
212 #if defined(OS_WIN) | |
213 DCHECK(g_listener == NULL); | 216 DCHECK(g_listener == NULL); |
214 g_listener = this; | 217 g_listener = this; |
215 #endif | |
216 } | 218 } |
217 | 219 |
218 NaClListener::~NaClListener() { | 220 NaClListener::~NaClListener() { |
219 NOTREACHED(); | 221 NOTREACHED(); |
220 shutdown_event_.Signal(); | 222 shutdown_event_.Signal(); |
221 #if defined(OS_WIN) | |
222 g_listener = NULL; | 223 g_listener = NULL; |
223 #endif | |
224 } | 224 } |
225 | 225 |
226 bool NaClListener::Send(IPC::Message* msg) { | 226 bool NaClListener::Send(IPC::Message* msg) { |
227 DCHECK(main_loop_ != NULL); | 227 DCHECK(main_loop_ != NULL); |
228 if (base::MessageLoop::current() == main_loop_) { | 228 if (base::MessageLoop::current() == main_loop_) { |
229 // This thread owns the channel. | 229 // This thread owns the channel. |
230 return channel_->Send(msg); | 230 return channel_->Send(msg); |
231 } else { | 231 } else { |
232 // This thread does not own the channel. | 232 // This thread does not own the channel. |
233 return filter_->Send(msg); | 233 return filter_->Send(msg); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 405 |
406 // Indicate that this is a PNaCl module. | 406 // Indicate that this is a PNaCl module. |
407 // TODO(jvoung): Plumb through something indicating that this is PNaCl | 407 // TODO(jvoung): Plumb through something indicating that this is PNaCl |
408 // instead of relying on enable_dyncode_syscalls. | 408 // instead of relying on enable_dyncode_syscalls. |
409 args->pnacl_mode = 1; | 409 args->pnacl_mode = 1; |
410 } | 410 } |
411 #if defined(OS_LINUX) || defined(OS_MACOSX) | 411 #if defined(OS_LINUX) || defined(OS_MACOSX) |
412 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( | 412 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( |
413 params.debug_stub_server_bound_socket); | 413 params.debug_stub_server_bound_socket); |
414 #endif | 414 #endif |
415 args->debug_stub_server_port_selected_handler_func = | |
416 DebugStubPortSelectedHandler; | |
415 #if defined(OS_WIN) | 417 #if defined(OS_WIN) |
416 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 418 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
417 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 419 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
418 #endif | 420 #endif |
419 #if defined(OS_LINUX) | 421 #if defined(OS_LINUX) |
420 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 422 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
421 #endif | 423 #endif |
422 | 424 |
423 #if defined(OS_LINUX) | 425 #if defined(OS_LINUX) |
424 if (params.uses_nonsfi_mode) { | 426 if (params.uses_nonsfi_mode) { |
425 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); | 427 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); |
426 return; | 428 return; |
427 } | 429 } |
428 #endif | 430 #endif |
429 NaClChromeMainStartApp(nap, args); | 431 NaClChromeMainStartApp(nap, args); |
430 NOTREACHED(); | 432 NOTREACHED(); |
431 } | 433 } |
OLD | NEW |