Bug 1895081 - Add extra assertions to nsThread initialization, r=xpcom-reviewers,jstutte

Differential Revision: https://phabricator.services.mozilla.com/D212313
This commit is contained in:
Nika Layzell 2024-06-04 18:36:18 +00:00
parent 175cb7f2fa
commit 49e71b90c7

View file

@ -455,11 +455,14 @@ void nsThread::InitCommon() {
{
#if defined(XP_LINUX)
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_getattr_np(pthread_self(), &attr);
int res = pthread_attr_init(&attr);
MOZ_RELEASE_ASSERT(!res);
res = pthread_getattr_np(pthread_self(), &attr);
MOZ_RELEASE_ASSERT(!res);
size_t stackSize;
pthread_attr_getstack(&attr, &mStackBase, &stackSize);
res = pthread_attr_getstack(&attr, &mStackBase, &stackSize);
MOZ_RELEASE_ASSERT(!res);
// Glibc prior to 2.27 reports the stack size and base including the guard
// region, so we need to compensate for it to get accurate accounting.
@ -477,7 +480,8 @@ void nsThread::InitCommon() {
});
if (sAdjustForGuardSize) {
size_t guardSize;
pthread_attr_getguardsize(&attr, &guardSize);
res = pthread_attr_getguardsize(&attr, &guardSize);
MOZ_RELEASE_ASSERT(!res);
// Note: This assumes that the stack grows down, as is the case on all of
// our tier 1 platforms. On platforms where the stack grows up, the
@ -504,7 +508,8 @@ void nsThread::InitCommon() {
// consumption of our allocated stacks.
madvise(mStackBase, stackSize, MADV_NOHUGEPAGE);
pthread_attr_destroy(&attr);
res = pthread_attr_destroy(&attr);
MOZ_RELEASE_ASSERT(!res);
#elif defined(XP_WIN)
static const StaticDynamicallyLinkedFunctionPtr<
GetCurrentThreadStackLimitsFn>