OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/nacl/nacl_listener.h" | 5 #include "chrome/nacl/nacl_listener.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "chrome/common/nacl_messages.h" | 13 #include "chrome/common/nacl_messages.h" |
14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
15 #include "ipc/ipc_switches.h" | 15 #include "ipc/ipc_switches.h" |
16 #include "native_client/src/shared/imc/nacl_imc.h" | 16 #include "native_client/src/shared/imc/nacl_imc.h" |
| 17 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" |
17 | 18 |
18 #if defined(OS_LINUX) | 19 #if defined(OS_LINUX) |
19 #include "content/public/common/child_process_sandbox_support_linux.h" | 20 #include "content/public/common/child_process_sandbox_support_linux.h" |
20 #endif | 21 #endif |
21 | 22 |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include <fcntl.h> | 24 #include <fcntl.h> |
24 #include <io.h> | 25 #include <io.h> |
25 #endif | 26 #endif |
26 | 27 |
27 // This is ugly. We need an interface header file for the exported | |
28 // sel_ldr interfaces. | |
29 // TODO(gregoryd,sehr): Add an interface header. | |
30 #if defined(OS_WIN) | |
31 typedef HANDLE NaClHandle; | |
32 #else | |
33 typedef int NaClHandle; | |
34 #endif // NaClHandle | |
35 | |
36 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
37 namespace { | 29 namespace { |
38 | 30 |
39 // On Mac OS X, shm_open() works in the sandbox but does not give us | 31 // On Mac OS X, shm_open() works in the sandbox but does not give us |
40 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to | 32 // an FD that we can map as PROT_EXEC. Rather than doing an IPC to |
41 // get an executable SHM region when CreateMemoryObject() is called, | 33 // get an executable SHM region when CreateMemoryObject() is called, |
42 // we preallocate one on startup, since NaCl's sel_ldr only needs one | 34 // we preallocate one on startup, since NaCl's sel_ldr only needs one |
43 // of them. This saves a round trip. | 35 // of them. This saves a round trip. |
44 | 36 |
45 base::subtle::Atomic32 g_shm_fd = -1; | 37 base::subtle::Atomic32 g_shm_fd = -1; |
(...skipping 16 matching lines...) Expand all Loading... |
62 return result_fd; | 54 return result_fd; |
63 } | 55 } |
64 } | 56 } |
65 // Fall back to NaCl's default implementation. | 57 // Fall back to NaCl's default implementation. |
66 return -1; | 58 return -1; |
67 } | 59 } |
68 | 60 |
69 } // namespace | 61 } // namespace |
70 #endif // defined(OS_MACOSX) | 62 #endif // defined(OS_MACOSX) |
71 | 63 |
72 extern "C" void NaClMainForChromium(int handle_count, | |
73 const NaClHandle* handles, | |
74 int debug); | |
75 extern "C" void NaClSetIrtFileDesc(int fd); | |
76 | |
77 NaClListener::NaClListener() : debug_enabled_(false) {} | 64 NaClListener::NaClListener() : debug_enabled_(false) {} |
78 | 65 |
79 NaClListener::~NaClListener() {} | 66 NaClListener::~NaClListener() {} |
80 | 67 |
81 void NaClListener::Listen() { | 68 void NaClListener::Listen() { |
82 std::string channel_name = | 69 std::string channel_name = |
83 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 70 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
84 switches::kProcessChannelID); | 71 switches::kProcessChannelID); |
85 IPC::Channel channel(channel_name, IPC::Channel::MODE_CLIENT, this); | 72 IPC::Channel channel(channel_name, IPC::Channel::MODE_CLIENT, this); |
86 CHECK(channel.Connect()); | 73 CHECK(channel.Connect()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 NaClSetIrtFileDesc(irt_desc); | 111 NaClSetIrtFileDesc(irt_desc); |
125 | 112 |
126 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]); | 113 scoped_array<NaClHandle> array(new NaClHandle[handles.size()]); |
127 for (size_t i = 0; i < handles.size(); i++) { | 114 for (size_t i = 0; i < handles.size(); i++) { |
128 array[i] = nacl::ToNativeHandle(handles[i]); | 115 array[i] = nacl::ToNativeHandle(handles[i]); |
129 } | 116 } |
130 NaClMainForChromium(static_cast<int>(handles.size()), array.get(), | 117 NaClMainForChromium(static_cast<int>(handles.size()), array.get(), |
131 debug_enabled_); | 118 debug_enabled_); |
132 NOTREACHED(); | 119 NOTREACHED(); |
133 } | 120 } |
OLD | NEW |