From 4e0070f16d999d12752ef88be097322227062609 Mon Sep 17 00:00:00 2001 From: Eladash Date: Thu, 23 Jan 2020 22:24:38 +0200 Subject: [PATCH] Log sys_spu thread group and thread names Also safely read thread name after relevant error checks passed. --- rpcs3/Emu/Cell/lv2/sys_spu.cpp | 54 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.cpp b/rpcs3/Emu/Cell/lv2/sys_spu.cpp index 692d17fea1..efccb068da 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_spu.cpp @@ -272,33 +272,11 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr thread, u32 g return CELL_EINVAL; } - // Read thread name - const std::string thread_name(attr->name.get_ptr(), std::max(attr->name_len, 1) - 1); - - const auto group = idm::get(group_id); - - if (!group) - { - return CELL_ESRCH; - } - - if (spu_num >= group->threads_map.size()) - { - return CELL_EINVAL; - } - if (img->type != SYS_SPU_IMAGE_TYPE_KERNEL && img->type != SYS_SPU_IMAGE_TYPE_USER) { return CELL_EINVAL; } - std::lock_guard lock(group->mutex); - - if (group->threads_map[spu_num] != -1 || group->run_state != SPU_THREAD_GROUP_STATUS_NOT_INITIALIZED) - { - return CELL_EBUSY; - } - sys_spu_image image = *img; if (img->type == SYS_SPU_IMAGE_TYPE_KERNEL) @@ -314,6 +292,28 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr thread, u32 g image.entry_point = handle->e_entry; } + // Read thread name + const std::string thread_name(attr->name.get_ptr(), std::max(attr->name_len, 1) - 1); + + const auto group = idm::get(group_id); + + if (!group) + { + return CELL_ESRCH; + } + + if (spu_num >= group->threads_map.size()) + { + return CELL_EINVAL; + } + + std::lock_guard lock(group->mutex); + + if (group->threads_map[spu_num] != -1 || group->run_state != SPU_THREAD_GROUP_STATUS_NOT_INITIALIZED) + { + return CELL_EBUSY; + } + if (u32 option = attr->option) { sys_spu.warning("Unimplemented SPU Thread options (0x%x)", option); @@ -362,6 +362,7 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr thread, u32 g group->run_state = SPU_THREAD_GROUP_STATUS_INITIALIZED; } + sys_spu.warning(u8"sys_spu_thread_initialize(): Thread ā€œ%sā€ created (id=0x%x)", thread_name, tid); return CELL_OK; } @@ -426,8 +427,15 @@ error_code sys_spu_thread_group_create(ppu_thread& ppu, vm::ptr id, u32 num sys_spu.warning("sys_spu_thread_group_create(): SPU Thread Group type (0x%x)", attr->type); } - *id = idm::make(std::string(attr->name.get_ptr(), std::max(attr->nsize, 1) - 1), num, prio, attr->type, attr->ct); + const auto group = idm::make_ptr(std::string(attr->name.get_ptr(), std::max(attr->nsize, 1) - 1), num, prio, attr->type, attr->ct); + if (!group) + { + return CELL_EAGAIN; + } + + *id = idm::last_id(); + sys_spu.warning(u8"sys_spu_thread_group_create(): Thread group ā€œ%sā€ created (id=0x%x)", group->name, idm::last_id()); return CELL_OK; }