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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 namespace { | 158 namespace { |
157 | 159 |
158 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 160 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
159 content::ZygoteHandle g_nacl_zygote; | 161 content::ZygoteHandle g_nacl_zygote; |
160 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 162 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
161 | 163 |
162 // NOTE: changes to this class need to be reviewed by the security team. | 164 // NOTE: changes to this class need to be reviewed by the security team. |
163 class NaClSandboxedProcessLauncherDelegate | 165 class NaClSandboxedProcessLauncherDelegate |
164 : public content::SandboxedProcessLauncherDelegate { | 166 : public content::SandboxedProcessLauncherDelegate { |
165 public: | 167 public: |
166 NaClSandboxedProcessLauncherDelegate(ChildProcessHost* host) | 168 NaClSandboxedProcessLauncherDelegate(ChildProcessHost* host) {} |
167 #if defined(OS_POSIX) | |
168 : ipc_fd_(host->TakeClientFileDescriptor()) | |
169 #endif | |
170 {} | |
171 | 169 |
172 ~NaClSandboxedProcessLauncherDelegate() override {} | 170 ~NaClSandboxedProcessLauncherDelegate() override {} |
173 | 171 |
174 #if defined(OS_WIN) | 172 #if defined(OS_WIN) |
175 void PostSpawnTarget(base::ProcessHandle process) override { | 173 void PostSpawnTarget(base::ProcessHandle process) override { |
176 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of | 174 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of |
177 // address space to prevent later failure due to address space fragmentation | 175 // address space to prevent later failure due to address space fragmentation |
178 // from .dll loading. The NaCl process will attempt to locate this space by | 176 // from .dll loading. The NaCl process will attempt to locate this space by |
179 // scanning the address space using VirtualQuery. | 177 // scanning the address space using VirtualQuery. |
180 // TODO(bbudge) Handle the --no-sandbox case. | 178 // TODO(bbudge) Handle the --no-sandbox case. |
181 // http://code.google.com/p/nativeclient/issues/detail?id=2131 | 179 // http://code.google.com/p/nativeclient/issues/detail?id=2131 |
182 const SIZE_T kNaClSandboxSize = 1 << 30; | 180 const SIZE_T kNaClSandboxSize = 1 << 30; |
183 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { | 181 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { |
184 DLOG(WARNING) << "Failed to reserve address space for Native Client"; | 182 DLOG(WARNING) << "Failed to reserve address space for Native Client"; |
185 } | 183 } |
186 } | 184 } |
187 #elif defined(OS_POSIX) | 185 #elif defined(OS_POSIX) |
188 #if !defined(OS_MACOSX) | 186 #if !defined(OS_MACOSX) |
189 content::ZygoteHandle* GetZygote() override { | 187 content::ZygoteHandle* GetZygote() override { |
190 return content::GetGenericZygote(); | 188 return content::GetGenericZygote(); |
191 } | 189 } |
192 #endif // !defined(OS_MACOSX) | 190 #endif // !defined(OS_MACOSX) |
193 | 191 |
194 base::ScopedFD TakeIpcFd() override { return std::move(ipc_fd_); } | 192 base::ScopedFD TakeIpcFd() override { return base::ScopedFD(-1); } |
Mark Seaborn
2016/07/08 20:26:19
Nit: I think you can use base::ScopedFD() without
Anand Mistry (off Chromium)
2016/07/12 07:26:23
Although it's correct here, I've undone this chang
| |
195 #endif // OS_WIN | 193 #endif // OS_WIN |
196 | |
197 private: | |
198 #if defined(OS_POSIX) | |
199 base::ScopedFD ipc_fd_; | |
200 #endif // OS_POSIX | |
201 }; | 194 }; |
202 | 195 |
203 void CloseFile(base::File file) { | 196 void CloseFile(base::File file) { |
204 // The base::File destructor will close the file for us. | 197 // The base::File destructor will close the file for us. |
205 } | 198 } |
206 | 199 |
207 } // namespace | 200 } // namespace |
208 | 201 |
209 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = | 202 unsigned NaClProcessHost::keepalive_throttle_interval_milliseconds_ = |
210 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; | 203 ppapi::kKeepaliveThrottleIntervalDefaultMilliseconds; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 #if defined(OS_WIN) | 293 #if defined(OS_WIN) |
301 debug_exception_handler_requested_(false), | 294 debug_exception_handler_requested_(false), |
302 #endif | 295 #endif |
303 uses_nonsfi_mode_(uses_nonsfi_mode), | 296 uses_nonsfi_mode_(uses_nonsfi_mode), |
304 enable_debug_stub_(false), | 297 enable_debug_stub_(false), |
305 enable_crash_throttling_(false), | 298 enable_crash_throttling_(false), |
306 off_the_record_(off_the_record), | 299 off_the_record_(off_the_record), |
307 process_type_(process_type), | 300 process_type_(process_type), |
308 profile_directory_(profile_directory), | 301 profile_directory_(profile_directory), |
309 render_view_id_(render_view_id), | 302 render_view_id_(render_view_id), |
303 mojo_child_token_(mojo::edk::GenerateRandomToken()), | |
310 weak_factory_(this) { | 304 weak_factory_(this) { |
311 process_.reset(content::BrowserChildProcessHost::Create( | 305 process_.reset(content::BrowserChildProcessHost::Create( |
312 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_LOADER), this)); | 306 static_cast<content::ProcessType>(PROCESS_TYPE_NACL_LOADER), this, |
307 mojo_child_token_)); | |
313 | 308 |
314 // Set the display name so the user knows what plugin the process is running. | 309 // Set the display name so the user knows what plugin the process is running. |
315 // We aren't on the UI thread so getting the pref locale for language | 310 // We aren't on the UI thread so getting the pref locale for language |
316 // formatting isn't possible, so IDN will be lost, but this is probably OK | 311 // formatting isn't possible, so IDN will be lost, but this is probably OK |
317 // for this use case. | 312 // for this use case. |
318 process_->SetName(url_formatter::FormatUrl(manifest_url_)); | 313 process_->SetName(url_formatter::FormatUrl(manifest_url_)); |
319 | 314 |
320 enable_debug_stub_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 315 enable_debug_stub_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
321 switches::kEnableNaClDebug); | 316 switches::kEnableNaClDebug); |
322 DCHECK(process_type_ != kUnknownNaClProcessType); | 317 DCHECK(process_type_ != kUnknownNaClProcessType); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 base::FilePath script = | 565 base::FilePath script = |
571 command_line.GetSwitchValuePath(switches::kNaClGdbScript); | 566 command_line.GetSwitchValuePath(switches::kNaClGdbScript); |
572 if (!script.empty()) { | 567 if (!script.empty()) { |
573 cmd_line.AppendArg("--command"); | 568 cmd_line.AppendArg("--command"); |
574 cmd_line.AppendArgNative(script.value()); | 569 cmd_line.AppendArgNative(script.value()); |
575 } | 570 } |
576 base::LaunchProcess(cmd_line, base::LaunchOptions()); | 571 base::LaunchProcess(cmd_line, base::LaunchOptions()); |
577 } | 572 } |
578 | 573 |
579 bool NaClProcessHost::LaunchSelLdr() { | 574 bool NaClProcessHost::LaunchSelLdr() { |
580 std::string channel_id = process_->GetHost()->CreateChannel(); | 575 std::string mojo_channel_token = |
581 if (channel_id.empty()) { | 576 process_->GetHost()->CreateChannelMojo(mojo_child_token_); |
Mark Seaborn
2016/07/08 20:26:19
Since mojo_child_token_ isn't used after this, you
Anand Mistry (off Chromium)
2016/07/12 07:26:23
Done.
| |
582 SendErrorToRenderer("CreateChannel() failed"); | 577 if (mojo_channel_token.empty()) { |
578 SendErrorToRenderer("CreateChannelMojo() failed"); | |
583 return false; | 579 return false; |
584 } | 580 } |
585 | 581 |
586 // Build command line for nacl. | 582 // Build command line for nacl. |
587 | 583 |
588 #if defined(OS_LINUX) | 584 #if defined(OS_LINUX) |
589 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 585 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
590 #else | 586 #else |
591 int flags = ChildProcessHost::CHILD_NORMAL; | 587 int flags = ChildProcessHost::CHILD_NORMAL; |
592 #endif | 588 #endif |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 } | 628 } |
633 #endif | 629 #endif |
634 | 630 |
635 std::unique_ptr<base::CommandLine> cmd_line(new base::CommandLine(exe_path)); | 631 std::unique_ptr<base::CommandLine> cmd_line(new base::CommandLine(exe_path)); |
636 CopyNaClCommandLineArguments(cmd_line.get()); | 632 CopyNaClCommandLineArguments(cmd_line.get()); |
637 | 633 |
638 cmd_line->AppendSwitchASCII(switches::kProcessType, | 634 cmd_line->AppendSwitchASCII(switches::kProcessType, |
639 (uses_nonsfi_mode_ ? | 635 (uses_nonsfi_mode_ ? |
640 switches::kNaClLoaderNonSfiProcess : | 636 switches::kNaClLoaderNonSfiProcess : |
641 switches::kNaClLoaderProcess)); | 637 switches::kNaClLoaderProcess)); |
642 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 638 cmd_line->AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
643 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) | 639 if (NaClBrowser::GetDelegate()->DialogsAreSuppressed()) |
644 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 640 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
645 | 641 |
646 #if defined(OS_WIN) | 642 #if defined(OS_WIN) |
647 cmd_line->AppendArg(switches::kPrefetchArgumentOther); | 643 cmd_line->AppendArg(switches::kPrefetchArgumentOther); |
648 #endif // defined(OS_WIN) | 644 #endif // defined(OS_WIN) |
649 | 645 |
650 // On Windows we might need to start the broker process to launch a new loader | 646 // On Windows we might need to start the broker process to launch a new loader |
651 #if defined(OS_WIN) | 647 #if defined(OS_WIN) |
652 if (RunningOnWOW64()) { | 648 if (RunningOnWOW64()) { |
653 if (!NaClBrokerService::GetInstance()->LaunchLoader( | 649 if (!NaClBrokerService::GetInstance()->LaunchLoader( |
654 weak_factory_.GetWeakPtr(), channel_id)) { | 650 weak_factory_.GetWeakPtr(), mojo_channel_token)) { |
655 SendErrorToRenderer("broker service did not launch process"); | 651 SendErrorToRenderer("broker service did not launch process"); |
656 return false; | 652 return false; |
657 } | 653 } |
658 return true; | 654 return true; |
659 } | 655 } |
660 #endif | 656 #endif |
661 process_->Launch( | 657 process_->Launch( |
662 new NaClSandboxedProcessLauncherDelegate(process_->GetHost()), | 658 new NaClSandboxedProcessLauncherDelegate(process_->GetHost()), |
663 cmd_line.release(), | 659 cmd_line.release(), |
664 true); | 660 true); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 NaClStartDebugExceptionHandlerThread( | 1286 NaClStartDebugExceptionHandlerThread( |
1291 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), | 1287 std::move(process), info, base::ThreadTaskRunnerHandle::Get(), |
1292 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1288 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1293 weak_factory_.GetWeakPtr())); | 1289 weak_factory_.GetWeakPtr())); |
1294 return true; | 1290 return true; |
1295 } | 1291 } |
1296 } | 1292 } |
1297 #endif | 1293 #endif |
1298 | 1294 |
1299 } // namespace nacl | 1295 } // namespace nacl |
OLD | NEW |