mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 13:28:01 +03:00
Add thread_ctrl::get_thread_stack
Returns addr and size of current thread's stack.
This commit is contained in:
parent
d7e1cf7dd2
commit
d789250976
2 changed files with 27 additions and 0 deletions
|
@ -2702,3 +2702,27 @@ u64 thread_ctrl::get_thread_affinity_mask()
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#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};
|
||||||
|
}
|
||||||
|
|
|
@ -262,6 +262,9 @@ public:
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
static u64 get_thread_affinity_mask();
|
static u64 get_thread_affinity_mask();
|
||||||
|
|
||||||
|
// Get current thread stack addr and size
|
||||||
|
static std::pair<void*, std::size_t> get_thread_stack();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
static const u64 process_affinity_mask;
|
static const u64 process_affinity_mask;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue