| 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 #ifndef CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ | 5 #ifndef CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ |
| 6 #define CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ | 6 #define CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/containers/small_map.h" | 14 #include "base/containers/small_map.h" |
| 14 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 15 #include "base/memory/scoped_vector.h" | |
| 16 #include "base/posix/global_descriptors.h" | 16 #include "base/posix/global_descriptors.h" |
| 17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
| 18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
| 19 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class PickleIterator; | 23 class PickleIterator; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 class ZygoteForkDelegate; | 28 class ZygoteForkDelegate; |
| 29 | 29 |
| 30 // This is the object which implements the zygote. The ZygoteMain function, | 30 // This is the object which implements the zygote. The ZygoteMain function, |
| 31 // which is called from ChromeMain, simply constructs one of these objects and | 31 // which is called from ChromeMain, simply constructs one of these objects and |
| 32 // runs it. | 32 // runs it. |
| 33 class Zygote { | 33 class Zygote { |
| 34 public: | 34 public: |
| 35 Zygote(int sandbox_flags, ScopedVector<ZygoteForkDelegate> helpers, | 35 Zygote(int sandbox_flags, |
| 36 std::vector<std::unique_ptr<ZygoteForkDelegate>> helpers, |
| 36 const std::vector<base::ProcessHandle>& extra_children, | 37 const std::vector<base::ProcessHandle>& extra_children, |
| 37 const std::vector<int>& extra_fds); | 38 const std::vector<int>& extra_fds); |
| 38 ~Zygote(); | 39 ~Zygote(); |
| 39 | 40 |
| 40 bool ProcessRequests(); | 41 bool ProcessRequests(); |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 struct ZygoteProcessInfo { | 44 struct ZygoteProcessInfo { |
| 44 // Pid from inside the Zygote's PID namespace. | 45 // Pid from inside the Zygote's PID namespace. |
| 45 base::ProcessHandle internal_pid; | 46 base::ProcessHandle internal_pid; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // Attempt to reap all outstanding children in |to_reap_|. | 129 // Attempt to reap all outstanding children in |to_reap_|. |
| 129 void ReapChildren(); | 130 void ReapChildren(); |
| 130 | 131 |
| 131 // The Zygote needs to keep some information about each process. Most | 132 // The Zygote needs to keep some information about each process. Most |
| 132 // notably what the PID of the process is inside the PID namespace of | 133 // notably what the PID of the process is inside the PID namespace of |
| 133 // the Zygote and whether or not a process was started by the | 134 // the Zygote and whether or not a process was started by the |
| 134 // ZygoteForkDelegate helper. | 135 // ZygoteForkDelegate helper. |
| 135 ZygoteProcessMap process_info_map_; | 136 ZygoteProcessMap process_info_map_; |
| 136 | 137 |
| 137 const int sandbox_flags_; | 138 const int sandbox_flags_; |
| 138 ScopedVector<ZygoteForkDelegate> helpers_; | 139 std::vector<std::unique_ptr<ZygoteForkDelegate>> helpers_; |
| 139 | 140 |
| 140 // Count of how many fork delegates for which we've invoked InitialUMA(). | 141 // Count of how many fork delegates for which we've invoked InitialUMA(). |
| 141 size_t initial_uma_index_; | 142 size_t initial_uma_index_; |
| 142 | 143 |
| 143 // This vector contains the PIDs of any child processes which have been | 144 // This vector contains the PIDs of any child processes which have been |
| 144 // created prior to the construction of the Zygote object, and must be reaped | 145 // created prior to the construction of the Zygote object, and must be reaped |
| 145 // before the Zygote exits. The Zygote will perform a blocking wait on these | 146 // before the Zygote exits. The Zygote will perform a blocking wait on these |
| 146 // children, so they must be guaranteed to be exiting by the time the Zygote | 147 // children, so they must be guaranteed to be exiting by the time the Zygote |
| 147 // exits. | 148 // exits. |
| 148 std::vector<base::ProcessHandle> extra_children_; | 149 std::vector<base::ProcessHandle> extra_children_; |
| 149 | 150 |
| 150 // This vector contains the FDs that must be closed before reaping the extra | 151 // This vector contains the FDs that must be closed before reaping the extra |
| 151 // children. | 152 // children. |
| 152 std::vector<int> extra_fds_; | 153 std::vector<int> extra_fds_; |
| 153 | 154 |
| 154 // The vector contains the child processes that need to be reaped. | 155 // The vector contains the child processes that need to be reaped. |
| 155 std::vector<ZygoteProcessInfo> to_reap_; | 156 std::vector<ZygoteProcessInfo> to_reap_; |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 } // namespace content | 159 } // namespace content |
| 159 | 160 |
| 160 #endif // CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ | 161 #endif // CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ |
| OLD | NEW |