Files
ppsspp/Core/HLE/HLEUtil.h
T
2026-08-11 10:28:36 +02:00

18 lines
583 B
C++

#pragma once
#include <cstring>
#include "Core/MemMap.h"
// Used in various places in the PSP OS.
template<typename T> bool ReadVariableSizedStruct(u32 addr, T *out) {
int size = Memory::ReadUnchecked_U32(addr);
if (!Memory::IsValid4AlignedRange(addr, size)) {
return false;
}
memset(out, 0, sizeof(*out));
// Only copy the right size to support different struct versions.
// Let's add a debug assert in case we have a struct that is too small for the data.
_dbg_assert_(sizeof(*out) >= size);
Memory::Memcpy(out, addr, std::min(size, (int)sizeof(*out)));
return true;
}