Bug 1977130 - Error-check pthread_getattr_np. r=glandium,spidermonkey-reviewers,jandem, a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D258648
This commit is contained in:
Steve Fink
2025-07-29 00:58:13 +00:00
committed by rvandermeulen@mozilla.com
parent aa0c95ed72
commit c446c5e360
2 changed files with 10 additions and 9 deletions

View File

@@ -95,17 +95,16 @@ void* js::GetNativeStackBaseImpl() {
pthread_t thread = pthread_self(); pthread_t thread = pthread_self();
pthread_attr_t sattr; pthread_attr_t sattr;
pthread_attr_init(&sattr); pthread_attr_init(&sattr);
pthread_getattr_np(thread, &sattr); int rc = pthread_getattr_np(thread, &sattr);
MOZ_RELEASE_ASSERT(rc == 0, "pthread_getattr_np failed");
// stackBase will be the *lowest* address on all architectures. // stackBase will be the *lowest* address on all architectures.
void* stackBase = nullptr; void* stackBase = nullptr;
size_t stackSize = 0; size_t stackSize = 0;
int rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize); rc = pthread_attr_getstack(&sattr, &stackBase, &stackSize);
if (rc) { MOZ_RELEASE_ASSERT(rc == 0,
MOZ_CRASH( "call to pthread_attr_getstack failed, unable to setup "
"call to pthread_attr_getstack failed, unable to setup stack range for " "stack range for JS");
"JS");
}
MOZ_RELEASE_ASSERT(stackBase, MOZ_RELEASE_ASSERT(stackBase,
"invalid stack base, unable to setup stack range for JS"); "invalid stack base, unable to setup stack range for JS");
pthread_attr_destroy(&sattr); pthread_attr_destroy(&sattr);
@@ -148,7 +147,8 @@ void* js::GetNativeStackBaseImpl() {
* FIXME: this function is non-portable; * FIXME: this function is non-portable;
* other POSIX systems may have different np alternatives * other POSIX systems may have different np alternatives
*/ */
pthread_getattr_np(thread, &sattr); MOZ_RELEASE_ASSERT(pthread_getattr_np(thread, &sattr) == 0,
"pthread_getattr_np failed");
# endif # endif
void* stackBase = 0; void* stackBase = 0;

View File

@@ -949,7 +949,8 @@ MFBT_API void MozStackWalk(MozWalkStackCallback aCallback,
# elif defined(ANDROID) # elif defined(ANDROID)
pthread_attr_t sattr; pthread_attr_t sattr;
pthread_attr_init(&sattr); pthread_attr_init(&sattr);
pthread_getattr_np(pthread_self(), &sattr); int rc = pthread_getattr_np(pthread_self(), &sattr);
MOZ_RELEASE_ASSERT(rc == 0, "pthread_getattr_np failed");
void* stackBase = stackEnd = nullptr; void* stackBase = stackEnd = nullptr;
size_t stackSize = 0; size_t stackSize = 0;
if (gettid() != getpid()) { if (gettid() != getpid()) {