diff --git a/hphp/runtime/base/program_functions.cpp b/hphp/runtime/base/program_functions.cpp index e12e997cd..e86be5f4e 100644 --- a/hphp/runtime/base/program_functions.cpp +++ b/hphp/runtime/base/program_functions.cpp @@ -1300,7 +1300,7 @@ static void on_timeout(int sig, siginfo_t* info, void* context) { void hphp_process_init() { pthread_attr_t attr; -#ifndef __APPLE__ +#ifdef _GNU_SOURCE pthread_getattr_np(pthread_self(), &attr); #else pthread_attr_init(&attr); diff --git a/hphp/runtime/ext/ext_hotprofiler.cpp b/hphp/runtime/ext/ext_hotprofiler.cpp index 7ecfdb81b..f28856288 100644 --- a/hphp/runtime/ext/ext_hotprofiler.cpp +++ b/hphp/runtime/ext/ext_hotprofiler.cpp @@ -27,32 +27,33 @@ #include "hphp/util/cycles.h" #ifdef __FreeBSD__ -# include -# include -# define cpu_set_t cpuset_t -# define SET_AFFINITY(pid, size, mask) \ +#include +#include +#include +#define cpu_set_t cpuset_t +#define SET_AFFINITY(pid, size, mask) \ cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask) -# define GET_AFFINITY(pid, size, mask) \ +#define GET_AFFINITY(pid, size, mask) \ cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, size, mask) -#elif __APPLE__ -# include -# include -# include +#elif defined(__APPLE__) +#include +#include +#include -# define cpu_set_t thread_affinity_policy_data_t -# define CPU_SET(cpu_id, new_mask) \ +#define cpu_set_t thread_affinity_policy_data_t +#define CPU_SET(cpu_id, new_mask) \ (*(new_mask)).affinity_tag = (cpu_id + 1) -# define CPU_ZERO(new_mask) \ +#define CPU_ZERO(new_mask) \ (*(new_mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL -# define GET_AFFINITY(pid, size, mask) \ +#define GET_AFFINITY(pid, size, mask) \ (*(mask)).affinity_tag = THREAD_AFFINITY_TAG_NULL -# define SET_AFFINITY(pid, size, mask) \ +#define SET_AFFINITY(pid, size, mask) \ thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, \ (int *)mask, THREAD_AFFINITY_POLICY_COUNT) #else -# include -# define SET_AFFINITY(pid, size, mask) sched_setaffinity(0, size, mask) -# define GET_AFFINITY(pid, size, mask) sched_getaffinity(0, size, mask) +#include +#define SET_AFFINITY(pid, size, mask) sched_setaffinity(0, size, mask) +#define GET_AFFINITY(pid, size, mask) sched_getaffinity(0, size, mask) #endif diff --git a/hphp/runtime/ext/ext_posix.cpp b/hphp/runtime/ext/ext_posix.cpp index c636882a9..75a9729c3 100644 --- a/hphp/runtime/ext/ext_posix.cpp +++ b/hphp/runtime/ext/ext_posix.cpp @@ -20,6 +20,9 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#endif #include #include #include @@ -421,7 +424,7 @@ Variant f_posix_uname() { ret.set(s_release, String(u.release, CopyString)); ret.set(s_version, String(u.version, CopyString)); ret.set(s_machine, String(u.machine, CopyString)); -#if defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(__FreeBSD__) +#if defined(_GNU_SOURCE) ret.set(s_domainname, String(u.domainname, CopyString)); #endif return ret; diff --git a/hphp/runtime/vm/debug/dwarf.cpp b/hphp/runtime/vm/debug/dwarf.cpp index 89572b373..4b24ce100 100644 --- a/hphp/runtime/vm/debug/dwarf.cpp +++ b/hphp/runtime/vm/debug/dwarf.cpp @@ -17,7 +17,7 @@ #include #include "debug.h" -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__FreeBSD__) #include "hphp/runtime/vm/debug/elfwriter.h" #endif #include "hphp/runtime/vm/debug/gdb-jit.h" @@ -36,7 +36,7 @@ namespace Debug { int g_dwarfCallback(char *name, int size, Dwarf_Unsigned type, Dwarf_Unsigned flags, Dwarf_Unsigned link, Dwarf_Unsigned info, Dwarf_Unsigned *sect_name_index, Dwarf_Ptr handle, int *error) { -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__FreeBSD__) ElfWriter *e = reinterpret_cast(handle); return e->dwarfCallback(name, size, type, flags, link, info); #else @@ -221,7 +221,7 @@ void DwarfInfo::compactChunks() { m_dwarfChunks[j] = nullptr; } m_dwarfChunks[i] = chunk; -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__FreeBSD__) // register compacted chunk with gdb ElfWriter e = ElfWriter(chunk); #endif @@ -291,7 +291,7 @@ DwarfChunk* DwarfInfo::addTracelet(TCRange range, const char* name, f->m_chunk = chunk; } -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__FreeBSD__) if (f->m_chunk->m_functions.size() >= RuntimeOption::EvalGdbSyncChunks) { ElfWriter e = ElfWriter(f->m_chunk); } @@ -306,7 +306,7 @@ void DwarfInfo::syncChunks() { for (i = 0; i < m_dwarfChunks.size(); i++) { if (m_dwarfChunks[i] && !m_dwarfChunks[i]->isSynced()) { unregister_gdb_chunk(m_dwarfChunks[i]); -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__FreeBSD__) ElfWriter e = ElfWriter(m_dwarfChunks[i]); #endif } diff --git a/hphp/runtime/vm/jit/translator-x64.cpp b/hphp/runtime/vm/jit/translator-x64.cpp index 28fce3ab4..d8b694e04 100644 --- a/hphp/runtime/vm/jit/translator-x64.cpp +++ b/hphp/runtime/vm/jit/translator-x64.cpp @@ -28,6 +28,9 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#endif #ifdef __FreeBSD__ #define RIP_REGISTER(v) (v).mc_rip diff --git a/hphp/util/assertions.h b/hphp/util/assertions.h index a6210ca9e..c09f08b79 100644 --- a/hphp/util/assertions.h +++ b/hphp/util/assertions.h @@ -86,7 +86,7 @@ inline void assert_fail(const char* e, const char* file, unsigned int line, const char* func) { -#if !defined(NDEBUG) && !defined(__APPLE__) +#if !defined(NDEBUG) && defined(_GNU_SOURCE) __assert_fail(e, file, line, func); #else extern void impl_assert_fail(const char*, diff --git a/hphp/util/compatibility.cpp b/hphp/util/compatibility.cpp index 239c00ece..2bb5cec61 100644 --- a/hphp/util/compatibility.cpp +++ b/hphp/util/compatibility.cpp @@ -20,7 +20,7 @@ namespace HPHP { /////////////////////////////////////////////////////////////////////////////// -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__FreeBSD__) char *strndup(const char* str, size_t len) { size_t str_len = strlen(str); if (len < str_len) { @@ -54,7 +54,7 @@ int dprintf(int fd, const char *format, ...) { #endif int gettime(clockid_t which_clock, struct timespec *tp) { -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__FreeBSD__) // XXX: OSX doesn't support realtime so we ignore which_clock struct timeval tv; int ret = gettimeofday(&tv, nullptr); diff --git a/hphp/util/compatibility.h b/hphp/util/compatibility.h index fb3ba77d2..1475d2a0d 100644 --- a/hphp/util/compatibility.h +++ b/hphp/util/compatibility.h @@ -24,7 +24,7 @@ namespace HPHP { #define PHP_DIR_SEPARATOR '/' -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__FreeBSD__) char *strndup(const char* str, size_t len); int dprintf(int fd, const char *format, ...) ATTRIBUTE_PRINTF(2,3); typedef int clockid_t; diff --git a/hphp/util/vdso.cpp b/hphp/util/vdso.cpp index d60bcbeb3..10bf685e2 100644 --- a/hphp/util/vdso.cpp +++ b/hphp/util/vdso.cpp @@ -14,9 +14,9 @@ +----------------------------------------------------------------------+ */ -#define _GNU_SOURCE 1 #include "hphp/util/vdso.h" +#define _GNU_SOURCE 1 #include