Commit Graph
308 Commits
Author SHA1 Message Date
Henrik Rydgård 68085804be Merge pull request #22093 from hrydgard/debugger-work
More websocket debugger features, per-module symbol maps
2026-08-17 23:20:11 +02:00
Henrik RydgårdandClaude Sonnet 5 83b1d13c88 Debugger: add kernel object introspection over the WebSocket API
New events, all read-only (never mutate kernel state, no cleanup/sort calls
- see HLEKernelObjectSubscriber.cpp's header comment):

- hle.object.list: every live kernel object of every type at once (uid,
  type, name, one-line quickInfo), with an optional 'type' filter. Uses
  KernelObjectPool::IterateAll(), a new type-agnostic sibling of the
  existing Iterate<T>().
- hle.eventflag.list/info, hle.mutex.list/info, hle.semaphore.list/info,
  hle.msgpipe.list/info, hle.callback.list/info: per-type full detail
  (all Native* status struct fields plus waiting-thread lists), reading
  straight off the classes exposed in the previous commit.

Also adds JsonWriter::DictScope/ArrayScope (Common/Data/Format/JSONWriter.h)
- RAII push/pop for pushDict()/pushArray(), used throughout the new
  handlers. A forgotten or early-returned pop() previously just produced
  silently malformed JSON; with 11 new handlers each writing a handful of
  nested arrays/dicts, that seemed worth fixing at the API level rather
  than trusting every call site to pair things up by hand. Existing
  handlers are untouched - this is purely additive.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 16:01:23 +02:00
Henrik RydgårdandClaude Opus 5 8265044a79 Add Hashmaps unit tests, stop tombstones from filling the table
DenseHashMap and PrehashMap are the open-addressed, linear-probing maps behind
the texture cache, the shader managers and the software renderer's
sampler/drawpixel caches, and had no coverage.

Writing the tests turned up a latent hang. Removal leaves tombstones, which
occupy probe slots exactly like live entries, but the load factor check only
looked at count_. So a workload that inserts and removes distinct keys keeps
count_ low forever while REMOVED fills the table, and no Grow is ever triggered.
Once there is no FREE bucket left, a lookup for a missing key has nothing to
terminate on - and the probe loops don't break out after their "Hit full"
assert, which is compiled out in release builds. The test reproduced it as a
hard hang in about a second.

Two fixes: count tombstones towards the load factor (rebuilding in place when
the load is mostly tombstones, growing otherwise), and make the probe loops
return instead of spinning if they ever do wrap all the way around.

Not reachable today - nothing in GPU/ calls Remove() on these maps, and
Maintain(), which exists to rebuild when tombstones pile up, is never called
anywhere. But Remove() is public API and the first caller to use it in a loop
would have hit an unexplained freeze.

Tests cover insert/get/miss/remove/size, tombstones not cutting a probe chain,
Iterate visiting exactly the live entries, Clear, growth past the initial
capacity, Rebuild compacting, a 20000-operation differential test against
std::unordered_map, and the tombstone churn above. PrehashMap gets the same
treatment.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 14:50:57 +02:00
Henrik RydgårdandClaude Opus 5 6a05ef290d Fix four WebSocket debugger bugs found while stress testing
memory.readString could kill the connection: it copied raw emulated memory
straight into a JSON string, so any address not holding valid UTF-8 produced an
invalid WebSocket text frame.

hle.data.remove wiped the name of a function sharing the address. Labels are
shared between data and function symbols, so removing the data label left the
function showing up in hle.func.list with an empty name.

hle.data.add silently did nothing outside a loaded module. GetModuleIndex()
returns -1 for e.g. a heap or stack address, and symbols under that index never
reach the active maps - so the add reported success while the symbol was
invisible to list, and rename/remove then failed with "No data symbol found".
Falls back to module index 0 ("no module, absolute address"), which is the right
answer for a label the user put somewhere after a memory.search.

hle.thread.list reported the thread's stack base address in a field called
initialStackSize. Renamed to initialStack, matching the SceKernelThreadInfo
field it comes from.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
2026-08-17 00:25:39 +02:00
Henrik Rydgård 4239c29928 BackgroundAudio: fix crashes and OOB reads parsing WAV/AT3 files
raw_bytes_per_frame (the 'fmt ' chunk's blockAlign field) is
unvalidated file data, and was used unchecked in three places:
- Divided into the 'data' chunk size to compute numFrames - a value
  of 0 divides by zero (crash).
- malloc()'d for raw_data was never null-checked before ReadData()
  wrote into it.
- Passed directly as the read length to the audio decoder on every
  frame, regardless of how much data is actually left in raw_data at
  the current offset - a bogus blockAlign larger than the real 'data'
  chunk size reads past the (padded) allocation into the decoder.
  Clamp it to what's actually available.

IsSimpleWAV() only checked raw_bytes_per_frame's upper bound, not that
it exactly matched one of the two cases Sample::Load() actually
handles (16-bit or 8-bit raw PCM) - a value in between passed the
check but matched neither of Load()'s conversion branches, leaving its
output buffer uninitialized and played back as heap garbage.

Reachable via a WAV/AT3 file parsed by BackgroundAudio.cpp - either
the menu background music preview (any EBOOT.PBP's SND0.AT3 track,
just from browsing the game list) or a user-configurable achievement
sound file.
2026-08-12 09:29:17 +02:00
Henrik Rydgård cd052ea640 Adjust the level of Claude-based paranoia here and there 2026-08-11 20:08:01 +02:00
Henrik RydgårdandClaude Sonnet 5 b0ab7fbaf7 FastVec::insert: fix off-by-one moving one element too many
The memmove length was computed from size_ after ExtendByOne() had
already bumped it, so it moved (oldSize - pos + 1) elements instead of
(oldSize - pos) - reading one uninitialized element past the old data
and writing one element past the new logical size. Currently masked
by ExtendByOne()'s growth policy always leaving capacity slack, but
a real overflow waiting for that assumption to not hold. Now captures
the old size before extending.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:03 +02:00
Henrik RydgårdandClaude Sonnet 5 2360705a43 CharQueue: don't assert when '\r' is buffered but '\n' hasn't arrived yet
next_crlf_offset() called peek() one byte past the currently buffered
data whenever a '\r' was the very last byte received (a normal TCP
fragmentation boundary) - peek() has no way to signal "not enough
data yet" and just asserts. Now checks there's actually a next byte
before peeking.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:03 +02:00
Henrik RydgårdandClaude Sonnet 5 c45ceb6e2f ShiftJIS: don't consume the null terminator as a second byte
next() would read a truncated lead byte's "second byte" unconditionally,
even when that byte was actually the string's null terminator - leaving
index_ one past the terminator, so a subsequent end()/next() call read
one byte out of bounds. Now checks for the terminator before consuming
it, returning INVALID without advancing past it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:02 +02:00
Henrik RydgårdandClaude Sonnet 5 406033dc3d RIFF/BackgroundAudio: fix OOB reads on short/corrupt WAV chunks
RIFFReader::ReadData() trusted its count argument completely and
memcpy'd straight from the internal buffer with no bounds check.
Hardened it to clamp against the buffer and zero-fill any shortfall,
as defense in depth.

The actual reachable bug was in BackgroundAudio.cpp: it read a WAV
'smpl' chunk into a vector sized by GetCurrentChunkSize(), then
unconditionally indexed smplData[28] (and, for the loop array,
smplData[36]) with no check that the chunk was actually that large -
a short/corrupt chunk in a game's background-music WAV caused a heap
OOB read. Also fixes &smplData[0] being UB when the chunk is empty.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:02 +02:00
Henrik RydgårdandClaude Sonnet 5 44b5a4df74 JSONReader: fix null deref in getInt/getFloat/getBool no-default overloads
These dereferenced get()'s result unconditionally, unlike the
two/three-arg "OrDefault" overloads which check. Hit on externally
sourced JSON: UI/Store.cpp reads the remote homebrew-store listing,
UI/DriverManagerScreen.cpp reads user-supplied GPU driver package
metadata - a field simply missing from either crashed the app instead
of failing gracefully.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:02 +02:00
Henrik Rydgård cd254c9ec3 Merge branch 'master' into minor-tweaks 2026-08-07 15:14:47 +02:00
Henrik Rydgård b5a880568d Fix some latent bugs, delete some code. 2026-08-07 14:45:45 +02:00
Henrik Rydgård 0323598941 Two bugs in Encoding 2026-08-07 14:43:56 +02:00
Henrik Rydgård 6f7de71ed0 Fix bugs in some UTF8 string handling utility functions 2026-08-07 11:56:14 +02:00
Henrik Rydgård a7b1b319ce Limit PNG decode dimensions to prevent decompression bombs
pngLoadPtr allocated the decoded buffer directly from attacker-controlled
PNG IHDR dimensions with no upper bound, so browsing a crafted game icon
or savedata could trigger a multi-gigabyte allocation.

- Add maxWidth/maxHeight parameters to pngLoadPtr (default 8192x8192)
  and reject images larger than the limits.
- Thread the limits through LoadTextureLevelsFromFileData,
  CreateTextureFromFileData, and CreateTextureFromFile.
- Limit game icons to 256x128 in GameInfoCache and IconCache.
2026-08-01 11:41:24 +02:00
Ren 3abb56e7f5 Savestate: store only live audio queue data (AudioChannel section v3)
FixedSizeQueue::DoState serializes the entire fixed backing store. For
the sceAudio channel queues that is 512KB per channel (32768*8 s16
samples), or ~4.6MB of mostly dead bytes in every savestate across the
nine channels - the live sample count at any moment is normally a few
KB. This addresses the existing TODO in DoState.

Add DoStateCompact(), which stores only the live [head, head+count)
region and restores it linearized at the front of storage. A wrapped
live region is written as its two pieces in pop order; since the POD
DoArray path writes raw bytes with no per-element or per-call header,
the single linear read on load consumes them identically. The count is
validated on load and a bad value fails the load cleanly via
p.SetError.

AudioChannel bumps its section to v3 to use the compact form; old
states still load through the unchanged full-storage path. This shrinks
every savestate by several MB uncompressed and cuts the copy/compress
cost of each save, including the rewind feature's periodic states.
2026-07-27 16:20:49 +02:00
Acts1631 e34fe29625 Validate ZIM image sizes before loading
Check the ZIM header, dimensions, mip count, allocation arithmetic,
and uncompressed payload size before allocating or copying image data.
This prevents crafted texture files from overflowing the image buffer.
2026-07-23 15:17:11 -04:00
Henrik Rydgård 93b570f8c7 Reverse the bits so we actually get the desired shader sorting order in the debug shader viewer 2026-07-07 20:16:37 +02:00
Henrik Rydgård 6508ae0aae Reorganize the vertex ShaderId bits, better sorting order 2026-07-07 20:16:32 +02:00
Henrik Rydgård c5931ea690 Unify more shader uniform update code, fix bug in fallback for Uint8x3ToFloat4. 2026-06-13 10:14:39 +02:00
Henrik Rydgård c46774c923 Fix the ImGe debugger vertex list 2026-06-02 14:53:37 +02:00
Henrik Rydgård 8113cb9147 Misc cleanup and renaming 2026-06-02 11:39:33 +02:00
Henrik Rydgård f60e27a9b7 Just some refactoring of the GPUStatistics struct, and more use of StringWriter 2026-05-29 14:40:31 +02:00
Henrik Rydgård ed274c8a7e Just some lint fixing 2026-05-13 11:37:26 +02:00
Henrik Rydgård bc9a047ef1 Search: Skip spaces and control characters, code cleanup, fix minor issue on desktop 2026-05-11 11:45:04 +02:00
Henrik Rydgård d108fe25d1 Rework constant buffer loading, barrier fix 2026-04-23 13:32:06 +02:00
Henrik Rydgård 61e76fcf68 Add the ability to hide adhoc servers using a "hidden" entry in the json.
Useful when servers are temporarily down.
2026-04-23 11:12:58 +02:00
Henrik Rydgård 786b835ba1 Smoother directory navigation using search. Normalize away full-width chars for search. 2026-04-16 12:46:34 -06:00
Henrik Rydgård 0153761de0 IniFile: Disallow section headers from starting at other line offsets than 0.
See #21479
2026-03-26 13:04:23 -06:00
Henrik Rydgård 56be37a2e4 Correct two minor bugs causing reported crashes 2026-03-13 10:16:25 +01:00
Henrik Rydgård cf28fd3a8d More cleanup in pngLoadPtr 2026-02-26 23:41:38 +01:00
Henrik Rydgård 48dc36be2e pngLoadPtr: Protect against over-reads from truncated files 2026-02-26 23:37:52 +01:00
Henrik Rydgård 5a5c7028b9 Assorted warning fixes and data initialization to please valgrind 2026-02-19 11:24:46 +01:00
Henrik Rydgård d8c40eefe8 Windows: Use a different window title for debug asserts
Fix bug in FastVec.h
2026-02-05 13:26:20 +01:00
Henrik Rydgård 841e4c8564 Add various checks trying to avoid various crashes found in Google Play crash reports. 2026-02-05 11:12:53 +01:00
Henrik Rydgård fb4d2a0f3f Fix rendering of the hold-overlay for main screen buttons without icons 2026-02-01 14:19:51 +01:00
Henrik Rydgård 31dc48c815 Add a unit test to mat4 x mat4 2026-01-31 13:11:02 +01:00
Henrik Rydgård c0cb010e42 MSVC project: Move the aemu_postoffice files into Common/ext 2026-01-22 01:35:08 +01:00
Henrik Rydgård 45c029cd7c Fix issue with missing strings in I18n.cpp 2026-01-22 01:30:38 +01:00
Henrik Rydgård 8b8c776491 Fix visual issue with rotation button on the pause screen 2026-01-19 17:00:41 +01:00
刘皓 fde7821b77 Merge branch 'master' into libretro-vfs 2026-01-08 11:59:20 -05:00
Henrik Rydgård 75f8a5c0e3 NiceTimeFormat: Show up to two minutes as seconds, and up to two hours as minutes. Avoids the plural problem and is nicer. 2026-01-06 20:52:37 +01:00
刘皓 18ac1ec937 Use the libretro VFS when reading/writing cheats 2026-01-02 17:07:22 -05:00
刘皓 5716cbd41d Use the libretro VFS interface in libretro builds 2026-01-01 00:24:01 -05:00
Henrik Rydgård 800a68f32d Sanity checking in Utf8.cpp, improve logging for missing translations 2025-12-15 17:17:23 +01:00
Henrik Rydgård f949bc8faf RetroAchievements: Show subset names 2025-11-27 11:03:56 +01:00
Henrik Rydgård 3116eba395 More UI work (#21035)
* Improve a couple of on-screen buttons (menu, fastforward)

* Fix the new continue button, oops

* Add some missing translations

* Split a translation string to make portrait look better

* More GameScreen redesign

* Don't accidentally go into game-specific mode

* Fix layout issue with popupscreens, fix context menu positioning

* One more icon
2025-11-24 20:33:13 +01:00
Henrik Rydgård 21026a38d7 Change Android launch mode to singleInstance, work-around minor text wrapping issue 2025-11-23 20:04:19 +01:00
Henrik Rydgård 6d1973edfb Add banners on the top of settings pages, if editing game-specific settings show the icon. 2025-11-09 08:51:41 +01:00