Fix code path that can overflow the native stack

We had a bug where a PHP program can infinitely recurse in a certain way
that doesn't hit any of our native stack overflow checks and causes the
process to segfault. Below I've included a snippet of the callstack that
caused HHVM to crash.

The fix is to make invokeFunc(), invokeFuncFew(), and invokeContFunc()
unconditionally perform a stack overflow check for the native stack. I
tried to keep the fix minimal and non-invasive so that we can get this
hotfixed if needed.

  #0  0x00000000032ba2ef in malloc ()
  #1  0x000000000257401e in HPHP::Util::canonicalize(char const*, unsigned long, bool) ()
  #2  0x0000000001c15f0e in HPHP::resolve_include(HPHP::String const&, char const*, bool (*)(HPHP::String const&, void*), void*) ()
  #3  0x0000000001bd0327 in HPHP::Eval::resolveVmInclude(HPHP::StringData*, char const*, stat*) ()
  #4  0x0000000001fe47d0 in HPHP::VMExecutionContext::lookupPhpFile(HPHP::StringData*, char const*, bool*) ()
  #5  0x0000000001fe521a in HPHP::VMExecutionContext::evalInclude(HPHP::StringData*, HPHP::StringData const*, bool*) ()
  #6  0x0000000001c17231 in HPHP::AutoloadHandler::Result HPHP::AutoloadHandler::loadFromMap<HPHP::ConstantExistsChecker>(HPHP::String const&, HPHP::String const&, bool, HPHP::ConstantExistsChecker const&) ()
  #7  0x0000000001c174ed in HPHP::AutoloadHandler::autoloadConstant(HPHP::StringData*) ()
  #8  0x00000000020c1c73 in HPHP::Unit::loadCns(HPHP::StringData const*) ()
  #9  0x0000000001f1d10e in HPHP::Transl::lookupCnsHelper(HPHP::TypedValue const*, HPHP::StringData*, bool) ()
  #10 0x000000002827f855 in ?? ()
  #11 0x00000000026e566e in enterTCHelper ()
  #12 0x0000000001f35ef0 in HPHP::Transl::TranslatorX64::enterTC(unsigned char*, void*) ()
  #13 0x0000000002018004 in HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::ActRec*) ()
  #14 0x000000000201821c in HPHP::VMExecutionContext::reenterVM(HPHP::TypedValue*, HPHP::ActRec*, HPHP::TypedValue*) ()
  #15 0x0000000002018612 in HPHP::VMExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::Func const*, HPHP::Array const&, HPHP::ObjectData*, HPHP::Class*, HPHP::VarEnv*, HPHP::StringData*, HPHP::VMExecutionContext::InvokeFlags) ()
  #16 0x0000000001c146d0 in HPHP::vm_call_user_func(HPHP::Variant const&, HPHP::Array const&, bool) ()
  #17 0x0000000001c17107 in HPHP::AutoloadHandler::Result HPHP::AutoloadHandler::loadFromMap<HPHP::ConstantExistsChecker>(HPHP::String const&, HPHP::String const&, bool, HPHP::ConstantExistsChecker const&) ()
  #18 0x0000000001c174ed in HPHP::AutoloadHandler::autoloadConstant(HPHP::StringData*) ()
  #19 0x00000000020c1c73 in HPHP::Unit::loadCns(HPHP::StringData const*) ()
  #20 0x0000000001f1d10e in HPHP::Transl::lookupCnsHelper(HPHP::TypedValue const*, HPHP::StringData*, bool) ()
  #21 0x000000002827f855 in ?? ()
  #22 0x00000000026e566e in enterTCHelper ()
  #23 0x0000000001f35ef0 in HPHP::Transl::TranslatorX64::enterTC(unsigned char*, void*) ()
  #24 0x0000000002018004 in HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::ActRec*) ()
  ...
  #28992 0x0000000001c174ed in HPHP::AutoloadHandler::autoloadConstant(HPHP::StringData*) ()
  #28993 0x00000000020c1c73 in HPHP::Unit::loadCns(HPHP::StringData const*) ()
  #28994 0x0000000001f1d10e in HPHP::Transl::lookupCnsHelper(HPHP::TypedValue const*, HPHP::StringData*, bool) ()
  #28995 0x000000002827f855 in ?? ()
  #28996 0x00000000026e566e in enterTCHelper ()
  #28997 0x0000000001f35ef0 in HPHP::Transl::TranslatorX64::enterTC(unsigned char*, void*) ()
  #28998 0x0000000002018004 in HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::ActRec*) ()
  #28999 0x000000000201821c in HPHP::VMExecutionContext::reenterVM(HPHP::TypedValue*, HPHP::ActRec*, HPHP::TypedValue*) ()
  #29000 0x0000000002018612 in HPHP::VMExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::Func const*, HPHP::Array const&, HPHP::ObjectData*, HPHP::Class*, HPHP::VarEnv*, HPHP::StringData*, HPHP::VMExecutionContext::InvokeFlags) ()
  #29001 0x0000000001c146d0 in HPHP::vm_call_user_func(HPHP::Variant const&, HPHP::Array const&, bool) ()
  #29002 0x0000000001c17676 in HPHP::AutoloadHandler::Result HPHP::AutoloadHandler::loadFromMap<HPHP::ClassExistsChecker>(HPHP::String const&, HPHP::String const&, bool, HPHP::ClassExistsChecker const&) ()
  #29003 0x0000000001c17a57 in HPHP::AutoloadHandler::invokeHandler(HPHP::String const&, bool) ()
  #29004 0x00000000020cb504 in HPHP::Unit::loadClass(HPHP::NamedEntity const*, HPHP::StringData const*) ()
  #29005 0x000000000203247e in void HPHP::VMExecutionContext::dispatchImpl<2>(int) ()
  #29006 0x000000000203ef43 in HPHP::VMExecutionContext::dispatchBB() ()
  #29007 0x0000000001f35f70 in HPHP::Transl::TranslatorX64::enterTC(unsigned char*, void*) ()
  #29008 0x0000000002017ed7 in HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::ActRec*) ()
  #29009 0x000000000201888d in HPHP::VMExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::Func const*, HPHP::Array const&, HPHP::ObjectData*, HPHP::Class*, HPHP::VarEnv*, HPHP::StringData*, HPHP::VMExecutionContext::InvokeFlags) ()
  #29010 0x0000000002018ea0 in HPHP::VMExecutionContext::invokeUnit(HPHP::TypedValue*, HPHP::Unit*) ()
  #29011 0x0000000001c15964 in HPHP::invoke_file(HPHP::String const&, bool, char const*) ()
  #29012 0x0000000001c19a52 in HPHP::include_impl_invoke(HPHP::String const&, bool, char const*) ()
  #29013 0x0000000001c5d883 in HPHP::hphp_invoke(HPHP::ExecutionContext*, std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > const&, bool, HPHP::Array const&, HPHP::VRefParamValue const&, std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > const&, std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > const&, bool&, std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> >&, bool, bool, bool) ()
  #29014 0x0000000001b2659e in HPHP::RPCRequestHandler::executePHPFunction(HPHP::Transport*, HPHP::SourceRootInfo&, HPHP::RPCRequestHandler::ReturnEncodeType) ()
  #29015 0x0000000001b285d3 in HPHP::RPCRequestHandler::handleRequest(HPHP::Transport*) ()
  #29016 0x0000000001b6b85b in HPHP::XboxWorker::doJob(HPHP::XboxTransport*) ()
  #29017 0x0000000001b669a3 in HPHP::JobQueueWorker<HPHP::XboxTransport*, HPHP::Server*, true, false, HPHP::JobQueueDropVMStack>::start() ()
  #29018 0x000000000252c127 in HPHP::AsyncFuncImpl::ThreadFunc(void*) ()
  #29019 0x00007f1ce3787f88 in start_thread (arg=0x7f1c377ff700)

