From e6ba62d9bdfa02dc912fb61ceab935ce303e7410 Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:11:09 +0100 Subject: [PATCH] wiiu: Revise thread creation --- src/Platform.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Platform.c b/src/Platform.c index 6975186..625b924 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -287,19 +287,29 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE sceKernelStartThread(thread->handle, sizeof(struct thread_context), ctx); } #elif defined(__WIIU__) - int stack_size = 4 * 1024 * 1024; - void* stack_addr = (uint8_t *)memalign(8, stack_size) + stack_size; + memset(&thread->thread, 0, sizeof(thread->thread)); + // Allocate stack + const int stack_size = 4 * 1024 * 1024; + uint8_t* stack = (uint8_t*)memalign(16, stack_size); + if (stack == NULL) { + free(ctx); + return -1; + } + + // Create thread if (!OSCreateThread(&thread->thread, ThreadProc, 0, (char*)ctx, - stack_addr, stack_size, + stack + stack_size, stack_size, 0x10, OS_THREAD_ATTRIB_AFFINITY_ANY)) { free(ctx); + free(stack); return -1; } + OSSetThreadName(&thread->thread, name); OSSetThreadDeallocator(&thread->thread, thread_deallocator); OSResumeThread(&thread->thread); #elif defined(__3DS__)