summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjorgelo@chromium.org <jorgelo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 18:15:46 +0000
committerjorgelo@chromium.org <jorgelo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 18:15:46 +0000
commitcf0b9af9df0338af47b6d3a33a26903da75a3e79 (patch)
treeb20c57ba184ac9155654d2cf036e0659d340db30
parent370c6bed8312fe1b305f6b519ae1c4afe79ceeb8 (diff)
downloadchromium_src-cf0b9af9df0338af47b6d3a33a26903da75a3e79.zip
chromium_src-cf0b9af9df0338af47b6d3a33a26903da75a3e79.tar.gz
chromium_src-cf0b9af9df0338af47b6d3a33a26903da75a3e79.tar.bz2
Make SandboxIPCProcess a thread.
BUG=322185 Review URL: https://codereview.chromium.org/255693002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267583 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/memory_details.cc4
-rw-r--r--content/browser/renderer_host/render_sandbox_host_linux.cc34
-rw-r--r--content/browser/renderer_host/render_sandbox_host_linux.h12
-rw-r--r--content/browser/renderer_host/sandbox_ipc_linux.cc65
-rw-r--r--content/browser/renderer_host/sandbox_ipc_linux.h20
-rw-r--r--content/browser/zygote_host/zygote_host_impl_linux.cc4
-rw-r--r--content/browser/zygote_host/zygote_host_impl_linux.h1
-rw-r--r--content/public/browser/zygote_host_linux.h3
8 files changed, 48 insertions, 95 deletions
diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc
index ce72dc7..3979226 100644
--- a/chrome/browser/memory_details.cc
+++ b/chrome/browser/memory_details.cc
@@ -204,8 +204,6 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
const pid_t zygote_pid = content::ZygoteHost::GetInstance()->GetPid();
- const pid_t sandbox_helper_pid =
- content::ZygoteHost::GetInstance()->GetSandboxHelperPid();
#endif
ProcessData* const chrome_browser = ChromeBrowser();
@@ -339,8 +337,6 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
if (process.pid == zygote_pid) {
process.process_type = content::PROCESS_TYPE_ZYGOTE;
- } else if (process.pid == sandbox_helper_pid) {
- process.process_type = content::PROCESS_TYPE_SANDBOX_HELPER;
}
#endif
}
diff --git a/content/browser/renderer_host/render_sandbox_host_linux.cc b/content/browser/renderer_host/render_sandbox_host_linux.cc
index 02b5fee..a700f94 100644
--- a/content/browser/renderer_host/render_sandbox_host_linux.cc
+++ b/content/browser/renderer_host/render_sandbox_host_linux.cc
@@ -8,16 +8,12 @@
#include "base/memory/singleton.h"
#include "base/posix/eintr_wrapper.h"
-#include "content/browser/renderer_host/sandbox_ipc_linux.h"
namespace content {
// Runs on the main thread at startup.
RenderSandboxHostLinux::RenderSandboxHostLinux()
- : initialized_(false),
- renderer_socket_(0),
- childs_lifeline_fd_(0),
- pid_(0) {
+ : initialized_(false), renderer_socket_(0) {
}
// static
@@ -48,34 +44,18 @@ void RenderSandboxHostLinux::Init(const std::string& sandbox_path) {
// Instead, it replies on a temporary socket provided by the caller.
PCHECK(0 == shutdown(browser_socket, SHUT_WR)) << "shutdown";
- int pipefds[2];
- CHECK(0 == pipe(pipefds));
- const int child_lifeline_fd = pipefds[0];
- childs_lifeline_fd_ = pipefds[1];
-
- // We need to be monothreaded before we fork().
-#if !defined(THREAD_SANITIZER)
- DCHECK_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle()));
-#endif // !defined(THREAD_SANITIZER)
- pid_ = fork();
- if (pid_ == 0) {
- if (IGNORE_EINTR(close(fds[0])) < 0)
- DPLOG(ERROR) << "close";
- if (IGNORE_EINTR(close(pipefds[1])) < 0)
- DPLOG(ERROR) << "close";
-
- SandboxIPCProcess handler(child_lifeline_fd, browser_socket, sandbox_path);
- handler.Run();
- _exit(0);
- }
+ ipc_handler_.reset(new SandboxIPCHandler(browser_socket, sandbox_path));
+ ipc_thread_.reset(
+ new base::DelegateSimpleThread(ipc_handler_.get(), "sandbox_ipc_thread"));
+ ipc_thread_->Start();
}
RenderSandboxHostLinux::~RenderSandboxHostLinux() {
if (initialized_) {
if (IGNORE_EINTR(close(renderer_socket_)) < 0)
PLOG(ERROR) << "close";
- if (IGNORE_EINTR(close(childs_lifeline_fd_)) < 0)
- PLOG(ERROR) << "close";
+
+ ipc_thread_->Join();
}
}
diff --git a/content/browser/renderer_host/render_sandbox_host_linux.h b/content/browser/renderer_host/render_sandbox_host_linux.h
index 2c5df38..6c88dcc 100644
--- a/content/browser/renderer_host/render_sandbox_host_linux.h
+++ b/content/browser/renderer_host/render_sandbox_host_linux.h
@@ -8,6 +8,9 @@
#include <string>
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/simple_thread.h"
+#include "content/browser/renderer_host/sandbox_ipc_linux.h"
#include "content/common/content_export.h"
template <typename T> struct DefaultSingletonTraits;
@@ -27,10 +30,6 @@ class CONTENT_EXPORT RenderSandboxHostLinux {
DCHECK(initialized_);
return renderer_socket_;
}
- pid_t pid() const {
- DCHECK(initialized_);
- return pid_;
- }
void Init(const std::string& sandbox_path);
private:
@@ -43,8 +42,9 @@ class CONTENT_EXPORT RenderSandboxHostLinux {
bool initialized_;
int renderer_socket_;
- int childs_lifeline_fd_;
- pid_t pid_;
+
+ scoped_ptr<SandboxIPCHandler> ipc_handler_;
+ scoped_ptr<base::DelegateSimpleThread> ipc_thread_;
DISALLOW_COPY_AND_ASSIGN(RenderSandboxHostLinux);
};
diff --git a/content/browser/renderer_host/sandbox_ipc_linux.cc b/content/browser/renderer_host/sandbox_ipc_linux.cc
index f988ae9..4f3b7c7 100644
--- a/content/browser/renderer_host/sandbox_ipc_linux.cc
+++ b/content/browser/renderer_host/sandbox_ipc_linux.cc
@@ -129,10 +129,9 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
namespace content {
-SandboxIPCProcess::SandboxIPCProcess(int lifeline_fd,
- int browser_socket,
+SandboxIPCHandler::SandboxIPCHandler(int browser_socket,
std::string sandbox_cmd)
- : lifeline_fd_(lifeline_fd), browser_socket_(browser_socket) {
+ : browser_socket_(browser_socket) {
if (!sandbox_cmd.empty()) {
sandbox_cmd_.push_back(sandbox_cmd);
sandbox_cmd_.push_back(base::kFindInodeSwitch);
@@ -142,33 +141,23 @@ SandboxIPCProcess::SandboxIPCProcess(int lifeline_fd,
// positioning, so we pass the current setting through to WebKit.
WebFontInfo::setSubpixelPositioning(
gfx::GetDefaultWebkitSubpixelPositioning());
-
- CommandLine& command_line = *CommandLine::ForCurrentProcess();
- command_line.AppendSwitchASCII(switches::kProcessType,
- switches::kSandboxIPCProcess);
-
- // Update the process title. The argv was already cached by the call to
- // SetProcessTitleFromCommandLine in content_main_runner.cc, so we can pass
- // NULL here (we don't have the original argv at this point).
- SetProcessTitleFromCommandLine(NULL);
}
-void SandboxIPCProcess::Run() {
- struct pollfd pfds[2];
- pfds[0].fd = lifeline_fd_;
+void SandboxIPCHandler::Run() {
+ struct pollfd pfds[1];
+ pfds[0].fd = browser_socket_;
pfds[0].events = POLLIN;
- pfds[1].fd = browser_socket_;
- pfds[1].events = POLLIN;
int failed_polls = 0;
for (;;) {
- const int r = HANDLE_EINTR(poll(pfds, 2, -1 /* no timeout */));
+ const int r =
+ HANDLE_EINTR(poll(pfds, arraysize(pfds), -1 /* no timeout */));
// '0' is not a possible return value with no timeout.
DCHECK_NE(0, r);
if (r < 0) {
PLOG(WARNING) << "poll";
if (failed_polls++ == 3) {
- LOG(FATAL) << "poll(2) failing. RenderSandboxHostLinux aborting.";
+ LOG(FATAL) << "poll(2) failing. SandboxIPCHandler aborting.";
return;
}
continue;
@@ -176,18 +165,20 @@ void SandboxIPCProcess::Run() {
failed_polls = 0;
- if (pfds[0].revents) {
- // our parent died so we should too.
- _exit(0);
+ // If poll(2) reports an error condition in the fd,
+ // we assume the zygote is gone and we return.
+ if (pfds[0].revents & (POLLERR | POLLHUP)) {
+ VLOG(1) << "SandboxIPCHandler stopping.";
+ return;
}
- if (pfds[1].revents) {
+ if (pfds[0].revents & POLLIN) {
HandleRequestFromRenderer(browser_socket_);
}
}
}
-void SandboxIPCProcess::HandleRequestFromRenderer(int fd) {
+void SandboxIPCHandler::HandleRequestFromRenderer(int fd) {
ScopedVector<base::ScopedFD> fds;
// A FontConfigIPC::METHOD_MATCH message could be kMaxFontFamilyLength
@@ -231,7 +222,7 @@ void SandboxIPCProcess::HandleRequestFromRenderer(int fd) {
}
}
-int SandboxIPCProcess::FindOrAddPath(const SkString& path) {
+int SandboxIPCHandler::FindOrAddPath(const SkString& path) {
int count = paths_.count();
for (int i = 0; i < count; ++i) {
if (path == *paths_[i])
@@ -241,7 +232,7 @@ int SandboxIPCProcess::FindOrAddPath(const SkString& path) {
return count;
}
-void SandboxIPCProcess::HandleFontMatchRequest(
+void SandboxIPCHandler::HandleFontMatchRequest(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -281,7 +272,7 @@ void SandboxIPCProcess::HandleFontMatchRequest(
SendRendererReply(fds, reply, -1);
}
-void SandboxIPCProcess::HandleFontOpenRequest(
+void SandboxIPCHandler::HandleFontOpenRequest(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -310,13 +301,13 @@ void SandboxIPCProcess::HandleFontOpenRequest(
}
}
-void SandboxIPCProcess::HandleGetFontFamilyForChar(
+void SandboxIPCHandler::HandleGetFontFamilyForChar(
int fd,
const Pickle& pickle,
PickleIterator iter,
const std::vector<base::ScopedFD*>& fds) {
// The other side of this call is
- // chrome/renderer/renderer_sandbox_support_linux.cc
+ // content/common/child_process_sandbox_support_impl_linux.cc
EnsureWebKitInitialized();
WebUChar32 c;
@@ -341,7 +332,7 @@ void SandboxIPCProcess::HandleGetFontFamilyForChar(
SendRendererReply(fds, reply, -1);
}
-void SandboxIPCProcess::HandleGetStyleForStrike(
+void SandboxIPCHandler::HandleGetStyleForStrike(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -370,7 +361,7 @@ void SandboxIPCProcess::HandleGetStyleForStrike(
SendRendererReply(fds, reply, -1);
}
-void SandboxIPCProcess::HandleLocaltime(
+void SandboxIPCHandler::HandleLocaltime(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -403,7 +394,7 @@ void SandboxIPCProcess::HandleLocaltime(
SendRendererReply(fds, reply, -1);
}
-void SandboxIPCProcess::HandleGetChildWithInode(
+void SandboxIPCHandler::HandleGetChildWithInode(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -438,7 +429,7 @@ void SandboxIPCProcess::HandleGetChildWithInode(
SendRendererReply(fds, reply, -1);
}
-void SandboxIPCProcess::HandleMakeSharedMemorySegment(
+void SandboxIPCHandler::HandleMakeSharedMemorySegment(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -458,7 +449,7 @@ void SandboxIPCProcess::HandleMakeSharedMemorySegment(
SendRendererReply(fds, reply, shm_fd);
}
-void SandboxIPCProcess::HandleMatchWithFallback(
+void SandboxIPCHandler::HandleMatchWithFallback(
int fd,
const Pickle& pickle,
PickleIterator iter,
@@ -618,7 +609,7 @@ void SandboxIPCProcess::HandleMatchWithFallback(
}
}
-void SandboxIPCProcess::SendRendererReply(
+void SandboxIPCHandler::SendRendererReply(
const std::vector<base::ScopedFD*>& fds,
const Pickle& reply,
int reply_fd) {
@@ -654,13 +645,13 @@ void SandboxIPCProcess::SendRendererReply(
PLOG(ERROR) << "sendmsg";
}
-SandboxIPCProcess::~SandboxIPCProcess() {
+SandboxIPCHandler::~SandboxIPCHandler() {
paths_.deleteAll();
if (webkit_platform_support_)
blink::shutdownWithoutV8();
}
-void SandboxIPCProcess::EnsureWebKitInitialized() {
+void SandboxIPCHandler::EnsureWebKitInitialized() {
if (webkit_platform_support_)
return;
webkit_platform_support_.reset(new BlinkPlatformImpl);
diff --git a/content/browser/renderer_host/sandbox_ipc_linux.h b/content/browser/renderer_host/sandbox_ipc_linux.h
index e900954..86c2756 100644
--- a/content/browser/renderer_host/sandbox_ipc_linux.h
+++ b/content/browser/renderer_host/sandbox_ipc_linux.h
@@ -12,26 +12,21 @@
#include "base/files/scoped_file.h"
#include "base/memory/scoped_ptr.h"
#include "base/pickle.h"
+#include "base/threading/simple_thread.h"
#include "content/child/blink_platform_impl.h"
#include "skia/ext/skia_utils_base.h"
namespace content {
-class SandboxIPCProcess {
+class SandboxIPCHandler : public base::DelegateSimpleThread::Delegate {
public:
- // lifeline_fd: this is the read end of a pipe which the browser process
- // holds the other end of. If the browser process dies, its descriptors are
- // closed and we will noticed an EOF on the pipe. That's our signal to exit.
- // browser_socket: the browser's end of the sandbox IPC socketpair. From the
- // point of view of the renderer, it's talking to the browser but this
- // object actually services the requests.
+ // browser_socket: the browser's end of the sandbox IPC socketpair.
// sandbox_cmd: the path of the sandbox executable.
- SandboxIPCProcess(int lifeline_fd,
- int browser_socket,
+ SandboxIPCHandler(int browser_socket,
std::string sandbox_cmd);
- ~SandboxIPCProcess();
+ virtual ~SandboxIPCHandler();
- void Run();
+ virtual void Run() OVERRIDE;
private:
void EnsureWebKitInitialized();
@@ -84,13 +79,12 @@ class SandboxIPCProcess {
const Pickle& reply,
int reply_fd);
- const int lifeline_fd_;
const int browser_socket_;
std::vector<std::string> sandbox_cmd_;
scoped_ptr<BlinkPlatformImpl> webkit_platform_support_;
SkTDArray<SkString*> paths_;
- DISALLOW_COPY_AND_ASSIGN(SandboxIPCProcess);
+ DISALLOW_COPY_AND_ASSIGN(SandboxIPCHandler);
};
} // namespace content
diff --git a/content/browser/zygote_host/zygote_host_impl_linux.cc b/content/browser/zygote_host/zygote_host_impl_linux.cc
index 8e6cf89..cbe04c1 100644
--- a/content/browser/zygote_host/zygote_host_impl_linux.cc
+++ b/content/browser/zygote_host/zygote_host_impl_linux.cc
@@ -523,10 +523,6 @@ pid_t ZygoteHostImpl::GetPid() const {
return pid_;
}
-pid_t ZygoteHostImpl::GetSandboxHelperPid() const {
- return RenderSandboxHostLinux::GetInstance()->pid();
-}
-
int ZygoteHostImpl::GetSandboxStatus() const {
if (have_read_sandbox_status_word_)
return sandbox_status_;
diff --git a/content/browser/zygote_host/zygote_host_impl_linux.h b/content/browser/zygote_host/zygote_host_impl_linux.h
index 08044fa..c443546 100644
--- a/content/browser/zygote_host/zygote_host_impl_linux.h
+++ b/content/browser/zygote_host/zygote_host_impl_linux.h
@@ -55,7 +55,6 @@ class CONTENT_EXPORT ZygoteHostImpl : public ZygoteHost {
// ZygoteHost implementation:
virtual pid_t GetPid() const OVERRIDE;
- virtual pid_t GetSandboxHelperPid() const OVERRIDE;
virtual int GetSandboxStatus() const OVERRIDE;
virtual void AdjustRendererOOMScore(base::ProcessHandle process_handle,
int score) OVERRIDE;
diff --git a/content/public/browser/zygote_host_linux.h b/content/public/browser/zygote_host_linux.h
index 77cc00b..ebe5ee7 100644
--- a/content/public/browser/zygote_host_linux.h
+++ b/content/public/browser/zygote_host_linux.h
@@ -26,9 +26,6 @@ class ZygoteHost {
// Returns the pid of the Zygote process.
virtual pid_t GetPid() const = 0;
- // Returns the pid of the Sandbox Helper process.
- virtual pid_t GetSandboxHelperPid() const = 0;
-
// Returns an int which is a bitmask of kSandboxLinux* values. Only valid
// after the first render has been forked.
virtual int GetSandboxStatus() const = 0;