diff --git a/rpcs3/Emu/Cell/lv2/sys_cond.cpp b/rpcs3/Emu/Cell/lv2/sys_cond.cpp index 3bbef5d02e..343e5d2a51 100644 --- a/rpcs3/Emu/Cell/lv2/sys_cond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_cond.cpp @@ -24,13 +24,15 @@ error_code sys_cond_create(ppu_thread& ppu, vm::ptr cond_id, u32 mutex_id, return CELL_ESRCH; } - if (auto error = lv2_obj::create(attr->pshared, attr->ipc_key, attr->flags, [&] + const auto _attr = *attr; + + if (auto error = lv2_obj::create(_attr.pshared, _attr.ipc_key, _attr.flags, [&] { return std::make_shared( - attr->pshared, - attr->flags, - attr->ipc_key, - attr->name_u64, + _attr.pshared, + _attr.flags, + _attr.ipc_key, + _attr.name_u64, std::move(mutex)); })) { diff --git a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp index c6c21ba0db..c629099a6f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event_flag.cpp @@ -24,7 +24,9 @@ error_code sys_event_flag_create(ppu_thread& ppu, vm::ptr id, vm::ptrprotocol; + const auto _attr = *attr; + + const u32 protocol = _attr.protocol; if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_PRIORITY) { @@ -32,7 +34,7 @@ error_code sys_event_flag_create(ppu_thread& ppu, vm::ptr id, vm::ptrtype; + const u32 type = _attr.type; if (type != SYS_SYNC_WAITER_SINGLE && type != SYS_SYNC_WAITER_MULTIPLE) { @@ -40,15 +42,15 @@ error_code sys_event_flag_create(ppu_thread& ppu, vm::ptr id, vm::ptr(attr->pshared, attr->ipc_key, attr->flags, [&] + if (auto error = lv2_obj::create(_attr.pshared, _attr.ipc_key, _attr.flags, [&] { return std::make_shared( - attr->protocol, - attr->pshared, - attr->ipc_key, - attr->flags, - attr->type, - attr->name_u64, + _attr.protocol, + _attr.pshared, + _attr.ipc_key, + _attr.flags, + _attr.type, + _attr.name_u64, init); })) { diff --git a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp index 2b239542f0..8e1e92014f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_mutex.cpp @@ -22,7 +22,9 @@ error_code sys_mutex_create(ppu_thread& ppu, vm::ptr mutex_id, vm::ptrprotocol) + const auto _attr = *attr; + + switch (_attr.protocol) { case SYS_SYNC_FIFO: break; case SYS_SYNC_PRIORITY: break; @@ -31,37 +33,37 @@ error_code sys_mutex_create(ppu_thread& ppu, vm::ptr mutex_id, vm::ptrprotocol); + sys_mutex.error("sys_mutex_create(): unknown protocol (0x%x)", _attr.protocol); return CELL_EINVAL; } } - switch (attr->recursive) + switch (_attr.recursive) { case SYS_SYNC_RECURSIVE: break; case SYS_SYNC_NOT_RECURSIVE: break; default: { - sys_mutex.error("sys_mutex_create(): unknown recursive (0x%x)", attr->recursive); + sys_mutex.error("sys_mutex_create(): unknown recursive (0x%x)", _attr.recursive); return CELL_EINVAL; } } - if (attr->adaptive != SYS_SYNC_NOT_ADAPTIVE) + if (_attr.adaptive != SYS_SYNC_NOT_ADAPTIVE) { - sys_mutex.todo("sys_mutex_create(): unexpected adaptive (0x%x)", attr->adaptive); + sys_mutex.todo("sys_mutex_create(): unexpected adaptive (0x%x)", _attr.adaptive); } - if (auto error = lv2_obj::create(attr->pshared, attr->ipc_key, attr->flags, [&]() + if (auto error = lv2_obj::create(_attr.pshared, _attr.ipc_key, _attr.flags, [&]() { return std::make_shared( - attr->protocol, - attr->recursive, - attr->pshared, - attr->adaptive, - attr->ipc_key, - attr->flags, - attr->name_u64); + _attr.protocol, + _attr.recursive, + _attr.pshared, + _attr.adaptive, + _attr.ipc_key, + _attr.flags, + _attr.name_u64); })) { return error; diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp index 70d97d42ea..93a14d5daa 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.cpp @@ -364,6 +364,7 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptrentry.opd(); + const u32 tls = param->tls; // Clean some detached thread (hack) g_fxo->get()->clean(0); @@ -389,6 +390,13 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptr>([&]() { const u32 tid = idm::last_id(); @@ -397,10 +405,6 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptr thread_id, vm::ptrtls; + p.tls_addr = tls; p.entry = entry; p.arg0 = arg; p.arg1 = unk; @@ -426,7 +430,7 @@ error_code _sys_ppu_thread_create(vm::ptr thread_id, vm::ptr rw_lock_id, vm::ptrprotocol; + const auto _attr = *attr; + + const u32 protocol = _attr.protocol; if (protocol == SYS_SYNC_PRIORITY_INHERIT) sys_rwlock.todo("sys_rwlock_create(): SYS_SYNC_PRIORITY_INHERIT"); @@ -33,9 +35,9 @@ error_code sys_rwlock_create(ppu_thread& ppu, vm::ptr rw_lock_id, vm::ptr(attr->pshared, attr->ipc_key, attr->flags, [&] + if (auto error = lv2_obj::create(_attr.pshared, _attr.ipc_key, _attr.flags, [&] { - return std::make_shared(protocol, attr->pshared, attr->ipc_key, attr->flags, attr->name_u64); + return std::make_shared(protocol, _attr.pshared, _attr.ipc_key, _attr.flags, _attr.name_u64); })) { return error; diff --git a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp index f637258130..9ad520d306 100644 --- a/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_semaphore.cpp @@ -28,7 +28,9 @@ error_code sys_semaphore_create(ppu_thread& ppu, vm::ptr sem_id, vm::ptrprotocol; + const auto _attr = *attr; + + const u32 protocol = _attr.protocol; if (protocol != SYS_SYNC_FIFO && protocol != SYS_SYNC_PRIORITY) { @@ -36,9 +38,9 @@ error_code sys_semaphore_create(ppu_thread& ppu, vm::ptr sem_id, vm::ptr(attr->pshared, attr->ipc_key, attr->flags, [&] + if (auto error = lv2_obj::create(_attr.pshared, _attr.ipc_key, _attr.flags, [&] { - return std::make_shared(protocol, attr->pshared, attr->ipc_key, attr->flags, attr->name_u64, max_val, initial_val); + return std::make_shared(protocol, _attr.pshared, _attr.ipc_key, _attr.flags, _attr.name_u64, max_val, initial_val); })) { return error; @@ -268,13 +270,16 @@ error_code sys_semaphore_get_value(ppu_thread& ppu, u32 sem_id, vm::ptr cou return CELL_EFAULT; } - if (!idm::check(sem_id, [=](lv2_sema& sema) + const auto sema = idm::check(sem_id, [](lv2_sema& sema) { - *count = std::max(0, sema.val); - })) + return std::max(0, sema.val); + }); + + if (!sema) { return CELL_ESRCH; } + *count = sema.ret; return CELL_OK; }