replicant-frameworks_native/libs/binder
Johannes Carlsson db1597a989 Fix shutdown sequence to avoid SIGSEGV when running am command
When the app_process is shutting down the main thread will close the
binder fd while pool threads are executing an ioctl (in
IPCThreadState::stopProcess called by AppRuntime::onStarted in
app_main.c).

The binder driver will then return all pending calls in ioctl
without any error and with a command. One of the threads gets a
BR_SPAWN_LOOPER which will create a new thread (the other thread
gets a BR_NOOP). This new thread then calls
vm->AttachCurrentThread. Usually this results in a log entry with
"AndroidRuntime: NOTE: attach of thread 'Binder Thread #3' failed",
but sometimes it also causes a SIGSEGV. This depends on the timing
between the new thread an the main thread that calls DestroyJavaVM
(in AndroidRuntime::start).

If IPCThreadState.cpp is compiled with "#define LOG_NDEBUG 0" the
pool thread will loop and hit the
ALOG_ASSERT(mProcess->mDriverFD >= 0) in
IPCThreadState::talkWithDriver.

Crashes like this has been seen when running the am command and
other commands that use the app_process.

This fix makes sure that any command that is received when the driver
fd is closed are ignored and IPCThreadState::talkWithDriver instead
returns an error which will cause the pool thread to exit and detach
itself from the vm. A check to avoid calling ioctl to a fd with -1
was also added in IPCThreadState::threadDestructor.

Another solution might be to change the binder driver so that it
returns an error when the fd is closed (or atleast not a
BR_SPAWN_LOOPER command). It might also be possible to call exit(0)
which is done when System.exit(0) is called from java.

Change-Id: I3d1f0ff64896c44be2a5994b3a90f7a06d27f429
2012-06-25 13:58:47 -07:00
..
Android.mk get rid of MemoryHeapPmem 2012-02-27 19:58:57 -08:00
Binder.cpp Add callback hack to find out when to reload system properties. 2012-05-09 14:53:26 -07:00
BpBinder.cpp Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE 2012-01-08 13:19:13 +00:00
IInterface.cpp some work to try to reduce the code size of some native libraries 2009-05-26 16:12:20 -07:00
IMemory.cpp Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE 2012-01-08 13:19:13 +00:00
IPCThreadState.cpp Fix shutdown sequence to avoid SIGSEGV when running am command 2012-06-25 13:58:47 -07:00
IPermissionController.cpp Add Parcel::readExceptionCode() and Parcel::writeNoException() 2010-07-13 15:45:18 -07:00
IServiceManager.cpp Some hardening of isolated processes by restricting access to services. 2012-02-09 18:06:01 -08:00
MemoryBase.cpp move libbinder's header files under includes/binder 2009-05-20 12:55:03 -07:00
MemoryDealer.cpp Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE 2012-01-08 13:19:13 +00:00
MemoryHeapBase.cpp Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE 2012-01-08 13:19:13 +00:00
Parcel.cpp Aligning native Parcel implementation to Java. 2012-06-08 08:29:01 -07:00
PermissionCache.cpp Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF) DO NOT MERGE 2012-01-03 22:38:27 +00:00
ProcessState.cpp add set thread count 2012-04-18 17:50:03 -07:00
Static.cpp move libbinder's header files under includes/binder 2009-05-20 12:55:03 -07:00