Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup for most vm::temporary_unlock calls #9174

Merged
merged 9 commits into from Oct 30, 2020
2 changes: 0 additions & 2 deletions Utilities/StrFmt.h
Expand Up @@ -2,8 +2,6 @@

#include "types.h"

#include <exception>
#include <stdexcept>
#include <string>

namespace fmt
Expand Down
2 changes: 1 addition & 1 deletion Utilities/Thread.cpp
Expand Up @@ -1419,7 +1419,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
{
data2 = (SYS_MEMORY_PAGE_FAULT_TYPE_PPU_THREAD << 32) | cpu->id;
}
else
else if (cpu->id_type() == 2)
{
const auto& spu = static_cast<spu_thread&>(*cpu);

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/CPU/CPUThread.cpp
Expand Up @@ -671,7 +671,7 @@ bool cpu_thread::check_state() noexcept
}

verify(HERE), cpu_can_stop || !retval;
verify(HERE), cpu_can_stop || !(state & cpu_flag::wait);
verify(HERE), cpu_can_stop || Emu.IsStopped() || !(state & cpu_flag::wait);
return retval;
}

Expand Down
8 changes: 1 addition & 7 deletions rpcs3/Emu/CPU/CPUThread.h
Expand Up @@ -92,7 +92,7 @@ class cpu_thread
std::string get_name() const;

// Get CPU state dump (everything)
virtual std::string dump_all() const = 0;
virtual std::string dump_all() const;

// Get CPU register dump
virtual std::string dump_regs() const;
Expand All @@ -112,12 +112,6 @@ class cpu_thread
// Callback for cpu_flag::suspend
virtual void cpu_sleep() {}

// Callback for cpu_flag::memory
virtual void cpu_mem() {}

// Callback for vm::temporary_unlock
virtual void cpu_unmem() {}

// Callback for cpu_flag::ret
virtual void cpu_return() {}

Expand Down
14 changes: 7 additions & 7 deletions rpcs3/Emu/Cell/Modules/cellAudio.cpp
Expand Up @@ -1220,7 +1220,7 @@ error_code cellAudioPortOpen(vm::ptr<CellAudioPortParam> audioParam, vm::ptr<u32
{
return CELL_AUDIO_ERROR_PORT_FULL;
}

// TODO: is this necessary in any way? (Based on libaudio.prx)
//const u64 num_channels_non_0 = std::max<u64>(1, num_channels);

Expand Down Expand Up @@ -1491,7 +1491,7 @@ error_code cellAudioSetPortLevel(u32 portNum, float level)
return CELL_OK;
}

static error_code AudioCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key, u32 queue_type)
static error_code AudioCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key, u32 queue_type)
{
vm::var<sys_event_queue_attribute_t> attr;
attr->protocol = SYS_SYNC_FIFO;
Expand All @@ -1507,7 +1507,7 @@ static error_code AudioCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key,
// So check initialization as well
const u32 queue_depth = g_fxo->get<cell_audio>()->init && g_ps3_process_info.sdk_ver <= 0x35FFFF ? 2 : 8;

if (CellError res{sys_event_queue_create(id, attr, key_value, queue_depth) + 0u})
if (CellError res{sys_event_queue_create(ppu, id, attr, key_value, queue_depth) + 0u})
{
if (res != CELL_EEXIST)
{
Expand All @@ -1524,14 +1524,14 @@ static error_code AudioCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key,
return CELL_AUDIO_ERROR_EVENT_QUEUE;
}

error_code cellAudioCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key)
error_code cellAudioCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key)
{
cellAudio.warning("cellAudioCreateNotifyEventQueue(id=*0x%x, key=*0x%x)", id, key);

return AudioCreateNotifyEventQueue(id, key, SYS_PPU_QUEUE);
return AudioCreateNotifyEventQueue(ppu, id, key, SYS_PPU_QUEUE);
}

error_code cellAudioCreateNotifyEventQueueEx(vm::ptr<u32> id, vm::ptr<u64> key, u32 iFlags)
error_code cellAudioCreateNotifyEventQueueEx(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key, u32 iFlags)
{
cellAudio.warning("cellAudioCreateNotifyEventQueueEx(id=*0x%x, key=*0x%x, iFlags=0x%x)", id, key, iFlags);

Expand All @@ -1541,7 +1541,7 @@ error_code cellAudioCreateNotifyEventQueueEx(vm::ptr<u32> id, vm::ptr<u64> key,
}

const u32 queue_type = (iFlags & CELL_AUDIO_CREATEEVENTFLAG_SPU) ? SYS_SPU_QUEUE : SYS_PPU_QUEUE;
return AudioCreateNotifyEventQueue(id, key, queue_type);
return AudioCreateNotifyEventQueue(ppu, id, key, queue_type);
}

