Bug 753046 - Add IPC support for BSDs, ipc/chromium part. r=cjones

This commit is contained in:
Martin Husemann 2012-08-28 23:16:41 +02:00
Родитель 675f8473f1
Коммит 7579a5c9e1
15 изменённых файлов: 114 добавлений и 26 удалений

Просмотреть файл

@ -13,7 +13,7 @@
#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"

Просмотреть файл

@ -5,7 +5,7 @@
#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>
@ -17,9 +17,16 @@
#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"
@ -32,7 +39,7 @@ bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) {
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
@ -71,7 +78,15 @@ bool DebugUtil::BeingDebugged() {
// 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;
}

Просмотреть файл

@ -18,16 +18,20 @@
// 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

Просмотреть файл

@ -33,7 +33,7 @@
#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

Просмотреть файл

@ -19,7 +19,7 @@
#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
@ -119,7 +119,7 @@ MessageLoop::MessageLoop(Type type)
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) {

Просмотреть файл

@ -22,9 +22,11 @@ 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;

Просмотреть файл

@ -9,16 +9,24 @@
#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__)
#include <pthread_np.h>
#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
#if defined(OS_MACOSX)
namespace base {
void InitThreading();
@ -38,9 +46,20 @@ PlatformThreadId PlatformThread::CurrentId() {
// 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
@ -83,9 +102,9 @@ void PlatformThread::SetName(const char* name) {
// 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);

Просмотреть файл

@ -291,6 +291,7 @@ class NamedProcessIterator {
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.
@ -303,18 +304,24 @@ class NamedProcessIterator {
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);
};

Просмотреть файл

@ -116,6 +116,11 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) {
#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.
@ -199,7 +204,7 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) {
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));

Просмотреть файл

@ -18,6 +18,11 @@
#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"
@ -26,7 +31,11 @@ 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;
@ -52,6 +61,20 @@ int64 SysInfo::AmountOfPhysicalMemory() {
}
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);

Просмотреть файл

@ -167,7 +167,7 @@ TimeTicks TimeTicks::Now() {
// 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;

Просмотреть файл

@ -19,6 +19,12 @@
#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)
@ -27,9 +33,16 @@
#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

Просмотреть файл

@ -95,7 +95,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
};
// 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

Просмотреть файл

@ -218,7 +218,7 @@ struct ParamTraits<long long> {
};
#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> {
@ -271,7 +271,7 @@ struct ParamTraits<uint32> {
};
#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> {

Просмотреть файл

@ -7,7 +7,7 @@
#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
@ -66,7 +66,7 @@ class TransportDIB {
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;
@ -108,7 +108,7 @@ class TransportDIB {
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_;