thread: Configure stack and guard on POSIX hosts. (#1664)
Some checks are pending
Build and Release / reuse (push) Waiting to run
Build and Release / clang-format (push) Waiting to run
Build and Release / get-info (push) Waiting to run
Build and Release / windows-sdl (push) Blocked by required conditions
Build and Release / windows-qt (push) Blocked by required conditions
Build and Release / macos-sdl (push) Blocked by required conditions
Build and Release / macos-qt (push) Blocked by required conditions
Build and Release / linux-sdl (push) Blocked by required conditions
Build and Release / linux-qt (push) Blocked by required conditions
Build and Release / pre-release (push) Blocked by required conditions

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

View file

@ -281,7 +281,7 @@ int PS4_SYSV_ABI posix_pthread_create_name_np(PthreadT* thread, const PthreadAtt
/* Create 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);
if (ret) {
*thread = nullptr;

View file

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

View file

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