diff options
| author | JosJuice <josjuice@gmail.com> | 2023-03-03 22:27:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-03 22:27:16 +0100 |
| commit | 95ce41ac56f2774a1b18a1a1dafd2dadee248616 (patch) | |
| tree | d8c149104b2f9534e8e2bf7784fe617042505764 /Source/Core/Common/Thread.cpp | |
| parent | a93b5a4a3534cc4155eb60ad5b3eab38df82ce71 (diff) | |
| parent | b6256a57ef674be52bb3f6da46e61fd70644f4d6 (diff) | |
Merge pull request #11399 from JosJuice/jit-one-stack
Jit: Don't use a second stack
Diffstat (limited to 'Source/Core/Common/Thread.cpp')
| -rw-r--r-- | Source/Core/Common/Thread.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Source/Core/Common/Thread.cpp b/Source/Core/Common/Thread.cpp index 7bbc27e5f4..810db15d78 100644 --- a/Source/Core/Common/Thread.cpp +++ b/Source/Core/Common/Thread.cpp @@ -7,6 +7,7 @@ #include <Windows.h> #include <processthreadsapi.h> #else +#include <pthread.h> #include <unistd.h> #endif @@ -185,6 +186,41 @@ void SetCurrentThreadName(const char* name) #endif } +std::tuple<void*, size_t> GetCurrentThreadStack() +{ + void* stack_addr; + size_t stack_size; + + pthread_t self = pthread_self(); + +#ifdef __APPLE__ + stack_size = pthread_get_stacksize_np(self); + stack_addr = reinterpret_cast<u8*>(pthread_get_stackaddr_np(self)) - stack_size; +#elif defined __OpenBSD__ + stack_t stack; + pthread_stackseg_np(self, &stack); + + stack_addr = reinterpret_cast<u8*>(stack->ss_sp) - stack->ss_size; + stack_size = stack->ss_size; +#else + pthread_attr_t attr; + +#ifdef __FreeBSD__ + pthread_attr_init(&attr); + pthread_attr_get_np(self, &attr); +#else + // Linux and NetBSD + pthread_getattr_np(self, &attr); +#endif + + pthread_attr_getstack(&attr, &stack_addr, &stack_size); + + pthread_attr_destroy(&attr); +#endif + + return std::make_tuple(stack_addr, stack_size); +} + #endif } // namespace Common |
