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