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_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ | 5 #ifndef CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ |
6 #define CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ | 6 #define CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <map> |
mdempsky
2016/01/05 22:41:57
No need for <map> here.
Oh, you should add <sys/t
Greg K
2016/01/06 18:20:41
Done.
| |
9 | |
10 #include <set> | 9 #include <set> |
11 #include <string> | 10 #include <string> |
12 #include <vector> | |
13 | 11 |
14 #include "base/pickle.h" | |
15 #include "base/process/kill.h" | |
16 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
17 #include "content/public/browser/file_descriptor_info.h" | |
18 #include "content/public/browser/zygote_host_linux.h" | 13 #include "content/public/browser/zygote_host_linux.h" |
19 | 14 |
20 namespace base { | 15 namespace base { |
21 template<typename Type> | 16 template<typename Type> |
22 struct DefaultSingletonTraits; | 17 struct DefaultSingletonTraits; |
23 } // namespace base | 18 } // namespace base |
24 | 19 |
25 namespace content { | 20 namespace content { |
26 | 21 |
27 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost { | 22 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost { |
28 public: | 23 public: |
29 // Returns the singleton instance. | 24 // Returns the singleton instance. |
30 static ZygoteHostImpl* GetInstance(); | 25 static ZygoteHostImpl* GetInstance(); |
31 | 26 |
32 void Init(const std::string& sandbox_cmd); | 27 void Init(const std::string& sandbox_cmd); |
33 | 28 |
34 // After the last known Zygote child exits, notify the Zygote to exit. | 29 // Retrieves the sandbox command passed into Init(); |
35 void TearDownAfterLastChild(); | 30 const std::string& SandboxCommand() const; |
36 | 31 |
37 // Tries to start a process of type indicated by process_type. | 32 // Tells the ZygoteHost the PIDs of all the zygotes. |
38 // Returns its pid on success, otherwise | 33 void AddZygotePid(pid_t pid); |
39 // base::kNullProcessHandle; | |
40 pid_t ForkRequest(const std::vector<std::string>& command_line, | |
41 scoped_ptr<FileDescriptorInfo> mapping, | |
42 const std::string& process_type); | |
43 void EnsureProcessTerminated(pid_t process); | |
44 | 34 |
45 // Get the termination status (and, optionally, the exit code) of | 35 // Returns whether or not this pid is the pid of a zygote. |
46 // the process. |exit_code| is set to the exit code of the child | 36 bool IsZygotePid(pid_t pid) override; |
47 // process. (|exit_code| may be NULL.) | |
48 // Unfortunately the Zygote can not accurately figure out if a process | |
49 // is already dead without waiting synchronously for it. | |
50 // |known_dead| should be set to true when we already know that the process | |
51 // is dead. When |known_dead| is false, processes could be seen as | |
52 // still running, even when they're not. When |known_dead| is true, the | |
53 // process will be SIGKILL-ed first (which should have no effect if it was | |
54 // really dead). This is to prevent a waiting waitpid() from blocking in | |
55 // a single-threaded Zygote. See crbug.com/157458. | |
56 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, | |
57 bool known_dead, | |
58 int* exit_code); | |
59 | 37 |
60 // ZygoteHost implementation: | 38 void SetRendererSandboxStatus(int status); |
61 pid_t GetPid() const override; | 39 int GetRendererSandboxStatus() const override; |
62 int GetSandboxStatus() const override; | |
63 void AdjustRendererOOMScore(base::ProcessHandle process_handle, | 40 void AdjustRendererOOMScore(base::ProcessHandle process_handle, |
64 int score) override; | 41 int score) override; |
65 | 42 |
66 private: | 43 private: |
67 friend struct base::DefaultSingletonTraits<ZygoteHostImpl>; | 44 friend struct base::DefaultSingletonTraits<ZygoteHostImpl>; |
68 | 45 |
69 ZygoteHostImpl(); | 46 ZygoteHostImpl(); |
70 ~ZygoteHostImpl() override; | 47 ~ZygoteHostImpl() override; |
71 | 48 |
72 // Notify the Zygote to exit immediately. This object should not be | 49 int renderer_sandbox_status_; |
73 // used afterwards. | |
74 void TearDown(); | |
75 | |
76 // Should be called every time a Zygote child is born. | |
77 void ZygoteChildBorn(pid_t process); | |
78 | |
79 // Should be called every time a Zygote child died. | |
80 void ZygoteChildDied(pid_t process); | |
81 | |
82 // Sends |data| to the zygote via |control_fd_|. If |fds| is non-NULL, the | |
83 // included file descriptors will also be passed. The caller is responsible | |
84 // for acquiring |control_lock_|. | |
85 bool SendMessage(const base::Pickle& data, const std::vector<int>* fds); | |
86 | |
87 ssize_t ReadReply(void* buf, size_t buflen); | |
88 | |
89 // Whether we should use the namespace sandbox instead of the setuid sandbox. | |
90 bool ShouldUseNamespaceSandbox(); | |
91 | |
92 int control_fd_; // the socket to the zygote | |
93 // A lock protecting all communication with the zygote. This lock must be | |
94 // acquired before sending a command and released after the result has been | |
95 // received. | |
96 base::Lock control_lock_; | |
97 pid_t pid_; | |
98 bool init_; | |
99 bool use_suid_sandbox_for_adj_oom_score_; | 50 bool use_suid_sandbox_for_adj_oom_score_; |
100 std::string sandbox_binary_; | 51 std::string sandbox_binary_; |
101 bool have_read_sandbox_status_word_; | 52 // This lock protects the |zygote_pids_| set. |
102 int sandbox_status_; | 53 base::Lock zygote_pids_lock_; |
103 // A lock protecting list_of_running_zygote_children_ and | 54 // This is a set of PIDs representing all the running zygotes. |
104 // should_teardown_after_last_child_exits_. | 55 std::set<pid_t> zygote_pids_; |
105 base::Lock child_tracking_lock_; | |
106 std::set<pid_t> list_of_running_zygote_children_; | |
107 bool should_teardown_after_last_child_exits_; | |
108 }; | 56 }; |
109 | 57 |
110 } // namespace content | 58 } // namespace content |
111 | 59 |
112 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ | 60 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ |
OLD | NEW |