From ae4d87118317d246ed98ba7f840af7054d15db4d Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sun, 10 Jul 2022 15:19:55 +0200 Subject: [PATCH] AK: Port StackInfo to FreeBSD This can almost be identical to the Linux version, except that the `pthread_attr_t` object is populated using a call to `pthread_attr_get_np` instead of `pthread_getattr_np`. FreeBSD also needs `pthread_atttr_t` to be initialized using `pthread_attr_init` instead of zero-initialization, but it's the technically correct thing to do on Linux as well. --- AK/StackInfo.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/AK/StackInfo.cpp b/AK/StackInfo.cpp index 07b791d816e..4f53947881a 100644 --- a/AK/StackInfo.cpp +++ b/AK/StackInfo.cpp @@ -14,6 +14,9 @@ # include #elif defined(__linux__) or defined(AK_OS_MACOS) # include +#elif defined(__FreeBSD__) +# include +# include #endif namespace AK { @@ -25,13 +28,23 @@ StackInfo::StackInfo() perror("get_stack_bounds"); VERIFY_NOT_REACHED(); } -#elif defined(__linux__) +#elif defined(__linux__) or defined(__FreeBSD__) int rc; - pthread_attr_t attr = {}; + pthread_attr_t attr; + pthread_attr_init(&attr); + +# ifdef __linux__ if ((rc = pthread_getattr_np(pthread_self(), &attr)) != 0) { fprintf(stderr, "pthread_getattr_np: %s\n", strerror(rc)); VERIFY_NOT_REACHED(); } +# else + if ((rc = pthread_attr_get_np(pthread_self(), &attr)) != 0) { + fprintf(stderr, "pthread_attr_get_np: %s\n", strerror(rc)); + VERIFY_NOT_REACHED(); + } +# endif + if ((rc = pthread_attr_getstack(&attr, (void**)&m_base, &m_size)) != 0) { fprintf(stderr, "pthread_attr_getstack: %s\n", strerror(rc)); VERIFY_NOT_REACHED();