thread: Configure stack and guard on POSIX hosts. ()

This commit is contained in:
squidbus 2024-12-04 10:21:03 -08:00 committed by GitHub
parent 920acb8d8b
commit c019b54fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions
src/core
libraries/kernel/threads
thread.cppthread.h

View file

@ -281,7 +281,7 @@ int PS4_SYSV_ABI posix_pthread_create_name_np(PthreadT* thread, const PthreadAtt
/* Create thread */ /* Create thread */
new_thread->native_thr = Core::Thread(); new_thread->native_thr = Core::Thread();
int ret = new_thread->native_thr.Create(RunThread, new_thread); int ret = new_thread->native_thr.Create(RunThread, new_thread, &new_thread->attr);
ASSERT_MSG(ret == 0, "Failed to create thread with error {}", ret); ASSERT_MSG(ret == 0, "Failed to create thread with error {}", ret);
if (ret) { if (ret) {
*thread = nullptr; *thread = nullptr;

View file

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "libraries/kernel/threads/pthread.h"
#include "thread.h" #include "thread.h"
#ifdef _WIN64 #ifdef _WIN64
@ -15,7 +16,7 @@ Thread::Thread() : native_handle{0} {}
Thread::~Thread() {} Thread::~Thread() {}
int Thread::Create(ThreadFunc func, void* arg) { int Thread::Create(ThreadFunc func, void* arg, const ::Libraries::Kernel::PthreadAttr* attr) {
#ifdef _WIN64 #ifdef _WIN64
native_handle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, nullptr); native_handle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, nullptr);
return native_handle ? 0 : -1; return native_handle ? 0 : -1;
@ -23,6 +24,7 @@ int Thread::Create(ThreadFunc func, void* arg) {
pthread_t* pthr = reinterpret_cast<pthread_t*>(&native_handle); pthread_t* pthr = reinterpret_cast<pthread_t*>(&native_handle);
pthread_attr_t pattr; pthread_attr_t pattr;
pthread_attr_init(&pattr); pthread_attr_init(&pattr);
pthread_attr_setstack(&pattr, attr->stackaddr_attr, attr->stacksize_attr);
return pthread_create(pthr, &pattr, (PthreadFunc)func, arg); return pthread_create(pthr, &pattr, (PthreadFunc)func, arg);
#endif #endif
} }

View file

@ -5,6 +5,10 @@
#include "common/types.h" #include "common/types.h"
namespace Libraries::Kernel {
struct PthreadAttr;
} // namespace Libraries::Kernel
namespace Core { namespace Core {
class Thread { class Thread {
@ -15,7 +19,7 @@ public:
Thread(); Thread();
~Thread(); ~Thread();
int Create(ThreadFunc func, void* arg); int Create(ThreadFunc func, void* arg, const ::Libraries::Kernel::PthreadAttr* attr);
void Exit(); void Exit();
uintptr_t GetHandle() { uintptr_t GetHandle() {