1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Add thread_ctrl::get_thread_stack

Returns addr and size of current thread's stack.
This commit is contained in:
Nekotekina 2020-11-16 13:57:15 +03:00
parent d7e1cf7dd2
commit d789250976
2 changed files with 27 additions and 0 deletions

View File

@ -2702,3 +2702,27 @@ u64 thread_ctrl::get_thread_affinity_mask()
return -1;
#endif
}
std::pair<void*, std::size_t> thread_ctrl::get_thread_stack()
{
#ifdef _WIN32
ULONG_PTR _min = 0;
ULONG_PTR _max = 0;
GetCurrentThreadStackLimits(&_min, &_max);
const std::size_t ssize = _max - _min;
const auto saddr = reinterpret_cast<void*>(_min);
#else
void* saddr = 0;
std::size_t ssize = 0;
pthread_attr_t attr;
#ifdef __linux__
pthread_getattr_np(pthread_self(), &attr);
pthread_attr_getstack(&attr, &saddr, &ssize);
#else
pthread_attr_get_np(pthread_self(), &attr);
pthread_attr_getstackaddr(&attr, &saddr);
pthread_attr_getstacksize(&attr, &ssize);
#endif
#endif
return {saddr, ssize};
}

View File

@ -262,6 +262,9 @@ public:
// Miscellaneous
static u64 get_thread_affinity_mask();
// Get current thread stack addr and size
static std::pair<void*, std::size_t> get_thread_stack();
private:
// Miscellaneous
static const u64 process_affinity_mask;