Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 43 #include <fcntl.h> | 43 #include <fcntl.h> |
| 44 #include <io.h> | 44 #include <io.h> |
| 45 | 45 |
| 46 #include "content/public/common/sandbox_init.h" | 46 #include "content/public/common/sandbox_init.h" |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | |
| 51 NaClListener* g_listener; | |
| 52 | |
| 50 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
| 51 | 54 |
| 52 // On Mac OS X, shm_open() works in the sandbox but does not give us | 55 // On Mac OS X, shm_open() works in the sandbox but does not give us |
| 53 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to | 56 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to |
| 54 // get an executable SHM region when CreateMemoryObject() is called, | 57 // get an executable SHM region when CreateMemoryObject() is called, |
| 55 // we preallocate one on startup, since NaCl's sel_ldr only needs one | 58 // we preallocate one on startup, since NaCl's sel_ldr only needs one |
| 56 // of them. This saves a round trip. | 59 // of them. This saves a round trip. |
| 57 | 60 |
| 58 base::subtle::Atomic32 g_shm_fd = -1; | 61 base::subtle::Atomic32 g_shm_fd = -1; |
| 59 | 62 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 80 } | 83 } |
| 81 | 84 |
| 82 #elif defined(OS_LINUX) | 85 #elif defined(OS_LINUX) |
| 83 | 86 |
| 84 int CreateMemoryObject(size_t size, int executable) { | 87 int CreateMemoryObject(size_t size, int executable) { |
| 85 return content::MakeSharedMemorySegmentViaIPC(size, executable); | 88 return content::MakeSharedMemorySegmentViaIPC(size, executable); |
| 86 } | 89 } |
| 87 | 90 |
| 88 #elif defined(OS_WIN) | 91 #elif defined(OS_WIN) |
| 89 | 92 |
| 90 NaClListener* g_listener; | |
|
Mark Seaborn
2014/05/08 15:52:23
This should stay conditional on OS_WIN.
bradn
2014/05/08 17:00:24
Er, ok, back again...
| |
| 91 | |
| 92 // We wrap the function to convert the bool return value to an int. | 93 // We wrap the function to convert the bool return value to an int. |
| 93 int BrokerDuplicateHandle(NaClHandle source_handle, | 94 int BrokerDuplicateHandle(NaClHandle source_handle, |
| 94 uint32_t process_id, | 95 uint32_t process_id, |
| 95 NaClHandle* target_handle, | 96 NaClHandle* target_handle, |
| 96 uint32_t desired_access, | 97 uint32_t desired_access, |
| 97 uint32_t options) { | 98 uint32_t options) { |
| 98 return content::BrokerDuplicateHandle(source_handle, process_id, | 99 return content::BrokerDuplicateHandle(source_handle, process_id, |
| 99 target_handle, desired_access, | 100 target_handle, desired_access, |
| 100 options); | 101 options); |
| 101 } | 102 } |
| 102 | 103 |
| 103 int AttachDebugExceptionHandler(const void* info, size_t info_size) { | 104 int AttachDebugExceptionHandler(const void* info, size_t info_size) { |
| 104 std::string info_string(reinterpret_cast<const char*>(info), info_size); | 105 std::string info_string(reinterpret_cast<const char*>(info), info_size); |
| 105 bool result = false; | 106 bool result = false; |
| 106 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( | 107 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( |
| 107 info_string, &result))) | 108 info_string, &result))) |
| 108 return false; | 109 return false; |
| 109 return result; | 110 return result; |
| 110 } | 111 } |
| 111 | 112 |
| 112 #endif | 113 #endif |
| 113 | 114 |
| 115 void DebugStubPortSelectedHandler(uint16_t port) { | |
|
Mark Seaborn
2014/05/08 15:52:23
Also only needed on OS_WIN.
Currently you have we
bradn
2014/05/08 17:00:24
You've flip flopped here, in the previous version
Mark Seaborn
2014/05/08 18:04:44
To be fair, you sent me a change that didn't compi
| |
| 116 g_listener->Send(new NaClProcessHostMsg_DebugStubPortSelected(port)); | |
| 117 } | |
| 118 | |
| 114 // Creates the PPAPI IPC channel between the NaCl IRT and the host | 119 // Creates the PPAPI IPC channel between the NaCl IRT and the host |
| 115 // (browser/renderer) process, and starts to listen it on the thread where | 120 // (browser/renderer) process, and starts to listen it on the thread where |
| 116 // the given message_loop_proxy runs. | 121 // the given message_loop_proxy runs. |
| 117 // Also, creates and sets the corresponding NaClDesc to the given nap with | 122 // Also, creates and sets the corresponding NaClDesc to the given nap with |
| 118 // the FD #. | 123 // the FD #. |
| 119 void SetUpIPCAdapter(IPC::ChannelHandle* handle, | 124 void SetUpIPCAdapter(IPC::ChannelHandle* handle, |
| 120 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 125 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 121 struct NaClApp* nap, | 126 struct NaClApp* nap, |
| 122 int nacl_fd) { | 127 int nacl_fd) { |
| 123 scoped_refptr<NaClIPCAdapter> ipc_adapter( | 128 scoped_refptr<NaClIPCAdapter> ipc_adapter( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 uses_nonsfi_mode_(false), | 209 uses_nonsfi_mode_(false), |
| 205 #if defined(OS_LINUX) | 210 #if defined(OS_LINUX) |
| 206 prereserved_sandbox_size_(0), | 211 prereserved_sandbox_size_(0), |
| 207 #endif | 212 #endif |
| 208 #if defined(OS_POSIX) | 213 #if defined(OS_POSIX) |
| 209 number_of_cores_(-1), // unknown/error | 214 number_of_cores_(-1), // unknown/error |
| 210 #endif | 215 #endif |
| 211 main_loop_(NULL) { | 216 main_loop_(NULL) { |
| 212 io_thread_.StartWithOptions( | 217 io_thread_.StartWithOptions( |
| 213 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 218 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 214 #if defined(OS_WIN) | |
|
Mark Seaborn
2014/05/08 15:52:23
These conditionals can stay.
bradn
2014/05/08 17:00:24
Done.
| |
| 215 DCHECK(g_listener == NULL); | 219 DCHECK(g_listener == NULL); |
| 216 g_listener = this; | 220 g_listener = this; |
| 217 #endif | |
| 218 } | 221 } |
| 219 | 222 |
| 220 NaClListener::~NaClListener() { | 223 NaClListener::~NaClListener() { |
| 221 NOTREACHED(); | 224 NOTREACHED(); |
| 222 shutdown_event_.Signal(); | 225 shutdown_event_.Signal(); |
| 223 #if defined(OS_WIN) | |
| 224 g_listener = NULL; | 226 g_listener = NULL; |
| 225 #endif | |
| 226 } | 227 } |
| 227 | 228 |
| 228 bool NaClListener::Send(IPC::Message* msg) { | 229 bool NaClListener::Send(IPC::Message* msg) { |
| 229 DCHECK(main_loop_ != NULL); | 230 DCHECK(main_loop_ != NULL); |
| 230 if (base::MessageLoop::current() == main_loop_) { | 231 if (base::MessageLoop::current() == main_loop_) { |
| 231 // This thread owns the channel. | 232 // This thread owns the channel. |
| 232 return channel_->Send(msg); | 233 return channel_->Send(msg); |
| 233 } else { | 234 } else { |
| 234 // This thread does not own the channel. | 235 // This thread does not own the channel. |
| 235 return filter_->Send(msg); | 236 return filter_->Send(msg); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 // Indicate that this is a PNaCl module. | 450 // Indicate that this is a PNaCl module. |
| 450 // TODO(jvoung): Plumb through something indicating that this is PNaCl | 451 // TODO(jvoung): Plumb through something indicating that this is PNaCl |
| 451 // instead of relying on enable_dyncode_syscalls. | 452 // instead of relying on enable_dyncode_syscalls. |
| 452 args->pnacl_mode = 1; | 453 args->pnacl_mode = 1; |
| 453 } | 454 } |
| 454 #if defined(OS_LINUX) || defined(OS_MACOSX) | 455 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 455 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( | 456 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( |
| 456 params.debug_stub_server_bound_socket); | 457 params.debug_stub_server_bound_socket); |
| 457 #endif | 458 #endif |
| 458 #if defined(OS_WIN) | 459 #if defined(OS_WIN) |
| 460 args->debug_stub_server_port_selected_handler_func = | |
|
Mark Seaborn
2014/05/08 15:52:23
Nit: maybe put this after "args->attach_debug_exce
bradn
2014/05/08 17:00:24
Done.
| |
| 461 DebugStubPortSelectedHandler; | |
| 459 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 462 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
| 460 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 463 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
| 461 #endif | 464 #endif |
| 462 #if defined(OS_LINUX) | 465 #if defined(OS_LINUX) |
| 463 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 466 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
| 464 #endif | 467 #endif |
| 465 | 468 |
| 466 NaClChromeMainStartApp(nap, args); | 469 NaClChromeMainStartApp(nap, args); |
| 467 NOTREACHED(); | 470 NOTREACHED(); |
| 468 } | 471 } |
| OLD | NEW |