PR_CreateThread on Windows doesn't call PR_SetError on _beginthreadex failure
Categories
(NSPR :: NSPR, defect)
Tracking
(Not tracked)
People
(Reporter: jstutte, Assigned: jstutte)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 obsolete file)
Unfortunately it seems that we cannot call GetLastError after PR_CreateThread as the cleanup on the error path seems to overwrite it with ERROR_SUCCESS, so there seems to be no viable workaround. I came here through bug 2015433 while trying to improve diagnostics.
Following Claude's detailed findings:
The "Last Error" on all Windows crash reports for this signature is
ERROR_SUCCESS. I investigated what internal code condition could produce this and found that NSPR's cleanup path after_beginthreadexfailure callsTlsGetValue, which masksGetLastError().Background: Firefox uses the WIN95 NSPR target on Windows
Per moz.build, Firefox defines
WIN95=Truefor NSPR, so the thread implementation used is w95thred.c, notntthread.c._PR_USE_STATIC_TLSis not defined, so_MD_GET_ATTACHED_THREAD()unconditionally expands toTlsGetValue(_pr_currentThreadIndex)at compile time.
TlsGetValueis documented by Microsoft to callSetLastError(ERROR_SUCCESS)on success.The masking sequence
When
_beginthreadexfails in_PR_MD_CREATE_THREAD, the function simply returnsPR_FAILUREwithout capturingGetLastError()and without callingPR_SetError(). At this pointGetLastError()still holds the real Windows error from_beginthreadex/CreateThread.Control returns to
_PR_NativeCreateThread, which runs cleanup code that calls_PR_DecrActiveThreadCount. That function callsPR_Lock(_pr_activeLock), which immediately does:PRThread* me = _PR_MD_CURRENT_THREAD();
There might be value in checking other functions if they lack proper error propagation of GetLastError on Windows.
| Assignee | ||
Comment 1•27 days ago
|
||
Updated•27 days ago
|
| Assignee | ||
Comment 2•27 days ago
|
||
Updated•27 days ago
|
Comment 3•21 days ago
|
||
The severity field is not set for this bug.
:KaiE, could you have a look please?
For more information, please visit BugBot documentation.
Comment 4•16 days ago
|
||
Updated•16 days ago
|
Description
•