| 439 | } |
| 440 | |
| 441 | error_code _sys_ppu_thread_create(ppu_thread &ppu, vm::ptr<u64> thread_id, |
| 442 | vm::ptr<ppu_thread_param_t> param, u64 arg, |
| 443 | u64 unk, s32 prio, u32 _stacksz, u64 flags, |
| 444 | vm::cptr<char> threadname) { |
| 445 | ppu.state += cpu_flag::wait; |
| 446 | |
| 447 | sys_ppu_thread.warning( |
| 448 | "_sys_ppu_thread_create(thread_id=*0x%x, param=*0x%x, arg=0x%llx, " |
| 449 | "unk=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=*0x%x)", |
| 450 | thread_id, param, arg, unk, prio, _stacksz, flags, threadname); |
| 451 | |
| 452 | // thread_id is checked for null in stub -> CELL_ENOMEM |
| 453 | // unk is set to 0 in sys_ppu_thread_create stub |
| 454 | |
| 455 | if (!param || !param->entry) { |
| 456 | return CELL_EFAULT; |
| 457 | } |
| 458 | |
| 459 | if (prio < (g_ps3_process_info.debug_or_root() ? -512 : 0) || prio > 3071) { |
| 460 | return CELL_EINVAL; |
| 461 | } |
| 462 | |
| 463 | if ((flags & 3) == 3) // Check two flags: joinable + interrupt not allowed |
| 464 | { |
| 465 | return CELL_EPERM; |
| 466 | } |
| 467 | |
| 468 | const ppu_func_opd_t entry = param->entry.opd(); |
| 469 | const u32 tls = param->tls; |
| 470 | |
| 471 | // Compute actual stack size and allocate |
| 472 | const u32 stack_size = rx::alignUp<u32>(std::max<u32>(_stacksz, 4096), 4096); |
| 473 | |
| 474 | auto &dct = g_fxo->get<lv2_memory_container>(); |
| 475 | |
| 476 | // Try to obtain "physical memory" from the default container |
| 477 | if (!dct.take(stack_size)) { |
| 478 | return {CELL_ENOMEM, dct.size - dct.used}; |
| 479 | } |
| 480 | |
| 481 | const vm::addr_t stack_base{vm::alloc(stack_size, vm::stack, 4096)}; |
| 482 | |
| 483 | if (!stack_base) { |
| 484 | dct.free(stack_size); |
| 485 | return CELL_ENOMEM; |
| 486 | } |
| 487 | |
| 488 | std::string ppu_name; |
| 489 | |
| 490 | if (threadname) { |
| 491 | constexpr u32 max_size = |
| 492 | c_max_ppu_name_size - 1; // max size excluding null terminator |
| 493 | |
| 494 | if (!vm::read_string(threadname.addr(), max_size, ppu_name, true)) { |
| 495 | dct.free(stack_size); |
| 496 | return CELL_EFAULT; |
| 497 | } |
| 498 | } |
no test coverage detected