summaryrefslogtreecommitdiff
path: root/AK/StackInfo.cpp
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2022-07-10 15:19:55 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-19 12:39:24 +0200
commitae4d87118317d246ed98ba7f840af7054d15db4d (patch)
tree2dbe5d009be88778d95d9efb13f48abe4364ce0d /AK/StackInfo.cpp
parentcd0fb6dcc884a6bd96b31f7a50439d43f699c22e (diff)
downloadserenity-ae4d87118317d246ed98ba7f840af7054d15db4d.zip
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.
Diffstat (limited to 'AK/StackInfo.cpp')
-rw-r--r--AK/StackInfo.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/AK/StackInfo.cpp b/AK/StackInfo.cpp
index 07b791d816..4f53947881 100644
--- a/AK/StackInfo.cpp
+++ b/AK/StackInfo.cpp
@@ -14,6 +14,9 @@
# include <serenity.h>
#elif defined(__linux__) or defined(AK_OS_MACOS)
# include <pthread.h>
+#elif defined(__FreeBSD__)
+# include <pthread.h>
+# include <pthread_np.h>
#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();