mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-30 19:24:23 +01:00
More memory access cleanup
This commit is contained in:
1 parent
3bd41376da
commit
4cd10efe07
4 files changed
+100
-102
No files matched your search
+51
-35
@@ -560,7 +560,9 @@ static bool __IoCheckAsyncWait(FileNode *f, SceUID threadID, u32 &error, int res
|
||||
}
|
||||
|
||||
u32 address = __KernelGetWaitValue(threadID, error);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
if (Memory::IsValid4AlignedRange(address, 8)) {
|
||||
Memory::WriteUnchecked_U64((u64)f->asyncResult, address);
|
||||
}
|
||||
f->hasAsyncResult = false;
|
||||
|
||||
if (f->closePending) {
|
||||
@@ -1675,8 +1677,8 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
|
||||
switch (cmd) {
|
||||
case 0x01F20001:
|
||||
// Get UMD disc type
|
||||
if (Memory::IsValidAddress(outPtr) && outLen >= 8) {
|
||||
Memory::Write_U32(0x10, outPtr + 4); // Always return game disc (if present)
|
||||
if (Memory::IsValid4AlignedRange(outPtr, 8) && outLen >= 8) {
|
||||
Memory::WriteUnchecked_U32(0x10, outPtr + 4); // Always return game disc (if present)
|
||||
return hleLogDebug(Log::sceIo, 0);
|
||||
} else {
|
||||
return hleLogError(Log::sceIo, SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS);
|
||||
@@ -1684,17 +1686,17 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
|
||||
break;
|
||||
case 0x01F20002:
|
||||
// Get UMD current LBA
|
||||
if (Memory::IsValidAddress(outPtr) && outLen >= 4) {
|
||||
Memory::Write_U32(0x10, outPtr); // Assume first sector
|
||||
if (Memory::IsValid4AlignedRange(outPtr, 4) && outLen >= 4) {
|
||||
Memory::WriteUnchecked_U32(0x10, outPtr); // Assume first sector
|
||||
return hleLogDebug(Log::sceIo, 0);
|
||||
} else {
|
||||
return hleLogError(Log::sceIo, SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS);
|
||||
}
|
||||
break;
|
||||
case 0x01F20003:
|
||||
if (Memory::IsValidAddress(argAddr) && argLen >= 4) {
|
||||
if (Memory::IsValid4AlignedRange(argAddr, 4) && argLen >= 4) {
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo("umd1:");
|
||||
Memory::Write_U32((u32) (info.size) - 1, outPtr);
|
||||
Memory::WriteUnchecked_U32((u32) (info.size) - 1, outPtr);
|
||||
return hleLogDebug(Log::sceIo, 0);
|
||||
} else {
|
||||
return hleLogError(Log::sceIo, SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS);
|
||||
@@ -1719,7 +1721,11 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
|
||||
case 0x01F300A5:
|
||||
// Prepare UMD data into cache and get status
|
||||
if (Memory::IsValidAddress(argAddr) && argLen >= 4) {
|
||||
Memory::Write_U32(1, outPtr); // Status (unitary index of the requested read, greater or equal to 1)
|
||||
if (Memory::IsValid4AlignedAddress(outPtr)) {
|
||||
Memory::WriteUnchecked_U32(1, outPtr); // Status (unitary index of the requested read, greater or equal to 1)
|
||||
} else {
|
||||
return hleLogError(Log::sceIo, SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS, "bad outptr");
|
||||
}
|
||||
return hleLogDebug(Log::sceIo, 0);
|
||||
} else {
|
||||
return hleLogError(Log::sceIo, SCE_ERROR_MEMSTICK_DEVCTL_BAD_PARAMS);
|
||||
@@ -1771,12 +1777,12 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
|
||||
switch (cmd) {
|
||||
case 0x02025801:
|
||||
// Check the MemoryStick's driver status (mscmhc0: only.)
|
||||
if (Memory::IsValidAddress(outPtr) && outLen >= 4) {
|
||||
if (Memory::IsValidRange(outPtr, 4) && outLen >= 4) {
|
||||
if (MemoryStick_State() == PSP_MEMORYSTICK_STATE_INSERTED) {
|
||||
// 1 = not inserted (ready), 4 = inserted
|
||||
Memory::Write_U32(PSP_MEMORYSTICK_STATE_DEVICE_INSERTED, outPtr);
|
||||
Memory::WriteUnchecked_U32(PSP_MEMORYSTICK_STATE_DEVICE_INSERTED, outPtr);
|
||||
} else {
|
||||
Memory::Write_U32(PSP_MEMORYSTICK_STATE_DRIVER_READY, outPtr);
|
||||
Memory::WriteUnchecked_U32(PSP_MEMORYSTICK_STATE_DRIVER_READY, outPtr);
|
||||
}
|
||||
return hleLogDebug(Log::sceIo, 0);
|
||||
} else {
|
||||
@@ -1958,14 +1964,14 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
|
||||
// If the values added together are >= 0x80000000, or less than outPtr, invalid address.
|
||||
if (((int)outPtr + outLen) < (int)outPtr) {
|
||||
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "sceIoDevctl: fatms0: 0x02425823 command, bad address");
|
||||
} else if (!Memory::IsValidAddress(outPtr)) {
|
||||
} else if (!Memory::IsValidRange(outPtr, 4)) {
|
||||
// Technically, only checks for NULL, crashes for many bad addresses.
|
||||
ERROR_LOG(Log::sceIo, "sceIoDevctl: ");
|
||||
return hleLogError(Log::sceIo, SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT, "fatms0: 0x02425823 command, no output address");
|
||||
} else {
|
||||
// Does not care about outLen, even if it's 0.
|
||||
// Note: writes 1 when inserted, 0 when not inserted.
|
||||
Memory::Write_U32(MemoryStick_FatState(), outPtr);
|
||||
Memory::WriteUnchecked_U32(MemoryStick_FatState(), outPtr);
|
||||
return hleDelayResult(hleLogDebug(Log::sceIo, 0), "check fat state", cyclesToUs(23500));
|
||||
}
|
||||
break;
|
||||
@@ -2273,7 +2279,9 @@ static u32 sceIoGetAsyncStat(int id, u32 poll, u32 address) {
|
||||
}
|
||||
|
||||
DEBUG_LOG(Log::sceIo, "%lli = sceIoGetAsyncStat(%i, %i, %08x)", f->asyncResult, id, poll, address);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
if (Memory::IsValid4AlignedRange(address, 8)) {
|
||||
Memory::WriteUnchecked_U64((u64)f->asyncResult, address);
|
||||
}
|
||||
f->hasAsyncResult = false;
|
||||
|
||||
if (f->closePending) {
|
||||
@@ -2311,7 +2319,9 @@ static int sceIoWaitAsync(int id, u32 address) {
|
||||
if (!__KernelIsDispatchEnabled()) {
|
||||
return hleLogDebug(Log::sceIo, SCE_KERNEL_ERROR_CAN_NOT_WAIT, "dispatch disabled");
|
||||
}
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
if (Memory::IsValid4AlignedRange(address, 8)) {
|
||||
Memory::WriteUnchecked_U64((u64)f->asyncResult, address);
|
||||
}
|
||||
f->hasAsyncResult = false;
|
||||
|
||||
if (f->closePending) {
|
||||
@@ -2345,7 +2355,9 @@ static int sceIoWaitAsyncCB(int id, u32 address) {
|
||||
__KernelWaitCurThread(WAITTYPE_ASYNCIO, f->GetUID(), address, 0, true, "io waited");
|
||||
return hleLogDebug(Log::sceIo, 0, "waiting");
|
||||
} else if (f->hasAsyncResult) {
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
if (Memory::IsValid4AlignedRange(address, 8)) {
|
||||
Memory::WriteUnchecked_U64((u64)f->asyncResult, address);
|
||||
}
|
||||
f->hasAsyncResult = false;
|
||||
|
||||
if (f->closePending) {
|
||||
@@ -2368,7 +2380,9 @@ static u32 sceIoPollAsync(int id, u32 address) {
|
||||
if (f->pendingAsyncResult) {
|
||||
return hleLogVerbose(Log::sceIo, 1, "not ready");
|
||||
} else if (f->hasAsyncResult) {
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
if (Memory::IsValid4AlignedRange(address, 8)) {
|
||||
Memory::WriteUnchecked_U64((u64)f->asyncResult, address);
|
||||
}
|
||||
f->hasAsyncResult = false;
|
||||
|
||||
if (f->closePending) {
|
||||
@@ -2645,9 +2659,9 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
|
||||
// TODO: Should not work for umd0:/, ms0:/, etc.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
INFO_LOG(Log::sceIo, "sceIoIoctl: Asked for sector size of file %i", id);
|
||||
if (Memory::IsValidAddress(outdataPtr) && outlen >= 4) {
|
||||
if (Memory::IsValidRange(outdataPtr, 4) && outlen >= 4) {
|
||||
// ISOs always use 2048 sized sectors.
|
||||
Memory::Write_U32(2048, outdataPtr);
|
||||
Memory::WriteUnchecked_U32(2048, outdataPtr);
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -2658,25 +2672,26 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
|
||||
// TODO: Should not work for umd0:/, ms0:/, etc.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
DEBUG_LOG(Log::sceIo, "sceIoIoctl: Asked for file offset of file %d", id);
|
||||
if (Memory::IsValidAddress(outdataPtr) && outlen >= 4) {
|
||||
if (Memory::IsValidRange(outdataPtr, 4) && outlen >= 4) {
|
||||
u32 offset = (u32)pspFileSystem.GetSeekPos(f->handle);
|
||||
Memory::Write_U32(offset, outdataPtr);
|
||||
Memory::WriteUnchecked_U32(offset, outdataPtr);
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01010005:
|
||||
{
|
||||
// TODO: Should not work for umd0:/, ms0:/, etc.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
INFO_LOG(Log::sceIo, "sceIoIoctl: Seek for file %i", id);
|
||||
// Even if the size is 4, it still actually reads a 16 byte struct, it seems.
|
||||
if (Memory::IsValidAddress(indataPtr) && inlen >= 4) {
|
||||
struct SeekInfo {
|
||||
u64_le offset;
|
||||
u32_le unk;
|
||||
u32_le whence;
|
||||
};
|
||||
struct SeekInfo {
|
||||
u64_le offset;
|
||||
u32_le unk;
|
||||
u32_le whence;
|
||||
};
|
||||
if (Memory::IsValidRange(indataPtr, sizeof(SeekInfo)) && inlen >= 4) {
|
||||
const auto seekInfo = PSPPointer<SeekInfo>::Create(indataPtr);
|
||||
FileMove seek;
|
||||
s64 newPos = __IoLseekDest(f, seekInfo->offset, seekInfo->whence, seek);
|
||||
@@ -2689,14 +2704,15 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Get UMD file start sector.
|
||||
case 0x01020006:
|
||||
// TODO: Should not work for umd0:/, ms0:/, etc.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
INFO_LOG(Log::sceIo, "sceIoIoctl: Asked for start sector of file %i", id);
|
||||
if (Memory::IsValidAddress(outdataPtr) && outlen >= 4) {
|
||||
Memory::Write_U32(f->FileInfo().startSector, outdataPtr);
|
||||
if (Memory::IsValidRange(outdataPtr, 4) && outlen >= 4) {
|
||||
Memory::WriteUnchecked_U32(f->FileInfo().startSector, outdataPtr);
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -2707,8 +2723,8 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
|
||||
// TODO: Should not work for umd0:/, ms0:/, etc.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
INFO_LOG(Log::sceIo, "sceIoIoctl: Asked for size of file %i", id);
|
||||
if (Memory::IsValidAddress(outdataPtr) && outlen >= 8) {
|
||||
Memory::Write_U64(f->FileInfo().size, outdataPtr);
|
||||
if (Memory::IsValid4AlignedRange(outdataPtr, 8)) {
|
||||
Memory::WriteUnchecked_U64(f->FileInfo().size, outdataPtr);
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -2738,8 +2754,8 @@ int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 out
|
||||
// TODO: Should work only for umd0:/, etc. not for ms0:/ or disc0:/.
|
||||
// TODO: Should probably move this to something common between ISOFileSystem and VirtualDiscSystem.
|
||||
INFO_LOG(Log::sceIo, "sceIoIoctl: Sector tell from file %i", id);
|
||||
if (Memory::IsValidAddress(outdataPtr) && outlen >= 4) {
|
||||
Memory::Write_U32((u32)pspFileSystem.GetSeekPos(f->handle), outdataPtr);
|
||||
if (Memory::IsValidRange(outdataPtr, 4) && outlen >= 4) {
|
||||
Memory::WriteUnchecked_U32((u32)pspFileSystem.GetSeekPos(f->handle), outdataPtr);
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -2869,8 +2885,8 @@ static u32 sceIoGetFdList(u32 outAddr, int outSize, u32 fdNumAddr) {
|
||||
++count;
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(fdNumAddr))
|
||||
Memory::Write_U32(count, fdNumAddr);
|
||||
if (Memory::IsValidRange(fdNumAddr, 4))
|
||||
Memory::WriteUnchecked_U32(count, fdNumAddr);
|
||||
if (count >= outSize) {
|
||||
return outSize;
|
||||
} else {
|
||||
|
||||
@@ -69,8 +69,9 @@ void __KernelTimeDoState(PointerWrap &p)
|
||||
int sceKernelGetSystemTime(u32 sysclockPtr)
|
||||
{
|
||||
u64 t = CoreTiming::GetGlobalTimeUs();
|
||||
if (Memory::IsValidAddress(sysclockPtr))
|
||||
Memory::Write_U64(t, sysclockPtr);
|
||||
if (Memory::IsValid4AlignedRange(sysclockPtr, 8)) {
|
||||
Memory::WriteUnchecked_U64(t, sysclockPtr);
|
||||
}
|
||||
VERBOSE_LOG(Log::sceKernel, "sceKernelGetSystemTime(out:%16llx)", t);
|
||||
hleEatCycles(265);
|
||||
hleReSchedule("system time");
|
||||
@@ -83,8 +84,9 @@ u32 sceKernelGetSystemTimeLow()
|
||||
u64 t = CoreTiming::GetGlobalTimeUs();
|
||||
VERBOSE_LOG(Log::sceKernel,"%08x=sceKernelGetSystemTimeLow()",(u32)t);
|
||||
hleEatCycles(165);
|
||||
if (PSP_CoreParameter().compat.flags().KernelGetSystemTimeLowEatMoreCycles)
|
||||
if (PSP_CoreParameter().compat.flags().KernelGetSystemTimeLowEatMoreCycles) {
|
||||
hleEatCycles(70000);
|
||||
}
|
||||
hleReSchedule("system time");
|
||||
return hleNoLog((u32)t);
|
||||
}
|
||||
@@ -101,8 +103,9 @@ u64 sceKernelGetSystemTimeWide()
|
||||
int sceKernelUSec2SysClock(u32 usec, u32 clockPtr)
|
||||
{
|
||||
VERBOSE_LOG(Log::sceKernel, "sceKernelUSec2SysClock(%i, %08x)", usec, clockPtr);
|
||||
if (Memory::IsValidAddress(clockPtr))
|
||||
Memory::Write_U64((usec & 0xFFFFFFFFL), clockPtr);
|
||||
if (Memory::IsValid4AlignedRange(clockPtr, 8)) {
|
||||
Memory::WriteUnchecked_U64((usec & 0xFFFFFFFFL), clockPtr);
|
||||
}
|
||||
hleEatCycles(165);
|
||||
return hleNoLog(0);
|
||||
}
|
||||
|
||||
@@ -148,9 +148,10 @@ public:
|
||||
// Reserve some stack space for arguments.
|
||||
u32 argArea = currentMIPS->r[MIPS_REG_SP];
|
||||
currentMIPS->r[MIPS_REG_SP] -= HANDLER_STACK_SPACE;
|
||||
|
||||
Memory::Write_U64(vtimer->nvt.schedule, argArea - 16);
|
||||
Memory::Write_U64(__getVTimerCurrentTime(vtimer), argArea - 8);
|
||||
if (Memory::IsValidRange(argArea - HANDLER_STACK_SPACE, HANDLER_STACK_SPACE)) {
|
||||
Memory::WriteUnchecked_U64(vtimer->nvt.schedule, argArea - 16);
|
||||
Memory::WriteUnchecked_U64(__getVTimerCurrentTime(vtimer), argArea - 8);
|
||||
}
|
||||
|
||||
currentMIPS->pc = vtimer->nvt.handlerAddr;
|
||||
currentMIPS->r[MIPS_REG_A0] = vtimer->GetUID();
|
||||
@@ -261,8 +262,9 @@ u32 sceKernelGetVTimerBase(SceUID uid, u32 baseClockAddr) {
|
||||
return hleLogError(Log::sceKernel, error, "bad timer ID");
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(baseClockAddr))
|
||||
Memory::Write_U64(vt->nvt.base, baseClockAddr);
|
||||
if (Memory::IsValid4AlignedRange(baseClockAddr, 8)) {
|
||||
Memory::WriteUnchecked_U64(vt->nvt.base, baseClockAddr);
|
||||
}
|
||||
|
||||
return hleLogDebug(Log::sceKernel, 0);
|
||||
}
|
||||
@@ -285,9 +287,9 @@ u32 sceKernelGetVTimerTime(SceUID uid, u32 timeClockAddr) {
|
||||
}
|
||||
|
||||
u64 time = __getVTimerCurrentTime(vt);
|
||||
if (Memory::IsValidAddress(timeClockAddr))
|
||||
Memory::Write_U64(time, timeClockAddr);
|
||||
|
||||
if (Memory::IsValid4AlignedRange(timeClockAddr, 8)) {
|
||||
Memory::WriteUnchecked_U64(time, timeClockAddr);
|
||||
}
|
||||
return hleLogDebug(Log::sceKernel, 0);
|
||||
}
|
||||
|
||||
|
||||
+31
-54
@@ -280,8 +280,9 @@ static u32 sceRtcGetCurrentTick(u32 tickPtr)
|
||||
VERBOSE_LOG(Log::sceRtc, "sceRtcGetCurrentTick(%08x)", tickPtr);
|
||||
|
||||
u64 curTick = __RtcGetCurrentTick();
|
||||
if (Memory::IsValidAddress(tickPtr))
|
||||
Memory::Write_U64(curTick, tickPtr);
|
||||
if (Memory::IsValid4AlignedRange(tickPtr, 8)) {
|
||||
Memory::WriteUnchecked_U64(curTick, tickPtr);
|
||||
}
|
||||
hleEatCycles(300);
|
||||
hleReSchedule("rtc current tick");
|
||||
return hleNoLog(0);
|
||||
@@ -589,8 +590,7 @@ static int sceRtcGetDosTime(u32 datePtr, u32 dosTime) {
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcSetWin32FileTime(u32 datePtr, u64 win32Time)
|
||||
{
|
||||
static int sceRtcSetWin32FileTime(u32 datePtr, u64 win32Time) {
|
||||
if (!Memory::IsValidAddress(datePtr))
|
||||
{
|
||||
ERROR_LOG_REPORT(Log::sceRtc, "sceRtcSetWin32FileTime(%08x, %lld): invalid address", datePtr, win32Time);
|
||||
@@ -605,35 +605,32 @@ static int sceRtcSetWin32FileTime(u32 datePtr, u64 win32Time)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sceRtcGetWin32FileTime(u32 datePtr, u32 win32TimePtr)
|
||||
{
|
||||
if (!Memory::IsValidAddress(datePtr))
|
||||
{
|
||||
static int sceRtcGetWin32FileTime(u32 datePtr, u32 win32TimePtr) {
|
||||
if (!Memory::IsValidAddress(datePtr)) {
|
||||
ERROR_LOG_REPORT(Log::sceRtc, "sceRtcGetWin32FileTime(%08x, %08x): invalid address", datePtr, win32TimePtr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
DEBUG_LOG(Log::sceRtc, "sceRtcGetWin32FileTime(%08x, %08x)", datePtr, win32TimePtr);
|
||||
if (!Memory::IsValidAddress(win32TimePtr))
|
||||
if (!Memory::IsValid4AlignedRange(win32TimePtr, 8)) {
|
||||
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto pspTime = PSPPointer<const ScePspDateTime>::Create(datePtr);
|
||||
u64 result = __RtcPspTimeToTicks(*pspTime);
|
||||
|
||||
if (!__RtcValidatePspTime(*pspTime) || result < rtcFiletimeOffset)
|
||||
{
|
||||
Memory::Write_U64(0, win32TimePtr);
|
||||
if (!__RtcValidatePspTime(*pspTime) || result < rtcFiletimeOffset) {
|
||||
Memory::WriteUnchecked_U64(0, win32TimePtr);
|
||||
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
Memory::Write_U64((result - rtcFiletimeOffset) * 10, win32TimePtr);
|
||||
Memory::WriteUnchecked_U64((result - rtcFiletimeOffset) * 10, win32TimePtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr)
|
||||
{
|
||||
static int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr) {
|
||||
DEBUG_LOG(Log::sceRtc, "sceRtcCompareTick(%d,%d)", tick1Ptr, tick2Ptr);
|
||||
if (Memory::IsValid4AlignedAddress(tick1Ptr) && Memory::IsValid4AlignedAddress(tick2Ptr)) {
|
||||
if (Memory::IsValid4AlignedRange(tick1Ptr, 8) && Memory::IsValid4AlignedRange(tick2Ptr, 8)) {
|
||||
u64 tick1 = Memory::ReadUnchecked_U64(tick1Ptr);
|
||||
u64 tick2 = Memory::ReadUnchecked_U64(tick2Ptr);
|
||||
if (tick1 > tick2)
|
||||
@@ -644,10 +641,8 @@ static int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr)
|
||||
return hleNoLog(0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
u64 srcTick = Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numTicks;
|
||||
@@ -656,10 +651,8 @@ static int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks)
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddMicroseconds(u32 destTickPtr,u32 srcTickPtr, u64 numMS)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddMicroseconds(u32 destTickPtr,u32 srcTickPtr, u64 numMS) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numMS;
|
||||
@@ -668,10 +661,8 @@ static int sceRtcTickAddMicroseconds(u32 destTickPtr,u32 srcTickPtr, u64 numMS)
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddSeconds(u32 destTickPtr, u32 srcTickPtr, u64 numSecs)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddSeconds(u32 destTickPtr, u32 srcTickPtr, u64 numSecs) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numSecs * 1000000UL;
|
||||
@@ -680,10 +671,8 @@ static int sceRtcTickAddSeconds(u32 destTickPtr, u32 srcTickPtr, u64 numSecs)
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numMins*60000000UL;
|
||||
@@ -692,10 +681,8 @@ static int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins)
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
srcTick += numHours * 3600ULL * 1000000ULL;
|
||||
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
|
||||
@@ -703,32 +690,25 @@ static int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours)
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddDays(u32 destTickPtr, u32 srcTickPtr, int numDays)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddDays(u32 destTickPtr, u32 srcTickPtr, int numDays) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numDays * 86400ULL * 1000000ULL;
|
||||
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
|
||||
}
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddWeeks(u32 destTickPtr, u32 srcTickPtr, int numWeeks)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
static int sceRtcTickAddWeeks(u32 destTickPtr, u32 srcTickPtr, int numWeeks) {
|
||||
if (Memory::IsValid4AlignedRange(destTickPtr, 8) && Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
s64 srcTick = (s64)Memory::ReadUnchecked_U64(srcTickPtr);
|
||||
|
||||
srcTick += numWeeks * 7ULL * 86400ULL * 1000000ULL;
|
||||
Memory::WriteUnchecked_U64(srcTick, destTickPtr);
|
||||
}
|
||||
return hleLogDebug(Log::sceRtc, 0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
{
|
||||
static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths) {
|
||||
if (!Memory::IsValid4AlignedRange(destTickPtr, 8) || !Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
return hleLogWarning(Log::sceRtc, -1, "invalid address");
|
||||
}
|
||||
@@ -741,13 +721,11 @@ static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
pt.year += numMonths / 12;
|
||||
pt.month += numMonths % 12;
|
||||
|
||||
if (pt.month < 1)
|
||||
{
|
||||
if (pt.month < 1) {
|
||||
pt.month += 12;
|
||||
pt.year--;
|
||||
}
|
||||
if (pt.month > 12)
|
||||
{
|
||||
if (pt.month > 12) {
|
||||
pt.month -= 12;
|
||||
pt.year++;
|
||||
}
|
||||
@@ -763,8 +741,7 @@ static int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
return hleNoLog(0);
|
||||
}
|
||||
|
||||
static int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears)
|
||||
{
|
||||
static int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears) {
|
||||
if (!Memory::IsValid4AlignedRange(destTickPtr, 8) || !Memory::IsValid4AlignedRange(srcTickPtr, 8)) {
|
||||
return hleLogWarning(Log::sceRtc, -1, "invalid address");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user