Reviewed By: @jdelong

Differential Revision: D1052293
Fix GCC 4.7.x compilation issue with lambda

GCC 4.7.x on Amazon Linux AMI compilation results in the linker
being unable to find the lambda so de-lambdify it.

Closes #1264

Reviewed By: @ptarjan

Differential Revision: D1052778
Reimplemented RecursiveIteratorIterator

RecurisveIteratorIterator's original reverse engineer from lack
of PHP.net documentation had some parity differences -- make it better.

Closes #1260
Closes #1266

Reviewed By: @ptarjan

Differential Revision: D1052707

Pulled By: @scannell
Add proxies to our testing

We may be failing tests because the test needs access to the outside world, but we cannot get there due to the default firewall behavior. Provide the proxy info as part of the proc_open command to run the tests.

Also fixed a "thumb" problem. Better to rely on the contents of the expect file vs the out file to see if things ran as expected instead of setting variables all over the place.

Reviewed By: @ptarjan

Differential Revision: D1053079
Clean up lingering elements of old file-cache API

Fix callers which depended on old API, and drop compat hacks

Reviewed By: bmaurer

Differential Revision: D1038433
Fix whitespace error in expect file

we think it was arc land's fault

Reviewed By: @jdelong

Differential Revision: D1053214
Allow Zend to be used to run the unit tests for the frameworks

This gives the option to allow zend to be used to run the framework unit tests. This could be good for comparison purposes or to whitelist tests for HHVM that Zend also fails. Right now, we specify the path to the Zend binary. Later, we could see about using env variables or something to retrieve it.