error_code AudioSetNotifyEventQueue(u64 key, u32 iFlags)
Expand Down
32 changes: 16 additions & 16 deletions rpcs3/Emu/Cell/Modules/cellGcmSys.cpp
Expand Up @@ -75,7 +75,7 @@ u32 gcmGetLocalMemorySize(u32 sdk_version)
return 0x0E000000; // 224MB
}

error_code gcmMapEaIoAddress(u32 ea, u32 io, u32 size, bool is_strict);
error_code gcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size, bool is_strict);

u32 gcmIoOffsetToAddress(u32 ioOffset)
{
Expand Down Expand Up @@ -369,7 +369,7 @@ error_code _cellGcmInitBody(ppu_thread& ppu, vm::pptr<CellGcmContextData> contex
render->main_mem_size = 0x10000000;
}

if (gcmMapEaIoAddress(ioAddress, 0, ioSize, false) != CELL_OK)
if (gcmMapEaIoAddress(ppu, ioAddress, 0, ioSize, false) != CELL_OK)
{
return CELL_GCM_ERROR_FAILURE;
}
Expand Down Expand Up @@ -950,14 +950,14 @@ error_code cellGcmIoOffsetToAddress(u32 ioOffset, vm::ptr<u32> address)
return CELL_OK;
}

error_code gcmMapEaIoAddress(u32 ea, u32 io, u32 size, bool is_strict)
error_code gcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size, bool is_strict)
{
if (!size || (ea & 0xFFFFF) || (io & 0xFFFFF) || (size & 0xFFFFF))
{
return CELL_GCM_ERROR_FAILURE;
}

if (auto error = sys_rsx_context_iomap(0x55555555, io, ea, size, 0xe000000000000800ull | (u64{is_strict} << 60)))
if (auto error = sys_rsx_context_iomap(ppu, 0x55555555, io, ea, size, 0xe000000000000800ull | (u64{is_strict} << 60)))
{
return error;
}
Expand All @@ -977,17 +977,17 @@ error_code gcmMapEaIoAddress(u32 ea, u32 io, u32 size, bool is_strict)
return CELL_OK;
}

error_code cellGcmMapEaIoAddress(u32 ea, u32 io, u32 size)
error_code cellGcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size)
{
cellGcmSys.warning("cellGcmMapEaIoAddress(ea=0x%x, io=0x%x, size=0x%x)", ea, io, size);

const auto cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(cfg->gcmio_mutex);

return gcmMapEaIoAddress(ea, io, size, false);
return gcmMapEaIoAddress(ppu, ea, io, size, false);
}

error_code cellGcmMapEaIoAddressWithFlags(u32 ea, u32 io, u32 size, u32 flags)
error_code cellGcmMapEaIoAddressWithFlags(ppu_thread& ppu, u32 ea, u32 io, u32 size, u32 flags)
{
cellGcmSys.warning("cellGcmMapEaIoAddressWithFlags(ea=0x%x, io=0x%x, size=0x%x, flags=0x%x)", ea, io, size, flags);

Expand All @@ -996,7 +996,7 @@ error_code cellGcmMapEaIoAddressWithFlags(u32 ea, u32 io, u32 size, u32 flags)
const auto cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(cfg->gcmio_mutex);

return gcmMapEaIoAddress(ea, io, size, true);
return gcmMapEaIoAddress(ppu, ea, io, size, true);
}

error_code cellGcmMapLocalMemory(vm::ptr<u32> address, vm::ptr<u32> size)
Expand All @@ -1016,7 +1016,7 @@ error_code cellGcmMapLocalMemory(vm::ptr<u32> address, vm::ptr<u32> size)
return CELL_GCM_ERROR_FAILURE;
}

