platform_system_core/libutils/include/utils
Prabir Pradhan 729057ab8c Looper: Use sequence numbers in epoll_event to track requests
Previously, Looper internally kept track of the requests to add fds
using the fd value itself. It used an internal sequence number
associated with each request to add a callback to avoid a situation
where a callback is unexpectedly called. However, since it used the fd
value rather than the sequence number to register events into epoll,
there was still a way where unintended hangups could occur.

This exact sequence of events caused unintended behavior in Looper:
- An fd (FD) is added to the looper.
- Looper registers FD into epoll using its FD number.
- FD is closed.
- A hangup event arrives from epoll_wait while the Looper is polling.
Looper is waiting for the lock to process the callback for FD, because
it is blocked by:
- A new fd is created and added to the looper. Since the lowest number
fd is reused, this new fd has the same value as FD.
- The poll request for Looper is now unblocked, so it looks up the
callback associated with FD to process the hangup.
- Since FD is already associated with the new callback, the new callback
is called unintentionally.

This CL uses the sequence number to register fds into epoll. That way,
when we get a hangup from epoll that is associated with a sequence
number, there is no way an unexpected callback will called.

This CL also adds a test to verify this behavior. Due to the
nondeterministic nature of this multi-thread scenario, the test verifies
this scenario repeatedly. Without the fix in Looper, the test is flaky,
but should never fail after the fix.

Bug: 195020232
Bug: 189135695
Test: atest libutils_test --rerun-until-failure
Ignore-AOSP-First: Topic CL aosp/1799831 has a merge conflict with
internal master, resolved in ag/15613419.

Change-Id: Ib4edab7f2407adaef6a1708b29bc52634f25dbb6
2021-09-01 14:52:52 +00:00
..
AndroidThreads.h Revert "Add choice for changing sched policy when setting thread priority" 2020-09-27 11:21:11 +08:00
Atomic.h Usage suggestions. 2017-12-19 01:16:00 +00:00
BitSet.h Soften BitSet class comment. 2020-07-16 00:04:20 +00:00
ByteOrder.h Remove unused big-endian cruft. 2019-09-18 08:02:10 -07:00
CallStack.h CallStack: include prefix/tag when unlinked 2019-01-03 10:17:07 -08:00
Compat.h Fix mac build. 2020-05-08 15:30:21 -07:00
Condition.h [libutils] Modernize codebase by replacing NULL with nullptr 2018-07-16 18:11:34 -07:00
Debug.h Deprecate <utils/Debug.h>. 2020-08-17 10:07:29 -07:00
Endian.h
Errors.h Add statusToString function. 2019-11-18 17:38:22 +00:00
FastStrcmp.h logd: ASAN cleansing 2017-03-27 13:32:57 -07:00
FileMap.h Add noexcept to move constructors and assignment operators. 2018-10-05 16:43:47 +00:00
Flattenable.h Don't #include <utils/Debug.h> from <utils/Flattenable.h>. 2020-08-17 10:14:16 -07:00
Functor.h Move system/core/ off NO_ERROR. 2018-10-08 11:15:52 -07:00
JenkinsHash.h
KeyedVector.h Fix implicit cast from ssize_t to size_t in KeyedVector.h 2021-05-21 16:45:46 +00:00
LightRefBase.h libutils: LightRefBase: incStrongRequireStrong 2021-05-04 21:42:26 +00:00
List.h Remove more semicolons at the end of namespaces 2018-04-11 23:14:13 -07:00
Log.h Remove ALOGD_IF_SLOW 2017-07-14 19:51:57 +00:00
Looper.h Looper: Use sequence numbers in epoll_event to track requests 2021-09-01 14:52:52 +00:00
LruCache.h [libutils] Modernize codebase by replacing NULL with nullptr 2018-07-16 18:11:34 -07:00
misc.h Remove extra semicolon at end of namespace 2018-04-10 22:10:54 +00:00
Mutex.h libutils: Fix thread safety annotations in Mutex 2019-03-29 12:21:57 -07:00
NativeHandle.h
Printer.h [libutils] Modernize codebase by replacing NULL with nullptr 2018-07-16 18:11:34 -07:00
ProcessCallStack.h [libutils] Modernize codebase by replacing NULL with nullptr 2018-07-16 18:11:34 -07:00
RefBase.h libutils: group deprecated RefBase functions 2021-04-12 23:56:07 +00:00
RWLock.h Modernize codebase by replacing NULL with nullptr 2018-07-13 15:28:59 -07:00
Singleton.h Modernize codebase by replacing NULL with nullptr 2018-07-13 15:28:59 -07:00
SortedVector.h Remove more semicolons at the end of namespaces 2018-04-11 23:14:13 -07:00
StopWatch.h libutils: remove the unused StopWatch lap functionality. 2021-05-11 16:33:47 -07:00
String8.h Revert "Revert "Remove unused String8::setPathName."" 2021-07-19 20:19:44 +00:00
String16.h libutil: no special copy from StaticString16 2021-06-30 09:04:29 +09:00
StrongPointer.h libutils: group deprecated RefBase functions 2021-04-12 23:56:07 +00:00
SystemClock.h Add docs to SystemClock.h 2021-02-23 12:14:57 -08:00
Thread.h Suppress lint warnings on google-default-arguments 2018-10-29 23:06:23 +09:00
ThreadDefs.h Remove more semicolons at the end of namespaces 2018-04-11 23:14:13 -07:00
threads.h
Timers.h Make systemTime() abort on bad input. 2020-05-27 15:31:55 -07:00
Tokenizer.h Move system/core/ off NO_ERROR. 2018-10-08 11:15:52 -07:00
Trace.h Trace.h: explicitly use global namespace 2019-11-05 17:59:46 -08:00
TypeHelpers.h Remove extra semicolon at end of namespace 2018-04-10 22:10:54 +00:00
Unicode.h Remove move dead code. 2021-04-15 15:18:54 -07:00
Vector.h Update language to comply with Android's inclusive language guidance 2020-07-28 15:58:25 -07:00
VectorImpl.h Modernize codebase by replacing NULL with nullptr 2018-07-13 15:28:59 -07:00