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 <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> |
10 | 11 |
11 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
12 #include <unistd.h> | 13 #include <unistd.h> |
13 #endif | 14 #endif |
14 | 15 |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
39 #endif | 40 #endif |
40 | 41 |
41 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
42 #include <fcntl.h> | 43 #include <fcntl.h> |
43 #include <io.h> | 44 #include <io.h> |
44 | 45 |
45 #include "content/public/common/sandbox_init.h" | 46 #include "content/public/common/sandbox_init.h" |
46 #endif | 47 #endif |
47 | 48 |
48 namespace { | 49 namespace { |
| 50 |
| 51 NaClListener* g_listener; |
| 52 |
| 53 void FatalLogHandler(const char* data, size_t bytes) { |
| 54 // We use uint32_t rather than size_t for the case when the browser and NaCl |
| 55 // processes are a mix of 32-bit and 64-bit processes. |
| 56 uint32_t copy_bytes = std::min<uint32_t>(static_cast<uint32_t>(bytes), |
| 57 nacl::kNaClCrashInfoMaxLogSize); |
| 58 |
| 59 // We copy the length of the crash data to the start of the shared memory |
| 60 // segment so we know how much to copy. |
| 61 memcpy(g_listener->crash_info_shmem_memory(), ©_bytes, sizeof(uint32_t)); |
| 62 |
| 63 memcpy((char*)g_listener->crash_info_shmem_memory() + sizeof(uint32_t), |
| 64 data, |
| 65 copy_bytes); |
| 66 } |
| 67 |
49 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
50 | 69 |
51 // On Mac OS X, shm_open() works in the sandbox but does not give us | 70 // On Mac OS X, shm_open() works in the sandbox but does not give us |
52 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to | 71 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to |
53 // get an executable SHM region when CreateMemoryObject() is called, | 72 // get an executable SHM region when CreateMemoryObject() is called, |
54 // we preallocate one on startup, since NaCl's sel_ldr only needs one | 73 // we preallocate one on startup, since NaCl's sel_ldr only needs one |
55 // of them. This saves a round trip. | 74 // of them. This saves a round trip. |
56 | 75 |
57 base::subtle::Atomic32 g_shm_fd = -1; | 76 base::subtle::Atomic32 g_shm_fd = -1; |
58 | 77 |
(...skipping 19 matching lines...) Expand all Loading... |
78 return -1; | 97 return -1; |
79 } | 98 } |
80 | 99 |
81 #elif defined(OS_LINUX) | 100 #elif defined(OS_LINUX) |
82 | 101 |
83 int CreateMemoryObject(size_t size, int executable) { | 102 int CreateMemoryObject(size_t size, int executable) { |
84 return content::MakeSharedMemorySegmentViaIPC(size, executable); | 103 return content::MakeSharedMemorySegmentViaIPC(size, executable); |
85 } | 104 } |
86 | 105 |
87 #elif defined(OS_WIN) | 106 #elif defined(OS_WIN) |
88 | |
89 NaClListener* g_listener; | |
90 | |
91 // We wrap the function to convert the bool return value to an int. | 107 // We wrap the function to convert the bool return value to an int. |
92 int BrokerDuplicateHandle(NaClHandle source_handle, | 108 int BrokerDuplicateHandle(NaClHandle source_handle, |
93 uint32_t process_id, | 109 uint32_t process_id, |
94 NaClHandle* target_handle, | 110 NaClHandle* target_handle, |
95 uint32_t desired_access, | 111 uint32_t desired_access, |
96 uint32_t options) { | 112 uint32_t options) { |
97 return content::BrokerDuplicateHandle(source_handle, process_id, | 113 return content::BrokerDuplicateHandle(source_handle, process_id, |
98 target_handle, desired_access, | 114 target_handle, desired_access, |
99 options); | 115 options); |
100 } | 116 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 io_thread_("NaCl_IOThread"), | 222 io_thread_("NaCl_IOThread"), |
207 #if defined(OS_LINUX) | 223 #if defined(OS_LINUX) |
208 prereserved_sandbox_size_(0), | 224 prereserved_sandbox_size_(0), |
209 #endif | 225 #endif |
210 #if defined(OS_POSIX) | 226 #if defined(OS_POSIX) |
211 number_of_cores_(-1), // unknown/error | 227 number_of_cores_(-1), // unknown/error |
212 #endif | 228 #endif |
213 main_loop_(NULL) { | 229 main_loop_(NULL) { |
214 io_thread_.StartWithOptions( | 230 io_thread_.StartWithOptions( |
215 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 231 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
216 #if defined(OS_WIN) | |
217 DCHECK(g_listener == NULL); | 232 DCHECK(g_listener == NULL); |
218 g_listener = this; | 233 g_listener = this; |
219 #endif | |
220 } | 234 } |
221 | 235 |
222 NaClListener::~NaClListener() { | 236 NaClListener::~NaClListener() { |
223 NOTREACHED(); | 237 NOTREACHED(); |
224 shutdown_event_.Signal(); | 238 shutdown_event_.Signal(); |
225 #if defined(OS_WIN) | |
226 g_listener = NULL; | 239 g_listener = NULL; |
227 #endif | |
228 } | 240 } |
229 | 241 |
230 bool NaClListener::Send(IPC::Message* msg) { | 242 bool NaClListener::Send(IPC::Message* msg) { |
231 DCHECK(main_loop_ != NULL); | 243 DCHECK(main_loop_ != NULL); |
232 if (base::MessageLoop::current() == main_loop_) { | 244 if (base::MessageLoop::current() == main_loop_) { |
233 // This thread owns the channel. | 245 // This thread owns the channel. |
234 return channel_->Send(msg); | 246 return channel_->Send(msg); |
235 } else { | 247 } else { |
236 // This thread does not own the channel. | 248 // This thread does not own the channel. |
237 return filter_->Send(msg); | 249 return filter_->Send(msg); |
(...skipping 24 matching lines...) Expand all Loading... |
262 | 274 |
263 void NaClListener::OnStart(const nacl::NaClStartParams& params) { | 275 void NaClListener::OnStart(const nacl::NaClStartParams& params) { |
264 #if defined(OS_LINUX) || defined(OS_MACOSX) | 276 #if defined(OS_LINUX) || defined(OS_MACOSX) |
265 int urandom_fd = dup(base::GetUrandomFD()); | 277 int urandom_fd = dup(base::GetUrandomFD()); |
266 if (urandom_fd < 0) { | 278 if (urandom_fd < 0) { |
267 LOG(ERROR) << "Failed to dup() the urandom FD"; | 279 LOG(ERROR) << "Failed to dup() the urandom FD"; |
268 return; | 280 return; |
269 } | 281 } |
270 NaClChromeMainSetUrandomFd(urandom_fd); | 282 NaClChromeMainSetUrandomFd(urandom_fd); |
271 #endif | 283 #endif |
272 | |
273 struct NaClApp* nap = NULL; | 284 struct NaClApp* nap = NULL; |
274 NaClChromeMainInit(); | 285 NaClChromeMainInit(); |
| 286 |
| 287 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, |
| 288 false)); |
| 289 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); |
| 290 NaClSetFatalErrorCallback(&FatalLogHandler); |
| 291 |
275 nap = NaClAppCreate(); | 292 nap = NaClAppCreate(); |
276 if (nap == NULL) { | 293 if (nap == NULL) { |
277 LOG(ERROR) << "NaClAppCreate() failed"; | 294 LOG(ERROR) << "NaClAppCreate() failed"; |
278 return; | 295 return; |
279 } | 296 } |
280 | 297 |
281 IPC::ChannelHandle browser_handle; | 298 IPC::ChannelHandle browser_handle; |
282 IPC::ChannelHandle ppapi_renderer_handle; | 299 IPC::ChannelHandle ppapi_renderer_handle; |
283 | 300 |
284 if (params.enable_ipc_proxy) { | 301 if (params.enable_ipc_proxy) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 nexe_file_info.desc = nexe_file; | 412 nexe_file_info.desc = nexe_file; |
396 #else | 413 #else |
397 #error Unsupported target platform. | 414 #error Unsupported target platform. |
398 #endif | 415 #endif |
399 nexe_file_info.file_token.lo = params.nexe_token_lo; | 416 nexe_file_info.file_token.lo = params.nexe_token_lo; |
400 nexe_file_info.file_token.hi = params.nexe_token_hi; | 417 nexe_file_info.file_token.hi = params.nexe_token_hi; |
401 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); | 418 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); |
402 | 419 |
403 NaClChromeMainStartApp(nap, args); | 420 NaClChromeMainStartApp(nap, args); |
404 } | 421 } |
OLD | NEW |