Bug 753046 - Add IPC support for BSDs, ipc/chromium part. r=cjones
authorMartin Husemann <martin@NetBSD.ORG>
Tue, 28 Aug 2012 23:16:41 +0200
changeset 107315 00a80ec972d5fce9132a79b78df4722ab99dd3d7
parent 107314 aec398b6aeb524f9b651cbb884625c62c8c196c0
child 107316 99bb81d74a3d15ec8ab7286915d0a09903149750
push idunknown
push userunknown
push dateunknown
reviewerscjones
bugs753046
milestone18.0a1
Bug 753046 - Add IPC support for BSDs, ipc/chromium part. r=cjones
ipc/chromium/src/base/base_paths.h
ipc/chromium/src/base/debug_util_posix.cc
ipc/chromium/src/base/dir_reader_posix.h
ipc/chromium/src/base/file_util_posix.cc
ipc/chromium/src/base/message_loop.cc
ipc/chromium/src/base/platform_thread.h
ipc/chromium/src/base/platform_thread_posix.cc
ipc/chromium/src/base/process_util.h
ipc/chromium/src/base/process_util_posix.cc
ipc/chromium/src/base/sys_info_posix.cc
ipc/chromium/src/base/time_posix.cc
ipc/chromium/src/build/build_config.h
ipc/chromium/src/chrome/common/ipc_channel_posix.h
ipc/chromium/src/chrome/common/ipc_message_utils.h
ipc/chromium/src/chrome/common/transport_dib.h
--- a/ipc/chromium/src/base/base_paths.h
+++ b/ipc/chromium/src/base/base_paths.h
@@ -8,17 +8,17 @@
 // This file declares path keys for the base module.  These can be used with
 // the PathService to access various special directories and files.
 
 #include "base/basictypes.h"
 #if defined(OS_WIN)
 #include "base/base_paths_win.h"
 #elif defined(OS_MACOSX)
 #include "base/base_paths_mac.h"
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
 #include "base/base_paths_linux.h"
 #endif
 #include "base/path_service.h"
 
 namespace base {
 
 enum {
   PATH_START = 0,
--- a/ipc/chromium/src/base/debug_util_posix.cc
+++ b/ipc/chromium/src/base/debug_util_posix.cc
@@ -1,43 +1,50 @@
 // Copyright (c) 2006-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.
 
 #include "build/build_config.h"
 #include "base/debug_util.h"
 
-#define MOZ_HAVE_EXECINFO_H (!defined(ANDROID) && !defined(__OpenBSD__))
+#define MOZ_HAVE_EXECINFO_H (defined(OS_LINUX) && !defined(ANDROID))
 
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <limits.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <unistd.h>
 #if MOZ_HAVE_EXECINFO_H
 #include <execinfo.h>
+#endif
+
+#if defined(OS_MACOSX) || defined(OS_BSD)
 #include <sys/sysctl.h>
 #endif
 
+#if defined(OS_DRAGONFLY) || defined(OS_FREEBSD)
+#include <sys/user.h>
+#endif
+
 #include "base/basictypes.h"
 #include "base/eintr_wrapper.h"
 #include "base/logging.h"
 #include "base/scoped_ptr.h"
 #include "base/string_piece.h"
 
 // static
 bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) {
   NOTIMPLEMENTED();
   return false;
 }
 
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_BSD)
 
 // Based on Apple's recommended method as described in
 // http://developer.apple.com/qa/qa2004/qa1361.html
 // static
 bool DebugUtil::BeingDebugged() {
   // If the process is sandboxed then we can't use the sysctl, so cache the
   // value.
   static bool is_set = false;
@@ -66,17 +73,25 @@ bool DebugUtil::BeingDebugged() {
   if (sysctl_result != 0) {
     is_set = true;
     being_debugged = false;
     return being_debugged;
   }
 
   // This process is being debugged if the P_TRACED flag is set.
   is_set = true;
+#if defined(OS_DRAGONFLY)
+  being_debugged = (info.kp_flags & P_TRACED) != 0;
+#elif defined(OS_FREEBSD)
+  being_debugged = (info.ki_flag & P_TRACED) != 0;
+#elif defined(OS_OPENBSD)
+  being_debugged = (info.p_flag & P_TRACED) != 0;
+#else
   being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0;
+#endif
   return being_debugged;
 }
 
 #elif defined(OS_LINUX)
 
 // We can look in /proc/self/status for TracerPid.  We are likely used in crash
 // handling, so we are careful not to use the heap or have side effects.
 // Another option that is common is to try to ptrace yourself, but then we
--- a/ipc/chromium/src/base/dir_reader_posix.h
+++ b/ipc/chromium/src/base/dir_reader_posix.h
@@ -13,25 +13,29 @@
 // the generic fallback in dir_reader_fallback.h.
 
 // Mac note: OS X has getdirentries, but it only works if we restrict Chrome to
 // 32-bit inodes. There is a getdirentries64 syscall in 10.6, but it's not
 // wrapped and the direct syscall interface is unstable. Using an unstable API
 // seems worse than falling back to enumerating all file descriptors so we will
 // probably never implement this on the Mac.
 
-#if defined(OS_LINUX) && !defined(OS_OPENBSD)
+#if defined(OS_LINUX)
 #include "base/dir_reader_linux.h"
+#elif defined(OS_BSD)
+#include "base/dir_reader_bsd.h"
 #else
 #include "base/dir_reader_fallback.h"
 #endif
 
 namespace base {
 
-#if defined(OS_LINUX) && !defined(OS_OPENBSD)
+#if defined(OS_LINUX)
 typedef DirReaderLinux DirReaderPosix;
+#elif defined(OS_BSD)
+typedef DirReaderBSD DirReaderPosix;
 #else
 typedef DirReaderFallback DirReaderPosix;
 #endif
 
 }  // namespace base
 
 #endif // BASE_DIR_READER_POSIX_H_
--- a/ipc/chromium/src/base/file_util_posix.cc
+++ b/ipc/chromium/src/base/file_util_posix.cc
@@ -28,17 +28,17 @@
 #include "base/basictypes.h"
 #include "base/eintr_wrapper.h"
 #include "base/file_path.h"
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "base/time.h"
 
 // FreeBSD/OpenBSD lacks stat64, but its stat handles files >2GB just fine
-#if defined(OS_FREEBSD) || defined(OS_OPENBSD)
+#ifndef HAVE_STAT64
 #define stat64 stat
 #endif
 
 namespace file_util {
 
 #if defined(GOOGLE_CHROME_BUILD)
 static const char* kTempFileName = "com.google.chrome.XXXXXX";
 #else
--- a/ipc/chromium/src/base/message_loop.cc
+++ b/ipc/chromium/src/base/message_loop.cc
@@ -14,17 +14,17 @@
 #include "base/thread_local.h"
 
 #if defined(OS_MACOSX)
 #include "base/message_pump_mac.h"
 #endif
 #if defined(OS_POSIX)
 #include "base/message_pump_libevent.h"
 #endif
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
 #ifdef MOZ_WIDGET_GTK2
 #include "base/message_pump_glib.h"
 #endif
 #ifdef MOZ_WIDGET_QT
 #include "base/message_pump_qt.h"
 #endif
 #endif
 #ifdef ANDROID
@@ -114,17 +114,17 @@ MessageLoop::MessageLoop(Type type)
   } else {
     DCHECK(type_ == TYPE_UI);
     pump_ = new base::MessagePumpForUI();
   }
 #elif defined(OS_POSIX)
   if (type_ == TYPE_UI) {
 #if defined(OS_MACOSX)
     pump_ = base::MessagePumpMac::Create();
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
     pump_ = new base::MessagePumpForUI();
 #endif  // OS_LINUX
   } else if (type_ == TYPE_IO) {
     pump_ = new base::MessagePumpLibevent();
   } else {
     pump_ = new base::MessagePumpDefault();
   }
 #endif  // OS_POSIX
--- a/ipc/chromium/src/base/platform_thread.h
+++ b/ipc/chromium/src/base/platform_thread.h
@@ -17,19 +17,21 @@
 // constructor can safely "value initialize" using () in the initializer list.
 #if defined(OS_WIN)
 #include <windows.h>
 typedef DWORD PlatformThreadId;
 typedef void* PlatformThreadHandle;  // HANDLE
 #elif defined(OS_POSIX)
 #include <pthread.h>
 typedef pthread_t PlatformThreadHandle;
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_OPENBSD)
 #include <unistd.h>
 typedef pid_t PlatformThreadId;
