| 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 #include "content/zygote/zygote_linux.h" | 5 #include "content/zygote/zygote_linux.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "content/common/sandbox_linux/sandbox_linux.h" | 26 #include "content/common/sandbox_linux/sandbox_linux.h" |
| 27 #include "content/common/set_process_title.h" | 27 #include "content/common/set_process_title.h" |
| 28 #include "content/common/zygote_commands_linux.h" | 28 #include "content/common/zygote_commands_linux.h" |
| 29 #include "content/public/common/content_descriptors.h" | 29 #include "content/public/common/content_descriptors.h" |
| 30 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
| 31 #include "content/public/common/sandbox_linux.h" | 31 #include "content/public/common/sandbox_linux.h" |
| 32 #include "content/public/common/zygote_fork_delegate_linux.h" | 32 #include "content/public/common/zygote_fork_delegate_linux.h" |
| 33 #include "ipc/ipc_channel.h" | 33 #include "ipc/ipc_channel.h" |
| 34 #include "ipc/ipc_switches.h" | 34 #include "ipc/ipc_switches.h" |
| 35 | 35 |
| 36 #if defined(ADDRESS_SANITIZER) |
| 37 #include <sanitizer/asan_interface.h> |
| 38 #endif |
| 39 |
| 36 // See http://code.google.com/p/chromium/wiki/LinuxZygote | 40 // See http://code.google.com/p/chromium/wiki/LinuxZygote |
| 37 | 41 |
| 38 namespace content { | 42 namespace content { |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 // NOP function. See below where this handler is installed. | 46 // NOP function. See below where this handler is installed. |
| 43 void SIGCHLDHandler(int signal) { | 47 void SIGCHLDHandler(int signal) { |
| 44 } | 48 } |
| 45 | 49 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 } | 74 } |
| 71 | 75 |
| 72 // Kill the child process in case it's not already dead, so we can safely | 76 // Kill the child process in case it's not already dead, so we can safely |
| 73 // perform a blocking wait. | 77 // perform a blocking wait. |
| 74 PCHECK(0 == kill(pid, SIGKILL)); | 78 PCHECK(0 == kill(pid, SIGKILL)); |
| 75 PCHECK(pid == HANDLE_EINTR(waitpid(pid, NULL, 0))); | 79 PCHECK(pid == HANDLE_EINTR(waitpid(pid, NULL, 0))); |
| 76 } | 80 } |
| 77 | 81 |
| 78 } // namespace | 82 } // namespace |
| 79 | 83 |
| 80 Zygote::Zygote(int sandbox_flags, ScopedVector<ZygoteForkDelegate> helpers) | 84 Zygote::Zygote(int sandbox_flags, ScopedVector<ZygoteForkDelegate> helpers, |
| 85 const std::vector<base::ProcessHandle>& extra_children, |
| 86 const std::vector<int>& extra_fds) |
| 81 : sandbox_flags_(sandbox_flags), | 87 : sandbox_flags_(sandbox_flags), |
| 82 helpers_(helpers.Pass()), | 88 helpers_(helpers.Pass()), |
| 83 initial_uma_index_(0) { | 89 initial_uma_index_(0), |
| 84 } | 90 extra_children_(extra_children), |
| 91 extra_fds_(extra_fds) {} |
| 85 | 92 |
| 86 Zygote::~Zygote() { | 93 Zygote::~Zygote() { |
| 87 } | 94 } |
| 88 | 95 |
| 89 bool Zygote::ProcessRequests() { | 96 bool Zygote::ProcessRequests() { |
| 90 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the | 97 // A SOCK_SEQPACKET socket is installed in fd 3. We get commands from the |
| 91 // browser on it. | 98 // browser on it. |
| 92 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. | 99 // A SOCK_DGRAM is installed in fd 5. This is the sandbox IPC channel. |
| 93 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC | 100 // See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC |
| 94 | 101 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return sandbox_flags_ & kSandboxLinuxSUID; | 147 return sandbox_flags_ & kSandboxLinuxSUID; |
| 141 } | 148 } |
| 142 | 149 |
| 143 bool Zygote::HandleRequestFromBrowser(int fd) { | 150 bool Zygote::HandleRequestFromBrowser(int fd) { |
| 144 ScopedVector<base::ScopedFD> fds; | 151 ScopedVector<base::ScopedFD> fds; |
| 145 char buf[kZygoteMaxMessageLength]; | 152 char buf[kZygoteMaxMessageLength]; |
| 146 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); | 153 const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds); |
| 147 | 154 |
| 148 if (len == 0 || (len == -1 && errno == ECONNRESET)) { | 155 if (len == 0 || (len == -1 && errno == ECONNRESET)) { |
| 149 // EOF from the browser. We should die. | 156 // EOF from the browser. We should die. |
| 157 // TODO(earthdok): call __sanititizer_cov_dump() here to obtain code |
| 158 // coverage for the Zygote. Currently it's not possible because of |
| 159 // confusion over who is responsible for closing the file descriptor. |
| 160 for (std::vector<int>::iterator it = extra_fds_.begin(); |
| 161 it < extra_fds_.end(); ++it) { |
| 162 PCHECK(0 == IGNORE_EINTR(close(*it))); |
| 163 } |
| 164 #if !defined(ADDRESS_SANITIZER) |
| 165 // TODO(earthdok): add watchdog thread before using this in non-ASAN builds. |
| 166 CHECK(extra_children_.empty()); |
| 167 #endif |
| 168 for (std::vector<base::ProcessHandle>::iterator it = |
| 169 extra_children_.begin(); |
| 170 it < extra_children_.end(); ++it) { |
| 171 PCHECK(*it == HANDLE_EINTR(waitpid(*it, NULL, 0))); |
| 172 } |
| 150 _exit(0); | 173 _exit(0); |
| 151 return false; | 174 return false; |
| 152 } | 175 } |
| 153 | 176 |
| 154 if (len == -1) { | 177 if (len == -1) { |
| 155 PLOG(ERROR) << "Error reading message from browser"; | 178 PLOG(ERROR) << "Error reading message from browser"; |
| 156 return false; | 179 return false; |
| 157 } | 180 } |
| 158 | 181 |
| 159 Pickle pickle(buf, len); | 182 Pickle pickle(buf, len); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 PickleIterator iter) { | 584 PickleIterator iter) { |
| 562 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != | 585 if (HANDLE_EINTR(write(fd, &sandbox_flags_, sizeof(sandbox_flags_))) != |
| 563 sizeof(sandbox_flags_)) { | 586 sizeof(sandbox_flags_)) { |
| 564 PLOG(ERROR) << "write"; | 587 PLOG(ERROR) << "write"; |
| 565 } | 588 } |
| 566 | 589 |
| 567 return false; | 590 return false; |
| 568 } | 591 } |
| 569 | 592 |
| 570 } // namespace content | 593 } // namespace content |
| OLD | NEW |