Some cleanup

* Prefer default initializer over std::memset 0 when possible and more readable.
* Use std::format in trophy files name obtaining.
* Use vm::ptr<>::operator bool() instead of comparing vm::ptr to vm::null or using addr().
* Add a few std::memset calls in hle where it matters (or in some places just to document an actual firmware memcpy call).
This commit is contained in:
Eladash 2019-12-20 05:51:16 +02:00 committed by Ivan
parent 5de83e0425
commit 9690854e58
20 changed files with 52 additions and 88 deletions

View File

@ -210,7 +210,7 @@ public:
{
DemuxerTask task;
DemuxerStream stream = {};
ElementaryStream* esALL[96]; memset(esALL, 0, sizeof(esALL));
ElementaryStream* esALL[96]{};
ElementaryStream** esAVC = &esALL[0]; // AVC (max 16 minus M2V count)
ElementaryStream** esM2V = &esALL[16]; // M2V (max 16 minus AVC count)
ElementaryStream** esDATA = &esALL[32]; // user data (max 16)

View File

@ -229,7 +229,7 @@ static bool ds3_input_to_pad(const u32 port_no, be_t<u16>& digital_buttons, be_t
}
}
memset(&digital_buttons, 0, sizeof(digital_buttons));
digital_buttons = 0;
// map the Move key to R1 and the Trigger to R2
@ -310,10 +310,10 @@ static bool mouse_input_to_pad(const u32 mouse_no, be_t<u16>& digital_buttons, b
return false;
}
memset(&digital_buttons, 0, sizeof(digital_buttons));
const auto& mouse_data = handler->GetMice().at(0);
digital_buttons = 0;
if ((mouse_data.buttons & CELL_MOUSE_BUTTON_1) && (mouse_data.buttons & CELL_MOUSE_BUTTON_2))
digital_buttons |= CELL_GEM_CTRL_CIRCLE;
if (mouse_data.buttons & CELL_MOUSE_BUTTON_3)

View File

@ -251,6 +251,8 @@ error_code cellKbGetInfo(vm::ptr<CellKbInfo> info)
if (!info)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::memset(info.get_ptr(), 0, info.size());
std::lock_guard<std::mutex> lock(handler->m_mutex);
const KbInfo& current_info = handler->GetInfo();

View File