+#elif defined(OS_BSD)
+typedef lwpid_t PlatformThreadId;
 #elif defined(OS_MACOSX)
 #include <mach/mach.h>
 typedef mach_port_t PlatformThreadId;
 #endif
 #endif
 
 // A namespace for low-level thread functions.
 class PlatformThread {
--- a/ipc/chromium/src/base/platform_thread_posix.cc
+++ b/ipc/chromium/src/base/platform_thread_posix.cc
@@ -4,25 +4,33 @@
 
 #include "base/platform_thread.h"
 
 #include <errno.h>
 #include <sched.h>
 
 #if defined(OS_MACOSX)
 #include <mach/mach.h>
+#elif defined(OS_NETBSD)
+#include <lwp.h>
 #elif defined(OS_LINUX)
 #include <sys/syscall.h>
-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
 #include <sys/prctl.h>
-#elif !defined(__NetBSD__)
+#elif defined(OS_FREEBSD)
+#include <sys/param.h>
+#include <sys/thr.h>
+#endif
+
+#if !defined(OS_MACOSX)
+#include <unistd.h>
+#endif
+
+#if defined(OS_BSD) && !defined(OS_NETBSD)
 #include <pthread_np.h>
 #endif
-#include <unistd.h>
-#endif
 
 #if defined(OS_MACOSX)
 namespace base {
 void InitThreading();
 }  // namespace
 #endif
 
 static void* ThreadFunc(void* closure) {
@@ -33,19 +41,30 @@ static void* ThreadFunc(void* closure) {
 }
 
 // static
 PlatformThreadId PlatformThread::CurrentId() {
   // Pthreads doesn't have the concept of a thread ID, so we have to reach down
   // into the kernel.
 #if defined(OS_MACOSX)
   return mach_thread_self();
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
-  // TODO(BSD): find a better thread ID
-  return (intptr_t)(pthread_self());
+#elif defined(OS_NETBSD)
+  return _lwp_self();
+#elif defined(OS_DRAGONFLY)
+  return lwp_gettid();
+#elif defined(OS_FREEBSD)
+#  if __FreeBSD_version > 900030
+    return pthread_getthreadid_np();
+#  else
+    long lwpid;
+    thr_self(&lwpid);
+    return lwpid;
+#  endif
+#elif defined(OS_OPENBSD)
+  return (intptr_t) (pthread_self());
 #elif defined(OS_LINUX)
   return syscall(__NR_gettid);
 #endif
 }
 
 // static
 void PlatformThread::YieldCurrentThread() {
   sched_yield();
@@ -78,19 +97,19 @@ void PlatformThread::SetName(const char*
   if (PlatformThread::CurrentId() == getpid())
     return;
 
   // http://0pointer.de/blog/projects/name-your-threads.html
   // Set the name for the LWP (which gets truncated to 15 characters).
   // Note that glibc also has a 'pthread_setname_np' api, but it may not be
   // available everywhere and it's only benefit over using prctl directly is
   // that it can set the name of threads other than the current thread.
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(OS_BSD) && !defined(OS_NETBSD)
   pthread_set_name_np(pthread_self(), name);
-#elif defined(__NetBSD__)
+#elif defined(OS_NETBSD)
   pthread_setname_np(pthread_self(), "%s", (void *)name);
 #else
   prctl(PR_SET_NAME, reinterpret_cast<uintptr_t>(name), 0, 0, 0); 
 #endif
 }
 #endif // !OS_MACOSX
 
 namespace {
--- a/ipc/chromium/src/base/process_util.h
+++ b/ipc/chromium/src/base/process_util.h
@@ -286,40 +286,47 @@ class NamedProcessIterator {
   // If there's another process that matches the given executable name,
   // returns a const pointer to the corresponding PROCESSENTRY32.
   // If there are no more matching processes, returns NULL.
   // The returned pointer will remain valid until NextProcessEntry()
   // is called again or this NamedProcessIterator goes out of scope.
   const ProcessEntry* NextProcessEntry();
 
  private:
+#if !defined(OS_BSD)
   // Determines whether there's another process (regardless of executable)
   // left in the list of all processes.  Returns true and sets entry_ to
   // that process's info if there is one, false otherwise.
   bool CheckForNextProcess();
 
   bool IncludeEntry();
 
   // Initializes a PROCESSENTRY32 data structure so that it's ready for
   // use with Process32First/Process32Next.
   void InitProcessEntry(ProcessEntry* entry);
 
   std::wstring executable_name_;
+#endif
 
 #if defined(OS_WIN)
   HANDLE snapshot_;
   bool started_iteration_;
 #elif defined(OS_LINUX)
   DIR *procfs_dir_;
+#elif defined(OS_BSD)
+  std::vector<ProcessEntry> content;
+  size_t nextEntry;
 #elif defined(OS_MACOSX)
   std::vector<kinfo_proc> kinfo_procs_;
   size_t index_of_kinfo_proc_;
 #endif
+#if !defined(OS_BSD)
   ProcessEntry entry_;
   const ProcessFilter* filter_;
+#endif
 
   DISALLOW_EVIL_CONSTRUCTORS(NamedProcessIterator);
 };
 
 // Working Set (resident) memory usage broken down by
 // priv (private): These pages (kbytes) cannot be shared with any other process.
 // shareable:      These pages (kbytes) can be shared with other processes under
 //                 the right circumstances.
--- a/ipc/chromium/src/base/process_util_posix.cc
+++ b/ipc/chromium/src/base/process_util_posix.cc
@@ -111,16 +111,21 @@ void CloseSuperfluousFds(const base::Inj
   static const rlim_t kSystemDefaultMaxFds = 1024;
   static const char kFDDir[] = "/proc/self/fd";
 #elif defined(OS_LINUX)
   static const rlim_t kSystemDefaultMaxFds = 8192;
   static const char kFDDir[] = "/proc/self/fd";
 #elif defined(OS_MACOSX)
   static const rlim_t kSystemDefaultMaxFds = 256;
   static const char kFDDir[] = "/dev/fd";
+#elif defined(OS_BSD)
+  // the getrlimit below should never fail, so whatever ..
+  static const rlim_t kSystemDefaultMaxFds = 1024;
+  // at least /dev/fd will exist
+  static const char kFDDir[] = "/dev/fd";
 #endif
 
   // Get the maximum number of FDs possible.
   struct rlimit nofile;
   rlim_t max_fds;
   if (getrlimit(RLIMIT_NOFILE, &nofile)) {
     // getrlimit failed. Take a best guess.
     max_fds = kSystemDefaultMaxFds;
@@ -194,17 +199,17 @@ void CloseSuperfluousFds(const base::Inj
 
 // Sets all file descriptors to close on exec except for stdin, stdout
 // and stderr.
 // TODO(agl): Remove this function. It's fundamentally broken for multithreaded
 // apps.
 void SetAllFDsToCloseOnExec() {
 #if defined(OS_LINUX)
   const char fd_dir[] = "/proc/self/fd";
-#elif defined(OS_MACOSX)
+#elif defined(OS_MACOSX) || defined(OS_BSD)
   const char fd_dir[] = "/dev/fd";
 #endif
   ScopedDIR dir_closer(opendir(fd_dir));
   DIR *dir = dir_closer.get();
   if (NULL == dir) {
     DLOG(ERROR) << "Unable to open " << fd_dir;
     return;
   }
--- a/ipc/chromium/src/base/sys_info_posix.cc
+++ b/ipc/chromium/src/base/sys_info_posix.cc
@@ -13,25 +13,34 @@
 #include <sys/utsname.h>
 #include <unistd.h>
 
 #if defined(OS_MACOSX)
 #include <mach/mach_host.h>
 #include <mach/mach_init.h>
 #endif
 
+#if defined(OS_NETBSD)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 #include "base/logging.h"
 #include "base/string_util.h"
 
 namespace base {
 
 int SysInfo::NumberOfProcessors() {
   // It seems that sysconf returns the number of "logical" processors on both
   // mac and linux.  So we get the number of "online logical" processors.
+#ifdef _SC_NPROCESSORS_ONLN
   static long res = sysconf(_SC_NPROCESSORS_ONLN);
+#else
+  static long res = 1;
+#endif
   if (res == -1) {
     NOTREACHED();
     return 1;
   }
 
   return static_cast<int>(res);
 }
 
@@ -47,16 +56,30 @@ int64 SysInfo::AmountOfPhysicalMemory() 
                          &count);
   DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
   if (result != KERN_SUCCESS) {
     NOTREACHED();
     return 0;
   }
 
   return static_cast<int64>(hostinfo.max_mem);
+#elif defined(OS_NETBSD)
+  int mib[2];
+  int rc;
+  int64_t memSize;
+  size_t len = sizeof(memSize);
+
+  mib[0] = CTL_HW;
+  mib[1] = HW_PHYSMEM64;
+  rc = sysctl( mib, 2, &memSize, &len, NULL, 0 );
+  if (-1 != rc)  {
+    return memSize;
+  }
+  return 0;
+
 #else
   long pages = sysconf(_SC_PHYS_PAGES);
   long page_size = sysconf(_SC_PAGE_SIZE);
   if (pages == -1 || page_size == -1) {
     NOTREACHED();
     return 0;
   }
 
--- a/ipc/chromium/src/base/time_posix.cc
+++ b/ipc/chromium/src/base/time_posix.cc
@@ -162,17 +162,17 @@ TimeTicks TimeTicks::Now() {
   // to microseconds up front to stave off overflows.
   absolute_micro = mach_absolute_time() / Time::kNanosecondsPerMicrosecond *
                    timebase_info.numer / timebase_info.denom;
 
   // Don't bother with the rollover handling that the Windows version does.
   // With numer and denom = 1 (the expected case), the 64-bit absolute time
   // reported in nanoseconds is enough to last nearly 585 years.
 
-#elif defined(__OpenBSD__) || defined(OS_POSIX) && \
+#elif defined(OS_OPENBSD) || defined(OS_POSIX) && \
       defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
 
   struct timespec ts;
   if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
     NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed.";
     return TimeTicks();
   }
 
--- a/ipc/chromium/src/build/build_config.h
+++ b/ipc/chromium/src/build/build_config.h
@@ -14,27 +14,40 @@
 #ifndef BUILD_BUILD_CONFIG_H_
 #define BUILD_BUILD_CONFIG_H_
 
 // A set of macros to use for platform detection.
 #if defined(__APPLE__)
 #define OS_MACOSX 1
 #elif defined(__linux__) || defined(ANDROID)
 #define OS_LINUX 1
+#elif defined(__DragonFly__)
+#define OS_DRAGONFLY 1
+#elif defined(__FreeBSD__)
+#define OS_FREEBSD 1
+#elif defined(__NetBSD__)
+#define OS_NETBSD 1
 #elif defined(__OpenBSD__)
 #define OS_OPENBSD 1
 #elif defined(_WIN32)
 #define OS_WIN 1
 #else
 #error Please add support for your platform in build/build_config.h
 #endif
 
+// For access to standard BSD features, use OS_BSD instead of a
+// more specific macro.
+#if defined(OS_DRAGONFLY) || defined(OS_FREEBSD)	\
+  || defined(OS_NETBSD) || defined(OS_OPENBSD)
+#define OS_BSD 1
+#endif
+
 // For access to standard POSIX features, use OS_POSIX instead of a more
 // specific macro.
-#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_OPENBSD)
+#if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_BSD)
 #define OS_POSIX 1
 #endif
 
 // Compiler detection.
 #if defined(__GNUC__)
 #define COMPILER_GCC 1
 #elif defined(_MSC_VER)
 #define COMPILER_MSVC 1
--- a/ipc/chromium/src/chrome/common/ipc_channel_posix.h
+++ b/ipc/chromium/src/chrome/common/ipc_channel_posix.h
@@ -90,17 +90,17 @@ class Channel::ChannelImpl : public Mess
   enum {
     // We assume a worst case: kReadBufferSize bytes of messages, where each
     // message has no payload and a full complement of descriptors.
     MAX_READ_FDS = (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) *
                    FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE,
   };
 
   // This is a control message buffer large enough to hold kMaxReadFDs
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(OS_NETBSD)
   // TODO(agl): OSX appears to have non-constant CMSG macros!
   char input_cmsg_buf_[1024];
 #else
   char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)];
 #endif
 
   // Large messages that span multiple pipe buffers, get built-up using
   // this buffer.
--- a/ipc/chromium/src/chrome/common/ipc_message_utils.h
+++ b/ipc/chromium/src/chrome/common/ipc_message_utils.h
@@ -213,17 +213,17 @@ struct ParamTraits<long long> {
     return result;
   }
   static void Log(const param_type& p, std::wstring* l) {
     l->append(StringPrintf(L"%ll", p));
   }
 };
 #endif
 
-#if !(defined(OS_MACOSX) || defined(OS_OPENBSD) || defined(OS_WIN) || (defined(OS_LINUX) && defined(ARCH_CPU_64_BITS)) || defined(ARCH_CPU_S390))
+#if !(defined(OS_MACOSX) || defined(OS_OPENBSD) || defined(OS_WIN) || ((defined(OS_BSD) || defined(OS_LINUX)) && defined(ARCH_CPU_64_BITS)) || defined(ARCH_CPU_S390))
 // There size_t is a synonym for |unsigned long| ...
 template <>
 struct ParamTraits<size_t> {
   typedef size_t param_type;
   static void Write(Message* m, const param_type& p) {
     m->WriteSize(p);
   }
   static bool Read(const Message* m, void** iter, param_type* r) {
@@ -266,17 +266,17 @@ struct ParamTraits<uint32> {
     return m->ReadUInt32(iter, r);
   }
   static void Log(const param_type& p, std::wstring* l) {
     l->append(StringPrintf(L"%u", p));
   }
 };
 #endif  // defined(OS_MACOSX)
 
-#if !(defined(OS_LINUX) && defined(ARCH_CPU_64_BITS))
+#if !((defined(OS_BSD) || defined(OS_LINUX)) && defined(ARCH_CPU_64_BITS))
 // int64 is |long int| on 64-bit systems, uint64 is |unsigned long|
 template <>
 struct ParamTraits<int64> {
   typedef int64 param_type;
   static void Write(Message* m, const param_type& p) {
     m->WriteInt64(p);
   }
   static bool Read(const Message* m, void** iter, param_type* r) {
--- a/ipc/chromium/src/chrome/common/transport_dib.h
+++ b/ipc/chromium/src/chrome/common/transport_dib.h
@@ -2,17 +2,17 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #ifndef CHROME_COMMON_TRANSPORT_DIB_H_
 #define CHROME_COMMON_TRANSPORT_DIB_H_
 
 #include "base/basictypes.h"
 
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_BSD)
 #include "base/shared_memory.h"
 #endif
 
 #if defined(OS_WIN)
 #include <windows.h>
 #elif defined(OS_LINUX)
 #include "chrome/common/x11_util.h"
 #endif
@@ -61,17 +61,17 @@ class TransportDIB {
         return other.handle < handle;
       return other.sequence_num < sequence_num;
     }
 
     HANDLE handle;
     uint32 sequence_num;
   };
   typedef HandleAndSequenceNum Id;
-#elif defined(OS_MACOSX)
+#elif defined(OS_MACOSX) || defined(OS_BSD)
   typedef base::SharedMemoryHandle Handle;
   // On Mac, the inode number of the backing file is used as an id.
   typedef base::SharedMemoryId Id;
 #elif defined(OS_LINUX)
   typedef int Handle;  // These two ints are SysV IPC shared memory keys
   typedef int Id;
 #endif
 
@@ -103,17 +103,17 @@ class TransportDIB {
 #if defined(OS_LINUX)
   // Map the shared memory into the X server and return an id for the shared
   // segment.
   XID MapToX(Display* connection);
 #endif
 
  private:
   TransportDIB();
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_BSD)
   explicit TransportDIB(base::SharedMemoryHandle dib);
   base::SharedMemory shared_memory_;
   uint32 sequence_num_;
 #elif defined(OS_LINUX)
   int key_;  // SysV shared memory id
   void* address_;  // mapped address
   XID x_shm_;  // X id for the shared segment
   Display* display_;  // connection to the X server