1. 27 Jan, 2017 1 commit
    • Christopher Dykes's avatar
      Make most implicit integer truncations and sign conversions explicit · fa172175
      Christopher Dykes authored
      Summary:
      This makes a large number of implicit truncations and sign conversions into explicit casts, in preparation for eventually enabling `-Wconversion` on Folly.
      This set of changes should have zero semantic change.
      
      This focuses on the core of Folly and leaves the tests alone for the most part. A future diff will cleanup the warnings in the tests as well.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4454096
      
      fbshipit-source-id: af1e1831675a804ec5679266c30c1fae62e8c35c
      fa172175
  2. 26 Jan, 2017 1 commit
    • Christopher Dykes's avatar
      Add __builtin___clear_cache to the portability headers · cc0ca971
      Christopher Dykes authored
      Summary:
      HHVM uses this heavily in it's ARM JIT, so provide an implementation. With GCC & Clang this function is a no-op on x86_64 where the requirement doesn't exist, so do the same in the portability header.
      This doesn't include the Windows portability header on x64 specifically because it is a very heavy header and this is currently very lightweight.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4451032
      
      fbshipit-source-id: 0af57448577635f9cd690ea9b09ce46a244191e1
      cc0ca971
  3. 25 Jan, 2017 6 commits
    • Daniel Sommermann's avatar
      Add ability to set custom SSLContext on TestSSLServer · d0d34d8e
      Daniel Sommermann authored
      Summary:
      This is needed if you want to test other scenarios where the
      server has other OpenSSL settings.
      
      Differential Revision: D4463587
      
      fbshipit-source-id: ffd4019e921649dee703363b2ff028b4d8063210
      d0d34d8e
    • Michael Lee's avatar
      Re-Gate setenv/unsetenv · 2eab3687
      Michael Lee authored
      Summary: `setenv`/`unsetenv` is not always declared the same way on all of the places folly is compiled.
      
      Reviewed By: matbd
      
      Differential Revision: D4462056
      
      fbshipit-source-id: 6dd68f6fc5a6a435f145cbaa43bee02b5fa7170c
      2eab3687
    • Daniel Sommermann's avatar
      Split out SSL test server for reuse · f1317625
      Daniel Sommermann authored
      Summary:
      The TestSSLServer is useful to have on its own for reuse. This
      diff separates it out to make reuse possible.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4457976
      
      fbshipit-source-id: 1fe6b71e930859ef04487e29047dcf603a79834b
      f1317625
    • Christopher Dykes's avatar
      Fix JemallocNodumpAllocator when compiled without folly-config.h · 904ebc63
      Christopher Dykes authored
      Summary: HHVM compiles without `folly-config.h`, so this was preventing us from updating to the newest version of Folly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4456890
      
      fbshipit-source-id: ed118ff0cf7f254a5f99be68f171d1b34ebf5c5c
      904ebc63
    • Petr Lapukhov's avatar
      Add disableTransparentTls call · a73e2ed6
      Petr Lapukhov authored
      Summary: Similar to AsyncSocket, allow setting reserved sockopt after bind(). This will be recognized by intercepted accept4() call and forked sockets will properly have the TLS flag disabled.
      
      Reviewed By: djwatson
      
      Differential Revision: D4458831
      
      fbshipit-source-id: fa753b9d849bd661563364d36229113f7abb0ee0
      a73e2ed6
    • Christopher Dykes's avatar
      Actually allow SFINAE to occur with setThreadName · eb8b2d91
      Christopher Dykes authored
      Summary:
      It wasn't actually SFINAE the way it was setup previously, which meant it was just a hard error under MSVC.
      Whoops.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4453702
      
      fbshipit-source-id: 5be600fb5ecdc8255795fefbd37c1fe26e7266dd
      eb8b2d91
  4. 24 Jan, 2017 3 commits
    • Mathieu Baudet's avatar
      folly: remove unused includes · b1974960
      Mathieu Baudet authored
      Summary:
      Found with our include analysis tool.
      
      I had to tweak `portability/Environment.h` to avoid a false positive breaking win32.
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D4452463
      
      fbshipit-source-id: e2e862e204892037ddde8815218e4deab1bfbb06
      b1974960
    • Ryan Wilson's avatar
      Add needsPeerVerification function to check if peer cert should be verified · a857f83b
      Ryan Wilson authored
      Summary:
      This patch adds a function to AsyncSSLSocket, so the user can check if the peer cert
      should be verified. This allows the user to implement custom logic for peer cert validation.
      
      Reviewed By: Orvid
      
      Differential Revision: D4456402
      
      fbshipit-source-id: 2f8a5c932d0341d6c9290bcb52264dd4fa174263
      a857f83b
    • Christopher Dykes's avatar
      Ensure portability/Windows.h is included before OpenSSL headers · a393e1cc
      Christopher Dykes authored
      Summary: Because OpenSSL is evil to Windows, and you have to forcefully include winsock2 before winsock.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4453742
      
      fbshipit-source-id: 3b1b5b1f999722559693164148245f52b1e94104
      a393e1cc
  5. 20 Jan, 2017 6 commits
    • Igor Zinkovsky's avatar
      fix use-after-free in addFunctionOnce · 61d6143a
      Igor Zinkovsky authored
      Summary: see title
      
      Reviewed By: meyering
      
      Differential Revision: D4441266
      
      fbshipit-source-id: 4a8f589e2995a463e54b3979035a623824acf39e
      61d6143a
    • Maged Michael's avatar
      Made atomics generic in hazptr_owner member functions · dd5a72f2
      Maged Michael authored
      Summary:
      As suggested by the C++ committee in November 2016, made atomics generic to allow other atomic types (e.g.,  folly::DeterministicAtomic<T*>),
      
      Also removed obsolete comments.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D4443355
      
      fbshipit-source-id: d9e21a959f2c7e3dd07c0ed4808236da80ef6dcd
      dd5a72f2
    • Christopher Dykes's avatar
      Define AF_LOCAL in the socket portability layer · 3866e5d3
      Christopher Dykes authored
      Summary: It's the exact same as `PF_LOCAL`, and is used interchangibly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4439558
      
      fbshipit-source-id: fd1ff813db5349369fc77888dfd854fc36a2a3be
      3866e5d3
    • Kyle Nekritz's avatar
      Clear OpenSSL error stack after loading certificate file. · d9793261
      Kyle Nekritz authored
      Summary: SSL_CTX_load_verify_locations interally end up using X509_load_cert_crt_file, which has an unchecked call to X509_STORE_add_cert. This can fail and add an error to the error stack without causing SSL_CTX_load_verify_locations to return an error.
      
      Reviewed By: siyengar
      
      Differential Revision: D4442017
      
      fbshipit-source-id: a4cf7f5ee2c18d90d5d61baf3acb99ffca6b8af0
      d9793261
    • Luca Niccolini's avatar
      Revert D4389970: add an option to clear error before calling ssl methods · b9591985
      Luca Niccolini authored
      Summary: This reverts commit 12da254d6b281c2b9d522ba19999b2489c0083a2
      
      Differential Revision: D4389970
      
      fbshipit-source-id: 7651425adcf3b86c066d657308af1a0aa6bce5dd
      b9591985
    • Maxim Georgiev's avatar
      Enable EOR flag configuration for folly::AsyncSocket. · 5c74326f
      Maxim Georgiev authored
      Summary: EOR flag was hardcoded to "false" in folly::AsyncSocket. This diff enables changing EOR flag using AsyncSocket::setEorTracking() method.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4421966
      
      fbshipit-source-id: 2e1b9b19ced6555845396ec33bfd3d5feb710640
      5c74326f
  6. 19 Jan, 2017 2 commits
    • Phil Willoughby's avatar
      Modernise and clang-format existing formatting benchmark · c72b52a3
      Phil Willoughby authored
      Summary: Changes nothing fundamental, just makes it easier to work on in the future.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4435805
      
      fbshipit-source-id: 725944a12922abde137bb7e21726c97beb558b5f
      c72b52a3
    • Andrii Grynenko's avatar
      Add fiber-print-limit command · 7feeb55d
      Andrii Grynenko authored
      Summary: Limits number of fibers printed for each FiberManager.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4432488
      
      fbshipit-source-id: 1791c2bfe6d5b0c2f54142dc068b473fd72f5d5d
      7feeb55d
  7. 18 Jan, 2017 2 commits
  8. 16 Jan, 2017 3 commits
    • Christopher Dykes's avatar
      Drop unneeded Pthread include · b2dd1005
      Christopher Dykes authored
      Summary: It was killed in an earlier diff.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418832
      
      fbshipit-source-id: c9a5134fa100b24a3394607dea20e6e8a8d341e1
      b2dd1005
    • Christopher Dykes's avatar
      Don't use Pthread in EventBase · 01f97980
      Christopher Dykes authored
      Summary:
      Pthread is currently a dependency of Folly that is not really necessary on Windows, or even with standard C++ for the most part, so start work on killing it in Folly.
      This switches EventBase to using `std::thread::id`'s instead, which also means we aren't reliant on the implementation detail that thread id 0 is invalid. Well, we are, but it's now the standard library's fault not ours.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418128
      
      fbshipit-source-id: a9c95ac6c7305c960156a4ad684b6db89b5856d9
      01f97980
    • Christopher Dykes's avatar
      Support setting thread name via std::thread::id · f57ddfc7
      Christopher Dykes authored
      Summary: It's possible via some hackery, so wrap it up nicely into the API.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4418728
      
      fbshipit-source-id: f00aed95cdbdc3cc83a0ab96565117cd01141c2e
      f57ddfc7
  9. 14 Jan, 2017 1 commit
  10. 13 Jan, 2017 4 commits
    • Marcus Holland-Moritz's avatar
      Protect memcpy calls against undefined behaviour · b0c9ca0f
      Marcus Holland-Moritz authored
      Summary:
      While running a UBSan enabled binary, I got:
      
        folly/io/IOBuf.cpp:671:15: runtime error: null pointer passed as argument 2, which is declared to never be null
      
      This change protects all calls to memcpy from passing `nullptr`.
      
      Reviewed By: pixelb
      
      Differential Revision: D4415355
      
      fbshipit-source-id: a27ba74244abcca8cd4e106967222890a67f5b6d
      b0c9ca0f
    • Jim Meyering's avatar
      folly/Traits.h: fix a deep problem with FBVector · 73199d4c
      Jim Meyering authored
      Summary:
      This started when many fbvector-related tests began failing with reports of
      ASAN-detected heap abuse (usually invalid free of an address 16 bytes
      into an already-freed buffer).
      
      It was very specific, though. The bug struck only when:
        - gcc-5-based platform
        - compiling with clang (~3.8) and GCC5's libstdc++, not gcc
        - strings were short enough to reside within an in-situ std::string
      
      Why? because FBVector.h:1588's conditional:
      
        if (folly::IsRelocatable<T>::value && usingStdAllocator::value) {
      
      was true for clang (erroneously), but false for gcc. The difference
      was in `IsRelocatable<std::string>::value`.  However, manual tests showed that
      each component from the definition of `IsRelocatable` were the same for both
      gcc and clang. Then Jay Feldblum realized that we'd probably specialized
      that trait for `std::string`, and sure enough, I found the culprit:
      
      ```
      FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
      ```
      
      Reviewed By: pixelb
      
      Differential Revision: D4414159
      
      fbshipit-source-id: 60e3fb4b096ec77cbd2b48c561e5c6ec8f128fff
      73199d4c
    • Eric Niebler's avatar
      capture exception information when creating exception_wrapper · 0e7c824d
      Eric Niebler authored
      Summary:
      prefer creating an exception_wrapper with a reference to the active exception
      
      Depends on D4410421
      
      Reviewed By: spacedentist
      
      Differential Revision: D4410455
      
      fbshipit-source-id: d6b6aeb5fa72782e31d754a0b853514af5fdb8cd
      0e7c824d
    • Dave Watson's avatar
      Add AsyncSSLSocket option to turn off transparent tls · 1e531547
      Dave Watson authored
      Summary: Folly parts of D4383906.
      
      Reviewed By: plapukhov
      
      Differential Revision: D4387254
      
      fbshipit-source-id: 3c039720c88c91b7292d60a85272dd1978510296
      1e531547
  11. 11 Jan, 2017 2 commits
    • Yedidya Feldblum's avatar
      Slight simplification of exception_wrapper constructor · f144d224
      Yedidya Feldblum authored
      Summary: [Folly] Slight simplification of `exception_wrapper` constructor.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4391899
      
      fbshipit-source-id: ddb066723bcd10abb0dbbaeab12b1e9be4f39acc
      f144d224
    • Subodh Iyengar's avatar
      add an option to clear error before calling ssl methods · 3a8c98ea
      Subodh Iyengar authored
      Summary:
      Normally clearing out the error before calling into an openssl method
      is a bad idea. However there might be other code outside AsyncSSLSocket
      calling into openssl in the same thread that doesn't use openssl
      correctly. This allows users of AsyncSSLSocket to safeguard themselves
      from such code.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D4389970
      
      fbshipit-source-id: 12da254d6b281c2b9d522ba19999b2489c0083a2
      3a8c98ea
  12. 10 Jan, 2017 4 commits
    • Yedidya Feldblum's avatar
      Fix an inefficiency in json-serializing a dynamic with sorted keys · 266c8377
      Yedidya Feldblum authored
      Summary:
      [Folly] Fix an inefficiency in json-serializing a `dynamic` with sorted keys.
      
      The inefficiency is that, at each level of the `dynamic` which is map-typed, we effectively make a full copy of the `dynamic` object. This can be expensive.
      
      Reviewed By: Gownta
      
      Differential Revision: D4389671
      
      fbshipit-source-id: 223739397f913d3e65a421a9a4dcb089ec757ec6
      266c8377
    • kumagi's avatar
      fix typo in comments. s/unitialized/uninitialized/g · f47621ec
      kumagi authored
      Summary:
      `unitialized` seems to be typo.
      Closes https://github.com/facebook/folly/pull/538
      
      Reviewed By: igorsugak
      
      Differential Revision: D4397318
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: a2e6c665b4dfe95d769430405886b0725423aac2
      f47621ec
    • Yedidya Feldblum's avatar
      Rename exception_wrapper::getExceptionPtr to to_exception_ptr · cd058f18
      Yedidya Feldblum authored
      Summary:
      [Folly] Rename `exception_wrapper::getExceptionPtr` to `to_exception_ptr`.
      
      Make it clear that this will sometimes be an expensive operation. Using the word `to` evokes the possibility of an expensive conversion, while using the word `get` implies cheap access.
      
      Reviewed By: djwatson
      
      Differential Revision: D4391621
      
      fbshipit-source-id: 33ca051d9be5a6050ba9f30b20faee35b7e58afb
      cd058f18
    • Maged Michael's avatar
      Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil()... · 232f650c
      Maged Michael authored
      Fix dynamic MPMCQueue tryObtainPromisedPushTicket() to prevent tryWriteUntil() and writeIfNotFull() from blocking indefinitely for a matching read.
      
      Summary:
      The bug was reported by Alexander Pronchenkov in https://fb.facebook.com/groups/560979627394613/permalink/837052843120622/
      
      Under certain conditions a `tryWriteUntil()`--and also `writeIfNotFull()`--operation may block indefinitely awaiting a matching read. This could happen because in each dynamic MPMCQueue expansion, typically one or two tickets are associated with the closed array not the new one. In the incorrect code, a `tryWriteUntil()` operation that induced expansion but gets a ticket associated with the closed array, incorrectly assumes that because the expansion succeeded then there is space for it. However because the ticket is associated with the closed array, the operation needs to wait (possibly indefinitely) for space to open in the closed array.
      
      The fix: Changed the code in tryObtainPromisedPushTicket() such that the operation tries to acquire a ticket only if there is promised space in the array associated with that ticket. If there is no space, an expansion is attempted if the ticket is not associated with a closed array. If not or if expansion fails because of reaching maximum capacity or for being out-of-memory, then the operation returns false without attempting to acquire the ticket.
      
      Other changes:
      - Added a note about this difference in semantic between the dynamic and non-dynamic version to the main comment about the dynamic version.
      - Changed `oldCap` to `curCap` because the value is actually current not old.
      - Added two tests for checking that tryWriteUntil() never blocks indefinitely for both dynamic and non-dynamic versions.
      - Removed all the `never_fail` tests for the dynamic version, because such operations may fails as described above.
      - Added `asm_volatile_pause` when spinning on the seqlock.
      
      Reviewed By: djwatson
      
      Differential Revision: D4389347
      
      fbshipit-source-id: c46dbefc9fe08e146250d2ad8ba68b0887f97436
      232f650c
  13. 09 Jan, 2017 5 commits
    • Christopher Dykes's avatar
      Use 2 second loop smoothing period rather than 20 seconds · 410f652b
      Christopher Dykes authored
      Summary: This was accidentally changed in D4375539.
      
      Reviewed By: philippv
      
      Differential Revision: D4393574
      
      fbshipit-source-id: 0420223575bad0c6b0e89f8cf5ed138e063462b9
      410f652b
    • Kyle Nekritz's avatar
      Add pre received data API to AsyncSSLSocket. · 3a033f27
      Kyle Nekritz authored
      Summary: This allows something else (ie fizz) to read data from a socket, and then later decide to to accept an SSL connection with OpenSSL by inserting the data it read in front of future reads on the socket.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D4325634
      
      fbshipit-source-id: 05076d2d911fda681b9c4e5d9d3375559293ea35
      3a033f27
    • Kyle Nekritz's avatar
      Set custom ssl bio read method. · f3c3434c
      Kyle Nekritz authored
      Summary: Similar to the bio write method. This should be essentially a no-op, bioRead has the same functionality as the openssl version. This is needed in the next diff.
      
      Reviewed By: siyengar
      
      Differential Revision: D4325622
      
      fbshipit-source-id: a90b9ec06bee920a1a73551a3ea4c77e1ee0ab08
      f3c3434c
    • Zonr Chang's avatar
      Include <errno.h> for using "errno" and ENOMEM. · 94dad222
      Zonr Chang authored
      Summary: Closes https://github.com/facebook/folly/pull/537
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4391871
      
      Pulled By: Orvid
      
      fbshipit-source-id: 80401dd65ae376f9ebbb0b079577d0a1fd15475b
      94dad222
    • Nick Wolchko's avatar
      Remove folly::Future conversion constructor · 22d54e0b
      Nick Wolchko authored
      Summary:
      This constructor is unsafe. The check it uses before doing the comparison isn't a safe enough check to see if the cast is valid. For example, this is broken in the presence of multiple inheritance because it doesn't adjust the pointer offset to the correct vtable.
      
      e.g.
        struct A {
          virtual ~A() {};
          virtual void doSomething() = 0;
        };
        struct B {
          virtual ~B() {}
          virtual void doSomethingElse() = 0;
        };
        struct C : public B, public A {
          virtual ~C() {}
          void doSomething() override {
            std::cout << "Something!" << std::endl;
          }
          void doSomethingElse() override {
            std::cout << "Something Else!" << std::endl;
          }
        };
        int main (int argc, char **argv) {
          auto c = folly::makeFuture<std::shared_ptr<C>>(std::make_shared<C>());
          folly::Future<std::shared_ptr<A>> a = std::move(c);
          a.get()->doSomething();
          return 0;
        }
      This code will print "Something else!" when run.
      
      Reviewed By: siyengar
      
      Differential Revision: D3679673
      
      fbshipit-source-id: dcbf40ca82d458f17ee11191591f8b8daf58c919
      22d54e0b