bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Log dead LIBCx mutex owner on assertions #96

Closed dmik closed 3 years ago

dmik commented 3 years ago

When a LIBCx process terminates due to an assertion, it writes some post-mortem statistics to the log which includes the current owner of the LIBCx mutex. It looks like this in -libcx.log:

...
===== LIBCx global mutex owner =====
mutex handle: 800100f4
owner PID:    018f (399)
owner TID:    1
===== LIBCx stats end =====

However, this info is only printed if DosQueryMutexSem returns NO_ERROR. For the process that owns the mutex at the time of the crash, it is always so and we get this info. However, all subsequent processes that try to do so after that will receive ERROR_SEM_OWNER_DIED from DosQueryMutexSem which will effectively make this info go away. And this is usually what happens after the owner dies: all other LIBCx processes die at once because of the intermediate non-recoverable LIBCx state but we don't see who was the guilty owner unless it wrote out own -libcx.log. But the log file of a normal release build is written only if the owning process crashes with an assertion but this is not always the case. If it crashes in some other place (due to some hidden bug or whatever) it will only leave an -exceptq.txt report — if we are lucky. Or not leave anything at all (not even a POPUPLOG.OS2 entry) if something goes wrong really hard.

Luckily, DosQueryMutexSem specifically provides the PID/TID of the dead owner when it returns ERROR_SEM_OWNER_DIED (the docs were just not very clear on that). So the solution is trivial: make this info printed on ERROR_SEM_OWNER_DIED too.