From 33cd860de332a6f6ea90cfbddf87a00cc5d74c4a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 09:47:17 -0700 Subject: [PATCH 1/9] Fix a crash in reporting without gpu set. --- Core/Reporting.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index 52a4c739ae..26b9ee44af 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -243,7 +243,8 @@ namespace Reporting Payload &payload = payloadBuffer[pos]; std::string gpuPrimary, gpuFull; - gpu->GetReportingInfo(gpuPrimary, gpuFull); + if (gpu) + gpu->GetReportingInfo(gpuPrimary, gpuFull); UrlEncoder postdata; postdata.Add("version", PPSSPP_GIT_VERSION); From f16858ac4b91088055386c2be2415d8b7567bd6d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:17:23 -0700 Subject: [PATCH 2/9] Ignore POSIX warnings in zlib. --- ext/zlib/zlib.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/zlib/zlib.vcxproj b/ext/zlib/zlib.vcxproj index 34232043d4..849dd3289f 100644 --- a/ext/zlib/zlib.vcxproj +++ b/ext/zlib/zlib.vcxproj @@ -141,7 +141,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE StreamingSIMDExtensions2 false Fast From e3e5b24bf8e318e9911f500cd4eaeb55ae9f8eff Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:17:58 -0700 Subject: [PATCH 3/9] Prevent some warnings in vfpu, add reporting. Uninitialized value and out of bounds error. --- Core/MIPS/MIPSIntVFPU.cpp | 58 +++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index b6f1c2c4c5..cdfc5027a2 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -623,18 +623,17 @@ namespace MIPSInt continue; } double sv = s[i] * mult; // (float)0x7fffffff == (float)0x80000000 - int dsv; // Cap/floor it to 0x7fffffff / 0x80000000 if (sv > 0x7fffffff) sv = 0x7fffffff; if (sv < (int)0x80000000) sv = (int)0x80000000; switch ((op >> 21) & 0x1f) { - case 16: dsv = (int)rint(sv); break; //n - case 17: dsv = s[i]>=0 ? (int)floor(sv) : (int)ceil(sv); break; //z - case 18: dsv = (int)ceil(sv); break; //u - case 19: dsv = (int)floor(sv); break; //d + case 16: d[i] = (int)rint(sv); break; //n + case 17: d[i] = s[i]>=0 ? (int)floor(sv) : (int)ceil(sv); break; //z + case 18: d[i] = (int)ceil(sv); break; //u + case 19: d[i] = (int)floor(sv); break; //d + default: d[i] = 0x7FFFFFFF; break; } - d[i] = (int) dsv; } ApplyPrefixD((float*)d, sz, true); WriteVector((float*)d, sz, vd); @@ -837,24 +836,47 @@ namespace MIPSInt break; case 2: // vus2i - for (int i = 0; i < GetNumVectorElements(sz); i++) { - u32 value = s[i]; - d[i * 2] = (value & 0xFFFF) << 15; - d[i * 2 + 1] = (value & 0xFFFF0000) >> 1; - } oz = V_Pair; - if (sz == V_Pair) oz = V_Quad; + switch (sz) + { + case V_Pair: + oz = V_Quad; + // Intentional fallthrough. + case V_Single: + for (int i = 0; i < GetNumVectorElements(sz); i++) { + u32 value = s[i]; + d[i * 2] = (value & 0xFFFF) << 15; + d[i * 2 + 1] = (value & 0xFFFF0000) >> 1; + } + break; + + default: + ERROR_LOG_REPORT(CPU, "vus2i with more than 2 elements."); + break; + } break; case 3: // vs2i - for (int i = 0; i < GetNumVectorElements(sz); i++) { - u32 value = s[i]; - d[i * 2] = (value & 0xFFFF) << 16; - d[i * 2 + 1] = value & 0xFFFF0000; - } oz = V_Pair; - if (sz == V_Pair) oz = V_Quad; + switch (sz) + { + case V_Pair: + oz = V_Quad; + // Intentional fallthrough. + case V_Single: + for (int i = 0; i < GetNumVectorElements(sz); i++) { + u32 value = s[i]; + d[i * 2] = (value & 0xFFFF) << 16; + d[i * 2 + 1] = value & 0xFFFF0000; + } + break; + + default: + ERROR_LOG_REPORT(CPU, "vs2i with more than 2 elements."); + break; + } break; + default: _dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted"); break; From 3931f078523d38cdedda6fa87f238a5743aebc3c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:18:52 -0700 Subject: [PATCH 4/9] Fix a couple bad bounds checks in VAG/Mpeg. --- Core/HW/MediaEngine.cpp | 2 +- Core/HW/SasAudio.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 0fe8a7062f..2e598f0ac3 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -23,7 +23,7 @@ static const int modeBpp[4] = { 2, 2, 2, 4 }; void MediaEngine::writeVideoImage(u32 bufferPtr, int frameWidth, int videoPixelMode) { - if (videoPixelMode > (int)(sizeof(modeBpp) / sizeof(modeBpp[0])) || videoPixelMode < 0) + if (videoPixelMode >= (int)(sizeof(modeBpp) / sizeof(modeBpp[0])) || videoPixelMode < 0) { ERROR_LOG(ME, "Unexpected videoPixelMode %d, using 0 instead.", videoPixelMode); videoPixelMode = 0; diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 5cf90ba173..84806d52db 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -47,7 +47,7 @@ void VagDecoder::DecodeBlock(u8 *&readp) { int predict_nr = *readp++; int shift_factor = predict_nr & 0xf; predict_nr >>= 4; - if (predict_nr >= sizeof(f) / sizeof(s8)) { + if (predict_nr >= sizeof(f) / sizeof(f[0])) { predict_nr = 0; } int flags = *readp++; @@ -311,7 +311,7 @@ void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) { break; case VOICETYPE_PCM: { - int size = std::min(voice.pcmSize, (int)(numSamples * sizeof(s16))); + u32 size = std::min(voice.pcmSize, (int)(numSamples * sizeof(s16))); Memory::Memcpy(resampleBuffer + 2, voice.pcmAddr, size); if (numSamples * sizeof(s16) > size) memset(resampleBuffer + 2 + voice.pcmSize, 0, numSamples * sizeof(s16) - size); From f91135cedf7185f3401d8fa7aa76e600da66321f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:19:34 -0700 Subject: [PATCH 5/9] Prevent some threading related NULL derefs. --- Core/HLE/sceKernelThread.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 4eef476f63..21b47cfe07 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -651,8 +651,12 @@ private: int size = cur->end - cur->first; if (size >= cur->capacity - 2) { - cur->capacity *= 2; - cur->data = (SceUID *)realloc(cur->data, cur->capacity * sizeof(SceUID)); + SceUID *new_data = (SceUID *)realloc(cur->data, cur->capacity * sizeof(SceUID)); + if (new_data != NULL) + { + cur->capacity *= 2; + cur->data = new_data; + } } int newFirst = (cur->capacity - size) / 2; @@ -2735,6 +2739,8 @@ void __KernelSwitchContext(Thread *target, const char *reason) hleCurrentThreadName = target->nt.name; __KernelChangeReadyState(target, currentThread, false); target->nt.status = (target->nt.status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY; + + __KernelLoadContext(&target->context, (target->nt.attr & PSP_THREAD_ATTR_VFPU) != 0); } else { @@ -2742,8 +2748,6 @@ void __KernelSwitchContext(Thread *target, const char *reason) hleCurrentThreadName = NULL; } - __KernelLoadContext(&target->context, (target->nt.attr & PSP_THREAD_ATTR_VFPU) != 0); - bool fromIdle = oldUID == threadIdleID[0] || oldUID == threadIdleID[1]; bool toIdle = currentThread == threadIdleID[0] || currentThread == threadIdleID[1]; if (!(fromIdle && toIdle)) From 7dc5842798ae19405d366e2c79a71d0c152771de Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:20:13 -0700 Subject: [PATCH 6/9] Clean up some variable shadowing. --- Core/HLE/sceDisplay.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 808c2b6caf..4bb32564c4 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -494,8 +494,8 @@ u32 sceDisplaySetFramebuf(u32 topaddr, int linesize, int pixelformat, int sync) return 0; } -bool __DisplayGetFramebuf(u8 **topaddr, u32 *linesize, u32 *pixelFormat, int mode) { - const FrameBufferState &fbState = mode == 1 ? latchedFramebuf : framebuf; +bool __DisplayGetFramebuf(u8 **topaddr, u32 *linesize, u32 *pixelFormat, int latchedMode) { + const FrameBufferState &fbState = latchedMode == 1 ? latchedFramebuf : framebuf; if (topaddr != NULL) *topaddr = Memory::GetPointer(fbState.topaddr); if (linesize != NULL) @@ -506,8 +506,8 @@ bool __DisplayGetFramebuf(u8 **topaddr, u32 *linesize, u32 *pixelFormat, int mod return true; } -u32 sceDisplayGetFramebuf(u32 topaddrPtr, u32 linesizePtr, u32 pixelFormatPtr, int mode) { - const FrameBufferState &fbState = mode == 1 ? latchedFramebuf : framebuf; +u32 sceDisplayGetFramebuf(u32 topaddrPtr, u32 linesizePtr, u32 pixelFormatPtr, int latchedMode) { + const FrameBufferState &fbState = latchedMode == 1 ? latchedFramebuf : framebuf; DEBUG_LOG(HLE,"sceDisplayGetFramebuf(*%08x = %08x, *%08x = %08x, *%08x = %08x, %i)", topaddrPtr, fbState.topaddr, linesizePtr, fbState.pspFramebufLinesize, pixelFormatPtr, fbState.pspFramebufFormat, mode); if (Memory::IsValidAddress(topaddrPtr)) @@ -602,9 +602,9 @@ u32 sceDisplayGetAccumulatedHcount() { } float sceDisplayGetFramePerSec() { - float fps = 59.9400599f; - DEBUG_LOG(HLE,"%f=sceDisplayGetFramePerSec()", fps); - return fps; // (9MHz * 1)/(525 * 286) + const static float framePerSec = 59.9400599f; + DEBUG_LOG(HLE,"%f=sceDisplayGetFramePerSec()", framePerSec); + return framePerSec; // (9MHz * 1)/(525 * 286) } u32 sceDisplayIsForeground() { From f67d4f959f77bc8413ea71179f0c22fd82dfa978 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:20:39 -0700 Subject: [PATCH 7/9] Clean up some atrac-related type/shadow warnings. --- Core/HLE/sceAtrac.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index b258ab0522..15ca3e3192 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -371,7 +371,7 @@ void Atrac::Analyze() if (chunkSize < 36) break; int checkNumLoops = Memory::Read_U32(first.addr + offset + 28); - if (chunkSize >= 36 + checkNumLoops * 24) { + if (chunkSize >= 36 + (u32)checkNumLoops * 24) { loopinfoNum = checkNumLoops; loopinfo.resize(loopinfoNum); u32 loopinfoAddr = first.addr + offset + 36; @@ -479,13 +479,13 @@ u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishF atrac->SeekToSample(forceseekSample); atrac->SeekToSample(atrac->currentSample); AVPacket packet; - int got_frame, ret; + int got_frame, avret; while (av_read_frame(atrac->pFormatCtx, &packet) >= 0) { if (packet.stream_index == atrac->audio_stream_index) { got_frame = 0; - ret = avcodec_decode_audio4(atrac->pCodecCtx, atrac->pFrame, &got_frame, &packet); - if (ret < 0) { - ERROR_LOG(HLE, "avcodec_decode_audio4: Error decoding audio %d", ret); + avret = avcodec_decode_audio4(atrac->pCodecCtx, atrac->pFrame, &got_frame, &packet); + if (avret < 0) { + ERROR_LOG(HLE, "avcodec_decode_audio4: Error decoding audio %d", avret); av_free_packet(&packet); break; } @@ -496,10 +496,10 @@ u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishF atrac->pFrame->nb_samples, (AVSampleFormat)atrac->pFrame->format, 1); u8* out = Memory::GetPointer(outAddr); numSamples = atrac->pFrame->nb_samples; - ret = swr_convert(atrac->pSwrCtx, &out, atrac->pFrame->nb_samples, + avret = swr_convert(atrac->pSwrCtx, &out, atrac->pFrame->nb_samples, (const u8**)atrac->pFrame->extended_data, atrac->pFrame->nb_samples); - if (ret < 0) { - ERROR_LOG(HLE, "swr_convert: Error while converting %d", ret); + if (avret < 0) { + ERROR_LOG(HLE, "swr_convert: Error while converting %d", avret); } } @@ -720,9 +720,9 @@ u32 sceAtracGetSecondBufferInfo(int atracID, u32 outposAddr, u32 outBytesAddr) if (!atrac) { //return -1; } - if (Memory::IsValidAddress(outposAddr)) + if (Memory::IsValidAddress(outposAddr) && atrac) Memory::Write_U32(atrac->second.fileoffset, outposAddr); - if (Memory::IsValidAddress(outBytesAddr)) + if (Memory::IsValidAddress(outBytesAddr) && atrac) Memory::Write_U32(atrac->second.writableBytes, outBytesAddr); // TODO: Maybe don't write the above? return ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED; @@ -813,13 +813,13 @@ int64_t _AtracSeekbuffer(void *opaque, int64_t offset, int whence) Atrac *atrac = (Atrac*)opaque; switch (whence) { case SEEK_SET: - atrac->decodePos = offset; + atrac->decodePos = (u32)offset; break; case SEEK_CUR: - atrac->decodePos += offset; + atrac->decodePos += (u32)offset; break; case SEEK_END: - atrac->decodePos = atrac->first.filesize - offset; + atrac->decodePos = atrac->first.filesize - (u32)offset; break; } return offset; From 81f1383beb14f36b0479aede8bdcc30b35ca538f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:21:04 -0700 Subject: [PATCH 8/9] Prevent a type comparison warning. --- Core/Config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Config.h b/Core/Config.h index dd6acefcdb..2643f25471 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -20,6 +20,7 @@ #include #include #include +#include "CommonTypes.h" extern const char *PPSSPP_GIT_VERSION; @@ -78,7 +79,7 @@ public: int iTexScalingType; // 0 = xBRZ, 1 = Hybrid bool bTexDeposterize; int iFpsLimit; - int iMaxRecent; + u32 iMaxRecent; // Sound bool bEnableSound; From 1f2480fff31c60f8a960a291ab4a91c2f47e68c9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 18 May 2013 10:21:21 -0700 Subject: [PATCH 9/9] Add a bounds check for interrupts. --- Core/HLE/sceKernelInterrupt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 1242eef768..c7dcc9a8ae 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -431,6 +431,8 @@ SubIntrHandler *__RegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 int __ReleaseSubIntrHandler(int intrNumber, int subIntrNumber) { + if (intrNumber >= PSP_NUMBER_INTERRUPTS) + return -1; if (!intrHandlers[intrNumber]->has(subIntrNumber)) return -1;