mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-25 22:09:35 +00:00
Check that RDRAM area is writable before writing buffer data into it.
Fixed Problem with Project64's protect memory option #764
This commit is contained in:
parent
2ac29acf29
commit
03022db791
|
@ -278,6 +278,9 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
|
|||
<ClCompile Include="..\..\src\mupenplus\Config_mupenplus.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\mupenplus\MemoryStatus_mupenplus.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\mupenplus\MupenPlusAPIImpl.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
|
@ -335,6 +338,9 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
|
|||
<ClCompile Include="..\..\src\windows\GLideN64_windows.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug_mupenplus' Or '$(Configuration)'=='Release_mupenplus'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\windows\MemoryStatus_windows.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug_mupenplus' Or '$(Configuration)'=='Release_mupenplus'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\windows\ZilmarAPIImpl_windows.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug_mupenplus' Or '$(Configuration)'=='Release_mupenplus'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
|
@ -406,6 +412,7 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
|
|||
<ClInclude Include="..\..\src\inc\glext.h" />
|
||||
<ClInclude Include="..\..\src\Keys.h" />
|
||||
<ClInclude Include="..\..\src\Log.h" />
|
||||
<ClInclude Include="..\..\src\MemoryStatus.h" />
|
||||
<ClInclude Include="..\..\src\mupenplus\GLideN64_mupenplus.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
|
@ -470,4 +477,4 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -392,6 +392,12 @@
|
|||
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_FXAA.cpp">
|
||||
<Filter>Source Files\Graphics\OpenGL\GLSL</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\windows\MemoryStatus_windows.cpp">
|
||||
<Filter>Source Files\windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\mupenplus\MemoryStatus_mupenplus.cpp">
|
||||
<Filter>Source Files\mupenplus</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\3DMath.h">
|
||||
|
@ -721,5 +727,8 @@
|
|||
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_FXAA.h">
|
||||
<Filter>Header Files\Graphics\OpenGL\GLSL</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\MemoryStatus.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -10,6 +10,7 @@
|
|||
#include <N64.h>
|
||||
#include <VI.h>
|
||||
#include "Log.h"
|
||||
#include "MemoryStatus.h"
|
||||
|
||||
/*
|
||||
#include "ColorBufferToRDRAM_GL.h"
|
||||
|
@ -318,6 +319,8 @@ u32 ColorBufferToRDRAM::_getRealWidth(u32 _viWidth)
|
|||
|
||||
void ColorBufferToRDRAM::copyToRDRAM(u32 _address, bool _sync)
|
||||
{
|
||||
if (!isMemoryWritable(RDRAM + _address, gDP.colorImage.width << gDP.colorImage.size >> 1))
|
||||
return;
|
||||
if (!_prepareCopy(_address))
|
||||
return;
|
||||
const u32 numBytes = (m_pCurFrameBuffer->m_width*m_pCurFrameBuffer->m_height) << m_pCurFrameBuffer->m_size >> 1;
|
||||
|
@ -328,6 +331,8 @@ void ColorBufferToRDRAM::copyChunkToRDRAM(u32 _startAddress)
|
|||
{
|
||||
const u32 endAddress = (_startAddress & ~0xfff) + 0x1000;
|
||||
|
||||
if (!isMemoryWritable(RDRAM + _startAddress, endAddress - _startAddress))
|
||||
return;
|
||||
if (!_prepareCopy(_startAddress))
|
||||
return;
|
||||
_copy(_startAddress, endAddress, true);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "DepthBufferToRDRAM.h"
|
||||
#include "WriteToRDRAM.h"
|
||||
#include "MemoryStatus.h"
|
||||
|
||||
#include <FrameBuffer.h>
|
||||
#include <DepthBuffer.h>
|
||||
|
@ -282,11 +283,15 @@ bool DepthBufferToRDRAM::copyToRDRAM(u32 _address)
|
|||
if (!m_pbuf)
|
||||
return false;
|
||||
|
||||
if (!isMemoryWritable(RDRAM + _address, gDP.colorImage.width * 2))
|
||||
return false;
|
||||
|
||||
if (!_prepareCopy(_address, false))
|
||||
return false;
|
||||
|
||||
const u32 endAddress = m_pCurFrameBuffer->m_pDepthBuffer->m_address +
|
||||
m_pCurFrameBuffer->m_width * m_pCurFrameBuffer->m_height * 2;
|
||||
|
||||
return _copy(m_pCurFrameBuffer->m_pDepthBuffer->m_address, endAddress);
|
||||
}
|
||||
|
||||
|
@ -300,6 +305,9 @@ bool DepthBufferToRDRAM::copyChunkToRDRAM(u32 _startAddress)
|
|||
|
||||
const u32 endAddress = (_startAddress & ~0xfff) + 0x1000;
|
||||
|
||||
if (!isMemoryWritable(RDRAM + _startAddress, endAddress - _startAddress))
|
||||
return false;
|
||||
|
||||
if (!_prepareCopy(_startAddress, true))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ if(MUPENPLUSAPI)
|
|||
MupenPlusPluginAPI.cpp
|
||||
mupenplus/Config_mupenplus.cpp
|
||||
mupenplus/CommonAPIImpl_mupenplus.cpp
|
||||
mupenplus/MemoryStatus_mupenplus.cpp
|
||||
mupenplus/MupenPlusAPIImpl.cpp
|
||||
Graphics/OpenGLContext/mupen64plus/mupen64plus_DisplayWindow.cpp
|
||||
)
|
||||
|
@ -158,6 +159,7 @@ else(MUPENPLUSAPI)
|
|||
windows/Config_windows.cpp
|
||||
windows/CommonAPIImpl_windows.cpp
|
||||
windows/GLideN64_windows.cpp
|
||||
windows/MemoryStatus_windows.cpp
|
||||
common/GLFunctions.cpp
|
||||
windows/ZilmarAPIImpl_windows.cpp
|
||||
Graphics/OpenGLContext/windows/windows_DisplayWindow.cpp
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "PostProcessor.h"
|
||||
#include "FrameBufferInfo.h"
|
||||
#include "Log.h"
|
||||
#include "MemoryStatus.h"
|
||||
|
||||
#include "BufferCopy/ColorBufferToRDRAM.h"
|
||||
#include "BufferCopy/DepthBufferToRDRAM.h"
|
||||
|
@ -1553,6 +1554,8 @@ void FrameBufferList::fillRDRAM(s32 ulx, s32 uly, s32 lrx, s32 lry)
|
|||
lrx >>= (3 - gDP.colorImage.size);
|
||||
u32 * dst = (u32*)(RDRAM + gDP.colorImage.address);
|
||||
dst += uly * ci_width_in_dwords;
|
||||
if (!isMemoryWritable(dst, lowerBound - gDP.colorImage.address))
|
||||
return;
|
||||
for (s32 y = uly; y < lry; ++y) {
|
||||
for (s32 x = ulx; x < lrx; ++x) {
|
||||
dst[x] = gDP.fillColor.color;
|
||||
|
|
5
src/MemoryStatus.h
Normal file
5
src/MemoryStatus.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
#include "Platform.h"
|
||||
#include "Types.h"
|
||||
|
||||
bool isMemoryWritable(void * ptr, size_t byteCount);
|
|
@ -56,6 +56,7 @@ MY_LOCAL_SRC_FILES :=
|
|||
$(SRCDIR)/common/CommonAPIImpl_common.cpp \
|
||||
$(SRCDIR)/mupenplus/CommonAPIImpl_mupenplus.cpp \
|
||||
$(SRCDIR)/mupenplus/Config_mupenplus.cpp \
|
||||
$(SRCDIR)/mupenplus/MemoryStatus_mupenplus.cpp \
|
||||
$(SRCDIR)/mupenplus/MupenPlusAPIImpl.cpp \
|
||||
$(SRCDIR)/DepthBufferRender/ClipPolygon.cpp \
|
||||
$(SRCDIR)/DepthBufferRender/DepthBufferRender.cpp \
|
||||
|
|
6
src/mupenplus/MemoryStatus_mupenplus.cpp
Normal file
6
src/mupenplus/MemoryStatus_mupenplus.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "../MemoryStatus.h"
|
||||
|
||||
bool isMemoryWritable(void * ptr, size_t byteCount)
|
||||
{
|
||||
return true;
|
||||
}
|
25
src/windows/MemoryStatus_windows.cpp
Normal file
25
src/windows/MemoryStatus_windows.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "../MemoryStatus.h"
|
||||
|
||||
/* Code taken from stackoverflow.com/questions/18394647 */
|
||||
bool isMemoryWritable(void * ptr, size_t byteCount)
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
if (VirtualQuery(ptr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0)
|
||||
return false;
|
||||
|
||||
if (mbi.State != MEM_COMMIT)
|
||||
return false;
|
||||
|
||||
if ((mbi.Protect & (PAGE_NOACCESS | PAGE_EXECUTE | PAGE_READONLY)) != 0)
|
||||
return false;
|
||||
|
||||
// Check that the start of memory block is in the same "region" as the end.
|
||||
// If it isn't, "simplify" the problem into checking that the rest of the memory is writeable.
|
||||
size_t blockOffset = (size_t)(reinterpret_cast<u8*>(ptr) - reinterpret_cast<u8*>(mbi.BaseAddress));
|
||||
size_t blockBytesPostPtr = mbi.RegionSize - blockOffset;
|
||||
|
||||
if (blockBytesPostPtr < byteCount)
|
||||
return isMemoryWritable(reinterpret_cast<u8*>(ptr) + blockBytesPostPtr, byteCount - blockBytesPostPtr);
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue
Block a user