The first time I encountered this bug, it was an irregular low probability, and finally found a more easily reproducible step:
Start the system
Then go to Google +
Create a new account (note that you are creating a new account)
It's been restarted in a few steps.
This bug, the beginning of tracking is also no clue, in this bug appears, the system Debuggerd still have some problems, pt_regs set and the kernel does not correspond, tombstone information is completely useless, core dump function is also unable to use, The only clue is a little bit of logcat Trace, trace as follows:
D/openglrenderer (2021): Flushing caches (Mode 1) d/openglrenderer (2021): Flushing caches (Mode 0) d/openglrenderer (1986) : Flushing caches (Mode 1) w/surfacetexture (1451): Freeallbufferslocked called but Mqueue was not emptyd/openglrenderer (19 : Flushing caches (Mode 0) f/libc (1451): Fatal signal One (SIGSEGV) at 0x00000024 (code=1) i/debug (1449): * * * * * * * * * * * * * * * * * * * * * * * * * * * ***I/DEBUG (1449): Build fingerprint: ' xxxx/iml74k/eng.freshui.201 20213.154128:user/test-keys ' I/debug (1449): pid:1451, tid:1455 >>>/system/bin/surfaceflinger <<<I /debug (1449): Signal (SIGSEGV), Code 1 (segv_maperr), fault addr 00000024
The current error is basically similar to the trace. Start looking for it from here. A word in the trace:
W/surfacetexture (1451): Freeallbufferslocked called but Mqueue was not empty
Is the biggest suspect, based on the experience of catching insects, first make assumptions, can already explain the cause and phenomenon of the error:
- Mqueue is usually used by two modules, a enqueue, a dequeue
- Error, to the mqueue to free, but mqueue not empty, indicating that someone is using
- If this warning is not given, forcing the mqueue to free will most likely cause another module to use the free memory to cause a segment error
Turn back to see Code, SURFACETEXTURE.CPP, check the use of Mqueue, where there is a free buffer, Mqueue is not empty possible? Check it out, and really find it, look at this function:
[Java]View Plaincopy
- status_t surfacetexture::setbuffercount (int bufferCount) {
- ST_LOGV ("setbuffercount:count=%d", BufferCount);
- Mutex::autolock Lock (Mmutex);
- if (mabandoned) {
- St_loge ("Setbuffercount:surfacetexture has been abandoned!");
- return no_init;
- }
- if (BufferCount > Num_buffer_slots) {
- St_loge ("Setbuffercount:buffercount larger than slots available");
- return bad_value;
- }
- //Error out if the user has dequeued buffers
- For (int i=0; i<mbuffercount; i++) {
- if (mslots[i].mbufferstate = = Bufferslot::D equeued) {
- St_loge ("Setbuffercount:client owns some buffers");
- Return-einval;
- }
- }
- const int minbufferslots = Msynchronousmode?
- Min_sync_buffer_slots:min_async_buffer_slots;
- if (bufferCount = = 0) {
- Mclientbuffercount = 0;
- BufferCount = (Mserverbuffercount >= minbufferslots)?
- Mserverbuffercount:minbufferslots;
- return setbuffercountserverlocked (BufferCount);
- }
- if (BufferCount < minbufferslots) {
- St_loge ("setbuffercount:requested buffer count (%d) is less than"
- "Minimum (%d)", BufferCount, Minbufferslots);
- return bad_value;
- }
- //Here we ' re guaranteed that the client doesn ' t has dequeued buffers
- //And would release all of the its buffer references.
- Freeallbufferslocked ();
- Mbuffercount = BufferCount;
- Mclientbuffercount = BufferCount;
- Mcurrenttexture = Invalid_buffer_slot;
- Mqueue.clear ();
- Mdequeuecondition.signal ();
- return OK;
- }
After the problem is found, before the freeallbufferslocked () call, the mqueue will be drained, and so on, and so on the use of the client is finished and then free.
After the modification, no such errors have been encountered.
Of course, the problem of the troubleshooting and resolution process is not so smooth, but also for several days. The solution and the cause of the problem is not to elaborate, meet and prepare to catch the worm's classmates should see clearly.
Hehe, this again can be attributed to the problem of multi-threaded synchronization/state machine, basically I have a serious problem with Android is this kind of
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Bug (ii)-Wild pointer in surfacetexture