Error
startUsrCfgServiceThread()
{
   // Create message queue
   auto error = IOS_CreateMessageQueue(phys_addrof(sData->messageBuffer),
                                       static_cast<uint32_t>(sData->messageBuffer.size()));
   if (error < Error::OK) {
      return error;
   }
   sData->messageQueueId = static_cast<MessageQueueId>(error);

   // Register the device
   error = mcp::MCP_RegisterResourceManager("/dev/usr_cfg", sData->messageQueueId);
   if (error < Error::OK) {
      IOS_DestroyMessageQueue(sData->messageQueueId);
      return error;
   }

   // Create thread
   error = IOS_CreateThread(&usrCfgServiceThreadEntry, nullptr,
                            phys_addrof(sData->threadStack) + sData->threadStack.size(),
                            static_cast<uint32_t>(sData->threadStack.size()),
                            UCServiceThreadPriority,
                            ThreadFlags::Detached);
   if (error < Error::OK) {
      IOS_DestroyMessageQueue(sData->messageQueueId);
      return error;
   }

   sData->threadId = static_cast<ThreadId>(error);
   kernel::internal::setThreadName(sData->threadId, "UsrCfgServiceThread");

   return IOS_StartThread(sData->threadId);
}
Esempio n. 2
0
Result
Thread::start(ThreadEntryFn entry,
              phys_ptr<void> context,
              phys_ptr<uint8_t> stackTop,
              uint32_t stackSize,
              ThreadPriority priority)
{
   auto tlsDataSize = tlsGetDataSize();
   auto userStackTop = stackTop;

   // Allocate TLS data from stack
   stackTop = align_down(stackTop - tlsDataSize, 8);
   auto tlsData = phys_cast<void *>(stackTop);
   tlsInitialiseData(tlsData);

   // Allocate thread start context from stack
   stackTop = align_down(stackTop - sizeof(ThreadStartData), 8);
   auto threadStartData = phys_cast<ThreadStartData *>(stackTop);
   threadStartData->entry = entry;
   threadStartData->context = context;
   threadStartData->tlsData = tlsData;

   // Calculate new stack size
   stackSize -= static_cast<uint32_t>(userStackTop - stackTop);

   auto error = IOS_CreateThread(threadEntryPoint,
                                 threadStartData,
                                 stackTop,
                                 stackSize,
                                 priority,
                                 ThreadFlags::AllocateTLS);
   if (error < ::ios::Error::OK) {
      return ios::convertError(error);
   }

   mThreadId = static_cast<ThreadId>(error);

   error = IOS_StartThread(mThreadId);
   if (error < ::ios::Error::OK) {
      return ios::convertError(error);
   }

   mJoined = false;
   return ios::ResultOK;
}
Esempio n. 3
0
Error
startPpcThread()
{
   // Create thread
   auto error = IOS_CreateThread(&ppcThreadEntry, nullptr,
                                 phys_addrof(sPpcThreadData->threadStack) + sPpcThreadData->threadStack.size(),
                                 static_cast<uint32_t>(sPpcThreadData->threadStack.size()),
                                 PpcThreadPriority,
                                 ThreadFlags::Detached);
   if (error < Error::OK) {
      return error;
   }

   sPpcThreadData->threadId = static_cast<ThreadId>(error);
   kernel::internal::setThreadName(sPpcThreadData->threadId, "PpcThread");

   return IOS_StartThread(sPpcThreadData->threadId);
}