From: Michael Lee Date: Tue, 19 Apr 2016 14:52:23 +0000 (-0700) Subject: `detail::Futex` wants 4 bytes but MicroLock only gives you one X-Git-Tag: 2016.07.26~342 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9b139cb46477c8bc488becaad2a6245c184d3045;p=folly.git `detail::Futex` wants 4 bytes but MicroLock only gives you one Summary: ^^^ this is a stack overflow in the test, and a possible stack or heap overflow. Reviewed By: dcolascione Differential Revision: D3151717 fb-gh-sync-id: b4f0660ebbb89139dff003870e132c312068d9a8 fbshipit-source-id: b4f0660ebbb89139dff003870e132c312068d9a8 --- diff --git a/folly/MicroLock.h b/folly/MicroLock.h index 8f0b09f7..5c509553 100644 --- a/folly/MicroLock.h +++ b/folly/MicroLock.h @@ -22,6 +22,12 @@ #include #include +#if defined(__clang__) +#define NO_SANITIZE_ADDRESS __attribute__((__no_sanitize__("address"))) +#else +#define NO_SANITIZE_ADDRESS +#endif + namespace folly { /** @@ -88,7 +94,12 @@ namespace folly { class MicroLockCore { protected: +#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) && \ + (defined(__GNUC__) || defined(__GNUG__)) + uint32_t lock_; +#else uint8_t lock_; +#endif inline detail::Futex<>* word() const; inline uint32_t baseShift(unsigned slot) const; inline uint32_t heldBit(unsigned slot) const; @@ -100,7 +111,7 @@ class MicroLockCore { unsigned maxYields); public: - inline void unlock(unsigned slot); + inline void unlock(unsigned slot) NO_SANITIZE_ADDRESS; inline void unlock() { unlock(0); } // Initializes all the slots. inline void init() { lock_ = 0; } @@ -151,9 +162,9 @@ void MicroLockCore::unlock(unsigned slot) { template class MicroLockBase : public MicroLockCore { public: - inline void lock(unsigned slot); + inline void lock(unsigned slot) NO_SANITIZE_ADDRESS; inline void lock() { lock(0); } - inline bool try_lock(unsigned slot); + inline bool try_lock(unsigned slot) NO_SANITIZE_ADDRESS; inline bool try_lock() { return try_lock(0); } }; diff --git a/folly/test/SmallLocksTest.cpp b/folly/test/SmallLocksTest.cpp index ad6a8378..5aef9ea1 100644 --- a/folly/test/SmallLocksTest.cpp +++ b/folly/test/SmallLocksTest.cpp @@ -181,7 +181,12 @@ TEST(SmallLocks, RegClobber) { } FOLLY_PACK_PUSH +#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) && \ + (defined(__GNUC__) || defined(__GNUG__)) +static_assert(sizeof(MicroLock) == 4, "Size check failed"); +#else static_assert(sizeof(MicroLock) == 1, "Size check failed"); +#endif FOLLY_PACK_POP namespace {