Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: content/browser/zygote_host/zygote_host_impl_linux.h

Issue 1640123005: Revert of Have each SandboxedProcessLauncherDelegate maintain a zygote. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sys/types.h> 8 #include <stddef.h>
9 9
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector>
12 13
13 #include "base/process/process_handle.h" 14 #include "base/pickle.h"
15 #include "base/process/kill.h"
14 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "content/public/browser/file_descriptor_info.h"
15 #include "content/public/browser/zygote_host_linux.h" 18 #include "content/public/browser/zygote_host_linux.h"
16 19
17 namespace base { 20 namespace base {
18 template<typename Type> 21 template<typename Type>
19 struct DefaultSingletonTraits; 22 struct DefaultSingletonTraits;
20 } // namespace base 23 } // namespace base
21 24
22 namespace content { 25 namespace content {
23 26
24 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost { 27 class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost {
25 public: 28 public:
26 // Returns the singleton instance. 29 // Returns the singleton instance.
27 static ZygoteHostImpl* GetInstance(); 30 static ZygoteHostImpl* GetInstance();
28 31
29 void Init(const std::string& sandbox_cmd); 32 void Init(const std::string& sandbox_cmd);
30 33
31 // Retrieves the sandbox command passed into Init(); 34 // After the last known Zygote child exits, notify the Zygote to exit.
32 const std::string& SandboxCommand() const; 35 void TearDownAfterLastChild();
33 36
34 // Tells the ZygoteHost the PIDs of all the zygotes. 37 // Tries to start a process of type indicated by process_type.
35 void AddZygotePid(pid_t pid); 38 // Returns its pid on success, otherwise
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);
36 44
37 // Returns whether or not this pid is the pid of a zygote. 45 // Get the termination status (and, optionally, the exit code) of
38 bool IsZygotePid(pid_t pid) override; 46 // the process. |exit_code| is set to the exit code of the child
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);
39 59
40 void SetRendererSandboxStatus(int status); 60 // ZygoteHost implementation:
41 int GetRendererSandboxStatus() const override; 61 pid_t GetPid() const override;
62 int GetSandboxStatus() const override;
42 void AdjustRendererOOMScore(base::ProcessHandle process_handle, 63 void AdjustRendererOOMScore(base::ProcessHandle process_handle,
43 int score) override; 64 int score) override;
44 65
45 private: 66 private:
46 friend struct base::DefaultSingletonTraits<ZygoteHostImpl>; 67 friend struct base::DefaultSingletonTraits<ZygoteHostImpl>;
47 68
48 ZygoteHostImpl(); 69 ZygoteHostImpl();
49 ~ZygoteHostImpl() override; 70 ~ZygoteHostImpl() override;
50 71
51 int renderer_sandbox_status_; 72 // Notify the Zygote to exit immediately. This object should not be
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_;
52 bool use_suid_sandbox_for_adj_oom_score_; 99 bool use_suid_sandbox_for_adj_oom_score_;
53 std::string sandbox_binary_; 100 std::string sandbox_binary_;
54 // This lock protects the |zygote_pids_| set. 101 bool have_read_sandbox_status_word_;
55 base::Lock zygote_pids_lock_; 102 int sandbox_status_;
56 // This is a set of PIDs representing all the running zygotes. 103 // A lock protecting list_of_running_zygote_children_ and
57 std::set<pid_t> zygote_pids_; 104 // should_teardown_after_last_child_exits_.
105 base::Lock child_tracking_lock_;
106 std::set<pid_t> list_of_running_zygote_children_;
107 bool should_teardown_after_last_child_exits_;
58 }; 108 };
59 109
60 } // namespace content 110 } // namespace content
61 111
62 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_ 112 #endif // CONTENT_BROWSER_ZYGOTE_HOST_ZYGOTE_HOST_IMPL_LINUX_H_
OLDNEW
« no previous file with comments | « content/browser/zygote_host/zygote_handle_linux.cc ('k') | content/browser/zygote_host/zygote_host_impl_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698