@@ -767,7 +767,12 @@ error_code sys_spu_thread_initialize(ppu_thread& ppu, vm::ptr<u32> thread, u32 g
767767 }
768768
769769 // Read thread name
770- const std::string thread_name (attr_data.name .get_ptr (), std::max<u32 >(attr_data.name_len , 1 ) - 1 );
770+ std::string thread_name;
771+
772+ if (attr_data.name_len && !vm::read_string (attr_data.name .addr (), attr_data.name_len - 1 , thread_name, true ))
773+ {
774+ return { CELL_EFAULT, attr_data.name .addr () };
775+ }
771776
772777 const auto group = idm::get_unlocked<lv2_spu_group>(group_id);
773778
@@ -906,21 +911,40 @@ error_code sys_spu_thread_get_exit_status(ppu_thread& ppu, u32 id, vm::ptr<s32>
906911 return CELL_ESTAT;
907912}
908913
909- error_code sys_spu_thread_group_create (ppu_thread& ppu, vm::ptr<u32 > id, u32 num, s32 prio, vm::ptr<sys_spu_thread_group_attribute > attr)
914+ error_code sys_spu_thread_group_create (ppu_thread& ppu, vm::ptr<u32 > id, u32 num, s32 prio, vm::ptr<reduced_sys_spu_thread_group_attribute > attr)
910915{
911916 ppu.state += cpu_flag::wait;
912917
913918 sys_spu.warning (" sys_spu_thread_group_create(id=*0x%x, num=%d, prio=%d, attr=*0x%x)" , id, num, prio, attr);
914919
915920 const s32 min_prio = g_ps3_process_info.has_root_perm () ? 0 : 16 ;
916921
917- const sys_spu_thread_group_attribute attr_data = *attr;
922+ sys_spu_thread_group_attribute attr_data{};
923+ {
924+ const reduced_sys_spu_thread_group_attribute attr_reduced = *attr;
925+ attr_data.name = attr_reduced.name ;
926+ attr_data.nsize = attr_reduced.nsize ;
927+ attr_data.type = attr_reduced.type ;
928+
929+ // Read container-id member at offset 12 bytes conditionally (that's what LV2 does)
930+ if (attr_data.type & SYS_SPU_THREAD_GROUP_TYPE_MEMORY_FROM_CONTAINER)
931+ {
932+ attr_data.ct = vm::unsafe_ptr_cast<sys_spu_thread_group_attribute>(attr)->ct ;
933+ }
934+ }
918935
919936 if (attr_data.nsize > 0x80 || !num)
920937 {
921938 return CELL_EINVAL;
922939 }
923940
941+ std::string group_name;
942+
943+ if (attr_data.nsize && !vm::read_string (attr_data.name .addr (), attr_data.nsize - 1 , group_name, true ))
944+ {
945+ return { CELL_EFAULT, attr_data.name .addr () };
946+ }
947+
924948 const s32 type = attr_data.type ;
925949
926950 bool use_scheduler = true ;
@@ -1075,7 +1099,7 @@ error_code sys_spu_thread_group_create(ppu_thread& ppu, vm::ptr<u32> id, u32 num
10751099 return CELL_EBUSY;
10761100 }
10771101
1078- const auto group = idm::make_ptr<lv2_spu_group>(std::string (attr_data. name . get_ptr (), std::max< u32 >(attr_data. nsize , 1 ) - 1 ), num, prio, type, ct, use_scheduler, mem_size);
1102+ const auto group = idm::make_ptr<lv2_spu_group>(std::move (group_name ), num, prio, type, ct, use_scheduler, mem_size);
10791103
10801104 if (!group)
10811105 {
0 commit comments