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