| 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 #include <unistd.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/global_descriptors_posix.h" | 14 #include "base/global_descriptors_posix.h" |
| 15 #include "base/lock.h" | 15 #include "base/lock.h" |
| 16 #include "base/process.h" | 16 #include "base/process.h" |
| 17 #include "base/process_util.h" |
| 17 | 18 |
| 18 template<typename Type> | 19 template<typename Type> |
| 19 struct DefaultSingletonTraits; | 20 struct DefaultSingletonTraits; |
| 20 | 21 |
| 21 static const char kZygoteMagic[] = "ZYGOTE_OK"; | 22 static const char kZygoteMagic[] = "ZYGOTE_OK"; |
| 22 | 23 |
| 23 // http://code.google.com/p/chromium/wiki/LinuxZygote | 24 // http://code.google.com/p/chromium/wiki/LinuxZygote |
| 24 | 25 |
| 25 // The zygote host is the interface, in the browser process, to the zygote | 26 // The zygote host is the interface, in the browser process, to the zygote |
| 26 // process. | 27 // process. |
| 27 class ZygoteHost { | 28 class ZygoteHost { |
| 28 public: | 29 public: |
| 29 void Init(const std::string& sandbox_cmd); | 30 void Init(const std::string& sandbox_cmd); |
| 30 | 31 |
| 31 // Tries to start a renderer process. Returns its pid on success, otherwise | 32 // Tries to start a renderer process. Returns its pid on success, otherwise |
| 32 // base::kNullProcessHandle; | 33 // base::kNullProcessHandle; |
| 33 pid_t ForkRenderer(const std::vector<std::string>& command_line, | 34 pid_t ForkRenderer(const std::vector<std::string>& command_line, |
| 34 const base::GlobalDescriptors::Mapping& mapping); | 35 const base::GlobalDescriptors::Mapping& mapping); |
| 35 void EnsureProcessTerminated(pid_t process); | 36 void EnsureProcessTerminated(pid_t process); |
| 36 | 37 |
| 37 // Get the termination status (exit code) of the process and return true if | 38 // Get the termination status (and, optionally, the exit code) of |
| 38 // the status indicates the process crashed. |child_exited| is set to true | 39 // the process. |exit_code| is set to the exit code of the child |
| 39 // iff the child process has terminated. (|child_exited| may be NULL.) | 40 // process. (|exit_code| may be NULL.) |
| 40 bool DidProcessCrash(base::ProcessHandle handle, bool* child_exited); | 41 base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle, |
| 42 int* exit_code); |
| 41 | 43 |
| 42 // These are the command codes used on the wire between the browser and the | 44 // These are the command codes used on the wire between the browser and the |
| 43 // zygote. | 45 // zygote. |
| 44 enum { | 46 enum { |
| 45 kCmdFork = 0, // Fork off a new renderer. | 47 kCmdFork = 0, // Fork off a new renderer. |
| 46 kCmdReap = 1, // Reap a renderer child. | 48 kCmdReap = 1, // Reap a renderer child. |
| 47 kCmdDidProcessCrash = 2, // Check if child process crashed. | 49 kCmdGetTerminationStatus = 2, // Check what happend to a child process. |
| 48 kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox* | 50 kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox* |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 // These form a bitmask which describes the conditions of the sandbox that | 53 // These form a bitmask which describes the conditions of the sandbox that |
| 52 // the zygote finds itself in. | 54 // the zygote finds itself in. |
| 53 enum { | 55 enum { |
| 54 kSandboxSUID = 1 << 0, // SUID sandbox active | 56 kSandboxSUID = 1 << 0, // SUID sandbox active |
| 55 kSandboxPIDNS = 1 << 1, // SUID sandbox is using the PID namespace | 57 kSandboxPIDNS = 1 << 1, // SUID sandbox is using the PID namespace |
| 56 kSandboxNetNS = 1 << 2, // SUID sandbox is using the network namespace | 58 kSandboxNetNS = 1 << 2, // SUID sandbox is using the network namespace |
| 57 kSandboxSeccomp = 1 << 3, // seccomp sandbox active. | 59 kSandboxSeccomp = 1 << 3, // seccomp sandbox active. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 81 Lock control_lock_; | 83 Lock control_lock_; |
| 82 pid_t pid_; | 84 pid_t pid_; |
| 83 bool init_; | 85 bool init_; |
| 84 bool using_suid_sandbox_; | 86 bool using_suid_sandbox_; |
| 85 std::string sandbox_binary_; | 87 std::string sandbox_binary_; |
| 86 bool have_read_sandbox_status_word_; | 88 bool have_read_sandbox_status_word_; |
| 87 int sandbox_status_; | 89 int sandbox_status_; |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ | 92 #endif // CHROME_BROWSER_ZYGOTE_HOST_LINUX_H_ |
| OLD | NEW |