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 <string> | 10 #include <string> |
11 | 11 |
12 #include "base/containers/small_map.h" | 12 #include "base/containers/small_map.h" |
13 #include "base/files/scoped_file.h" | 13 #include "base/files/scoped_file.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/posix/global_descriptors.h" | 15 #include "base/posix/global_descriptors.h" |
16 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 | 18 |
| 19 namespace base { |
19 class Pickle; | 20 class Pickle; |
20 class PickleIterator; | 21 class PickleIterator; |
| 22 } |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 class ZygoteForkDelegate; | 26 class ZygoteForkDelegate; |
25 | 27 |
26 // This is the object which implements the zygote. The ZygoteMain function, | 28 // This is the object which implements the zygote. The ZygoteMain function, |
27 // which is called from ChromeMain, simply constructs one of these objects and | 29 // which is called from ChromeMain, simply constructs one of these objects and |
28 // runs it. | 30 // runs it. |
29 class Zygote { | 31 class Zygote { |
30 public: | 32 public: |
(...skipping 25 matching lines...) Expand all Loading... |
56 // Returns true if the NS sandbox is active. | 58 // Returns true if the NS sandbox is active. |
57 bool UsingNSSandbox() const; | 59 bool UsingNSSandbox() const; |
58 | 60 |
59 // --------------------------------------------------------------------------- | 61 // --------------------------------------------------------------------------- |
60 // Requests from the browser... | 62 // Requests from the browser... |
61 | 63 |
62 // Read and process a request from the browser. Returns true if we are in a | 64 // Read and process a request from the browser. Returns true if we are in a |
63 // new process and thus need to unwind back into ChromeMain. | 65 // new process and thus need to unwind back into ChromeMain. |
64 bool HandleRequestFromBrowser(int fd); | 66 bool HandleRequestFromBrowser(int fd); |
65 | 67 |
66 void HandleReapRequest(int fd, PickleIterator iter); | 68 void HandleReapRequest(int fd, base::PickleIterator iter); |
67 | 69 |
68 // Get the termination status of |real_pid|. |real_pid| is the PID as it | 70 // Get the termination status of |real_pid|. |real_pid| is the PID as it |
69 // appears outside of the sandbox. | 71 // appears outside of the sandbox. |
70 // Return true if it managed to get the termination status and return the | 72 // Return true if it managed to get the termination status and return the |
71 // status in |status| and the exit code in |exit_code|. | 73 // status in |status| and the exit code in |exit_code|. |
72 bool GetTerminationStatus(base::ProcessHandle real_pid, bool known_dead, | 74 bool GetTerminationStatus(base::ProcessHandle real_pid, bool known_dead, |
73 base::TerminationStatus* status, | 75 base::TerminationStatus* status, |
74 int* exit_code); | 76 int* exit_code); |
75 | 77 |
76 void HandleGetTerminationStatus(int fd, | 78 void HandleGetTerminationStatus(int fd, |
77 PickleIterator iter); | 79 base::PickleIterator iter); |
78 | 80 |
79 // This is equivalent to fork(), except that, when using the SUID sandbox, it | 81 // This is equivalent to fork(), except that, when using the SUID sandbox, it |
80 // returns the real PID of the child process as it appears outside the | 82 // returns the real PID of the child process as it appears outside the |
81 // sandbox, rather than returning the PID inside the sandbox. The child's | 83 // sandbox, rather than returning the PID inside the sandbox. The child's |
82 // real PID is determined by having it call content::SendZygoteChildPing(int) | 84 // real PID is determined by having it call content::SendZygoteChildPing(int) |
83 // using the |pid_oracle| descriptor. | 85 // using the |pid_oracle| descriptor. |
84 // Finally, when using a ZygoteForkDelegate helper, |uma_name|, |uma_sample|, | 86 // Finally, when using a ZygoteForkDelegate helper, |uma_name|, |uma_sample|, |
85 // and |uma_boundary_value| may be set if the helper wants to make a UMA | 87 // and |uma_boundary_value| may be set if the helper wants to make a UMA |
86 // report via UMA_HISTOGRAM_ENUMERATION. | 88 // report via UMA_HISTOGRAM_ENUMERATION. |
87 int ForkWithRealPid(const std::string& process_type, | 89 int ForkWithRealPid(const std::string& process_type, |
88 const base::GlobalDescriptors::Mapping& fd_mapping, | 90 const base::GlobalDescriptors::Mapping& fd_mapping, |
89 const std::string& channel_id, | 91 const std::string& channel_id, |
90 base::ScopedFD pid_oracle, | 92 base::ScopedFD pid_oracle, |
91 std::string* uma_name, | 93 std::string* uma_name, |
92 int* uma_sample, | 94 int* uma_sample, |
93 int* uma_boundary_value); | 95 int* uma_boundary_value); |
94 | 96 |
95 // Unpacks process type and arguments from |iter| and forks a new process. | 97 // Unpacks process type and arguments from |iter| and forks a new process. |
96 // Returns -1 on error, otherwise returns twice, returning 0 to the child | 98 // Returns -1 on error, otherwise returns twice, returning 0 to the child |
97 // process and the child process ID to the parent process, like fork(). | 99 // process and the child process ID to the parent process, like fork(). |
98 base::ProcessId ReadArgsAndFork(PickleIterator iter, | 100 base::ProcessId ReadArgsAndFork(base::PickleIterator iter, |
99 ScopedVector<base::ScopedFD> fds, | 101 ScopedVector<base::ScopedFD> fds, |
100 std::string* uma_name, | 102 std::string* uma_name, |
101 int* uma_sample, | 103 int* uma_sample, |
102 int* uma_boundary_value); | 104 int* uma_boundary_value); |
103 | 105 |
104 // Handle a 'fork' request from the browser: this means that the browser | 106 // Handle a 'fork' request from the browser: this means that the browser |
105 // wishes to start a new renderer. Returns true if we are in a new process, | 107 // wishes to start a new renderer. Returns true if we are in a new process, |
106 // otherwise writes the child_pid back to the browser via |fd|. Writes a | 108 // otherwise writes the child_pid back to the browser via |fd|. Writes a |
107 // child_pid of -1 on error. | 109 // child_pid of -1 on error. |
108 bool HandleForkRequest(int fd, | 110 bool HandleForkRequest(int fd, |
109 PickleIterator iter, | 111 base::PickleIterator iter, |
110 ScopedVector<base::ScopedFD> fds); | 112 ScopedVector<base::ScopedFD> fds); |
111 | 113 |
112 bool HandleGetSandboxStatus(int fd, | 114 bool HandleGetSandboxStatus(int fd, |
113 PickleIterator iter); | 115 base::PickleIterator iter); |
114 | 116 |
115 // The Zygote needs to keep some information about each process. Most | 117 // The Zygote needs to keep some information about each process. Most |
116 // notably what the PID of the process is inside the PID namespace of | 118 // notably what the PID of the process is inside the PID namespace of |
117 // the Zygote and whether or not a process was started by the | 119 // the Zygote and whether or not a process was started by the |
118 // ZygoteForkDelegate helper. | 120 // ZygoteForkDelegate helper. |
119 ZygoteProcessMap process_info_map_; | 121 ZygoteProcessMap process_info_map_; |
120 | 122 |
121 const int sandbox_flags_; | 123 const int sandbox_flags_; |
122 ScopedVector<ZygoteForkDelegate> helpers_; | 124 ScopedVector<ZygoteForkDelegate> helpers_; |
123 | 125 |
124 // Count of how many fork delegates for which we've invoked InitialUMA(). | 126 // Count of how many fork delegates for which we've invoked InitialUMA(). |
125 size_t initial_uma_index_; | 127 size_t initial_uma_index_; |
126 | 128 |
127 // This vector contains the PIDs of any child processes which have been | 129 // This vector contains the PIDs of any child processes which have been |
128 // created prior to the construction of the Zygote object, and must be reaped | 130 // created prior to the construction of the Zygote object, and must be reaped |
129 // before the Zygote exits. The Zygote will perform a blocking wait on these | 131 // before the Zygote exits. The Zygote will perform a blocking wait on these |
130 // children, so they must be guaranteed to be exiting by the time the Zygote | 132 // children, so they must be guaranteed to be exiting by the time the Zygote |
131 // exits. | 133 // exits. |
132 std::vector<base::ProcessHandle> extra_children_; | 134 std::vector<base::ProcessHandle> extra_children_; |
133 | 135 |
134 // This vector contains the FDs that must be closed before reaping the extra | 136 // This vector contains the FDs that must be closed before reaping the extra |
135 // children. | 137 // children. |
136 std::vector<int> extra_fds_; | 138 std::vector<int> extra_fds_; |
137 }; | 139 }; |
138 | 140 |
139 } // namespace content | 141 } // namespace content |
140 | 142 |
141 #endif // CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ | 143 #endif // CONTENT_ZYGOTE_ZYGOTE_LINUX_H_ |
OLD | NEW |