Reviewed By: @ptarjan

Differential Revision: D1053279
Minor optimization to the common path in hhvm extension stubs

Reduce the number of instructions needed on what ought to be the most common path on some of the simpler extension stubs. For calls to functions on this_ with no locals the tests in free_frame_locals_inl and friends were redundant. Provided a path to avoid those. Also out-lined a bit of code which should be more rare to try to save a little code size, and added some LIKELY/UNLIKELY markers. Switched a memcpy to a struct assignment. Looking at the asm output for th_10WaitHandle_getWaitHandle() shows a leaner and straighter path after the call thru to the return. The difference bewtween the memcpy and the struct assignment is (strangely) slightly different register scheduling which produces what I imagine could be fewer stalls.

Reviewed By: @jdelong

Differential Revision: D1051867
Remove a few dead functions from runtime.cpp

Reviewed By: @ottoni

Differential Revision: D1051475
teach array_push about collections

Straight forward for Vectors and Sets: continue to throw
 exceptions for mapping types. ## array_push ## takes its array
 parameter as a reference, so the semantics are very close to a
 collection helper function.

Reviewed By: anietoro

Differential Revision: D1049841
Fix install bug after move to Framework classes

This bug basically prohibited the install of frameworks. Why? Because I was doing setXXX calls in the Framework constructor even if the framework wasn't installed. So I fixed that. To do this quickly, I removed the parallelization of multiple framework installs. But since the install should be rare, this quick fix is worth the time hit.

Failing flib tests have nothing to do with this script

Reviewed By: @ptarjan

Differential Revision: D1053633
Print better test run information.

Print out the actual command line string to run a given test. This will be printed in the errors/fatals/diff files.

Reviewed By: @ptarjan

Differential Revision: D1053801
Define ENT_SUBSTITUTE, fix flags handling in f_html* functions

We were just casting the flags argument from an int to a
StringUtil::QuoteStyle, but the arg can have more bits set in it.

Reviewed By: @ptarjan

Differential Revision: D1053206
Tweak magic call prologues to be a bit more efficient

They were doing increfs and decrefs while trying to get the
args into the packed array, and went through a C++ helper.  They also
would jump backward in the nPassed = 2 case and do a BIND_JMP in the
middle of the prologue, which prevents fallthrough from ever working.
This fixes that, uses the empty array for nPassed = 0, and
disentangles the code from the other prologues.  (I didn't do the same
for the ARM version for now.)

Reviewed By: @markw65

Differential Revision: D1049527
Move string out of bounds warning under HH syntax

Zend doesn't raise a warning, and this causes Joomla tests to fail

Reviewed By: @ptarjan

Differential Revision: D1051636
Replace REQ_INTERPRET with judicious interp-ones

REQ_INTERPRET is kind of heavyweight when we really just want a
conditional interp-one. This diff replaces REQ_INTERPRET in failure
cases with an interp-one on an exit trace, and removes the ReqInterpret
instruction. We still need the service requests, for the debugger case.

Reviewed By: @swtaarrs

Differential Revision: D1052990
Fix the flakiness of Pear

WTF PEAR!!?!?!

Well, Pear was out of control running tests in separate process with wildly changing statuseses for a given test depending on the time of day and alignment of the moon. So created a serial option...

We have consistency now. --record and subsequent runs give the same results.

In the future, maybe allow the parallel/serial flag to be set at the command line, but for now just setting this within the framework class itself.

Pear runs much slower this way. Results can't be viewed piecemail (gotta wait until the end of the run). And I will need to fix the test run messages that get printed in the diff/errors/fatals file to extract single test files this way (the message now tells you to run the entire test suite again).

This script is not affecting flib tests.

Reviewed By: @ptarjan

Differential Revision: D1054205
collections cleanup: throw_expected_array{_or_collection}_exception

Some array_* utils were migrated to understand collections,
 but still warn that "array_xyz expects array(s)" when passed a
 scalar.  This diff audits all instances of throw_bad_array_exception
 and renames some to throw_expected_array_exception and others to
 throw_expected_array_or_collection_exception, depending on whether
 the function has been migrated.

Reviewed By: anietoro

Differential Revision: D1053736
Fix bug causing Pear to fatal

Framework::$parallel needs to be set in the constructor only, or Pear fatals

Reviewed By: @JoelMarcey

Differential Revision: D1054784
Differential Revision: D1054961
Differential Revision: D1055096
Bump Twig Hash to add large int parsing fix

@ptarjan successfully got an upstream Twig pull request accepted for tests that parse large ints.

We are now Twig=100% :)

Reviewed By: @alexmalyshev

Differential Revision: D1055267