More Read_U32 and Read_U64

This commit is contained in:
Henrik Rydgård committed 2026-08-11 09:08:52 +02:00
1 parent 4f8859d0ec
commit af9891cd7d
8 files changed
+90 -86

No files matched your search

+8 -8
View File
@@ -61,18 +61,18 @@ static u32 sceAacExit(u32 id) {
static u32 sceAacInit(u32 id)
{
if (!Memory::IsValidAddress(id)) {
if (!Memory::IsValidRange(id, 36)) {
return hleLogError(Log::ME, ERROR_AAC_INVALID_ADDRESS, "AAC Invalid id address %08x", id);
}
AuCtx *aac = new AuCtx();
aac->startPos = Memory::Read_U64(id); // AUDIO stream start position.
aac->endPos = Memory::Read_U32(id + 8); // AUDIO stream end position.
aac->AuBuf = Memory::Read_U32(id + 16); // Input AAC data buffer.
aac->AuBufSize = Memory::Read_U32(id + 20); // Input AAC data buffer size.
aac->PCMBuf = Memory::Read_U32(id + 24); // Output PCM data buffer.
aac->PCMBufSize = Memory::Read_U32(id + 28); // Output PCM data buffer size.
aac->freq = Memory::Read_U32(id + 32); // Frequency.
aac->startPos = Memory::ReadUnchecked_U64(id); // AUDIO stream start position.
aac->endPos = Memory::ReadUnchecked_U32(id + 8); // AUDIO stream end position.
aac->AuBuf = Memory::ReadUnchecked_U32(id + 16); // Input AAC data buffer.
aac->AuBufSize = Memory::ReadUnchecked_U32(id + 20); // Input AAC data buffer size.
aac->PCMBuf = Memory::ReadUnchecked_U32(id + 24); // Output PCM data buffer.
aac->PCMBufSize = Memory::ReadUnchecked_U32(id + 28); // Output PCM data buffer size.
aac->freq = Memory::ReadUnchecked_U32(id + 32); // Frequency.
if (aac->AuBuf == 0 || aac->PCMBuf == 0) {
ERROR_LOG(Log::ME, "sceAacInit() AAC INVALID ADDRESS AuBuf %08x PCMBuf %08x", aac->AuBuf, aac->PCMBuf);
delete aac;
+2 -2
View File
@@ -803,8 +803,8 @@ static int sceHttpGetContentLength(int requestID, u32 contentLengthPtr) {
if (len < 0)
return hleLogError(Log::sceNet, SCE_HTTP_ERROR_NO_CONTENT_LENGTH, "no content length");
DEBUG_LOG(Log::sceNet, "ContentLength = %lld (in) => %lld (out)", Memory::Read_U64(contentLengthPtr), (u64)len);
Memory::Write_U64((u64)len, contentLengthPtr);
DEBUG_LOG(Log::sceNet, "ContentLength = %lld (in) => %lld (out)", Memory::ReadUnchecked_U64(contentLengthPtr), (u64)len);
Memory::WriteUnchecked_U64((u64)len, contentLengthPtr);
NotifyMemInfo(MemBlockFlags::WRITE, contentLengthPtr, 8, "HttpGetContentLength");
return 0;
}
+12 -15
View File
@@ -174,47 +174,44 @@ SceUID sceKernelSetAlarm(SceUInt micro, u32 handlerPtr, u32 commonPtr) {
return hleLogDebug(Log::sceKernel, __KernelSetAlarm((u64) micro, handlerPtr, commonPtr));
}
SceUID sceKernelSetSysClockAlarm(u32 microPtr, u32 handlerPtr, u32 commonPtr)
{
SceUID sceKernelSetSysClockAlarm(u32 microPtr, u32 handlerPtr, u32 commonPtr) {
u64 micro;
if (Memory::IsValidAddress(microPtr))
micro = Memory::Read_U64(microPtr);
if (Memory::IsValid4AlignedAddress(microPtr)) // 8-aligned?
micro = Memory::ReadUnchecked_U64(microPtr);
else
return -1;
return hleLogDebug(Log::sceKernel, __KernelSetAlarm(micro, handlerPtr, commonPtr));
}
int sceKernelCancelAlarm(SceUID uid)
{
int sceKernelCancelAlarm(SceUID uid) {
CoreTiming::UnscheduleEvent(alarmTimer, uid);
return hleLogDebug(Log::sceKernel, kernelObjects.Destroy<PSPAlarm>(uid));
}
int sceKernelReferAlarmStatus(SceUID uid, u32 infoPtr)
{
int sceKernelReferAlarmStatus(SceUID uid, u32 infoPtr) {
u32 error;
PSPAlarm *alarm = kernelObjects.Get<PSPAlarm>(uid, error);
if (!alarm) {
return hleLogError(Log::sceKernel, error, "invalid alarm");
}
if (!Memory::IsValidAddress(infoPtr))
if (!Memory::IsValidRange(infoPtr, 20)) {
return hleLogError(Log::sceKernel, -1);
}
u32 size = Memory::Read_U32(infoPtr);
u32 size = Memory::ReadUnchecked_U32(infoPtr);
// Alarms actually respect size and write (kinda) what it can hold.
if (size > 0)
Memory::Write_U32(alarm->alm.size, infoPtr);
Memory::WriteUnchecked_U32(alarm->alm.size, infoPtr);
if (size > 4)
Memory::Write_U64(alarm->alm.schedule, infoPtr + 4);
Memory::WriteUnchecked_U64(alarm->alm.schedule, infoPtr + 4);
if (size > 12)
Memory::Write_U32(alarm->alm.handlerPtr, infoPtr + 12);
Memory::WriteUnchecked_U32(alarm->alm.handlerPtr, infoPtr + 12);
if (size > 16)
Memory::Write_U32(alarm->alm.commonPtr, infoPtr + 16);
Memory::WriteUnchecked_U32(alarm->alm.commonPtr, infoPtr + 16);
return hleLogDebug(Log::sceKernel, 0);
}
+15 -12
View File
@@ -114,31 +114,34 @@ u64 sceKernelUSec2SysClockWide(u32 usec)
return hleNoLog(usec);
}
int sceKernelSysClock2USec(u32 sysclockPtr, u32 highPtr, u32 lowPtr)
{
int sceKernelSysClock2USec(u32 sysclockPtr, u32 highPtr, u32 lowPtr) {
DEBUG_LOG(Log::sceKernel, "sceKernelSysClock2USec(clock = %08x, lo = %08x, hi = %08x)", sysclockPtr, highPtr, lowPtr);
u64 time = Memory::Read_U64(sysclockPtr);
if (!Memory::IsValidRange(sysclockPtr, 8)) {
return hleLogError(Log::sceKernel, -1, "sceKernelSysClock2USec: Invalid sysclockPtr %08x", sysclockPtr);
}
u64 time = Memory::ReadUnchecked_U64(sysclockPtr);
u32 highResult = (u32)(time / 1000000);
u32 lowResult = (u32)(time % 1000000);
if (Memory::IsValidAddress(highPtr))
if (Memory::IsValid4AlignedAddress(highPtr))
Memory::WriteUnchecked_U32(highResult, highPtr);
if (Memory::IsValidAddress(lowPtr))
if (Memory::IsValid4AlignedAddress(lowPtr))
Memory::WriteUnchecked_U32(lowResult, lowPtr);
hleEatCycles(415);
return hleNoLog(0);
}
int sceKernelSysClock2USecWide(u32 lowClock, u32 highClock, u32 lowPtr, u32 highPtr)
{
int sceKernelSysClock2USecWide(u32 lowClock, u32 highClock, u32 lowPtr, u32 highPtr) {
u64 sysClock = lowClock | ((u64)highClock << 32);
DEBUG_LOG(Log::sceKernel, "sceKernelSysClock2USecWide(clock = %llu, lo = %08x, hi = %08x)", sysClock, lowPtr, highPtr);
if (Memory::IsValidAddress(lowPtr)) {
if (Memory::IsValid4AlignedAddress(lowPtr)) {
Memory::WriteUnchecked_U32((u32)(sysClock / 1000000), lowPtr);
if (Memory::IsValidAddress(highPtr))
if (Memory::IsValid4AlignedAddress(highPtr))
Memory::WriteUnchecked_U32((u32)(sysClock % 1000000), highPtr);
} else
if (Memory::IsValidAddress(highPtr))
Memory::WriteUnchecked_U32((int) sysClock, highPtr);
} else {
if (Memory::IsValid4AlignedAddress(highPtr)) {
Memory::WriteUnchecked_U32((int)sysClock, highPtr);
}
}
hleEatCycles(385);
return hleNoLog(0);
}
+6 -3
View File
@@ -319,10 +319,13 @@ u32 sceKernelSetVTimerTime(SceUID uid, u32 timeClockAddr) {
if (!vt) {
return hleLogError(Log::sceKernel, error, "bad timer ID");
}
u64 time = Memory::Read_U64(timeClockAddr);
if (Memory::IsValidAddress(timeClockAddr))
if (Memory::IsValidAddress(timeClockAddr)) {
u64 time = Memory::Read_U64(timeClockAddr);
Memory::Write_U64(__KernelSetVTimer(vt, time), timeClockAddr);
} else {
_dbg_assert_(false);
}
return hleLogDebug(Log::sceKernel, 0);
}
+8 -7
View File
@@ -263,12 +263,12 @@ static u32 sceMp3ReserveMp3Handle(u32 mp3Addr) {
AuCtx *Au = new AuCtx;
if (mp3Addr) {
Au->startPos = Memory::Read_U64(mp3Addr); // AUDIO stream start position.
Au->endPos = Memory::Read_U64(mp3Addr + 8); // AUDIO stream end position.
Au->AuBuf = Memory::Read_U32(mp3Addr + 16); // Input Au data buffer.
Au->AuBufSize = Memory::Read_U32(mp3Addr + 20); // Input Au data buffer size.
Au->PCMBuf = Memory::Read_U32(mp3Addr + 24); // Output PCM data buffer.
Au->PCMBufSize = Memory::Read_U32(mp3Addr + 28); // Output PCM data buffer size.
Au->startPos = Memory::ReadUnchecked_U64(mp3Addr); // AUDIO stream start position.
Au->endPos = Memory::ReadUnchecked_U64(mp3Addr + 8); // AUDIO stream end position.
Au->AuBuf = Memory::ReadUnchecked_U32(mp3Addr + 16); // Input Au data buffer.
Au->AuBufSize = Memory::ReadUnchecked_U32(mp3Addr + 20); // Input Au data buffer size.
Au->PCMBuf = Memory::ReadUnchecked_U32(mp3Addr + 24); // Output PCM data buffer.
Au->PCMBufSize = Memory::ReadUnchecked_U32(mp3Addr + 28); // Output PCM data buffer size.
if (Au->startPos >= Au->endPos) {
delete Au;
@@ -437,8 +437,9 @@ static int sceMp3Init(u32 mp3) {
// First, let's search for the MP3 header. It can be offset by at most 1439 bytes.
// If we have an ID3 tag, we'll get past it based on frame sync. Don't modify startPos.
int header = 0;
if (FindMp3Header(ctx, header, 1440) < 0)
if (FindMp3Header(ctx, header, 1440) < 0) {
return hleDelayResult(hleLogWarning(Log::ME, SCE_AVCODEC_ERROR_INVALID_DATA, "no header found"), "mp3 init", PARSE_DELAY_MS);
}
// Parse the Mp3 header
int layerBits = (header >> 17) & 0x3;
+31 -39
View File
@@ -435,9 +435,9 @@ static u32 sceRtcIsLeapYear(u32 year)
static int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr)
{
DEBUG_LOG(Log::sceRtc, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr);
if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr))
if (Memory::IsValidRange(tickLocalPtr, 8) && Memory::IsValidAddress(tickUTCPtr))
{
u64 srcTick = Memory::Read_U64(tickLocalPtr);
u64 srcTick = Memory::ReadUnchecked_U64(tickLocalPtr);
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
#ifdef _WIN32
long timezone_val;
@@ -457,12 +457,11 @@ static int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr)
return 0;
}
static int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr)
static int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr, u32 tickLocalPtr)
{
DEBUG_LOG(Log::sceRtc, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr);
if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr))
{
u64 srcTick = Memory::Read_U64(tickUTCPtr);
if (Memory::IsValidRange(tickLocalPtr, 8) && Memory::IsValidRange(tickUTCPtr, 8)) {
u64 srcTick = Memory::ReadUnchecked_U64(tickUTCPtr);
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
#ifdef _WIN32
long timezone_val;
@@ -473,10 +472,8 @@ static int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr)
tm *time = localtime(&timezone);
srcTick += time->tm_gmtoff*1000000ULL;
#endif
Memory::Write_U64(srcTick, tickLocalPtr);
}
else
{
Memory::WriteUnchecked_U64(srcTick, tickLocalPtr);
} else {
return 1;
}
return 0;
@@ -636,10 +633,9 @@ static int sceRtcGetWin32FileTime(u32 datePtr, u32 win32TimePtr)
static int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr)
{
DEBUG_LOG(Log::sceRtc, "sceRtcCompareTick(%d,%d)", tick1Ptr, tick2Ptr);
if (Memory::IsValidAddress(tick1Ptr) && Memory::IsValidAddress(tick2Ptr))
{
u64 tick1 = Memory::Read_U64(tick1Ptr);
u64 tick2 = Memory::Read_U64(tick2Ptr);
if (Memory::IsValid4AlignedAddress(tick1Ptr) && Memory::IsValid4AlignedAddress(tick2Ptr)) {
u64 tick1 = Memory::ReadUnchecked_U64(tick1Ptr);
u64 tick2 = Memory::ReadUnchecked_U64(tick2Ptr);
if (tick1 > tick2)
return hleNoLog(1);
if (tick1 < tick2)
@@ -652,10 +648,10 @@ static int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
u64 srcTick = Memory::Read_U64(srcTickPtr);
u64 srcTick = Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numTicks;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -664,10 +660,10 @@ static int sceRtcTickAddMicroseconds(u32 destTickPtr,u32 srcTickPtr, u64 numMS)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numMS;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -676,10 +672,10 @@ static int sceRtcTickAddSeconds(u32 destTickPtr, u32 srcTickPtr, u64 numSecs)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numSecs * 1000000UL;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -688,10 +684,10 @@ static int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numMins*60000000UL;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -700,9 +696,9 @@ static int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numHours * 3600ULL * 1000000ULL;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -711,10 +707,10 @@ static int sceRtcTickAddDays(u32 destTickPtr, u32 srcTickPtr, int numDays)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numDays * 86400ULL * 1000000ULL;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -723,10 +719,10 @@ static int sceRtcTickAddWeeks(u32 destTickPtr, u32 srcTickPtr, int numWeeks)
{
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
{
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
srcTick += numWeeks * 7ULL * 86400ULL * 1000000ULL;
Memory::Write_U64(srcTick, destTickPtr);
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
}
return hleLogDebug(Log::sceRtc, 0);
}
@@ -740,8 +736,7 @@ static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
u64 srcTick = Memory::Read_U64(srcTickPtr);
ScePspDateTime pt;
memset(&pt, 0, sizeof(pt));
ScePspDateTime pt{};
__RtcTicksToPspTime(pt,srcTick);
pt.year += numMonths / 12;
@@ -758,12 +753,11 @@ static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
pt.year++;
}
if (__RtcValidatePspTime(pt))
{
if (__RtcValidatePspTime(pt)) {
// Did we land on a year that isn't a leap year?
if (pt.month == 2 && pt.day == 29 && !__RtcIsLeapYear((s16)pt.year))
pt.day = 28;
Memory::Write_U64(__RtcPspTimeToTicks(pt), destTickPtr);
Memory::WriteUnchecked_U64(__RtcPspTimeToTicks(pt), destTickPtr);
}
DEBUG_LOG(Log::sceRtc, "sceRtcTickAddMonths(%08x, %08x = %lld, %d)", destTickPtr, srcTickPtr, srcTick, numMonths);
@@ -776,20 +770,18 @@ static int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears)
return hleLogWarning(Log::sceRtc, -1, "invalid address");
}
u64 srcTick = Memory::Read_U64(srcTickPtr);
u64 srcTick = Memory::ReadUnchecked_U64(srcTickPtr);
ScePspDateTime pt;
memset(&pt, 0, sizeof(pt));
ScePspDateTime pt{};
__RtcTicksToPspTime(pt, srcTick);
pt.year += numYears;
if (__RtcValidatePspTime(pt))
{
if (__RtcValidatePspTime(pt)) {
// Did we land on a year that isn't a leap year?
if (pt.month == 2 && pt.day == 29 && !__RtcIsLeapYear((s16)pt.year))
pt.day = 28;
Memory::Write_U64(__RtcPspTimeToTicks(pt), destTickPtr);
Memory::WriteUnchecked_U64(__RtcPspTimeToTicks(pt), destTickPtr);
}
DEBUG_LOG(Log::sceRtc, "sceRtcTickAddYears(%08x, %08x = %lld, %d)", destTickPtr, srcTickPtr, srcTick, numYears);
+8
View File
@@ -198,6 +198,14 @@ inline u8 ReadUnchecked_U8(const u32 address) {
#endif
}
inline void WriteUnchecked_U64(u64 data, u32 address) {
#ifdef MASKED_PSP_MEMORY
*(u64_le *)(base + (address & MEMVIEW32_MASK)) = data;
#else
*(u64_le *)(base + address) = data;
#endif
}
inline void WriteUnchecked_U32(u32 data, u32 address) {
#ifdef MASKED_PSP_MEMORY
*(u32_le *)(base + (address & MEMVIEW32_MASK)) = data;