OLD | NEW |
1 // Copyright (c) 2012 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 "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "components/nacl/common/nacl_switches.h" | 42 #include "components/nacl/common/nacl_switches.h" |
43 #include "components/url_formatter/url_formatter.h" | 43 #include "components/url_formatter/url_formatter.h" |
44 #include "content/public/browser/browser_child_process_host.h" | 44 #include "content/public/browser/browser_child_process_host.h" |
45 #include "content/public/browser/browser_ppapi_host.h" | 45 #include "content/public/browser/browser_ppapi_host.h" |
46 #include "content/public/browser/child_process_data.h" | 46 #include "content/public/browser/child_process_data.h" |
47 #include "content/public/browser/plugin_service.h" | 47 #include "content/public/browser/plugin_service.h" |
48 #include "content/public/browser/render_process_host.h" | 48 #include "content/public/browser/render_process_host.h" |
49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
50 #include "content/public/common/child_process_host.h" | 50 #include "content/public/common/child_process_host.h" |
51 #include "content/public/common/content_switches.h" | 51 #include "content/public/common/content_switches.h" |
| 52 #include "content/public/common/mojo_channel_switches.h" |
52 #include "content/public/common/process_type.h" | 53 #include "content/public/common/process_type.h" |
53 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 54 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
54 #include "ipc/ipc_channel.h" | 55 #include "ipc/ipc_channel.h" |
55 #include "ipc/ipc_switches.h" | 56 #include "ipc/ipc_switches.h" |
| 57 #include "mojo/edk/embedder/embedder.h" |
56 #include "net/socket/socket_descriptor.h" | 58 #include "net/socket/socket_descriptor.h" |
57 #include "ppapi/host/host_factory.h" | 59 #include "ppapi/host/host_factory.h" |
58 #include "ppapi/host/ppapi_host.h" | 60 #include "ppapi/host/ppapi_host.h" |
59 #include "ppapi/proxy/ppapi_messages.h" | 61 #include "ppapi/proxy/ppapi_messages.h" |
60 #include "ppapi/shared_impl/ppapi_constants.h" | 62 #include "ppapi/shared_impl/ppapi_constants.h" |
61 #include "ppapi/shared_impl/ppapi_nacl_plugin_args.h" | 63 #include "ppapi/shared_impl/ppapi_nacl_plugin_args.h" |
62 | 64 |
63 #if defined(OS_POSIX) | 65 #if defined(OS_POSIX) |
64 | 66 |
65 #include <arpa/inet.h> | 67 #include <arpa/inet.h> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 namespace { | 159 namespace { |
158 | 160 |
159 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 161 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
160 content::ZygoteHandle g_nacl_zygote; | 162 content::ZygoteHandle g_nacl_zygote; |
161 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 163 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
162 | 164 |
163 // NOTE: changes to this class need to be reviewed by the security team. | 165 // NOTE: changes to this class need to be reviewed by the security team. |
164 class NaClSandboxedProcessLauncherDelegate | 166 class NaClSandboxedProcessLauncherDelegate |
165 : public content::SandboxedProcessLauncherDelegate { | 167 : public content::SandboxedProcessLauncherDelegate { |
166 public: | 168 public: |
167 NaClSandboxedProcessLauncherDelegate(ChildProcessHost* host) | 169 NaClSandboxedProcessLauncherDelegate(ChildProcessHost* host) {} |
168 #if defined(OS_POSIX) | |
169 : ipc_fd_(host->TakeClientFileDescriptor()) | |
170 #endif | |
171 {} | |
172 | 170 |
173 ~NaClSandboxedProcessLauncherDelegate() override {} | 171 ~NaClSandboxedProcessLauncherDelegate() override {} |
174 | 172 |
175 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
176 void PostSpawnTarget(base::ProcessHandle process) override { | 174 void PostSpawnTarget(base::ProcessHandle process) override { |
177 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of | 175 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of |
178 // address space to prevent later failure due to address space fragmentation | 176 // address space to prevent later failure due to address space fragmentation |
179 // from .dll loading. The NaCl process will attempt to locate this space by | 177 // from .dll loading. The NaCl process will attempt to locate this space by |
180 // scanning the address space using VirtualQuery. | 178 // scanning the address space using VirtualQuery. |
181 // TODO(bbudge) Handle the --no-sandbox case. | 179 // TODO(bbudge) Handle the --no-sandbox case. |
182 // http://code.google.com/p/nativeclient/issues/detail?id=2131 | 180 // http://code.google.com/p/nativeclient/issues/detail?id=2131 |
183 const SIZE_T kNaClSandboxSize = 1 << 30; | 181 const SIZE_T kNaClSandboxSize = 1 << 30; |
184 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { | 182 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { |
185 DLOG(WARNING) << "Failed to reserve address space for Native Client"; | 183 DLOG(WARNING) << "Failed to reserve address space for Native Client"; |
186 } | 184 } |
187 } | 185 } |
188 #elif defined(OS_POSIX) | 186 #elif defined(OS_POSIX) |
189 #if !defined(OS_MACOSX) | 187 #if !defined(OS_MACOSX) |
190 content::ZygoteHandle* GetZygote() override { | 188 content::ZygoteHandle* GetZygote() override { |
191 return content::GetGenericZygote(); | 189 return content::GetGenericZygote(); |
192 } | 190 } |
193 #endif // !defined(OS_MACOSX) | 191 #endif // !defined(OS_MACOSX) |
194 | 192 |
195 base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); } | 193 base::ScopedFD TakeIpcFd() override { return base::ScopedFD(-1); } |
196 #endif // OS_WIN | 194 #endif // OS_WIN |
197 | |
198 private: | |
199 #if defined(OS_POSIX) | |
200 base::ScopedFD ipc_fd_; | |
201 #endif // OS_POSIX | |
202 }; | 195 }; |
203 | 196 |
204 void CloseFile(base::File file) { | 197 void CloseFile(base::File file) { |
205 // The base::File destructor will close the file for us. | 198 // The base::File destructor will close the file for us. |
206 } | 199 } |
207 | 200 |
208 } // namespace | 201 } // namespace |
209 | 202 |
210 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = | 203 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = |
211 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; | 204 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
302 debug_exception_handler_requested_(false), | 295 debug_exception_handler_requested_(false), |
303 #endif | 296 #endif |
304 uses_nonsfi_mode_(uses_nonsfi_mode), | 297 uses_nonsfi_mode_(uses_nonsfi_mode), |
305 enable_debug_stub_(false), | 298 enable_debug_stub_(false), |
306 enable_crash_throttling_(false), | 299 enable_crash_throttling_(false), |
307 off_the_record_(off_the_record), | 300 off_the_record_(off_the_record), |
308 process_type_(process_type), | 301 process_type_(process_type), |
309 profile_directory_(profile_directory), | 302 profile_directory_(profile_directory), |
310 render_view_id_(render_view_id), | 303 render_view_id_(render_view_id), |
| 304 mojo_child_token_(mojo::edk::GenerateRandomToken()), |
311 weak_factory_(this) { | 305 weak_factory_(this) { |
312 process_.reset(content::BrowserChildProcessHost::Create( | 306 process_.reset(content::BrowserChildProcessHost::Create( |
313 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_LOADER), this)); | 307 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_LOADER), this, |
| 308 mojo_child_token_)); |
314 | 309 |
315 // Set the display name so the user knows what plugin the process is running. | 310 // Set the display name so the user knows what plugin the process is running. |
316 // We aren't on the UI thread so getting the pref locale for language | 311 // We aren't on the UI thread so getting the pref locale for language |
317 // formatting isn't possible, so IDN will be lost, but this is probably OK | 312 // formatting isn't possible, so IDN will be lost, but this is probably OK |
318 // for this use case. | 313 // for this use case. |
319 process_->SetName(url_formatter::FormatUrl(manifest_url_)); | 314 process_->SetName(url_formatter::FormatUrl(manifest_url_)); |
320 | 315 |
321 enable_debug_stub_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 316 enable_debug_stub_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
322 switches::kEnableNaClDebug); | 317 switches::kEnableNaClDebug); |
323 DCHECK(process_type_ != kUnknownNaClProcessType); | 318 DCHECK(process_type_ != kUnknownNaClProcessType); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 base::FilePath script = | 566 base::FilePath script = |
572 command_line.GetSwitchValuePath(switches::kNaClGdbScript); | 567 command_line.GetSwitchValuePath(switches::kNaClGdbScript); |
573 if (!script.empty()) { | 568 if (!script.empty()) { |
574 cmd_line.AppendArg("--command"); | 569 cmd_line.AppendArg("--command"); |
575 cmd_line.AppendArgNative(script.value()); | 570 cmd_line.AppendArgNative(script.value()); |
576 } | 571 } |
577 base::LaunchProcess(cmd_line, base::LaunchOptions()); | 572 base::LaunchProcess(cmd_line, base::LaunchOptions()); |
578 } | 573 } |
579 | 574 |
580 bool NaClProcessHost::LaunchSelLdr() { | 575 bool NaClProcessHost::LaunchSelLdr() { |
581 std::string channel_id = process_->GetHost()->CreateChannel(); | 576 std::string mojo_channel_token = |
582 if (channel_id.empty()) { | 577 process_->GetHost()->CreateChannelMojo(mojo_child_token_); |
583 SendErrorToRenderer("CreateChannel() failed"); | 578 if (mojo_channel_token.empty()) { |
| 579 SendErrorToRenderer("CreateChannelMojo() failed"); |
584 return false; | 580 return false; |
585 } | 581 } |
586 | 582 |
587 // Build command line for nacl. | 583 // Build command line for nacl. |
588 | 584 |
589 #if defined(OS_LINUX) | 585 #if defined(OS_LINUX) |
590 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 586 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
591 #else | 587 #else |
592 int flags = ChildProcessHost::CHILD_NORMAL; | 588 int flags = ChildProcessHost::CHILD_NORMAL; |
593 #endif | 589 #endif |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 629 } |
634 #endif | 630 #endif |
635 | 631 |
636 std::unique_ptr<base::CommandLine> cmd_line(new base::CommandLine(exe_path)); | 632 std::unique_ptr<base::CommandLine> cmd_line(new base::CommandLine(exe_path)); |
637 CopyNaClCommandLineArguments(cmd_line.get()); | 633 CopyNaClCommandLineArguments(cmd_line.get()); |
638 | 634 |
639 cmd_line->AppendSwitchASCII(switches::kProcessType, | 635 cmd_line->AppendSwitchASCII(switches::kProcessType, |
640 (uses_nonsfi_mode_ ? | 636 (uses_nonsfi_mode_ ? |
641 switches::kNaClLoaderNonSfiProcess : | 637 switches::kNaClLoaderNonSfiProcess : |
642 switches::kNaClLoaderProcess)); | 638 switches::kNaClLoaderProcess)); |
643 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 639 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
644 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 640 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
645 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 641 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
646 | 642 |
647 #if defined(OS_WIN) | 643 #if defined(OS_WIN) |
648 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) | 644 if (startup_metric_utils::GetPreReadOptions().use_prefetch_argument) |
649 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 645 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
650 #endif // defined(OS_WIN) | 646 #endif // defined(OS_WIN) |
651 | 647 |
652 // On Windows we might need to start the broker process to launch a new loader | 648 // On Windows we might need to start the broker process to launch a new loader |
653 #if defined(OS_WIN) | 649 #if defined(OS_WIN) |
654 if (RunningOnWOW64()) { | 650 if (RunningOnWOW64()) { |
655 if (!NaClBrokerService::GetInstance()->LaunchLoader( | 651 if (!NaClBrokerService::GetInstance()->LaunchLoader( |
656 weak_factory_.GetWeakPtr(), channel_id)) { | 652 weak_factory_.GetWeakPtr(), mojo_channel_token)) { |
657 SendErrorToRenderer("broker service did not launch process"); | 653 SendErrorToRenderer("broker service did not launch process"); |
658 return false; | 654 return false; |
659 } | 655 } |
660 return true; | 656 return true; |
661 } | 657 } |
662 #endif | 658 #endif |
663 process_->Launch( | 659 process_->Launch( |
664 new NaClSandboxedProcessLauncherDelegate(process_->GetHost()), | 660 new NaClSandboxedProcessLauncherDelegate(process_->GetHost()), |
665 cmd_line.release(), | 661 cmd_line.release(), |
666 true); | 662 true); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 NaClStartDebugExceptionHandlerThread( | 1288 NaClStartDebugExceptionHandlerThread( |
1293 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), | 1289 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), |
1294 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1290 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1295 weak_factory_.GetWeakPtr())); | 1291 weak_factory_.GetWeakPtr())); |
1296 return true; | 1292 return true; |
1297 } | 1293 } |
1298 } | 1294 } |
1299 #endif | 1295 #endif |
1300 | 1296 |
1301 } // namespace nacl | 1297 } // namespace nacl |
OLD | NEW |