@ -285,7 +285,7 @@ s32 _ConvertStr(s32 src_code, const void *src, s32 src_len, s32 dst_code, void *
s32 _L10nConvertStr(s32 src_code, vm::cptr<void> src, vm::cptr<s32> src_len, s32 dst_code, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
s32 dstLen = *dst_len;
s32 result = _ConvertStr(src_code, src.get_ptr(), *src_len, dst_code, dst == vm::null ? NULL : dst.get_ptr(), &dstLen, false);
s32 result = _ConvertStr(src_code, src.get_ptr(), *src_len, dst_code, dst ? dst.get_ptr() : nullptr, &dstLen, false);
*dst_len = dstLen;
return result;
}
@ -413,7 +413,7 @@ s32 jstrnchk(vm::cptr<u8> src, s32 src_len)
for (s32 len = 0; len < src_len; len++)
{
if (src != vm::null)
if (src)
{
if (*src >= 0xa1 && *src <= 0xfe)
{
@ -1274,7 +1274,7 @@ s32 UTF16stoUTF8s(vm::cptr<u16> utf16, vm::ref<s32> utf16_len, vm::ptr<u8> utf8,
// return SRCIllegal;
//}
if (utf8 != vm::null)
if (utf8)
{
if (len > max_len)
{

View File

@ -119,6 +119,8 @@ error_code cellMouseGetInfo(vm::ptr<CellMouseInfo> info)
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
std::memset(info.get_ptr(), 0, info.size());
const MouseInfo& current_info = handler->GetInfo();
info->max_connect = current_info.max_connect;
info->now_connect = current_info.now_connect;
@ -192,13 +194,14 @@ error_code cellMouseGetData(u32 port_no, vm::ptr<CellMouseData> data)
return CELL_MOUSE_ERROR_NO_DEVICE;
}
std::memset(data.get_ptr(), 0, data.size());
// TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact
MouseDataList& data_list = handler->GetDataList(port_no);
if (data_list.empty())
{
*data = {};
return CELL_OK;
}

View File

@ -113,7 +113,7 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
std::memset(osk->osk_text, 0, sizeof(osk->osk_text));
std::memset(osk->osk_text_old, 0, sizeof(osk->osk_text_old));
if (inputFieldInfo->init_text.addr() != 0)
if (inputFieldInfo->init_text)
{
for (u32 i = 0; (i < maxLength) && (inputFieldInfo->init_text[i] != 0); i++)
{
@ -124,10 +124,9 @@ error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dia
// Get message to display above the input field
// Guarantees 0 terminated (+1). In praxis only 128 but for now lets display all of it
char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1];
std::memset(message, 0, sizeof(message));
char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1]{};
if (inputFieldInfo->message.addr() != 0)
if (inputFieldInfo->message)
{
for (u32 i = 0; (i < CELL_OSKDIALOG_STRING_SIZE) && (inputFieldInfo->message[i] != 0); i++)
{

View File

@ -568,7 +568,7 @@ s32 pngDecSetParameter(PStream stream, PInParam in_param, POutParam out_param, P
// This shouldnt ever happen, but not sure what to do if it does, just want it logged for now
if (stream->info.bitDepth != 16 && in_param->outputBitDepth == 16)
cellPngDec.error("Output depth of 16 with non input depth of 16 specified!");
if (in_param->commandPtr != vm::null)
if (in_param->commandPtr)
cellPngDec.warning("Ignoring CommandPtr.");
if (stream->info.colorSpace != in_param->outputColorSpace)

View File

@ -3691,7 +3691,7 @@ s32 _cellSpursTasksetAttribute2Initialize(vm::ptr<CellSpursTasksetAttribute2> at
{
cellSpurs.warning("_cellSpursTasksetAttribute2Initialize(attribute=*0x%x, revision=%d)", attribute, revision);
memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute2));
std::memset(attribute.get_ptr(), 0, attribute.size());
attribute->revision = revision;
attribute->name = vm::null;
attribute->args = 0;
@ -3960,11 +3960,11 @@ s32 _cellSpursTasksetAttributeInitialize(vm::ptr<CellSpursTasksetAttribute> attr
}
}
memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute));
std::memset(attribute.get_ptr(), 0, attribute.size());
attribute->revision = revision;
attribute->sdk_version = sdk_version;
attribute->args = args;
memcpy(attribute->priority, priority.get_ptr(), 8);
std::memcpy(attribute->priority, priority.get_ptr(), 8);
attribute->taskset_size = 6400/*CellSpursTaskset::size*/;
attribute->max_contention = max_contention;
return CELL_OK;

View File

@ -903,16 +903,14 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus)
spursSysServiceCleanupAfterSystemWorkload(spu, ctxt);
// Trace - SERVICE: INIT
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_INIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
}
// Trace - START: Module='SYS '
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_START;
memcpy(pkt.data.start.module, "SYS ", 4);
pkt.data.start.level = 1; // Policy module
@ -928,14 +926,13 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus)
if (cellSpursModulePollStatus(spu, nullptr))
{
// Trace - SERVICE: EXIT
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_EXIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
// Trace - STOP: GUID
memset(&pkt, 0, sizeof(pkt));
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP;
pkt.data.stop = SPURS_GUID_SYS_WKL;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
@ -956,8 +953,7 @@ void spursSysServiceMain(spu_thread& spu, u32 pollStatus)
// If we reach here it means that the SPU is idling
// Trace - SERVICE: WAIT
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_WAIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
@ -1287,8 +1283,7 @@ void spursSysServiceCleanupAfterSystemWorkload(spu_thread& spu, SpursKernelConte
ctxt->wklCurrentId = wklId;
// Trace - STOP: GUID
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP;
pkt.data.stop = SPURS_GUID_SYS_WKL;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
@ -1638,8 +1633,7 @@ void spursTasksetExit(spu_thread& spu)
auto ctxt = vm::_ptr<SpursTasksetContext>(spu.offset + 0x2700);
// Trace - STOP
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = 0x54; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_STOP
pkt.data.stop = SPURS_GUID_TASKSET_PM;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
@ -1755,8 +1749,7 @@ void spursTasksetDispatch(spu_thread& spu)
taskInfo->elf.set(taskInfo->elf.addr() & 0xFFFFFFFFFFFFFFF8);
// Trace - Task: Incident=dispatch
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK;
pkt.data.task.incident = CELL_SPURS_TRACE_TASK_DISPATCH;
pkt.data.task.taskId = taskId;
@ -1791,7 +1784,7 @@ void spursTasksetDispatch(spu_thread& spu)
}
// Trace - GUID
memset(&pkt, 0, sizeof(pkt));
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID;
pkt.data.guid = 0; // TODO: Put GUID of taskId here
cellSpursModulePutTrace(&pkt, 0x1F);
@ -1845,7 +1838,7 @@ void spursTasksetDispatch(spu_thread& spu)
spu.set_ch_value(SPU_WrEventMask, ctxt->savedSpuWriteEventMask);
// Trace - GUID
memset(&pkt, 0, sizeof(pkt));
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID;
pkt.data.guid = 0; // TODO: Put GUID of taskId here
cellSpursModulePutTrace(&pkt, 0x1F);
@ -1949,8 +1942,7 @@ s32 spursTasksetProcessSyscall(spu_thread& spu, u32 syscallNum, u32 args)
if (incident)
{
// Trace - TASK
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK;
pkt.data.task.incident = incident;
pkt.data.task.taskId = ctxt->taskId;
@ -1982,8 +1974,7 @@ void spursTasksetInit(spu_thread& spu, u32 pollStatus)
kernelCtxt->moduleId[1] = 'K';
// Trace - START: Module='TKST'
CellSpursTracePacket pkt;
memset(&pkt, 0, sizeof(pkt));
CellSpursTracePacket pkt{};
pkt.header.tag = 0x52; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_START
memcpy(pkt.data.start.module, "TKST", 4);
pkt.data.start.level = 2;

View File

@ -458,7 +458,7 @@ error_code npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_pat
if (magic == "SCE\0"_u32)
{
if (k_licensee_addr == vm::null)
if (!k_licensee_addr)
k_licensee = get_default_self_klic();
if (verify_npdrm_self_headers(enc_file, k_licensee.data()))

View File

@ -588,9 +588,9 @@ error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptr<SceNpTrophyGa
}
if (details)
memset(details.get_ptr(), 0, sizeof(SceNpTrophyGameDetails));
*details = {};
if (data)
memset(data.get_ptr(), 0, sizeof(SceNpTrophyGameData));
*data = {};
for (std::shared_ptr<rXmlNode> n = trophy_base->GetChildren(); n; n = n->GetNext())
{
@ -691,19 +691,8 @@ error_code sceNpTrophyUnlockTrophy(u32 context, u32 handle, s32 trophyId, vm::pt
if (g_cfg.misc.show_trophy_popups)
{
// Figure out how many zeros are needed for padding. (either 0, 1, or 2)
std::string padding = "";
if (trophyId < 10)
{
padding = "00";
}
else if (trophyId < 100)
{
padding = "0";
}
// Get icon for the notification.
const std::string padded_trophy_id = padding + std::to_string(trophyId);
const std::string padded_trophy_id = fmt::format("%03u", trophyId);
const std::string trophy_icon_path = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROP" + padded_trophy_id + ".PNG";
fs::file trophy_icon_file = fs::file(vfs::get(trophy_icon_path));
std::vector<uchar> trophy_icon_data;
@ -823,9 +812,9 @@ error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::p
}
if (details)
memset(details.get_ptr(), 0, sizeof(SceNpTrophyDetails));
*details = {};
if (data)
memset(data.get_ptr(), 0, sizeof(SceNpTrophyData));
*data = {};
rXmlDocument doc;
doc.Read(config.to_string());

View File

@ -204,11 +204,11 @@ error_code sys_ppu_thread_register_atexit(ppu_thread& ppu, vm::ptr<void()> func)
}
}
for (auto& pp : *g_ppu_atexit)
for (auto& pf : *g_ppu_atexit)
{
if (pp == vm::null)
if (!pf)
{
pp = func;
pf = func;
return CELL_OK;
}
}

View File

@ -220,9 +220,7 @@ usb_handler_thread::~usb_handler_thread()
void usb_handler_thread::operator()()
{
timeval lusb_tv;
memset(&lusb_tv, 0, sizeof(timeval));
lusb_tv.tv_usec = 200;
timeval lusb_tv{0, 200};
while (thread_ctrl::state() != thread_state::aborting)
{

View File

@ -7,7 +7,7 @@ class NullKeyboardHandler final : public KeyboardHandlerBase
public:
void Init(const u32 max_connect) override
{
memset(&m_info, 0, sizeof(KbInfo));
m_info = {};
m_info.max_connect = max_connect;
m_keyboards.clear();
for (u32 i = 0; i < max_connect; i++)

View File

@ -7,7 +7,7 @@ class NullMouseHandler final : public MouseHandlerBase
public:
void Init(const u32 max_connect) override
{
memset(&m_info, 0, sizeof(MouseInfo));
m_info = {};
m_info.max_connect = max_connect;
m_mice.clear();
}

View File

@ -68,8 +68,11 @@ namespace rsx {
// 4GB memory space / 4096 bytes per page = 1048576 pages
// Initialized to utils::protection::rw
static constexpr size_t num_pages = 0x1'0000'0000 / 4096;
per_page_info_t _info[num_pages];
per_page_info_t _info[num_pages]{0};
static_assert(static_cast<u32>(utils::protection::rw) == 0, "utils::protection::rw must have value 0 for the above constructor to work");
static constexpr size_t rsx_address_to_index(u32 address)
{
@ -108,13 +111,6 @@ namespace rsx {
}
public:
tex_cache_checker_t()
{
// Initialize array to all 0
memset(&_info, 0, sizeof(_info));
}
static_assert(static_cast<u32>(utils::protection::rw) == 0, "utils::protection::rw must have value 0 for the above constructor to work");
void set_protection(const address_range& range, utils::protection prot)
{
AUDIT(range.is_page_range());

View File

@ -111,12 +111,7 @@ struct GcmZcullInfo
u32 sFunc;
u32 sRef;
u32 sMask;
bool binded;
GcmZcullInfo()
{
memset(this, 0, sizeof(*this));
}
bool binded = false;
CellGcmZcullInfo pack() const
{
@ -142,12 +137,7 @@ struct GcmTileInfo
u32 comp;
u32 base;
u32 bank;
bool binded;
GcmTileInfo()
{
memset(this, 0, sizeof(*this));
}
bool binded = false;
CellGcmTileInfo pack() const
{

View File

@ -918,7 +918,7 @@ namespace rsx
void thread::get_framebuffer_layout(rsx::framebuffer_creation_context context, framebuffer_layout &layout)
{
memset(&layout, 0, sizeof(layout));
layout = {};
layout.ignore_change = true;
layout.width = rsx::method_registers.surface_clip_width();

View File

@ -543,7 +543,7 @@ namespace rsx
vertex_arrays_info(fill_array<data_array_format_info>(registers, std::make_index_sequence<16>()))
{
//NOTE: Transform constants persist through a context reset (NPEB00913)
memset(transform_constants.data(), 0, 512 * 4 * sizeof(u32));
transform_constants = {};
}
~rsx_state() = default;

View File

@ -60,11 +60,7 @@ void pad_thread::Init()
}
}
const PadInfo pad_info(m_info);
std::memset(&m_info, 0, sizeof(m_info));
m_info.now_connect = 0;
m_info.system_info |= pad_info.system_info;
m_info.ignore_input = pad_info.ignore_input;
handlers.clear();