error_code cellGcmMapMainMemory(u32 ea, u32 size, vm::ptr<u32> offset)
error_code cellGcmMapMainMemory(ppu_thread& ppu, u32 ea, u32 size, vm::ptr<u32> offset)
{
cellGcmSys.warning("cellGcmMapMainMemory(ea=0x%x, size=0x%x, offset=*0x%x)", ea, size, offset);

Expand All @@ -1034,7 +1034,7 @@ error_code cellGcmMapMainMemory(u32 ea, u32 size, vm::ptr<u32> offset)
{
io <<= 20;

if (auto error = gcmMapEaIoAddress(ea, io, size, false))
if (auto error = gcmMapEaIoAddress(ppu, ea, io, size, false))
{
return error;
}
Expand Down Expand Up @@ -1074,11 +1074,11 @@ error_code cellGcmReserveIoMapSize(u32 size)
return CELL_OK;
}

error_code GcmUnmapIoAddress(gcm_config* cfg, u32 io)
error_code GcmUnmapIoAddress(ppu_thread& ppu, gcm_config* cfg, u32 io)
{
if (u32 ea = cfg->offsetTable.eaAddress[io >>= 20], size = cfg->IoMapTable[ea]; size)
{
if (auto error = sys_rsx_context_iounmap(0x55555555, io, size << 20))
if (auto error = sys_rsx_context_iounmap(ppu, 0x55555555, io, size << 20))
{
return error;
}
Expand All @@ -1098,7 +1098,7 @@ error_code GcmUnmapIoAddress(gcm_config* cfg, u32 io)
return CELL_GCM_ERROR_FAILURE;
}

error_code cellGcmUnmapEaIoAddress(u32 ea)
error_code cellGcmUnmapEaIoAddress(ppu_thread& ppu, u32 ea)
{
cellGcmSys.warning("cellGcmUnmapEaIoAddress(ea=0x%x)", ea);

Expand All @@ -1116,20 +1116,20 @@ error_code cellGcmUnmapEaIoAddress(u32 ea)
if (const u32 io = cfg->offsetTable.ioAddress[ea] << 20;
io < rsx::get_current_renderer()->main_mem_size)
{
return GcmUnmapIoAddress(cfg, io);
return GcmUnmapIoAddress(ppu, cfg, io);
}

return CELL_GCM_ERROR_FAILURE;
}

error_code cellGcmUnmapIoAddress(u32 io)
error_code cellGcmUnmapIoAddress(ppu_thread& ppu, u32 io)
{
cellGcmSys.warning("cellGcmUnmapIoAddress(io=0x%x)", io);

const auto cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(cfg->gcmio_mutex);

return GcmUnmapIoAddress(cfg, io);
return GcmUnmapIoAddress(ppu, cfg, io);
}

error_code cellGcmUnreserveIoMapSize(u32 size)
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/Modules/cellGem.cpp
Expand Up @@ -505,7 +505,7 @@ error_code cellGemEnableMagnetometer2()
return CELL_OK;
}

error_code cellGemEnd()
error_code cellGemEnd(ppu_thread& ppu)
{
cellGem.warning("cellGemEnd()");

Expand All @@ -517,7 +517,7 @@ error_code cellGemEnd()
{
if (u32 addr = gem->memory_ptr)
{
sys_memory_free(addr);
sys_memory_free(ppu, addr);
}

return CELL_OK;
Expand Down Expand Up @@ -950,7 +950,7 @@ error_code cellGemHSVtoRGB(f32 h, f32 s, f32 v, vm::ptr<f32> r, vm::ptr<f32> g,
return CELL_OK;
}

error_code cellGemInit(vm::cptr<CellGemAttribute> attribute)
error_code cellGemInit(ppu_thread& ppu, vm::cptr<CellGemAttribute> attribute)
{
cellGem.warning("cellGemInit(attribute=*0x%x)", attribute);

Expand All @@ -973,7 +973,7 @@ error_code cellGemInit(vm::cptr<CellGemAttribute> attribute)
vm::var<u32> addr(0);

// Decrease memory stats
if (sys_memory_allocate(GemGetMemorySize(attribute->max_connect), SYS_MEMORY_PAGE_SIZE_64K, +addr) != CELL_OK)
if (sys_memory_allocate(ppu, GemGetMemorySize(attribute->max_connect), SYS_MEMORY_PAGE_SIZE_64K, +addr) != CELL_OK)
{
return CELL_GEM_ERROR_RESOURCE_ALLOCATION_FAILED;
}
Expand Down
10 changes: 5 additions & 5 deletions rpcs3/Emu/Cell/Modules/cellSpurs.cpp
Expand Up @@ -509,7 +509,7 @@ bool _spurs::is_libprof_loaded()

s32 _spurs::create_lv2_eq(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<u32> queueId, vm::ptr<u8> port, s32 size, const sys_event_queue_attribute_t& attr)
{
if (s32 rc = sys_event_queue_create(queueId, vm::make_var(attr), SYS_EVENT_QUEUE_LOCAL, size))
if (s32 rc = sys_event_queue_create(ppu, queueId, vm::make_var(attr), SYS_EVENT_QUEUE_LOCAL, size))
{
return rc;
}
Expand Down Expand Up @@ -895,7 +895,7 @@ s32 _spurs::create_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 p
return rc;
}

if (s32 rc = sys_event_port_create(spurs.ptr(&CellSpurs::eventPort), SYS_EVENT_PORT_LOCAL, SYS_EVENT_PORT_NO_NAME))
if (s32 rc = sys_event_port_create(ppu, spurs.ptr(&CellSpurs::eventPort), SYS_EVENT_PORT_LOCAL, SYS_EVENT_PORT_NO_NAME))
{
if (s32 rc2 = _spurs::detach_lv2_eq(spurs, spurs->spuPort, true))
{
Expand All @@ -906,7 +906,7 @@ s32 _spurs::create_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 p
return CELL_SPURS_CORE_ERROR_AGAIN;
}

if (s32 rc = sys_event_port_connect_local(spurs->eventPort, spurs->eventQueue))
if (s32 rc = sys_event_port_connect_local(ppu, spurs->eventPort, spurs->eventQueue))
{
sys_event_port_destroy(ppu, spurs->eventPort);

Expand Down Expand Up @@ -3523,10 +3523,10 @@ s32 cellSpursEventFlagAttachLv2EventQueue(ppu_thread& ppu, vm::ptr<CellSpursEven
{
vm::var<u32> eventPortId;

s32 rc = sys_event_port_create(eventPortId, SYS_EVENT_PORT_LOCAL, 0);
s32 rc = sys_event_port_create(ppu, eventPortId, SYS_EVENT_PORT_LOCAL, 0);
if (rc == CELL_OK)
{
rc = sys_event_port_connect_local(*eventPortId, *eventQueueId);
rc = sys_event_port_connect_local(ppu, *eventPortId, *eventQueueId);
if (rc == CELL_OK)
{
eventFlag->eventPortId = *eventPortId;
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/Modules/cellVoice.cpp
Expand Up @@ -70,7 +70,7 @@ error_code cellVoiceConnectIPortToOPort(u32 ips, u32 ops)
return CELL_OK;
}

error_code cellVoiceCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key)
error_code cellVoiceCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key)
{
cellVoice.warning("cellVoiceCreateNotifyEventQueue(id=*0x%x, key=*0x%x)", id, key);

Expand All @@ -90,7 +90,7 @@ error_code cellVoiceCreateNotifyEventQueue(vm::ptr<u32> id, vm::ptr<u64> key)
{
// Create an event queue "bruteforcing" an available key
const u64 key_value = 0x80004d494f323285ull + i;
if (CellError res{sys_event_queue_create(id, attr, key_value, 0x40) + 0u})
if (CellError res{sys_event_queue_create(ppu, id, attr, key_value, 0x40) + 0u})
{
if (res != CELL_EEXIST)
{
Expand Down Expand Up @@ -858,7 +858,7 @@ error_code cellVoiceReadFromOPort(u32 ops, vm::ptr<void> data, vm::ptr<u32> size

if (!oport || oport->info.portType <= CELLVOICE_PORTTYPE_IN_VOICE)
return CELL_VOICE_ERROR_TOPOLOGY;

if (size)
*size = 0;

Expand Down
4 changes: 3 additions & 1 deletion rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp
Expand Up @@ -125,6 +125,8 @@ void sys_initialize_tls(ppu_thread& ppu, u64 main_thread_id, u32 tls_seg_addr, u

error_code sys_ppu_thread_create(ppu_thread& ppu, vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname)
{
ppu.state += cpu_flag::wait;

sysPrxForUser.warning("sys_ppu_thread_create(thread_id=*0x%x, entry=0x%x, arg=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=%s)",
thread_id, entry, arg, prio, stacksize, flags, threadname);

Expand All @@ -137,7 +139,7 @@ error_code sys_ppu_thread_create(ppu_thread& ppu, vm::ptr<u64> thread_id, u32 en
}

// Call the syscall
if (error_code res = _sys_ppu_thread_create(thread_id, vm::make_var(ppu_thread_param_t{ vm::cast(entry), tls_addr + 0x7030 }), arg, 0, prio, stacksize, flags, threadname))
if (error_code res = _sys_ppu_thread_create(ppu, thread_id, vm::make_var(ppu_thread_param_t{ vm::cast(entry), tls_addr + 0x7030 }), arg, 0, prio, stacksize, flags, threadname))
{
return res;
}
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/PPUFunction.h
Expand Up @@ -86,9 +86,9 @@ namespace ppu_func_detail
template<typename T, u32 g_count, u32 f_count, u32 v_count>
struct bind_arg<T, ARG_CONTEXT, g_count, f_count, v_count>
{
static_assert(std::is_same<std::decay_t<T>, ppu_thread>::value, "Invalid function argument type for ARG_CONTEXT");
static_assert(std::is_base_of<std::decay_t<T>, ppu_thread>::value, "Invalid function argument type for ARG_CONTEXT");

static FORCE_INLINE ppu_thread& get_arg(ppu_thread& ppu)
static FORCE_INLINE T& get_arg(ppu_thread& ppu)
{
return ppu;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace ppu_func_detail
// TODO: check calculations
const bool is_float = std::is_floating_point<T>::value;
const bool is_vector = std::is_same<std::decay_t<T>, v128>::value;
const bool is_context = std::is_same<std::decay_t<T>, ppu_thread>::value;
const bool is_context = std::is_base_of<std::decay_t<T>, ppu_thread>::value;
const bool is_variadic = std::is_same<std::decay_t<T>, ppu_va_args_t>::value;
const bool is_general = !is_float && !is_vector && !is_context && !is_variadic;

Expand Down