OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 5 #ifndef CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
6 #define CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 6 #define CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <unistd.h> | 9 // TODO(jam): remove this file when all files have been converted. |
10 | 10 #include "content/browser/zygote_host_linux.h" |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/global_descriptors_posix.h" | |
15 #include "base/process.h" | |
16 #include "base/process_util.h" | |
17 #include "base/synchronization/lock.h" | |
18 | |
19 template<typename Type> | |
20 struct DefaultSingletonTraits; | |
21 | |
22 static const char kZygoteMagic[] = "ZYGOTE_OK"; | |
23 | |
24 // http://code.google.com/p/chromium/wiki/LinuxZygote | |
25 | |
26 // The zygote host is the interface, in the browser process, to the zygote | |
27 // process. | |
28 class ZygoteHost { | |
29 public: | |
30 // Returns the singleton instance. | |
31 static ZygoteHost* GetInstance(); | |
32 | |
33 void Init(const std::string& sandbox_cmd); | |
34 | |
35 // Tries to start a renderer process. Returns its pid on success, otherwise | |
36 // base::kNullProcessHandle; | |
37 pid_t ForkRenderer(const std::vector<std::string>& command_line, | |
38 const base::GlobalDescriptors::Mapping& mapping); | |
39 void EnsureProcessTerminated(pid_t process); | |
40 | |
41 // Get the termination status (and, optionally, the exit code) of | |
42 // the process. |exit_code| is set to the exit code of the child | |
43 // process. (|exit_code| may be NULL.) | |
44 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, | |
45 int* exit_code); | |
46 | |
47 // These are the command codes used on the wire between the browser and the | |
48 // zygote. | |
49 enum { | |
50 kCmdFork = 0, // Fork off a new renderer. | |
51 kCmdReap = 1, // Reap a renderer child. | |
52 kCmdGetTerminationStatus = 2, // Check what happend to a child process. | |
53 kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox* | |
54 }; | |
55 | |
56 // These form a bitmask which describes the conditions of the sandbox that | |
57 // the zygote finds itself in. | |
58 enum { | |
59 kSandboxSUID = 1 << 0, // SUID sandbox active | |
60 kSandboxPIDNS = 1 << 1, // SUID sandbox is using the PID namespace | |
61 kSandboxNetNS = 1 << 2, // SUID sandbox is using the network namespace | |
62 kSandboxSeccomp = 1 << 3, // seccomp sandbox active. | |
63 }; | |
64 | |
65 pid_t pid() const { return pid_; } | |
66 | |
67 // Returns an int which is a bitmask of kSandbox* values. Only valid after | |
68 // the first render has been forked. | |
69 int sandbox_status() const { | |
70 if (have_read_sandbox_status_word_) | |
71 return sandbox_status_; | |
72 return 0; | |
73 } | |
74 | |
75 // Adjust the OOM score of the given renderer's PID. | |
76 void AdjustRendererOOMScore(base::ProcessHandle process_handle, int score); | |
77 | |
78 private: | |
79 friend struct DefaultSingletonTraits<ZygoteHost>; | |
80 ZygoteHost(); | |
81 ~ZygoteHost(); | |
82 | |
83 ssize_t ReadReply(void* buf, size_t buflen); | |
84 | |
85 int control_fd_; // the socket to the zygote | |
86 // A lock protecting all communication with the zygote. This lock must be | |
87 // acquired before sending a command and released after the result has been | |
88 // received. | |
89 base::Lock control_lock_; | |
90 pid_t pid_; | |
91 bool init_; | |
92 bool using_suid_sandbox_; | |
93 std::string sandbox_binary_; | |
94 bool have_read_sandbox_status_word_; | |
95 int sandbox_status_; | |
96 }; | |
97 | 11 |
98 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 12 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
OLD | NEW |