Skip to content

Instantly share code, notes, and snippets.

@danslo
Created March 27, 2014 16:40
Show Gist options
  • Save danslo/a30d4a4eca1a00521946 to your computer and use it in GitHub Desktop.
Save danslo/a30d4a4eca1a00521946 to your computer and use it in GitHub Desktop.
diff --git CMake/HPHPSetup.cmake CMake/HPHPSetup.cmake
index 812b789..e8c8d51 100644
--- CMake/HPHPSetup.cmake
+++ CMake/HPHPSetup.cmake
@@ -9,8 +9,9 @@ CHECK_CXX_SOURCE_COMPILES("
int main() { return 0; }" IS_AARCH64)
if (APPLE)
+ set(ENABLE_FASTCGI 1)
set(HHVM_ANCHOR_SYMS
- -Wl,-u,_register_libevent_server
+ -Wl,-u,_register_libevent_server,-u,_register_fastcgi_server
-Wl,-all_load hphp_runtime_static)
elseif (IS_AARCH64)
set(HHVM_ANCHOR_SYMS
diff --git hphp/runtime/base/thread-init-fini.cpp hphp/runtime/base/thread-init-fini.cpp
index 87bd5e4..b491151 100644
--- hphp/runtime/base/thread-init-fini.cpp
+++ hphp/runtime/base/thread-init-fini.cpp
@@ -53,7 +53,6 @@ InitFiniNode::InitFiniNode(void(*f)(), When init) {
void init_thread_locals(void *arg /* = NULL */) {
Sweepable::InitSweepableList();
ServerStats::GetLogger();
- zend_get_bigint_data();
zend_get_rand_data();
get_server_note();
g_persistentResources.getCheck();
diff --git hphp/runtime/base/zend-strtod.cpp hphp/runtime/base/zend-strtod.cpp
index 325304f..4aa5b2c 100644
--- hphp/runtime/base/zend-strtod.cpp
+++ hphp/runtime/base/zend-strtod.cpp
@@ -382,11 +382,7 @@ public:
Bigint **freelist;
Bigint *p5s;
};
-static IMPLEMENT_THREAD_LOCAL_NO_CHECK(BigintData, s_bigint_data);
-
-void zend_get_bigint_data() {
- s_bigint_data.getCheck();
-}
+static IMPLEMENT_THREAD_LOCAL(BigintData, s_bigint_data);
static Bigint * Balloc(int k)
{
diff --git hphp/runtime/base/zend-strtod.h hphp/runtime/base/zend-strtod.h
index 7259035..004be63 100644
--- hphp/runtime/base/zend-strtod.h
+++ hphp/runtime/base/zend-strtod.h
@@ -32,8 +32,6 @@ double zend_oct_strtod(const char *str, const char **endptr);
int zend_startup_strtod(void);
int zend_shutdown_strtod(void);
-void zend_get_bigint_data();
-
///////////////////////////////////////////////////////////////////////////////
}
diff --git hphp/runtime/ext/extension.cpp hphp/runtime/ext/extension.cpp
index a67560c..8d5ffa5 100644
--- hphp/runtime/ext/extension.cpp
+++ hphp/runtime/ext/extension.cpp
@@ -100,7 +100,7 @@ static const char* dlerror() {
Extension::Extension(litstr name, const char *version /* = "" */)
: m_hhvmAPIVersion(HHVM_API_VERSION)
- , m_name(makeStaticString(name))
+ , m_name(name)
, m_version(version ? version : "") {
if (s_registered_extensions == NULL) {
s_registered_extensions = new ExtensionMap();
@@ -238,11 +238,12 @@ Extension *Extension::GetExtension(const String& name) {
Array Extension::GetLoadedExtensions() {
assert(s_registered_extensions);
Array ret = Array::Create();
+ std::string apc = s_apc.toCppString();
for (auto& kv : *s_registered_extensions) {
- if (!apcExtension::Enable && kv.second->m_name == s_apc) {
+ if (!apcExtension::Enable && kv.second->m_name == apc) {
continue;
}
- ret.append(kv.second->m_name);
+ ret.append(String(kv.second->m_name));
}
return ret;
}
@@ -275,8 +276,7 @@ void Extension::CompileSystemlib(const std::string &slib,
*/
void Extension::loadSystemlib(const std::string& name /*= "" */) {
std::string hhas, slib, phpname("systemlib.php.");
- std::string n = name.empty() ?
- std::string(m_name.data(), m_name.size()) : name;
+ std::string n = name.empty() ? m_name : name;
phpname += n;
if (m_dsoName.empty() || !name.empty()) {
std::string section("ext.");
@@ -290,7 +290,7 @@ void Extension::loadSystemlib(const std::string& name /*= "" */) {
}
if (!hhas.empty()) {
std::string hhasname("systemlib.hhas.");
- hhasname += m_name.data();
+ hhasname += m_name;
CompileSystemlib(hhas, hhasname);
}
}
diff --git hphp/runtime/ext/extension.h hphp/runtime/ext/extension.h
index 27e0964..cf313f6 100644
--- hphp/runtime/ext/extension.h
+++ hphp/runtime/ext/extension.h
@@ -85,7 +85,7 @@ public:
// override these functions to implement module specific init/shutdown
// sequences and information display.
virtual void moduleLoad(Hdf hdf) {}
- virtual void moduleInfo(Array &info) { info.set(m_name, true);}
+ virtual void moduleInfo(Array &info) { info.set(String(m_name), true);}
virtual void moduleInit() {}
virtual void moduleShutdown() {}
virtual void threadInit() {}
@@ -102,7 +102,7 @@ private:
// this module was built against.
int64_t m_hhvmAPIVersion;
- const String m_name;
+ std::string m_name;
std::string m_version;
std::string m_dsoName;
};
diff --git hphp/third_party/thrift/lib/cpp/async/TAsyncServerSocket.cpp hphp/third_party/thrift/lib/cpp/async/TAsyncServerSocket.cpp
index 1585979..d59190d 100644
--- hphp/third_party/thrift/lib/cpp/async/TAsyncServerSocket.cpp
+++ hphp/third_party/thrift/lib/cpp/async/TAsyncServerSocket.cpp
@@ -591,7 +591,7 @@ void TAsyncServerSocket::handlerReady(
address.addressUpdated(addressFamily, addrLen);
int64_t nowMs = concurrency::Util::currentTime();
- int64_t timeSinceLastAccept = std::max(0L, nowMs - lastAccepTimestamp_);
+ int64_t timeSinceLastAccept = std::max((int64_t)0L, nowMs - lastAccepTimestamp_);
lastAccepTimestamp_ = nowMs;
if (acceptRate_ < 1) {
acceptRate_ *= 1 + acceptRateAdjustSpeed_ * timeSinceLastAccept;
diff --git hphp/third_party/thrift/lib/cpp/async/TAsyncSocket.cpp hphp/third_party/thrift/lib/cpp/async/TAsyncSocket.cpp
index 507c564..c05930a 100644
--- hphp/third_party/thrift/lib/cpp/async/TAsyncSocket.cpp
+++ hphp/third_party/thrift/lib/cpp/async/TAsyncSocket.cpp
@@ -1088,6 +1088,7 @@ int TAsyncSocket::setQuickAck(bool quickack) {
}
+#ifdef __linux__
int value = quickack ? 1 : 0;
if (setsockopt(fd_, IPPROTO_TCP, TCP_QUICKACK, &value, sizeof(value)) != 0) {
int errnoCopy = errno;
@@ -1096,6 +1097,7 @@ int TAsyncSocket::setQuickAck(bool quickack) {
<< strerror(errnoCopy);
return errnoCopy;
}
+#endif
return 0;
}
@@ -1613,12 +1615,18 @@ ssize_t TAsyncSocket::performWrite(const iovec* vec,
msg.msg_controllen = 0;
msg.msg_flags = 0;
+#ifndef __APPLE__
int msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
+#else
+ int msg_flags = MSG_DONTWAIT | SO_NOSIGPIPE;
+#endif
if (isSet(flags, WriteFlags::CORK)) {
// MSG_MORE tells the kernel we have more data to send, so wait for us to
// give it the rest of the data rather than immediately sending a partial
// frame, even when TCP_NODELAY is enabled.
+#ifndef __APPLE__
msg_flags |= MSG_MORE;
+#endif
}
if (isSet(flags, WriteFlags::EOR)) {
// marks that this is the last byte of a record (response)
diff --git hphp/third_party/thrift/lib/cpp/async/TEventFDWrapper.h hphp/third_party/thrift/lib/cpp/async/TEventFDWrapper.h
index 7b2d2b5..a9ef835 100644
--- hphp/third_party/thrift/lib/cpp/async/TEventFDWrapper.h
+++ hphp/third_party/thrift/lib/cpp/async/TEventFDWrapper.h
@@ -9,12 +9,10 @@
#ifndef HPHP_THRIFT_ASYNC_TEVENTFDWRAPPER_H
#define HPHP_THRIFT_ASYNC_TEVENTFDWRAPPER_H 1
-#include <features.h>
-
// <sys/eventfd.h> doesn't exist on older glibc versions
-#if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 9))
+#if defined(__GLIBC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 209)
#include <sys/eventfd.h>
-#else /* !(defined(__GLIBC__) && __GLIBC_PREREQ(2, 9)) */
+#else
#include <sys/syscall.h>
#include <unistd.h>
diff --git hphp/third_party/thrift/lib/cpp/async/TNotificationQueue.h hphp/third_party/thrift/lib/cpp/async/TNotificationQueue.h
index 26a698d..ec86cd7 100644
--- hphp/third_party/thrift/lib/cpp/async/TNotificationQueue.h
+++ hphp/third_party/thrift/lib/cpp/async/TNotificationQueue.h
@@ -186,6 +186,7 @@ class TNotificationQueue {
RequestContext::getStaticContext();
+#ifndef __APPLE__
if (fdType == FdType::EVENTFD) {
eventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK | EFD_SEMAPHORE);
if (eventfd_ == -1) {
@@ -202,6 +203,9 @@ class TNotificationQueue {
}
}
}
+#else
+ fdType = FdType::PIPE;
+#endif
if (fdType == FdType::PIPE) {
if (pipe(pipeFds_)) {
throw TLibraryException("Failed to create pipe for TNotificationQueue",
@@ -410,7 +414,7 @@ class TNotificationQueue {
// pipe semantics, add one message for each numAdded
bytes_expected = numAdded;
do {
- size_t messageSize = std::min(numAdded, sizeof(kPipeMessage));
+ size_t messageSize = std::min(numAdded, (uint64_t)sizeof(kPipeMessage));
ssize_t rc = ::write(pipeFds_[1], kPipeMessage, messageSize);
if (rc < 0) {
// TODO: if the pipe is full, write will fail with EAGAIN.
diff --git hphp/third_party/thrift/lib/cpp/concurrency/Mutex.cpp hphp/third_party/thrift/lib/cpp/concurrency/Mutex.cpp
index 8598294..8525e6a 100644
--- hphp/third_party/thrift/lib/cpp/concurrency/Mutex.cpp
+++ hphp/third_party/thrift/lib/cpp/concurrency/Mutex.cpp
@@ -25,6 +25,10 @@
#include <pthread.h>
#include <signal.h>
+#ifdef __APPLE__
+#include "hphp/util/pthread-timed-lock-shim.h"
+#endif
+
using std::shared_ptr;
namespace apache { namespace thrift { namespace concurrency {
diff --git hphp/third_party/thrift/lib/cpp/concurrency/PosixThreadFactory.cpp hphp/third_party/thrift/lib/cpp/concurrency/PosixThreadFactory.cpp
index 611c1ce..f25af84 100644
--- hphp/third_party/thrift/lib/cpp/concurrency/PosixThreadFactory.cpp
+++ hphp/third_party/thrift/lib/cpp/concurrency/PosixThreadFactory.cpp
@@ -368,7 +368,7 @@ class PosixThreadFactory::Impl {
void setDetachState(DetachState value) { detached_ = value; }
Thread::id_t getCurrentThreadId() const {
- return static_cast<Thread::id_t>(pthread_self());
+ return reinterpret_cast<Thread::id_t>(pthread_self());
}
};
diff --git hphp/third_party/thrift/lib/cpp/concurrency/Util.cpp hphp/third_party/thrift/lib/cpp/concurrency/Util.cpp
index bdbd0ce..e0cdae6 100644
--- hphp/third_party/thrift/lib/cpp/concurrency/Util.cpp
+++ hphp/third_party/thrift/lib/cpp/concurrency/Util.cpp
@@ -21,59 +21,29 @@
#include "thrift/lib/cpp/config.h"
#include "glog/logging.h"
+#include "hphp/util/timer.h"
-#if defined(HAVE_CLOCK_GETTIME)
-#include <time.h>
-#elif defined(HAVE_GETTIMEOFDAY)
-#include <sys/time.h>
-#endif // defined(HAVE_CLOCK_GETTIME)
#include <errno.h>
#include <assert.h>
+using HPHP::Timer;
+
namespace apache { namespace thrift { namespace concurrency {
const int64_t Util::currentTimeTicks(int64_t ticksPerSec) {
int64_t result;
-
-#if defined(HAVE_CLOCK_GETTIME)
struct timespec now;
- int ret = clock_gettime(CLOCK_REALTIME, &now);
- DCHECK(ret == 0);
+ Timer::GetRealtimeTime(now);
toTicks(result, now, ticksPerSec);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timeval now;
- int ret = gettimeofday(&now, nullptr);
- assert(ret == 0);
- toTicks(result, now, ticksPerSec);
-#else
-#error "No high-precision clock is available."
-#endif // defined(HAVE_CLOCK_GETTIME)
-
return result;
}
const int64_t Util::monotonicTimeTicks(int64_t ticksPerSec) {
-#if defined(HAVE_CLOCK_GETTIME)
- static bool useRealtime;
- if (useRealtime) {
- return currentTimeTicks(ticksPerSec);
- }
-
- struct timespec now;
- int ret = clock_gettime(CLOCK_MONOTONIC, &now);
- if (ret != 0) {
- // CLOCK_MONOTONIC is probably not supported on this system
- assert(errno == EINVAL);
- useRealtime = true;
- return currentTimeTicks(ticksPerSec);
- }
-
int64_t result;
+ struct timespec now;
+ Timer::GetMonotonicTime(now);
toTicks(result, now, ticksPerSec);
return result;
-#else
- return currentTimeTicks(ticksPerSec);
-#endif // defined(HAVE_CLOCK_GETTIME)
}
}}} // apache::thrift::concurrency
diff --git hphp/third_party/thrift/lib/cpp/thrift_config.h hphp/third_party/thrift/lib/cpp/thrift_config.h
index ac0fd56..5c66280 100644
--- hphp/third_party/thrift/lib/cpp/thrift_config.h
+++ hphp/third_party/thrift/lib/cpp/thrift_config.h
@@ -1,8 +1,6 @@
#ifndef THRIFT_THRIFT_CONFIG_H_
#define THRIFT_THRIFT_CONFIG_H_
-#include <features.h>
-
/* Define to 1 if you have the `clock_gettime' function. */
#define THRIFT_HAVE_CLOCK_GETTIME 1
diff --git hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.cpp hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.cpp
index a4a013f..8d99b1f 100644
--- hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.cpp
+++ hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.cpp
@@ -618,6 +618,7 @@ bool TSocketAddress::prefixMatch(const TSocketAddress& other,
uint32_t addr2 = other.storage_.ipv4.sin_addr.s_addr;
return (ntohl(addr1 ^ addr2) & mask) == 0;
}
+#ifndef __APPLE__
case AF_INET6:
{
const uint32_t* addr1 = storage_.ipv6.sin6_addr.s6_addr32;
@@ -637,6 +638,7 @@ bool TSocketAddress::prefixMatch(const TSocketAddress& other,
}
return true;
}
+#endif
default:
return false;
}
diff --git hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.h hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.h
index c524228..a27c652 100644
--- hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.h
+++ hphp/third_party/thrift/lib/cpp/transport/TSocketAddress.h
@@ -23,11 +23,11 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
-#include <features.h>
#include <netdb.h>
#include <cstddef>
#include <iostream>
#include <string>
+#include <cstring>
namespace apache { namespace thrift { namespace transport {
@@ -110,7 +110,7 @@ class TSocketAddress {
addr.storage_.addr.sa_family = AF_UNSPEC;
}
-#if __GNUC_PREREQ(4, 5)
+#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 405)
TSocketAddress& operator=(TSocketAddress&& addr) {
std::swap(storage_, addr.storage_);
return *this;
diff --git hphp/third_party/ti/proxygen/lib/transport/TransportInfo.cpp hphp/third_party/ti/proxygen/lib/transport/TransportInfo.cpp
index f9706b7..2e5890d 100644
--- hphp/third_party/ti/proxygen/lib/transport/TransportInfo.cpp
+++ hphp/third_party/ti/proxygen/lib/transport/TransportInfo.cpp
@@ -30,23 +30,30 @@ TransportInfo::TransportInfo()
}
bool TransportInfo::initWithSocket(const TAsyncSocket* sock) {
+#ifndef __APPLE__
if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) {
tcpinfoErrno = errno;
return false;
}
rtt = microseconds(tcpinfo.tcpi_rtt);
+#endif
validTcpinfo = true;
return true;
}
int64_t TransportInfo::readRTT(const TAsyncSocket* sock) {
+#ifndef __APPLE__
struct tcp_info tcpinfo;
if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) {
return -1;
}
return tcpinfo.tcpi_rtt;
+#else
+ return 0;
+#endif
}
+#ifndef __APPLE__
bool TransportInfo::readTcpInfo(struct tcp_info* tcpinfo,
const TAsyncSocket* sock) {
socklen_t len = sizeof(struct tcp_info);
@@ -60,6 +67,7 @@ bool TransportInfo::readTcpInfo(struct tcp_info* tcpinfo,
}
return true;
}
+#endif
TransportInfo::~TransportInfo() {
}
diff --git hphp/third_party/ti/proxygen/lib/transport/TransportInfo.h hphp/third_party/ti/proxygen/lib/transport/TransportInfo.h
index 299bf9b..4d84330 100644
--- hphp/third_party/ti/proxygen/lib/transport/TransportInfo.h
+++ hphp/third_party/ti/proxygen/lib/transport/TransportInfo.h
@@ -27,7 +27,9 @@ struct TransportInfo {
/*
* TCP information as fetched from getsockopt(2)
*/
+#ifndef __APPLE__
struct tcp_info tcpinfo;
+#endif
/*
* true if the tcpinfo was successfully read from the kernel
@@ -110,8 +112,10 @@ struct TransportInfo {
/*
* perform the getsockopt(2) syscall to fetch TCP info for a given socket
*/
+#ifndef __APPLE__
static bool readTcpInfo(struct tcp_info* tcpinfo,
const apache::thrift::async::TAsyncSocket* sock);
+#endif
};
}} // facebook::proxygen
diff --git hphp/util/mutex.h hphp/util/mutex.h
index 3bb5d4e..f4c474b 100644
--- hphp/util/mutex.h
+++ hphp/util/mutex.h
@@ -20,9 +20,6 @@
#include <pthread.h>
#include <time.h>
#include <tbb/concurrent_hash_map.h>
-#ifdef __APPLE__
-#include "pthread-spin-lock-shim.h"
-#endif
#include "hphp/util/portability.h"
#include "hphp/util/assertions.h"
diff --git hphp/util/pthread-timed-lock-shim.h hphp/util/pthread-timed-lock-shim.h
new file mode 100644
index 0000000..706903d
--- /dev/null
+++ hphp/util/pthread-timed-lock-shim.h
@@ -0,0 +1,65 @@
+/*
+ +----------------------------------------------------------------------+
+ | HipHop for PHP |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+*/
+#ifndef PTHREAD_TIMED_LOCK_SHIM
+#define PTHREAD_TIMED_LOCK_SHIM
+
+#define MUTEX_LOCK 1
+#define WRITE_LOCK 2
+#define READ_LOCK 3
+
+inline int _pthread_try_lock(void* lock, timespec* timeout, int type) {
+ switch (type) {
+ case MUTEX_LOCK:
+ return pthread_mutex_trylock((pthread_mutex_t*)lock);
+ case WRITE_LOCK:
+ return pthread_rwlock_trywrlock((pthread_rwlock_t*)lock);
+ case READ_LOCK:
+ return pthread_rwlock_tryrdlock((pthread_rwlock_t*)lock);
+ }
+ return 0;
+}
+
+int _pthread_timedlock(void* lock, timespec* timeout, int type) {
+ timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 10000000;
+
+ int ret;
+ while ((ret = _pthread_try_lock(lock, timeout, type)) == EBUSY) {
+ timeval now;
+ gettimeofday(&now, NULL);
+ if (now.tv_sec >= timeout->tv_sec &&
+ (now.tv_usec * 1000) >= timeout->tv_nsec) {
+ return ETIMEDOUT;
+ }
+ nanosleep(&ts, NULL);
+ }
+ return ret;
+}
+
+int pthread_mutex_timedlock(pthread_mutex_t* mutex, timespec* timeout) {
+ return _pthread_timedlock((void*)mutex, timeout, MUTEX_LOCK);
+}
+
+int pthread_rwlock_timedwrlock(pthread_rwlock_t* lock, timespec* timeout) {
+ return _pthread_timedlock((void*)lock, timeout, WRITE_LOCK);
+}
+
+int pthread_rwlock_timedrdlock(pthread_rwlock_t* lock, timespec* timeout) {
+ return _pthread_timedlock((void*)lock, timeout, READ_LOCK);
+}
+
+#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment