Closed Bug 1803322 Opened 1 year ago Closed 1 year ago

TestNativeNt broken in local build due to thread local storage pointer caching optimization

Categories

(Core :: mozglue, defect)

x86_64
Windows
defect

Tracking

()

RESOLVED FIXED
109 Branch
Tracking Status
firefox109 --- fixed

People

(Reporter: yannis, Assigned: yannis)

References

Details

Attachments

(1 file)

On my local machine, TestNativeNt is broken:

$ ./obj-x86_64-pc-mingw32/dist/bin/TestNativeNt.exe
sTlsData#1 = 00000000
Segmentation fault

The reason seems to be the same as what's mentioned in the comment above SwapThreadLocalStoragePointer:

// Need a non-inline function to bypass compiler optimization that the thread
// local storage pointer is cached in a register before accessing a thread-local
// variable.

In my case, it seems that the new nullptr value for the thread-local storage pointer gets cached when we call sTlsData.set(~kTlsDataValue); inside MOZ_SEH_TRY, resulting in the next call to sTlsData.get() to dereference a null pointer. Replacing the set line by a call to a non-inlinable variant fixes the local test:

MOZ_NEVER_INLINE void setTlsData(unsigned x) { sTlsData.set(x); }

I believe that in all functions that change the thread-local storage pointer value using SwapThreadLocalStoragePointer, we should use non-inlinable variants of our thread-local storage helpers to make sure that it is never cached at any point of the test. That would be TestNativeNt and also TestSafeThreadLocal.

This may also fix bug 1784210?

Pushed by yjuglaret@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/9615b6d6fc0b
Use non-inlinable thread-local helpers in TestNativeNt and TestSafeThreadLocal. r=glandium
Duplicate of this bug: 1784210
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 109 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: