Skip to content

Commit

Permalink
coreinit: Split pointer before passing to FiberThreadEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
exverge-0 committed Jul 10, 2024
1 parent 1842379 commit 9c188c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ void nnNfp_update();

namespace coreinit
{
#ifdef __arm64__
void __OSFiberThreadEntry(uint32, uint32);
#else
void __OSFiberThreadEntry(void* thread);
#endif
void __OSAddReadyThreadToRunQueue(OSThread_t* thread);
void __OSRemoveThreadFromRunQueues(OSThread_t* thread);
};
Expand All @@ -49,7 +53,7 @@ namespace coreinit

struct OSHostThread
{
OSHostThread(OSThread_t* thread) : m_thread(thread), m_fiber(__OSFiberThreadEntry, this, this)
OSHostThread(OSThread_t* thread) : m_thread(thread), m_fiber((void(*)(void*))__OSFiberThreadEntry, this, this)
{
}

Expand Down Expand Up @@ -1304,8 +1308,14 @@ namespace coreinit
__OSThreadStartTimeslice(hostThread->m_thread, &hostThread->ppcInstance);
}

#ifdef __arm64__
void __OSFiberThreadEntry(uint32 _high, uint32 _low)
{
uint64 _thread = (uint64) _high << 32 | _low;
#else
void __OSFiberThreadEntry(void* _thread)
{
#endif
OSHostThread* hostThread = (OSHostThread*)_thread;

#if defined(ARCH_X86_64)
Expand Down
5 changes: 5 additions & 0 deletions src/util/Fiber/FiberUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Fiber::Fiber(void(*FiberEntryPoint)(void* userParam), void* userParam, void* pri
ctx->uc_stack.ss_sp = m_stackPtr;
ctx->uc_stack.ss_size = stackSize;
ctx->uc_link = &ctx[0];
#ifdef __arm64__
// https://www.man7.org/linux/man-pages/man3/makecontext.3.html#NOTES
makecontext(ctx, (void(*)())FiberEntryPoint, 2, (uint64) userParam >> 32, userParam);
#else
makecontext(ctx, (void(*)())FiberEntryPoint, 1, userParam);
#endif
this->m_implData = (void*)ctx;
}

Expand Down

0 comments on commit 9c188c3

Please sign in to comment.