Commit Graph
159 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5 016f976b1f Fix a batch of missing or wrong range validation
Memory::IsValidAddress and friends tested the extended-RAM range with
(address & 0x3F000000), i.e. at 16MB granularity, so they accepted the whole 16MB
block containing the end of RAM. That's harmless at 32MB and 64MB, but the Sora no
Kiseki SC/3rd HD remasters run with 0x04C00000, so addresses from 0x0CC00000 to
0x0CFFFFFF read as valid, and MaxSizeAtAddress then underflowed to ~4GB there -
which defeats ClampValidSizeAt and IsValidRange entirely for that window. Mask
with 0x3FFFFFFF instead, in all five helpers and the copies in MemMapFunctions.cpp.

IsValidTextureAddress's extended-RAM branch repeated the first branch's whole mask
rather than just its alignment bits, so it was dead code and extended RAM was never
accepted as a texture source.

ComputeTextureHash checked IsValidAddress(addr + sizeInRAM), i.e. only the end
address, which can land in a different valid region than the start - a VRAM texture
with a large enough computed size ends exactly at the base of RAM and "passes"
while reading far past the 8MB VRAM view. Use IsValidRange.

TextureReplacer::ComputeHash's strided path had no range check at all, unlike the
contiguous path right above it. Also clamp the pack-supplied reduce-hash factor to
1.0 - it's a reduction, and the ini parser only rejects exactly 0.

ZipExtractFileToMemory read an uninitialized zip_stat when zip_stat_index failed
(it ignored the return value) and sized a host allocation directly from the zip's
declared uncompressed size. Reached just by opening an archive.

Memory::Reinit ignored Init()'s return value, and DoState fed it a memory size
taken straight from the savestate. A bogus size made the map fail to allocate and
left base null, after which DoMemoryVoid wrote RAM through it. Validate the size,
propagate the failure, and roll back to the previous size if reinit fails.

314 pspautotests pass, all unit tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCPmm7FoQUoqrbMdhfqhQ2
2026-08-30 23:05:04 +02:00
Henrik RydgårdandClaude Opus 5 75ff0d406c Rename Memory::Lock() to Core_LockAgainstShutdown(), move it to Core
It stopped being about memory when CPU_Shutdown started holding it across the
whole teardown - it's what keeps kernel objects, the symbol map and the memory
map from being freed while another thread reads them. The old name invited the
reading that it locks memory *access*, which it has never done.

