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