diff options
| author | Martin Ridgers <[email protected]> | 2021-09-09 13:40:47 +0200 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-09-14 14:29:28 +0200 |
| commit | d9cd120af0c9ca967fb0a8b6a9ebeb3362ef366c (patch) | |
| tree | fc80cb7c65514ec27a5d65357acef2223a46558b | |
| parent | Replaced use of "%ll?" format specifiers with PRI?64 (diff) | |
| download | zen-d9cd120af0c9ca967fb0a8b6a9ebeb3362ef366c.tar.xz zen-d9cd120af0c9ca967fb0a8b6a9ebeb3362ef366c.zip | |
IsPointerToStack() implementation for Linux
| -rw-r--r-- | zencore/zencore.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index c2a57b653..27ac779b0 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -2,7 +2,13 @@ #include <zencore/zencore.h> +#if ZEN_PLATFORM_WINDOWS #include <zencore/windows.h> +#endif + +#if ZEN_PLATFORM_LINUX +#include <pthread.h> +#endif #include <zencore/blake3.h> #include <zencore/compactbinary.h> @@ -25,12 +31,26 @@ bool IsPointerToStack(const void* ptr) { +#if ZEN_PLATFORM_WINDOWS ULONG_PTR low, high; GetCurrentThreadStackLimits(&low, &high); const uintptr_t intPtr = reinterpret_cast<uintptr_t>(ptr); return (intPtr - low) < (high - low); +#elif ZEN_PLATFORM_LINUX + pthread_t self = pthread_self(); + + pthread_attr_t attr; + pthread_getattr_np(self, &attr); + + void* low; + size_t size; + pthread_attr_getstack(&attr, &low, &size); + + return (uintptr_t(ptr) - uintptr_t(low)) < uintptr_t(size); +#elif 0 +#endif } zen::AssertException::AssertException(const char* Msg) : m_Msg(Msg) |