Merge pull request #11399 from JosJuice/jit-one-stack

Jit: Don't use a second stack
This commit is contained in:
JosJuice
2023-03-03 22:27:16 +01:00
committed by GitHub
12 changed files with 248 additions and 258 deletions

View File

@ -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

View File

@ -5,6 +5,10 @@
#include <thread>
#ifndef _WIN32
#include <tuple>
#endif
// Don't include Common.h here as it will break LogManager
#include "Common/CommonTypes.h"
@ -35,4 +39,9 @@ inline void YieldCPU()
void SetCurrentThreadName(const char* name);
#ifndef _WIN32
// Returns the lowest address of the stack and the size of the stack
std::tuple<void*, size_t> GetCurrentThreadStack();
#endif
} // namespace Common