Commit c532329a authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 2

Set a default value for slot in SharedMutex.h

Summary:
`SharedMutexImpl::lockSharedImpl` has a potentially uninitialized access:

  Assume state = 0
  canAlreadyDefer = (state & kMayDefer) != 0 ==> false
  aboveDeferThreshold = (state & kHasS) >= (kNumSharedToStartDeferring - 1) * kIncrHasS ==> false

  if (canAlreadyDefer || (aboveDeferThreshold && !drainInProgress)) ==> false

  line:1452: gotSlot(slot)->compare_exchange_strong(...) uses slot uninitialized

Reviewed By: Orvid

Differential Revision: D3933638

fbshipit-source-id: 0fbce5c00b8b1f34e50c302cb88def97853c5afe
parent 4b39d461
...@@ -1390,7 +1390,7 @@ bool SharedMutexImpl<ReaderPriority, Tag_, Atom, BlockImmediately>:: ...@@ -1390,7 +1390,7 @@ bool SharedMutexImpl<ReaderPriority, Tag_, Atom, BlockImmediately>::
return false; return false;
} }
uint32_t slot; uint32_t slot = tls_lastDeferredReaderSlot;
uintptr_t slotValue = 1; // any non-zero value will do uintptr_t slotValue = 1; // any non-zero value will do
bool canAlreadyDefer = (state & kMayDefer) != 0; bool canAlreadyDefer = (state & kMayDefer) != 0;
...@@ -1399,7 +1399,6 @@ bool SharedMutexImpl<ReaderPriority, Tag_, Atom, BlockImmediately>:: ...@@ -1399,7 +1399,6 @@ bool SharedMutexImpl<ReaderPriority, Tag_, Atom, BlockImmediately>::
bool drainInProgress = ReaderPriority && (state & kBegunE) != 0; bool drainInProgress = ReaderPriority && (state & kBegunE) != 0;
if (canAlreadyDefer || (aboveDeferThreshold && !drainInProgress)) { if (canAlreadyDefer || (aboveDeferThreshold && !drainInProgress)) {
/* Try using the most recent slot first. */ /* Try using the most recent slot first. */
slot = tls_lastDeferredReaderSlot;
slotValue = deferredReader(slot)->load(std::memory_order_relaxed); slotValue = deferredReader(slot)->load(std::memory_order_relaxed);
if (slotValue != 0) { if (slotValue != 0) {
// starting point for our empty-slot search, can change after // starting point for our empty-slot search, can change after
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment