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.
This commit is contained in:
Daniel Bertalan 2022-07-10 15:19:55 +02:00 committed by Andreas Kling
parent cd0fb6dcc8
commit ae4d871183
Notes: sideshowbarker 2024-07-17 08:46:23 +09:00

View file

@ -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();