summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2017-12-31 16:10:01 -0500
committerGravatar bunnei2017-12-31 16:10:01 -0500
commit9d0c3bda7f3d42e1574b12335f9150dd8f480112 (patch)
tree567b90f8920f2b032c9c909d7dd8c718f914fbb2 /src/core/hle/svc.cpp
parentsvc: Cleanup svcGetThreadPriority. (diff)
downloadyuzu-9d0c3bda7f3d42e1574b12335f9150dd8f480112.tar.gz
yuzu-9d0c3bda7f3d42e1574b12335f9150dd8f480112.tar.xz
yuzu-9d0c3bda7f3d42e1574b12335f9150dd8f480112.zip
svc: Implement svcCreateThread.
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 0c53db1c5..3b2eb5d5e 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -224,6 +224,62 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, VAdd
224 return QueryProcessMemory(memory_info, page_info, Kernel::CurrentProcess, addr); 224 return QueryProcessMemory(memory_info, page_info, Kernel::CurrentProcess, addr);
225} 225}
226 226
227/// Creates a new thread
228static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top,
229 u32 priority, s32 processor_id) {
230 std::string name = Common::StringFromFormat("unknown-%016" PRIX64, entry_point);
231
232 if (priority > THREADPRIO_LOWEST) {
233 return Kernel::ERR_OUT_OF_RANGE;
234 }
235
236 SharedPtr<Kernel::ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit;
237 if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) {
238 return Kernel::ERR_NOT_AUTHORIZED;
239 }
240
241 if (processor_id == THREADPROCESSORID_DEFAULT) {
242 // Set the target CPU to the one specified in the process' exheader.
243 processor_id = Kernel::g_current_process->ideal_processor;
244 ASSERT(processor_id != THREADPROCESSORID_DEFAULT);
245 }
246
247 switch (processor_id) {
248 case THREADPROCESSORID_0:
249 break;
250 case THREADPROCESSORID_ALL:
251 LOG_INFO(Kernel_SVC,
252 "Newly created thread is allowed to be run in any Core, unimplemented.");
253 break;
254 case THREADPROCESSORID_1:
255 LOG_ERROR(Kernel_SVC,
256 "Newly created thread must run in the SysCore (Core1), unimplemented.");
257 break;
258 default:
259 // TODO(bunnei): Implement support for other processor IDs
260 ASSERT_MSG(false, "Unsupported thread processor ID: %d", processor_id);
261 break;
262 }
263
264 CASCADE_RESULT(SharedPtr<Kernel::Thread> thread,
265 Kernel::Thread::Create(name, entry_point, priority, arg, processor_id, stack_top,
266 Kernel::g_current_process));
267
268 thread->context.fpscr =
269 FPSCR_DEFAULT_NAN | FPSCR_FLUSH_TO_ZERO | FPSCR_ROUND_TOZERO; // 0x03C00000
270
271 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread)));
272
273 Core::System::GetInstance().PrepareReschedule();
274
275 LOG_TRACE(Kernel_SVC,
276 "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
277 "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X",
278 entry_point, name.c_str(), arg, stack_top, priority, processor_id, *out_handle);
279
280 return RESULT_SUCCESS;
281}
282
227/// Starts the thread for the provided handle 283/// Starts the thread for the provided handle
228static ResultCode StartThread(Handle thread_handle) { 284static ResultCode StartThread(Handle thread_handle) {
229 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); 285 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle);
@@ -288,8 +344,7 @@ static const FunctionDef SVC_Table[] = {
288 {0x05, HLE::Wrap<UnmapMemory>, "svcUnmapMemory"}, 344 {0x05, HLE::Wrap<UnmapMemory>, "svcUnmapMemory"},
289 {0x06, HLE::Wrap<QueryMemory>, "svcQueryMemory"}, 345 {0x06, HLE::Wrap<QueryMemory>, "svcQueryMemory"},
290 {0x07, nullptr, "svcExitProcess"}, 346 {0x07, nullptr, "svcExitProcess"},
291 {0x08, nullptr, "svcCreateThread"}, 347 {0x08, HLE::Wrap<CreateThread>, "svcCreateThread"},
292 {0x09, nullptr, "svcStartThread"},
293 {0x09, HLE::Wrap<StartThread>, "svcStartThread"}, 348 {0x09, HLE::Wrap<StartThread>, "svcStartThread"},
294 {0x0A, nullptr, "svcExitThread"}, 349 {0x0A, nullptr, "svcExitThread"},
295 {0x0B, HLE::Wrap<SleepThread>, "svcSleepThread"}, 350 {0x0B, HLE::Wrap<SleepThread>, "svcSleepThread"},