diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index f02d806de8..441ff5491a 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -43,6 +43,10 @@ #include "Core/HLE/sceKernelInterrupt.h" #include "Core/HLE/HLE.h" +#ifdef BLACKBERRY +using std::strnlen; +#endif + enum { // Do nothing after the syscall. @@ -596,9 +600,22 @@ size_t hleFormatLogArgs(char *message, size_t sz, const char *argmask) { } break; + case 'P': + if (Memory::IsValidAddress(regval)) { + APPEND_FMT("%08x[%016llx]", regval, Memory::Read_U64(regval)); + } else { + APPEND_FMT("%08x[invalid]", regval); + } + break; + case 's': if (Memory::IsValidAddress(regval)) { - APPEND_FMT("%s", Memory::GetCharPointer(regval)); + const char *s = Memory::GetCharPointer(regval); + if (strnlen(s, 64) >= 64) { + APPEND_FMT("%.64s...", Memory::GetCharPointer(regval)); + } else { + APPEND_FMT("%s", Memory::GetCharPointer(regval)); + } } else { APPEND_FMT("(invalid)"); } @@ -649,22 +666,7 @@ size_t hleFormatLogArgs(char *message, size_t sz, const char *argmask) { return used; } -u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const char *file, int line, const char *reportTag, char retmask, const char *reason, ...) { - if (level > MAX_LOGLEVEL || !GenericLogEnabled(level, t)) { - return res; - } - - char formatted_reason[4096] = {0}; - if (reason != nullptr) { - va_list args; - va_start(args, reason); - formatted_reason[0] = ':'; - formatted_reason[1] = ' '; - vsnprintf(formatted_reason + 2, sizeof(formatted_reason) - 3, reason, args); - formatted_reason[sizeof(formatted_reason) - 1] = '\0'; - va_end(args); - } - +void hleDoLogInternal(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u64 res, const char *file, int line, const char *reportTag, char retmask, const char *reason, const char *formatted_reason) { char formatted_args[4096]; hleFormatLogArgs(formatted_args, sizeof(formatted_args), latestSyscall->argmask); @@ -675,12 +677,12 @@ u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const ch const char *fmt; // TODO: Floats and other types... move to another func (for return type?) Hmm. if (retmask == 'x') { - fmt = "%08x=%s(%s)%s"; - } else if (retmask == 'i') { - fmt = "%d=%s(%s)%s"; + fmt = "%08llx=%s(%s)%s"; + } else if (retmask == 'i' || retmask == 'I') { + fmt = "%lld=%s(%s)%s"; } else { _assert_msg_(HLE, false, "Invalid return format: %c", retmask); - fmt = "%08x=%s(%s)%s"; + fmt = "%08llx=%s(%s)%s"; } GenericLog(level, t, file, line, fmt, res, latestSyscall->name, formatted_args, formatted_reason); @@ -698,10 +700,4 @@ u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const ch Reporting::ReportMessageFormatted(key.c_str(), formatted_message); } } - - return res; -} - -u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const char *file, int line, const char *reportTag, char retmask) { - return hleDoLog(t, level, res, file, line, reportTag, retmask, nullptr); } diff --git a/Core/HLE/HLE.h b/Core/HLE/HLE.h index 80109dfefa..84f9c34121 100644 --- a/Core/HLE/HLE.h +++ b/Core/HLE/HLE.h @@ -17,6 +17,7 @@ #pragma once +#include #include "Common/CommonTypes.h" #include "Common/Log.h" #include "Core/MIPS/MIPS.h" @@ -146,8 +147,38 @@ const HLEFunction *GetSyscallInfo(MIPSOpcode op); // For jit, takes arg: const HLEFunction * void *GetQuickSyscallFunc(MIPSOpcode op); -u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const char *file, int line, const char *reportTag, char retmask, const char *reason, ...); -u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const char *file, int line, const char *reportTag, char retmask); +void hleDoLogInternal(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u64 res, const char *file, int line, const char *reportTag, char retmask, const char *reason, const char *formatted_reason); + +template +T hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, T res, const char *file, int line, const char *reportTag, char retmask, const char *reason, ...) { + if (level > MAX_LOGLEVEL || !GenericLogEnabled(level, t)) { + return res; + } + + char formatted_reason[4096] = {0}; + if (reason != nullptr) { + va_list args; + va_start(args, reason); + formatted_reason[0] = ':'; + formatted_reason[1] = ' '; + vsnprintf(formatted_reason + 2, sizeof(formatted_reason) - 3, reason, args); + formatted_reason[sizeof(formatted_reason) - 1] = '\0'; + va_end(args); + } + + hleDoLogInternal(t, level, res, file, line, reportTag, retmask, reason, formatted_reason); + return res; +} + +template +T hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, T res, const char *file, int line, const char *reportTag, char retmask) { + if (level > MAX_LOGLEVEL || !GenericLogEnabled(level, t)) { + return res; + } + + hleDoLogInternal(t, level, res, file, line, reportTag, retmask, nullptr, ""); + return res; +} // This is just a quick way to force logging to be more visible for one file. #ifdef HLE_LOG_FORCE @@ -163,8 +194,7 @@ u32 hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u32 res, const ch #define HLE_LOG_LVERBOSE LVERBOSE #endif -// Only one side of the ?: is evaluated (per c++ standard), so this should be safe. -#define hleLogHelper(t, level, res, retmask, ...) (LogTypes::level > MAX_LOGLEVEL ? res : hleDoLog(LogTypes::t, LogTypes::level, res, __FILE__, __LINE__, nullptr, retmask, ##__VA_ARGS__)) +#define hleLogHelper(t, level, res, retmask, ...) hleDoLog(LogTypes::t, LogTypes::level, res, __FILE__, __LINE__, nullptr, retmask, ##__VA_ARGS__) #define hleLogError(t, res, ...) hleLogHelper(t, LERROR, res, 'x', ##__VA_ARGS__) #define hleLogWarning(t, res, ...) hleLogHelper(t, LWARNING, res, 'x', ##__VA_ARGS__) #define hleLogDebug(t, res, ...) hleLogHelper(t, HLE_LOG_LDEBUG, res, 'x', ##__VA_ARGS__) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index abe300c1c1..f0dc09da74 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -2418,43 +2418,43 @@ KernelObject *__KernelDirListingObject() { } const HLEFunction IoFileMgrForUser[] = { - {0XB29DDF9C, &WrapU_C, "sceIoDopen", 'x', "s" }, - {0XE3EB004C, &WrapU_IU, "sceIoDread", 'x', "ix" }, - {0XEB092469, &WrapU_I, "sceIoDclose", 'x', "i" }, - {0XE95A012B, &WrapU_UUUUUU, "sceIoIoctlAsync", 'x', "xxxxxx"}, - {0X63632449, &WrapU_UUUUUU, "sceIoIoctl", 'x', "xxxxxx"}, - {0XACE946E8, &WrapU_CU, "sceIoGetstat", 'x', "sx" }, - {0XB8A740F4, &WrapU_CUU, "sceIoChstat", 'x', "sxx" }, - {0X55F4717D, &WrapU_C, "sceIoChdir", 'x', "s" }, + {0XB29DDF9C, &WrapU_C, "sceIoDopen", 'i', "s" }, + {0XE3EB004C, &WrapU_IU, "sceIoDread", 'i', "ix" }, + {0XEB092469, &WrapU_I, "sceIoDclose", 'i', "i" }, + {0XE95A012B, &WrapU_UUUUUU, "sceIoIoctlAsync", 'i', "ixpipi"}, + {0X63632449, &WrapU_UUUUUU, "sceIoIoctl", 'i', "ixpipi"}, + {0XACE946E8, &WrapU_CU, "sceIoGetstat", 'i', "sx" }, + {0XB8A740F4, &WrapU_CUU, "sceIoChstat", 'i', "sxx" }, + {0X55F4717D, &WrapU_C, "sceIoChdir", 'i', "s" }, {0X08BD7374, &WrapU_I, "sceIoGetDevType", 'x', "i" }, - {0XB2A628C1, &WrapU_UUUIUI, "sceIoAssign", 'x', "xxxixi"}, - {0XE8BC6571, &WrapU_I, "sceIoCancel", 'x', "i" }, - {0XB293727F, &WrapI_II, "sceIoChangeAsyncPriority", 'i', "ii" }, - {0X810C4BC3, &WrapU_I, "sceIoClose", 'x', "i" }, + {0XB2A628C1, &WrapU_UUUIUI, "sceIoAssign", 'i', "sssixi"}, + {0XE8BC6571, &WrapU_I, "sceIoCancel", 'i', "i" }, + {0XB293727F, &WrapI_II, "sceIoChangeAsyncPriority", 'i', "ix" }, + {0X810C4BC3, &WrapU_I, "sceIoClose", 'i', "i" }, {0XFF5940B6, &WrapI_I, "sceIoCloseAsync", 'i', "i" }, - {0X54F5FB11, &WrapU_CIUIUI, "sceIoDevctl", 'x', "sixixi"}, - {0XCB05F8D6, &WrapU_IUU, "sceIoGetAsyncStat", 'x', "ixx" }, + {0X54F5FB11, &WrapU_CIUIUI, "sceIoDevctl", 'i', "sxpipi"}, + {0XCB05F8D6, &WrapU_IUU, "sceIoGetAsyncStat", 'i', "iiP" }, {0X27EB27B8, &WrapI64_II64I, "sceIoLseek", 'I', "iIi" }, - {0X68963324, &WrapU_III, "sceIoLseek32", 'x', "iii" }, - {0X1B385D8F, &WrapU_III, "sceIoLseek32Async", 'x', "iii" }, - {0X71B19E77, &WrapU_II64I, "sceIoLseekAsync", 'x', "iIi" }, - {0X109F50BC, &WrapU_CII, "sceIoOpen", 'x', "sii" }, - {0X89AA9906, &WrapU_CII, "sceIoOpenAsync", 'x', "sii" }, - {0X06A70004, &WrapU_CI, "sceIoMkdir", 'x', "si" }, - {0X3251EA56, &WrapU_IU, "sceIoPollAsync", 'x', "ix" }, - {0X6A638D83, &WrapU_IUI, "sceIoRead", 'x', "ixi" }, - {0XA0B5A7C2, &WrapU_IUI, "sceIoReadAsync", 'x', "ixi" }, - {0XF27A9C51, &WrapU_C, "sceIoRemove", 'x', "s" }, - {0X779103A0, &WrapU_CC, "sceIoRename", 'x', "ss" }, - {0X1117C65F, &WrapU_C, "sceIoRmdir", 'x', "s" }, - {0XA12A0514, &WrapU_IUU, "sceIoSetAsyncCallback", 'x', "ixx" }, - {0XAB96437F, &WrapU_CI, "sceIoSync", 'x', "si" }, - {0X6D08A871, &WrapU_C, "sceIoUnassign", 'x', "s" }, - {0X42EC03AC, &WrapU_IUI, "sceIoWrite", 'x', "ixi" }, - {0X0FACAB19, &WrapU_IUI, "sceIoWriteAsync", 'x', "ixi" }, - {0X35DBD746, &WrapI_IU, "sceIoWaitAsyncCB", 'i', "ix" }, - {0XE23EEC33, &WrapI_IU, "sceIoWaitAsync", 'i', "ix" }, - {0X5C2BE2CC, &WrapU_UIU, "sceIoGetFdList", 'x', "xix" }, + {0X68963324, &WrapU_III, "sceIoLseek32", 'i', "iii" }, + {0X1B385D8F, &WrapU_III, "sceIoLseek32Async", 'i', "iii" }, + {0X71B19E77, &WrapU_II64I, "sceIoLseekAsync", 'i', "iIi" }, + {0X109F50BC, &WrapU_CII, "sceIoOpen", 'i', "sii" }, + {0X89AA9906, &WrapU_CII, "sceIoOpenAsync", 'i', "sii" }, + {0X06A70004, &WrapU_CI, "sceIoMkdir", 'i', "si" }, + {0X3251EA56, &WrapU_IU, "sceIoPollAsync", 'i', "iP" }, + {0X6A638D83, &WrapU_IUI, "sceIoRead", 'i', "ixi" }, + {0XA0B5A7C2, &WrapU_IUI, "sceIoReadAsync", 'i', "ixi" }, + {0XF27A9C51, &WrapU_C, "sceIoRemove", 'i', "s" }, + {0X779103A0, &WrapU_CC, "sceIoRename", 'i', "ss" }, + {0X1117C65F, &WrapU_C, "sceIoRmdir", 'i', "s" }, + {0XA12A0514, &WrapU_IUU, "sceIoSetAsyncCallback", 'i', "ixx" }, + {0XAB96437F, &WrapU_CI, "sceIoSync", 'i', "si" }, + {0X6D08A871, &WrapU_C, "sceIoUnassign", 'i', "s" }, + {0X42EC03AC, &WrapU_IUI, "sceIoWrite", 'i', "ixi" }, + {0X0FACAB19, &WrapU_IUI, "sceIoWriteAsync", 'i', "ixi" }, + {0X35DBD746, &WrapI_IU, "sceIoWaitAsyncCB", 'i', "iP" }, + {0XE23EEC33, &WrapI_IU, "sceIoWaitAsync", 'i', "iP" }, + {0X5C2BE2CC, &WrapU_UIU, "sceIoGetFdList", 'i', "xip" }, }; void Register_IoFileMgrForUser() { @@ -2463,11 +2463,11 @@ void Register_IoFileMgrForUser() { const HLEFunction StdioForUser[] = { - {0X172D316E, &WrapU_V, "sceKernelStdin", 'x', "" }, - {0XA6BAB2E9, &WrapU_V, "sceKernelStdout", 'x', "" }, - {0XF78BA90A, &WrapU_V, "sceKernelStderr", 'x', "" }, - {0X432D8F5C, &WrapU_U, "sceKernelRegisterStdoutPipe", 'x', "x" }, - {0X6F797E03, &WrapU_U, "sceKernelRegisterStderrPipe", 'x', "x" }, + {0X172D316E, &WrapU_V, "sceKernelStdin", 'i', "" }, + {0XA6BAB2E9, &WrapU_V, "sceKernelStdout", 'i', "" }, + {0XF78BA90A, &WrapU_V, "sceKernelStderr", 'i', "" }, + {0X432D8F5C, &WrapU_U, "sceKernelRegisterStdoutPipe", 'i', "x" }, + {0X6F797E03, &WrapU_U, "sceKernelRegisterStderrPipe", 'i', "x" }, {0XA46785C9, nullptr, "sceKernelStdioSendChar", '?', "" }, {0X0CBB0571, nullptr, "sceKernelStdioLseek", '?', "" }, {0X3054D478, nullptr, "sceKernelStdioRead", '?', "" },