Memory::Reinit() now holds it across both halves rather than relying on
Memory::Shutdown()'s own acquire: between Shutdown() and Init() there is no
memory map at all, and a reader could slip into that gap.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 13:11:16 +02:00
Henrik RydgårdandClaude Sonnet 5 28cbb3a967 Add the scratchpad's missing kernel-mode mirrors, fix a mask bug hiding them
The scratchpad (PSP's repurposed-cache scratch RAM, 0x00010000+) was only
mirrored for user-mode access (cached 0x00010000, uncached 0x40010000) -
kernel-mode code sees it at 0x80010000/0xC0010000 (the kernel bit,
0x80000000, is independent of and combinable with the uncached bit,
0x40000000 - not "the uncached bit" as an earlier doc note in this branch
mistakenly called it). Missing entirely from MemMap.cpp's views[] table,
causing a real SIGSEGV the first time kernel-mode code (flash0:/reboot.bin)
touched it.

Adding the two missing views wasn't sufficient: the scratchpad range check
is duplicated eight times (IsValidAddress/IsValid2AlignedAddress/
IsValid4AlignedAddress/MaxSizeAtAddress in MemMap.h, and four more in
MemMapFunctions.cpp), and all eight used a mask (0xBFFFC000) that cleared
the uncached bit but kept the kernel bit, rejecting 0x80010000 as invalid
before ever reaching the now-mapped memory. Fixed all eight to 0x3FFFC000,
matching Memory::MEMVIEW32_MASK (which the JIT backends already used
correctly for the equivalent runtime check).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-13 11:36:42 +02:00
Henrik Rydgård 6836a2bd4e Libretro buildfix, add a comment 2026-08-12 14:26:10 +02:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård 3bd41376da More memory cleanup 2026-08-11 20:12:10 +02:00
Henrik Rydgård 9396030f02 More Read_U32 cleanup 2026-08-11 09:08:52 +02:00
Henrik Rydgård 732288c03a Brave Story: Hack to make the bloom effect run much more efficiently.
Fixes #19820

Not ready for merge, it needs more checks and maybe a compat flag.
2026-01-23 23:13:04 +01:00
Henrik Rydgård 34473fc621 Add a compat flag to map some extra memory at address 0.
Can be used to work around certain types of crashes without having to
disable fast memory.
2026-01-23 15:14:15 +01:00
Henrik Rydgård 2940c64c95 MemMap: Minor refactor 2026-01-23 14:45:33 +01:00
Henrik Rydgård 4ef11c8262 Memory::Memset: Ignore addresses if size == 0 2025-12-30 20:31:07 +01:00
Henrik Rydgård f5a211884b Minor cleanups, comments
Comments and warnings
2025-12-30 20:31:06 +01:00
Henrik Rydgård c9bab212a3 Make Read_Instruction safer 2025-05-14 15:14:08 +02:00
Henrik Rydgård ff37cbe184 Minor memory safety fixes 2025-05-14 09:39:09 +02:00
Henrik Rydgård 8f262df4fe Improve (?) handling of invalid addresses in Memset to avoid a crash 2025-04-30 11:50:43 +02:00
Henrik Rydgård 088a02bfdb Cleanup a lot of the bootup state management. 2025-03-30 14:02:29 +02:00
Henrik Rydgård 2edc3085a5 PSPPointer<>: Replace some fiddly memsets with use of a new FillWithZero function. 2025-01-05 23:43:41 +01:00
Henrik Rydgård c91169e702 Restore removed <algorithm> includes.
Turns out these were needed after all. For some reason, on Windows and
Mac, <algorithm> gets auto-included by something else so I don't notice
when it's missing, and MSVC's include dependency tracker doesn't see it
either.
2024-12-19 09:53:07 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård ffe05bdf58 Memmap error message improvements 2024-11-15 15:59:16 +01:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård 2853b2f6db Fix very old typo in memmap table, for the unusual "kernel+uncached" combination 2023-09-08 12:02:56 +02:00
M4xw 5b6bc0cea7 [MemArena] Honor MV_MIRROR_PREVIOUS on ReleaseView
Allows for clean teardown of the Memory Map for Switch
2023-06-22 00:01:38 +02:00
Henrik Rydgård 0bc7854062 Android: Don't assert on failed Find4GBBase 2023-01-12 01:18:52 +01:00
Unknown W. Brackets 0496ca32ff Global: Cleanup some minor includes and typos. 2022-12-27 08:33:07 -08:00
Unknown W. Brackets e49668eea7 SaveState: Correct missing switch case warnings. 2022-12-04 07:57:30 -08:00
Unknown W. Brackets 3a372aa615 HLE: Remove misc usage of WriteStruct().
Prefer PSPPointer and notifying.
2022-09-03 10:44:11 -07:00
Henrik Rydgård e6403d7157 Split GetPointer into two versions, to help with const correctness 2022-07-24 13:26:19 +02:00
Unknown W. Brackets b8ab7f39df jit: Lock around changes to the jit pointer. 2021-11-28 10:04:22 -08:00
Henrik Rydgård 6c51dabe9a Somewhat improved error checking in MemArena. 2021-07-07 19:01:42 +02:00
Henrik Rydgård 3be5c7bd9a Make the minimum items per thread explicit. Found some bugs, optional arguments are evil. 2021-06-12 21:21:28 +02:00
Henrik Rydgård 73871b9b7e Implement new thread manager, port stuff to it. 2021-06-12 13:03:53 +02:00
Unknown W. Brackets f987c715aa MemMap: Map 0xC0000000 into virtual memory.
Technically, it should be 0xA0000000, but that causes problems for how we
manage 32-bit address space.  This at least makes things consistent.
2021-04-23 23:21:51 -07:00
Unknown W. Brackets 32ea8734fb MemMap: Cleanup memory mirror pointers. 2021-04-23 22:43:21 -07:00
Unknown W. Brackets 4f96169357 Core: Init memory on multiple threads.
Also init volatile at the same time for consistency.
2021-04-16 00:53:50 -07:00
Unknown W. Brackets b2f3f06768 Common: Set a min size on threadpool work chunks.
This should avoid slicing loops, etc. into too many chunks.  Generalize
the memcpy a bit.
2021-04-15 23:59:02 -07:00
Unknown W. Brackets b2d5f19e5e SaveState: Use memmove for the copy. 2021-04-12 18:16:57 -07:00
Unknown W. Brackets c5729bbd5e SaveState: Use SIMD to copy RAM faster.
We know its size and base are typically aligned, so abuse those facts.
2021-04-12 17:37:48 -07:00
Unknown W. Brackets 3400e6e517 SaveState: Copy RAM using threads. 2021-04-12 17:37:48 -07:00
Henrik Rydgård 797cc41a1c Remove std::string from memblockinfo 2021-03-13 17:12:30 +01:00
Unknown W. Brackets 5119d79082 Build: Remove IOS define. 2021-03-02 21:04:03 -08:00
Unknown W. Brackets 88e2b9b740 Debugger: Notate memset tags directly. 2021-02-15 15:01:23 -08:00
Unknown W. Brackets f7740edc6d Debugger: Add more metadata for memory usage. 2021-02-15 15:01:21 -08:00
Henrik Rydgård dd7983c8dd Fix a bad check, causing masked memory to fail on non-32-bit platforms even if desired. 2020-11-02 23:11:44 +01:00
Unknown W. Brackets 2714d59ceb Core: Fix memory size check.
It can be 93 MB, just not larger.
2020-09-27 12:54:34 -07:00
Unknown W. Brackets b8342fb8ec SaveState: Rename ChunkFile files to Serialize.
Makes more sense and less weird than ChunkFileDoMap, etc.
2020-08-10 08:04:05 +00:00
Unknown W. Brackets 4b4e3432cd SaveState: Split Do() into a separate header. 2020-08-10 08:03:41 +00:00
Henrik Rydgård 0829543987 Third part of getting rid of PanicAlert 2020-07-19 20:34:02 +02:00
Henrik Rydgård c5e0b799d9 Remove category from _assert_msg_ functions. We don't filter these by category anyway.
Fixes the inconsistency where we _assert_ didn't take a category but
_assert_msg_ did.
2020-07-19 20:33:25 +02:00
Henrik Rydgård 626d173d10 Split the fault handling from MemMap.cpp to MemFault.cpp. 2020-07-15 12:12:57 +02:00