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 "content/zygote/zygote_main.h" | 5 #include "content/zygote/zygote_main.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <signal.h> | 10 #include <signal.h> |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 #include <string.h> | 13 #include <string.h> |
14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 | 17 |
18 #include <memory> | |
19 #include <set> | 18 #include <set> |
20 #include <utility> | 19 #include <utility> |
21 #include <vector> | |
22 | 20 |
23 #include "base/bind.h" | 21 #include "base/bind.h" |
24 #include "base/command_line.h" | 22 #include "base/command_line.h" |
25 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
26 #include "base/lazy_instance.h" | 24 #include "base/lazy_instance.h" |
27 #include "base/memory/scoped_vector.h" | |
28 #include "base/native_library.h" | 25 #include "base/native_library.h" |
29 #include "base/pickle.h" | 26 #include "base/pickle.h" |
30 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
31 #include "base/posix/unix_domain_socket_linux.h" | 28 #include "base/posix/unix_domain_socket_linux.h" |
32 #include "base/rand_util.h" | 29 #include "base/rand_util.h" |
33 #include "base/strings/safe_sprintf.h" | 30 #include "base/strings/safe_sprintf.h" |
34 #include "base/strings/string_number_conversions.h" | 31 #include "base/strings/string_number_conversions.h" |
35 #include "base/sys_info.h" | 32 #include "base/sys_info.h" |
36 #include "build/build_config.h" | 33 #include "build/build_config.h" |
37 #include "content/common/child_process_sandbox_support_impl_linux.h" | 34 #include "content/common/child_process_sandbox_support_impl_linux.h" |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (setuid_sandbox->IsSuidSandboxChild()) { | 556 if (setuid_sandbox->IsSuidSandboxChild()) { |
560 CHECK(EnterSuidSandbox(setuid_sandbox, post_fork_parent_callback)) | 557 CHECK(EnterSuidSandbox(setuid_sandbox, post_fork_parent_callback)) |
561 << "Failed to enter setuid sandbox"; | 558 << "Failed to enter setuid sandbox"; |
562 } else if (sandbox::NamespaceSandbox::InNewUserNamespace()) { | 559 } else if (sandbox::NamespaceSandbox::InNewUserNamespace()) { |
563 EnterNamespaceSandbox(linux_sandbox, post_fork_parent_callback); | 560 EnterNamespaceSandbox(linux_sandbox, post_fork_parent_callback); |
564 } else { | 561 } else { |
565 CHECK(!using_layer1_sandbox); | 562 CHECK(!using_layer1_sandbox); |
566 } | 563 } |
567 } | 564 } |
568 | 565 |
569 bool ZygoteMain(const MainFunctionParams& params, | 566 bool ZygoteMain( |
570 ScopedVector<ZygoteForkDelegate> fork_delegates) { | 567 const MainFunctionParams& params, |
| 568 std::vector<std::unique_ptr<ZygoteForkDelegate>> fork_delegates) { |
571 g_am_zygote_or_renderer = true; | 569 g_am_zygote_or_renderer = true; |
572 | 570 |
573 std::vector<int> fds_to_close_post_fork; | 571 std::vector<int> fds_to_close_post_fork; |
574 | 572 |
575 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); | 573 LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance(); |
576 | 574 |
577 #if defined(SANITIZER_COVERAGE) | 575 #if defined(SANITIZER_COVERAGE) |
578 const std::string sancov_file_name = | 576 const std::string sancov_file_name = |
579 "zygote." + base::Uint64ToString(base::RandUint64()); | 577 "zygote." + base::Uint64ToString(base::RandUint64()); |
580 base::ScopedFD sancov_file_fd( | 578 base::ScopedFD sancov_file_fd( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 if (using_layer1_sandbox) { | 611 if (using_layer1_sandbox) { |
614 // Let the ZygoteHost know we're booting up. | 612 // Let the ZygoteHost know we're booting up. |
615 CHECK(base::UnixDomainSocket::SendMsg(kZygoteSocketPairFd, | 613 CHECK(base::UnixDomainSocket::SendMsg(kZygoteSocketPairFd, |
616 kZygoteBootMessage, | 614 kZygoteBootMessage, |
617 sizeof(kZygoteBootMessage), | 615 sizeof(kZygoteBootMessage), |
618 std::vector<int>())); | 616 std::vector<int>())); |
619 } | 617 } |
620 | 618 |
621 VLOG(1) << "ZygoteMain: initializing " << fork_delegates.size() | 619 VLOG(1) << "ZygoteMain: initializing " << fork_delegates.size() |
622 << " fork delegates"; | 620 << " fork delegates"; |
623 for (ZygoteForkDelegate* fork_delegate : fork_delegates) { | 621 for (const auto& fork_delegate : fork_delegates) { |
624 fork_delegate->Init(GetSandboxFD(), using_layer1_sandbox); | 622 fork_delegate->Init(GetSandboxFD(), using_layer1_sandbox); |
625 } | 623 } |
626 | 624 |
627 const std::vector<int> sandbox_fds_to_close_post_fork = | 625 const std::vector<int> sandbox_fds_to_close_post_fork = |
628 linux_sandbox->GetFileDescriptorsToClose(); | 626 linux_sandbox->GetFileDescriptorsToClose(); |
629 | 627 |
630 fds_to_close_post_fork.insert(fds_to_close_post_fork.end(), | 628 fds_to_close_post_fork.insert(fds_to_close_post_fork.end(), |
631 sandbox_fds_to_close_post_fork.begin(), | 629 sandbox_fds_to_close_post_fork.begin(), |
632 sandbox_fds_to_close_post_fork.end()); | 630 sandbox_fds_to_close_post_fork.end()); |
633 base::Closure post_fork_parent_callback = | 631 base::Closure post_fork_parent_callback = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; | 663 const bool namespace_sandbox_engaged = sandbox_flags & kSandboxLinuxUserNS; |
666 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); | 664 CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); |
667 | 665 |
668 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, | 666 Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, |
669 extra_fds); | 667 extra_fds); |
670 // This function call can return multiple times, once per fork(). | 668 // This function call can return multiple times, once per fork(). |
671 return zygote.ProcessRequests(); | 669 return zygote.ProcessRequests(); |
672 } | 670 } |
673 | 671 |
674 } // namespace content | 672 } // namespace content |
OLD | NEW |