summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-22 20:02:29 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-22 20:02:29 +0000
commitcf3ac397d5d729e299da8638c672055bba666e92 (patch)
tree4f3f8b634bdf3ebf92f424aef9b299e1a96d34fa /chrome
parent73db12c33f7b2e2ca53c2d962689b03e40e2106a (diff)
downloadchromium_src-cf3ac397d5d729e299da8638c672055bba666e92.zip
chromium_src-cf3ac397d5d729e299da8638c672055bba666e92.tar.gz
chromium_src-cf3ac397d5d729e299da8638c672055bba666e92.tar.bz2
Move unix domain socket support out of base and into chrome common. This is not
used outside of Chrome. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/5981006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/renderer_host/render_sandbox_host_linux.cc9
-rw-r--r--chrome/browser/zygote_host_linux.cc13
-rw-r--r--chrome/browser/zygote_main_linux.cc30
-rw-r--r--chrome/chrome_common.gypi18
-rw-r--r--chrome/common/font_config_ipc_linux.cc110
-rw-r--r--chrome/common/font_config_ipc_linux.h40
-rw-r--r--chrome/common/unix_domain_socket_posix.cc151
-rw-r--r--chrome/common/unix_domain_socket_posix.h54
-rw-r--r--chrome/renderer/renderer_sandbox_support_linux.cc26
9 files changed, 404 insertions, 47 deletions
diff --git a/chrome/browser/renderer_host/render_sandbox_host_linux.cc b/chrome/browser/renderer_host/render_sandbox_host_linux.cc
index 51fa55b..8f265b1 100644
--- a/chrome/browser/renderer_host/render_sandbox_host_linux.cc
+++ b/chrome/browser/renderer_host/render_sandbox_host_linux.cc
@@ -26,14 +26,13 @@
#include "base/singleton.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
-#include "base/unix_domain_socket_posix.h"
+#include "chrome/common/font_config_ipc_linux.h"
#include "chrome/common/sandbox_methods_linux.h"
+#include "chrome/common/unix_domain_socket_posix.h"
+#include "skia/ext/SkFontHost_fontconfig_direct.h"
#include "third_party/npapi/bindings/npapi_extensions.h"
#include "third_party/WebKit/WebKit/chromium/public/gtk/WebFontInfo.h"
-#include "SkFontHost_fontconfig_direct.h"
-#include "SkFontHost_fontconfig_ipc.h"
-
using WebKit::WebCString;
using WebKit::WebFontInfo;
using WebKit::WebUChar;
@@ -114,7 +113,7 @@ class SandboxIPCProcess {
// error for a maximum length message.
char buf[FontConfigInterface::kMaxFontFamilyLength + 128];
- const ssize_t len = base::RecvMsg(fd, buf, sizeof(buf), &fds);
+ const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds);
if (len == -1) {
// TODO: should send an error reply, or the sender might block forever.
NOTREACHED()
diff --git a/chrome/browser/zygote_host_linux.cc b/chrome/browser/zygote_host_linux.cc
index a908e86..6e2c7e3 100644
--- a/chrome/browser/zygote_host_linux.cc
+++ b/chrome/browser/zygote_host_linux.cc
@@ -20,15 +20,13 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/scoped_ptr.h"
-#include "base/unix_domain_socket_posix.h"
#include "base/utf_string_conversions.h"
-
#include "chrome/browser/renderer_host/render_sandbox_host_linux.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/process_watcher.h"
#include "chrome/common/result_codes.h"
-
+#include "chrome/common/unix_domain_socket_posix.h"
#include "sandbox/linux/suid/suid_unsafe_environment_variables.h"
static void SaveSUIDUnsafeEnvironmentVariables() {
@@ -154,7 +152,8 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) {
std::vector<int> fds_vec;
const int kExpectedLength = sizeof(kZygoteMagic);
char buf[kExpectedLength];
- const ssize_t len = base::RecvMsg(fds[0], buf, sizeof(buf), &fds_vec);
+ const ssize_t len = UnixDomainSocket::RecvMsg(fds[0], buf, sizeof(buf),
+ &fds_vec);
CHECK(len == kExpectedLength) << "Incorrect zygote magic length";
CHECK(0 == strcmp(buf, kZygoteMagic)) << "Incorrect zygote magic";
@@ -191,7 +190,8 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) {
Pickle pickle;
pickle.WriteInt(kCmdGetSandboxStatus);
std::vector<int> empty_fds;
- if (!base::SendMsg(control_fd_, pickle.data(), pickle.size(), empty_fds))
+ if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(),
+ empty_fds))
LOG(FATAL) << "Cannot communicate with zygote";
// We don't wait for the reply. We'll read it in ReadReply.
}
@@ -236,7 +236,8 @@ pid_t ZygoteHost::ForkRenderer(
pid_t pid;
{
AutoLock lock(control_lock_);
- if (!base::SendMsg(control_fd_, pickle.data(), pickle.size(), fds))
+ if (!UnixDomainSocket::SendMsg(control_fd_, pickle.data(), pickle.size(),
+ fds))
return base::kNullProcessHandle;
if (ReadReply(&pid, sizeof(pid)) != sizeof(pid))
diff --git a/chrome/browser/zygote_main_linux.cc b/chrome/browser/zygote_main_linux.cc
index 1b26a6b..c0ba88c 100644
--- a/chrome/browser/zygote_main_linux.cc
+++ b/chrome/browser/zygote_main_linux.cc
@@ -32,24 +32,20 @@
#include "base/rand_util.h"
#include "base/scoped_ptr.h"
#include "base/sys_info.h"
-#include "base/unix_domain_socket_posix.h"
#include "build/build_config.h"
-
#include "chrome/browser/zygote_host_linux.h"
#include "chrome/common/chrome_descriptors.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/font_config_ipc_linux.h"
#include "chrome/common/main_function_params.h"
#include "chrome/common/pepper_plugin_registry.h"
#include "chrome/common/process_watcher.h"
#include "chrome/common/result_codes.h"
#include "chrome/common/sandbox_methods_linux.h"
-
+#include "chrome/common/unix_domain_socket_posix.h"
#include "media/base/media.h"
-
-#include "skia/ext/SkFontHost_fontconfig_control.h"
-
#include "seccompsandbox/sandbox.h"
-
+#include "skia/ext/SkFontHost_fontconfig_control.h"
#include "unicode/timezone.h"
#if defined(ARCH_CPU_X86_FAMILY) && !defined(CHROMIUM_SELINUX) && \
@@ -116,8 +112,8 @@ class Zygote {
// Let the ZygoteHost know we are ready to go.
// The receiving code is in chrome/browser/zygote_host_linux.cc.
std::vector<int> empty;
- bool r = base::SendMsg(kBrowserDescriptor, kZygoteMagic,
- sizeof(kZygoteMagic), empty);
+ bool r = UnixDomainSocket::SendMsg(kBrowserDescriptor, kZygoteMagic,
+ sizeof(kZygoteMagic), empty);
CHECK(r) << "Sending zygote magic failed";
}
@@ -141,7 +137,7 @@ class Zygote {
std::vector<int> fds;
static const unsigned kMaxMessageLength = 1024;
char buf[kMaxMessageLength];
- const ssize_t len = base::RecvMsg(fd, buf, sizeof(buf), &fds);
+ const ssize_t len = UnixDomainSocket::RecvMsg(fd, buf, sizeof(buf), &fds);
if (len == 0 || (len == -1 && errno == ECONNRESET)) {
// EOF from the browser. We should die.
@@ -297,9 +293,9 @@ class Zygote {
request.WriteInt(LinuxSandbox::METHOD_GET_CHILD_WITH_INODE);
request.WriteUInt64(dummy_inode);
- const ssize_t r = base::SendRecvMsg(kMagicSandboxIPCDescriptor,
- reply_buf, sizeof(reply_buf),
- NULL, request);
+ const ssize_t r = UnixDomainSocket::SendRecvMsg(
+ kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL,
+ request);
if (r == -1) {
LOG(ERROR) << "Failed to get child process's real PID";
goto error;
@@ -453,7 +449,7 @@ static void ProxyLocaltimeCallToBrowser(time_t input, struct tm* output,
std::string(reinterpret_cast<char*>(&input), sizeof(input)));
uint8_t reply_buf[512];
- const ssize_t r = base::SendRecvMsg(
+ const ssize_t r = UnixDomainSocket::SendRecvMsg(
kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, request);
if (r == -1) {
memset(output, 0, sizeof(struct tm));
@@ -649,7 +645,8 @@ static bool EnterSandbox() {
return false;
}
- SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor);
+ SkiaFontConfigSetImplementation(
+ new FontConfigIPC(kMagicSandboxIPCDescriptor));
// Previously, we required that the binary be non-readable. This causes the
// kernel to mark the process as non-dumpable at startup. The thinking was
@@ -678,7 +675,8 @@ static bool EnterSandbox() {
}
} else if (switches::SeccompSandboxEnabled()) {
PreSandboxInit();
- SkiaFontConfigUseIPCImplementation(kMagicSandboxIPCDescriptor);
+ SkiaFontConfigSetImplementation(
+ new FontConfigIPC(kMagicSandboxIPCDescriptor));
} else {
SkiaFontConfigUseDirectImplementation();
}
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 80c1b0e..20b3093 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -28,8 +28,6 @@
'common/app_mode_common_mac.h',
'common/app_mode_common_mac.mm',
'common/bindings_policy.h',
- 'common/chrome_application_mac.h',
- 'common/chrome_application_mac.mm',
'common/child_process.cc',
'common/child_process.h',
'common/child_process_info.cc',
@@ -40,8 +38,12 @@
'common/child_process_logging_win.cc',
'common/child_thread.cc',
'common/child_thread.h',
+ 'common/chrome_application_mac.h',
+ 'common/chrome_application_mac.mm',
'common/chrome_counters.cc',
'common/chrome_counters.h',
+ 'common/chrome_version_info.cc',
+ 'common/chrome_version_info.h',
'common/common_param_traits.cc',
'common/common_param_traits.h',
'common/content_restriction.h',
@@ -71,22 +73,24 @@
'common/file_utilities_messages.h',
'common/font_descriptor_mac.h',
'common/font_descriptor_mac.mm',
+ 'common/font_config_ipc_linux.cc',
+ 'common/font_config_ipc_linux.h',
'common/geoposition.cc',
'common/geoposition.h',
'common/gpu_create_command_buffer_config.cc',
'common/gpu_create_command_buffer_config.h',
'common/gpu_feature_flags.cc',
'common/gpu_feature_flags.h',
- 'common/gpu_info.h',
'common/gpu_info.cc',
+ 'common/gpu_info.h',
'common/gpu_messages.cc',
'common/gpu_messages.h',
'common/gpu_messages_internal.h',
'common/gpu_param_traits.h',
'common/gpu_video_common.cc',
'common/gpu_video_common.h',
- 'common/guid.h',
'common/guid.cc',
+ 'common/guid.h',
'common/guid_posix.cc',
'common/guid_win.cc',
'common/indexed_db_key.cc',
@@ -126,10 +130,10 @@
'common/notification_type.h',
'common/pepper_file_messages.cc',
'common/pepper_file_messages.h',
+ 'common/process_watcher.h',
'common/process_watcher_mac.cc',
'common/process_watcher_posix.cc',
'common/process_watcher_win.cc',
- 'common/process_watcher.h',
'common/property_bag.cc',
'common/property_bag.h',
'common/ref_counted_util.h',
@@ -150,8 +154,8 @@
'common/switch_utils.h',
'common/time_format.cc',
'common/time_format.h',
- 'common/chrome_version_info.h',
- 'common/chrome_version_info.cc',
+ 'common/unix_domain_socket_posix.cc',
+ 'common/unix_domain_socket_posix.h',
'common/webblobregistry_impl.cc',
'common/webblobregistry_impl.h',
'common/win_safe_util.cc',
diff --git a/chrome/common/font_config_ipc_linux.cc b/chrome/common/font_config_ipc_linux.cc
new file mode 100644
index 0000000..a2e86a9
--- /dev/null
+++ b/chrome/common/font_config_ipc_linux.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/font_config_ipc_linux.h"
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
+#include "base/pickle.h"
+#include "chrome/common/unix_domain_socket_posix.h"
+
+FontConfigIPC::FontConfigIPC(int fd)
+ : fd_(fd) {
+}
+
+FontConfigIPC::~FontConfigIPC() {
+ close(fd_);
+}
+
+bool FontConfigIPC::Match(std::string* result_family,
+ unsigned* result_filefaceid,
+ bool filefaceid_valid, unsigned filefaceid,
+ const std::string& family,
+ const void* characters, size_t characters_bytes,
+ bool* is_bold, bool* is_italic) {
+ if (family.length() > kMaxFontFamilyLength)
+ return false;
+
+ Pickle request;
+ request.WriteInt(METHOD_MATCH);
+ request.WriteBool(filefaceid_valid);
+ if (filefaceid_valid)
+ request.WriteUInt32(filefaceid);
+
+ request.WriteBool(is_bold && *is_bold);
+ request.WriteBool(is_bold && *is_italic);
+
+ request.WriteUInt32(characters_bytes);
+ if (characters_bytes)
+ request.WriteBytes(characters, characters_bytes);
+
+ request.WriteString(family);
+
+ uint8_t reply_buf[512];
+ const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
+ sizeof(reply_buf), NULL,
+ request);
+ if (r == -1)
+ return false;
+
+ Pickle reply(reinterpret_cast<char*>(reply_buf), r);
+ void* iter = NULL;
+ bool result;
+ if (!reply.ReadBool(&iter, &result))
+ return false;
+ if (!result)
+ return false;
+
+ uint32_t reply_filefaceid;
+ std::string reply_family;
+ bool resulting_bold, resulting_italic;
+ if (!reply.ReadUInt32(&iter, &reply_filefaceid) ||
+ !reply.ReadString(&iter, &reply_family) ||
+ !reply.ReadBool(&iter, &resulting_bold) ||
+ !reply.ReadBool(&iter, &resulting_italic)) {
+ return false;
+ }
+
+ *result_filefaceid = reply_filefaceid;
+ if (result_family)
+ *result_family = reply_family;
+
+ if (is_bold)
+ *is_bold = resulting_bold;
+ if (is_italic)
+ *is_italic = resulting_italic;
+
+ return true;
+}
+
+int FontConfigIPC::Open(unsigned filefaceid) {
+ Pickle request;
+ request.WriteInt(METHOD_OPEN);
+ request.WriteUInt32(filefaceid);
+
+ int result_fd = -1;
+ uint8_t reply_buf[256];
+ const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
+ sizeof(reply_buf),
+ &result_fd, request);
+
+ if (r == -1)
+ return -1;
+
+ Pickle reply(reinterpret_cast<char*>(reply_buf), r);
+ bool result;
+ void* iter = NULL;
+ if (!reply.ReadBool(&iter, &result) ||
+ !result) {
+ if (result_fd)
+ close(result_fd);
+ return -1;
+ }
+
+ return result_fd;
+}
diff --git a/chrome/common/font_config_ipc_linux.h b/chrome/common/font_config_ipc_linux.h
new file mode 100644
index 0000000..e478f6a
--- /dev/null
+++ b/chrome/common/font_config_ipc_linux.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_FONT_CONFIG_IPC_LINUX_H_
+#define CHROME_COMMON_FONT_CONFIG_IPC_LINUX_H_
+#pragma once
+
+#include "skia/ext/SkFontHost_fontconfig_impl.h"
+
+#include <string>
+
+// FontConfig implementation for Skia that proxies out of process to get out
+// of the sandbox. See http://code.google.com/p/chromium/wiki/LinuxSandboxIPC
+class FontConfigIPC : public FontConfigInterface {
+ public:
+ explicit FontConfigIPC(int fd);
+ ~FontConfigIPC();
+
+ // FontConfigInterface implementation.
+ virtual bool Match(std::string* result_family,
+ unsigned* result_filefaceid,
+ bool filefaceid_valid,
+ unsigned filefaceid,
+ const std::string& family,
+ const void* characters,
+ size_t characters_bytes,
+ bool* is_bold, bool* is_italic);
+ virtual int Open(unsigned filefaceid);
+
+ enum Method {
+ METHOD_MATCH = 0,
+ METHOD_OPEN = 1,
+ };
+
+ private:
+ const int fd_;
+};
+
+#endif // CHROME_COMMON_FONT_CONFIG_IPC_LINUX_H_
diff --git a/chrome/common/unix_domain_socket_posix.cc b/chrome/common/unix_domain_socket_posix.cc
new file mode 100644
index 0000000..31f0135
--- /dev/null
+++ b/chrome/common/unix_domain_socket_posix.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/unix_domain_socket_posix.h"
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
+
+#include "base/eintr_wrapper.h"
+#include "base/logging.h"
+#include "base/pickle.h"
+
+// static
+bool UnixDomainSocket::SendMsg(int fd,
+ const void* buf,
+ size_t length,
+ const std::vector<int>& fds) {
+ struct msghdr msg;
+ memset(&msg, 0, sizeof(msg));
+ struct iovec iov = {const_cast<void*>(buf), length};
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ char* control_buffer = NULL;
+ if (fds.size()) {
+ const unsigned control_len = CMSG_SPACE(sizeof(int) * fds.size());
+ control_buffer = new char[control_len];
+
+ struct cmsghdr *cmsg;
+ msg.msg_control = control_buffer;
+ msg.msg_controllen = control_len;
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fds.size());
+ memcpy(CMSG_DATA(cmsg), &fds[0], sizeof(int) * fds.size());
+ msg.msg_controllen = cmsg->cmsg_len;
+ }
+
+ const ssize_t r = HANDLE_EINTR(sendmsg(fd, &msg, 0));
+ const bool ret = static_cast<ssize_t>(length) == r;
+ delete[] control_buffer;
+ return ret;
+}
+
+// static
+ssize_t UnixDomainSocket::RecvMsg(int fd,
+ void* buf,
+ size_t length,
+ std::vector<int>* fds) {
+ static const unsigned kMaxDescriptors = 16;
+
+ fds->clear();
+
+ struct msghdr msg;
+ memset(&msg, 0, sizeof(msg));
+ struct iovec iov = {buf, length};
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ char control_buffer[CMSG_SPACE(sizeof(int) * kMaxDescriptors)];
+ msg.msg_control = control_buffer;
+ msg.msg_controllen = sizeof(control_buffer);
+
+ const ssize_t r = HANDLE_EINTR(recvmsg(fd, &msg, 0));
+ if (r == -1)
+ return -1;
+
+ int* wire_fds = NULL;
+ unsigned wire_fds_len = 0;
+
+ if (msg.msg_controllen > 0) {
+ struct cmsghdr* cmsg;
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level == SOL_SOCKET &&
+ cmsg->cmsg_type == SCM_RIGHTS) {
+ const unsigned payload_len = cmsg->cmsg_len - CMSG_LEN(0);
+ DCHECK(payload_len % sizeof(int) == 0);
+ wire_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
+ wire_fds_len = payload_len / sizeof(int);
+ break;
+ }
+ }
+ }
+
+ if (msg.msg_flags & MSG_TRUNC || msg.msg_flags & MSG_CTRUNC) {
+ for (unsigned i = 0; i < wire_fds_len; ++i)
+ close(wire_fds[i]);
+ errno = EMSGSIZE;
+ return -1;
+ }
+
+ fds->resize(wire_fds_len);
+ memcpy(&(*fds)[0], wire_fds, sizeof(int) * wire_fds_len);
+
+ return r;
+}
+
+// static
+ssize_t UnixDomainSocket::SendRecvMsg(int fd,
+ uint8_t* reply,
+ unsigned max_reply_len,
+ int* result_fd,
+ const Pickle& request) {
+ int fds[2];
+
+ // This socketpair is only used for the IPC and is cleaned up before
+ // returning.
+ if (socketpair(AF_UNIX, SOCK_DGRAM, 0, fds) == -1)
+ return false;
+
+ std::vector<int> fd_vector;
+ fd_vector.push_back(fds[1]);
+ if (!SendMsg(fd, request.data(), request.size(), fd_vector)) {
+ close(fds[0]);
+ close(fds[1]);
+ return -1;
+ }
+ close(fds[1]);
+
+ fd_vector.clear();
+ const ssize_t reply_len = RecvMsg(fds[0], reply, max_reply_len, &fd_vector);
+ close(fds[0]);
+ if (reply_len == -1)
+ return -1;
+
+ if ((fd_vector.size() > 0 && result_fd == NULL) || fd_vector.size() > 1) {
+ for (std::vector<int>::const_iterator
+ i = fd_vector.begin(); i != fd_vector.end(); ++i) {
+ close(*i);
+ }
+
+ NOTREACHED();
+
+ return -1;
+ }
+
+ if (result_fd) {
+ if (fd_vector.size() == 0) {
+ *result_fd = -1;
+ } else {
+ *result_fd = fd_vector[0];
+ }
+ }
+
+ return reply_len;
+}
+
diff --git a/chrome/common/unix_domain_socket_posix.h b/chrome/common/unix_domain_socket_posix.h
new file mode 100644
index 0000000..405ca95
--- /dev/null
+++ b/chrome/common/unix_domain_socket_posix.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_
+#define CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_
+#pragma once
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <vector>
+
+class Pickle;
+
+class UnixDomainSocket {
+ public:
+ // Use sendmsg to write the given msg and include a vector of file
+ // descriptors. Returns true if successful.
+ static bool SendMsg(int fd,
+ const void* msg,
+ size_t length,
+ const std::vector<int>& fds);
+
+ // Use recvmsg to read a message and an array of file descriptors. Returns
+ // -1 on failure. Note: will read, at most, 16 descriptors.
+ static ssize_t RecvMsg(int fd,
+ void* msg,
+ size_t length,
+ std::vector<int>* fds);
+
+ // Perform a sendmsg/recvmsg pair.
+ // 1. This process creates a UNIX DGRAM socketpair.
+ // 2. This proces writes a request to |fd| with an SCM_RIGHTS control
+ // message containing on end of the fresh socket pair.
+ // 3. This process blocks reading from the other end of the fresh
+ // socketpair.
+ // 4. The target process receives the request, processes it and writes the
+ // reply to the end of the socketpair contained in the request.
+ // 5. This process wakes up and continues.
+ //
+ // fd: descriptor to send the request on
+ // reply: buffer for the reply
+ // reply_len: size of |reply|
+ // result_fd: (may be NULL) the file descriptor returned in the reply
+ // (if any)
+ // request: the bytes to send in the request
+ static ssize_t SendRecvMsg(int fd,
+ uint8_t* reply,
+ unsigned reply_len,
+ int* result_fd,
+ const Pickle& request);
+};
+
+#endif // CHROME_COMMON_UNIX_DOMAIN_SOCKET_POSIX_H_
diff --git a/chrome/renderer/renderer_sandbox_support_linux.cc b/chrome/renderer/renderer_sandbox_support_linux.cc
index 29fae48..539c9a4 100644
--- a/chrome/renderer/renderer_sandbox_support_linux.cc
+++ b/chrome/renderer/renderer_sandbox_support_linux.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/renderer/renderer_sandbox_support_linux.h"
@@ -10,9 +10,9 @@
#include "base/global_descriptors_posix.h"
#include "base/pickle.h"
#include "base/scoped_ptr.h"
-#include "base/unix_domain_socket_posix.h"
#include "chrome/common/chrome_descriptors.h"
#include "chrome/common/sandbox_methods_linux.h"
+#include "chrome/common/unix_domain_socket_posix.h"
#include "third_party/WebKit/WebKit/chromium/public/linux/WebFontRenderStyle.h"
@@ -31,8 +31,8 @@ std::string getFontFamilyForCharacters(const uint16_t* utf16,
request.WriteUInt32(utf16[i]);
uint8_t buf[512];
- const ssize_t n = base::SendRecvMsg(GetSandboxFD(), buf, sizeof(buf), NULL,
- request);
+ const ssize_t n = UnixDomainSocket::SendRecvMsg(GetSandboxFD(), buf,
+ sizeof(buf), NULL, request);
std::string family_name;
if (n != -1) {
@@ -52,8 +52,8 @@ void getRenderStyleForStrike(const char* family, int sizeAndStyle,
request.WriteInt(sizeAndStyle);
uint8_t buf[512];
- const ssize_t n = base::SendRecvMsg(GetSandboxFD(), buf, sizeof(buf), NULL,
- request);
+ const ssize_t n = UnixDomainSocket::SendRecvMsg(GetSandboxFD(), buf,
+ sizeof(buf), NULL, request);
out->setDefaults();
if (n == -1) {
@@ -84,9 +84,9 @@ int MakeSharedMemorySegmentViaIPC(size_t length, bool executable) {
request.WriteUInt32(length);
uint8_t reply_buf[10];
int result_fd;
- ssize_t result = base::SendRecvMsg(GetSandboxFD(),
- reply_buf, sizeof(reply_buf),
- &result_fd, request);
+ ssize_t result = UnixDomainSocket::SendRecvMsg(GetSandboxFD(),
+ reply_buf, sizeof(reply_buf),
+ &result_fd, request);
if (result == -1)
return -1;
return result_fd;
@@ -102,8 +102,8 @@ int MatchFontWithFallback(const std::string& face, bool bold,
request.WriteUInt32(charset);
uint8_t reply_buf[64];
int fd = -1;
- base::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
- &fd, request);
+ UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
+ &fd, request);
return fd;
}