dolphin/Source/Core
JosJuice 989bdb8d6d Common/CodeBlock: Call ResetCodePtr when decreasing region_size
Fixes https://bugs.dolphin-emu.org/issues/12827.

A description of what was going wrong:

JitArm64::Init first calls CodeBlock::AllocCodeSpace, after which
CodeBlock and Arm64Emitter consider us to have 96 MB of code space
available. JitArm64::Init then calls AddChildCodeSpace, which is
supposed to take 64 MiB of that space and give it to m_far_code.
CodeBlock's view of how much space there is gets updated from 96 MiB
to 32 MiB, but due to the missing call, Arm64Emitter keeps thinking
that it has 96 MiB of space available.

The last thing JitArm64::Init does is to call ResetFreeMemoryRanges.
This function asks Arm64Emitter how much code space is available and
stores a range of that size in m_free_ranges_near, meaning that
m_free_ranges_near ends up being backed by both nearcode and farcode!
This is a ticking time bomb; as soon as we grab memory from
m_free_ranges_near which is backed by farcode, we're in trouble.
The crash I ran into in my testing was caused by fastmem code being
allocated in farcode (our backpatch handler only handles accesses made
from nearcode), but you may as well get errors caused by code intended
for nearcode overwriting code intended for farcode or vice versa.

So why did NBA Live 2005 crash when most games had no problems,
and why was the bug bisected to the commit that increased the size
of far code from 16 MiB to 64 MiB? Well, as long as we're only
using the first 32 MiB of the big 96 MiB range, everything works.
What happens with NBA Live 2005 (I have not investigated exactly
through what mechanism this happens) is that at some point the range
in m_free_ranges_near gets split into two ranges, one which is
backed by nearcode and one which is backed by farcode. Dolphin
prefers to select the biggest range available (we don't want to
pick a tiny 1 KiB range that may not be able to fit the whole block
we're about to emit, after all), and after increasing the size of
farcode to 64 MiB, farcode is bigger than nearcode.
2022-02-12 17:51:32 +01:00
..
AudioCommon IOFile: Make origin parameter to Seek() an enum class. 2022-01-29 06:49:21 +01:00
Common Common/CodeBlock: Call ResetCodePtr when decreasing region_size 2022-02-12 17:51:32 +01:00
Core Merge pull request #10435 from AdmiralCurtiss/savestate-crash 2022-02-11 06:28:46 -05:00
DiscIO IOFile: Rename Clear() to ClearError() for clarity. 2022-01-29 06:49:22 +01:00
DolphinNoGUI Common/MsgHandler: Remove non-format variants of PanicAlert 2022-01-09 12:44:14 -08:00
DolphinQt FifoPlayer: Add missing call to LoadSettings() 2022-01-17 11:00:13 -08:00
DolphinTool CMakeLists: Change DiscIO dependency from common to core 2022-01-16 13:29:51 -08:00
InputCommon Use Common::ToLower and Common::ToUpper 2022-01-16 17:00:12 -08:00
MacUpdater CMakeLists: Replace tab characters with spaces 2022-01-16 15:20:40 -08:00
UICommon Don't create GBA saves dir when building without mGBA 2022-01-22 16:05:21 +01:00
UpdaterCommon UpdaterCommon: Copy content file to a temporary file before renaming on macOS 2022-01-30 15:40:28 -05:00
VideoBackends Treat alpha as 0 if alpha is 1 for blending 2022-02-08 15:15:15 -08:00
VideoCommon Treat alpha as 0 if alpha is 1 for blending 2022-02-08 15:15:15 -08:00
WinUpdater treewide: convert GPLv2+ license info to SPDX tags 2021-07-05 04:35:56 +02:00
CMakeLists.txt DolphinTool: CLI utility interface and disc image tools 2021-12-03 15:40:19 -06:00
DolphinLib.ARM64.props
DolphinLib.props Common: Create HRWrap 2022-01-09 12:44:15 -08:00
DolphinLib.vcxproj msbuild: Move DivUtils to DolphinLib.props 2021-08-31 22:48:07 -07:00
DolphinLib.vcxproj.user
DolphinLib.x64.props