rpcsx/rpcs3/Emu/Cell/lv2/sys_lwcond.h
eladash e40b76b253 sys_lwcond: Extract protocol from lwmutex at creation
This is the only reason theres a need to specify lwmutex_sq id at creation. unlike sys_cond, lwcond isn't connected to lwmutex at the lv2 level.
SYS_SYNC_RETRY fix is done explicitly at the firmware level.
This fixes issues when the original lwcond and lwmutexol data got corrupted or deallocated, this can happen when the program simply memcpy the control data to somewhere else.
Or if it uses direct lv2 the lwcond conrol param can even be NULL which will make it access violate when dereferncing it. (This param is unchecked and can be anything)
2019-07-29 21:58:04 +03:00

56 lines
1.2 KiB
C++

#pragma once
#include "sys_sync.h"
#include "Emu/Memory/vm_ptr.h"
struct sys_lwmutex_t;
struct sys_lwcond_attribute_t
{
union
{
u64 name_u64;
char name[sizeof(u64)];
};
};
struct sys_lwcond_t
{
vm::bptr<sys_lwmutex_t> lwmutex;
be_t<u32> lwcond_queue; // lwcond pseudo-id
};
struct lv2_lwcond final : lv2_obj
{
static const u32 id_base = 0x97000000;
const u64 name;
const u32 lwid;
const u32 protocol;
vm::ptr<sys_lwcond_t> control;
shared_mutex mutex;
atomic_t<u32> waiters{0};
std::deque<cpu_thread*> sq;
lv2_lwcond(u64 name, u32 lwid, u32 protocol, vm::ptr<sys_lwcond_t> control)
: name(name)
, lwid(lwid)
, protocol(protocol)
, control(control)
{
}
};
// Aux
class ppu_thread;
// Syscalls
error_code _sys_lwcond_create(ppu_thread& ppu, vm::ptr<u32> lwcond_id, u32 lwmutex_id, vm::ptr<sys_lwcond_t> control, u64 name, u32 arg5);
error_code _sys_lwcond_destroy(ppu_thread& ppu, u32 lwcond_id);
error_code _sys_lwcond_signal(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 ppu_thread_id, u32 mode);
error_code _sys_lwcond_signal_all(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u32 mode);
error_code _sys_lwcond_queue_wait(ppu_thread& ppu, u32 lwcond_id, u32 lwmutex_id, u64 timeout);