OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_ZYGOTE_COMMUNICATION_H_ |
| 6 #define CONTENT_COMMON_ZYGOTE_COMMUNICATION_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/process/kill.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "content/public/browser/file_descriptor_info.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class CONTENT_EXPORT ZygoteCommunication { |
| 19 public: |
| 20 ZygoteCommunication(); |
| 21 ~ZygoteCommunication(); |
| 22 |
| 23 void Init(); |
| 24 |
| 25 // Tries to start a process of type indicated by process_type. |
| 26 // Returns its pid on success, otherwise |
| 27 // base::kNullProcessHandle; |
| 28 pid_t ForkRequest(const std::vector<std::string>& command_line, |
| 29 scoped_ptr<FileDescriptorInfo> mapping, |
| 30 const std::string& process_type); |
| 31 |
| 32 void EnsureProcessTerminated(pid_t process); |
| 33 |
| 34 // Should be called every time a Zygote child died. |
| 35 void ZygoteChildDied(pid_t process); |
| 36 |
| 37 // Get the termination status (and, optionally, the exit code) of |
| 38 // the process. |exit_code| is set to the exit code of the child |
| 39 // process. (|exit_code| may be NULL.) |
| 40 // Unfortunately the Zygote can not accurately figure out if a process |
| 41 // is already dead without waiting synchronously for it. |
| 42 // |known_dead| should be set to true when we already know that the process |
| 43 // is dead. When |known_dead| is false, processes could be seen as |
| 44 // still running, even when they're not. When |known_dead| is true, the |
| 45 // process will be SIGKILL-ed first (which should have no effect if it was |
| 46 // really dead). This is to prevent a waiting waitpid() from blocking in |
| 47 // a single-threaded Zygote. See crbug.com/157458. |
| 48 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, |
| 49 bool known_dead, |
| 50 int* exit_code); |
| 51 |
| 52 // Returns the sandbox status of this zygote. |
| 53 int GetSandboxStatus(); |
| 54 |
| 55 private: |
| 56 // Whether we should use the namespace sandbox instead of the setuid sandbox. |
| 57 bool ShouldUseNamespaceSandbox(); |
| 58 |
| 59 // Should be called every time a Zygote child is born. |
| 60 void ZygoteChildBorn(pid_t process); |
| 61 |
| 62 // Read the reply from the zygote. |
| 63 ssize_t ReadReply(void* buf, size_t buf_len); |
| 64 |
| 65 // Sends |data| to the zygote via |control_fd_|. If |fds| is non-NULL, the |
| 66 // included file descriptors will also be passed. The caller is responsible |
| 67 // for acquiring |control_lock_|. |
| 68 bool SendMessage(const base::Pickle& data, const std::vector<int>* fds); |
| 69 |
| 70 // Get the sandbox status from the zygote. |
| 71 ssize_t ReadSandboxStatus(); |
| 72 |
| 73 // Set to true when this is initialiazed successfuly. |
| 74 bool init_; |
| 75 int control_fd_; // the socket to the zygote. |
| 76 // A lock protecting all communication with the zygote. This lock must be |
| 77 // acquired before sending a command and released after the result has been |
| 78 // received. |
| 79 base::Lock control_lock_; |
| 80 // The pid of the zygote. |
| 81 pid_t pid_; |
| 82 // The listen of running zygote children. |
| 83 std::set<pid_t> list_of_running_zygote_children_; |
| 84 // The lock to guard the list of running zygote children. |
| 85 base::Lock child_tracking_lock_; |
| 86 bool have_read_sandbox_status_word_; |
| 87 bool use_suid_sandbox_for_adj_oom_score_; |
| 88 int sandbox_status_; |
| 89 }; |
| 90 |
| 91 } // namespace content |
| 92 |
| 93 #endif // CONTENT_COMMON_ZYGOTE_COMMUNICATION_H_ |
OLD | NEW |