Commit Graph
378 Commits
Author SHA1 Message Date
LibretroAdmin 2698c7a6c1 samples/tasks/content_load: the close-waits-for-save lane holds the save in the core
A fast machine wrote the whole state before the close came, leaving it
nothing to wait for. The lane now takes a background save on the
threaded queue, which the harness core holds inside retro_serialize
until the close has waited three frames, so the save is in flight
however fast the machine is.
2026-11-16 16:49:58 +01:00
LibretroAdmin 6c2fddef40 samples: core_signature_test's loop index on Linux only; FLIPS_ASKED in d3d_failure_paths
core_signature_test declared its statfs loop index where macOS's clang
found it unused. d3d_failure_paths compiles d3d11.c's resize, which now
clears D3D11_ST_FLAG_FLIPS_ASKED, so the harness declares it.
2026-11-16 16:49:55 +01:00
libretroadmin ec27910f77 State tasks: a Load State cannot slip between a save's backup load and the save
A save over an existing file is two tasks: a load of that file for the
undo, whose callback pushes the save. With threaded tasks the queue
stops refusing a blocking task once the one in flight has finished on
its thread, so a Load State pressed after the backup load was done and
before its callback had run was pushed there and then, and read the
file the save was about to replace. The state tasks' own counts say
whether one is in flight - pushed, its callback still to come - and a
request is held behind it until then, as it is behind one still
running.

The state-load-latency lane of content_load_test takes that case, and
bounds a load by a display's frames where the machine is too busy for
the harness's own, microseconds long, to mean anything.
2026-11-16 16:24:37 +01:00
LibretroAdmin f54dea8c94 core signatures: volume facts from the VFS, asked once per check
The filesystem lists, the /proc mount lookup, the statvfs read-only
tests and the Windows drive-letter test move out of the check onto
retro_vfs_file_volume_impl() and retro_vfs_stat_volume_impl().

On the way, a quick check of a core with no record asks less:

- The open's one fstatfs() now gives both ctime_kept and whether the
  mount is read-only; before, the exemption and package rules each
  asked statvfs again.
- The identity the open took carries the owner, group and mode (never
  stored), so the exemption rule no longer fstat()s the file again;
  the macOS package re-check uses it too.
- RetroArch's own mount id is looked up once with the rest of its
  self lookup, instead of opening /proc/self/exe and asking its mount
  on every check.

Linux, unrecorded core, open + quick check: 21 -> 14 syscalls, about
5.9 -> 3.8 us. Every answer is unchanged: the rules read the same
uid, gid, mode, read-only and mount facts as before.

core_fd_mount(), core_fdinfo_mount() and core_fs_*_keeps_ctime() are
gone; core_file_unwritable() and core_file_in_package() take the
identity and RetroArch's own lookup.
2026-11-16 16:01:19 +01:00
LibretroAdmin 584a1982ef core signatures: look RetroArch's own file up once
core_self_find() - the device and owner of RetroArch's own executable
(or, on Android, its library or the APK holding it), for the store's
device and the folder exemption - stat()ed that file on every call:
each trust store load and save, and each quick check that reaches the
exemption (a core with no record). The file can't change under a
running RetroArch, so it is now looked up once per process.

Lock-free, with no wait: a caller that finds nothing published looks
it up itself and uses its own answer; the first to claim the slot
(retro_atomic_fetch_or) publishes it with a release store, and readers
take it with an acquire load. A lookup that finds nothing is kept as
such. Windows had no lookup and still has none.

One stat() of the executable per process where a store load and a save
made two (counted with strace on Linux), and none for later quick
checks. The core_signature harness checks a second call gives the same
answer; it passes on Linux and as a 64-bit Windows build under wine,
core_load_check passes under ThreadSanitizer, and core_trust_runtime,
core_install_check, core_load_paths (32 scenarios) and core_warning
pass; RetroArch builds with no new warnings.
2026-11-16 10:27:09 +01:00
LibretroAdmin a0ee2bd8a0 core signatures: no folder walk when a core's record answers anyway
Every quick check took the folder key first: SHA-256 of realpath() of
the core's folder, one readlink() per path component and an access
check - five or six system calls for a cores folder under ~/.config,
more the deeper it sits - on every core load, before even looking for
the core's record.

The key matters on the record path for one thing: a record of a signed
build is too old where its folder has seen a newer build of the same
name. core_check_record_folderless() says when no folder can make that
true - no build time, kept at any age (Always Trust), or no newest
build of its name anywhere newer than its own, the usual case of the
newest build seen - and the quick check then passes on the record
without taking the key. Otherwise it takes the key and checks as
before, so a downgraded core still meets the newest build of its
folder.

Nothing reads the key after a pass: a quick pass has neither record
nor raise_newest set, so core_trust_apply() returns before it, and the
key is still taken whenever the check goes on to hash. core_check_quick's
comment now says c->folder is zero after such a pass.

Measured on Linux, quick check of a recorded 20 MB core in
~/.config/retroarch/cores (open, identity, record), best of six passes
of 20000, three interleaved runs:

  unsigned record   before 3940 3829 3768 ns   after 1663 1538 1448 ns
  signed record     before 3771 3768 3792 ns   after 1463 1465 1521 ns

with five readlink() calls and a faccessat() fewer per load.

The core_signature harness checks the rule (newest of its name: no
key; a newer build of its name elsewhere: key; no build time; Always
Trust; no record) and, end to end, a quick pass on an Always Trust
record leaving the key unfilled while a newer build in the folder
still takes it and refuses. It passes on Linux and as 64-bit and
32-bit Windows builds under wine; core_trust_runtime,
core_install_check, core_load_check (and its Android build),
core_backup's signature test, the signed install test, core_load_paths
(32 scenarios) and core_warning pass; RetroArch builds with no new
warnings.
2026-11-16 09:52:01 +01:00
LibretroAdmin 1426691450 core signatures: open, read and identify cores through the VFS
The check kept its own per-platform file code beside the VFS: an open
denying writers (CreateFileW share-read on Windows, open() with
O_NONBLOCK/O_NOCTTY/O_CLOEXEC and an S_ISREG fstat elsewhere), reads,
file identity from the handle, and on Windows a mapping of its own for
the hash. All of it now goes through the VFS:

- core_file_t is the VFS stream itself (no wrapper allocation), opened
  with RETRO_VFS_FILE_ACCESS_HINT_IMPL_STABLE. A path the VFS opens by
  another scheme (smb://, cdrom://) drops that hint and is refused, so
  no stream is checked without its guarantees.
- Reads are retro_vfs_file_read_impl, retried here on EINTR as before
  (the VFS's descriptor read returns -1 then, and that is left alone).
- Identity is retro_vfs_file_identity_impl. On Windows its times are
  put back in seconds from 1601, as the trust store has kept them, so
  records already made still match. fs-verity, ctime_kept and the
  ownership checks stay here: they are the check's policy, not I/O.
- On Windows the hash runs in place over the mapping the VFS lends
  (retro_vfs_file_map_impl) instead of mapping 32 MiB views itself;
  still only on a local fixed drive, and a 32-bit build keeps reading
  cores over 256 MiB, since the lent mapping lives as long as the file
  is open. Elsewhere it reads, as before.

core_signature_io.c loses its open, close, read, identity and view
code for both platforms.

Cost, Linux, open + identity + close of a 20 MB core, best of six
passes of 20000, three runs: 1459/1439/1490 ns before, 1512/1516/1521
ns after - the same system calls (openat, two fstat, fstatfs, close
per load, counted with strace), about 50 ns more for the VFS stream's
allocation and copy of the path. On Windows the stable open adds
GetFileType and GetFileSizeEx to the CreateFileW it was; not timed on
Windows.

The core_signature harness passes on Linux and as 64-bit and 32-bit
Windows builds under wine (22416 / 22396 checks), the 40 MiB file
hashed through the mapping; core_trust_runtime, core_install_check,
core_load_check (and its Android build), core_backup's signature test,
the signed install test, core_load_paths (32 scenarios) and
core_warning pass; RetroArch builds with no new warnings.
2026-11-16 09:08:30 +01:00
LibretroAdmin b6bc4c202b core signatures: hash a core in place from a mapping on Windows
core_hash_step read each 64 KiB of a core into a heap buffer and hashed
the buffer: a copy of every byte of a core seen for the first time. On
Windows the check's handle denies writes and deletes, so nothing can cut
the file short while it is hashed, and the hash now runs straight over a
read-only mapping of it, a 32 MiB view at a time so a 32-bit process
needs no address space the size of the core. The buffer is then never
allocated. Each step still hashes at most 64 KiB, so tasks pace it as
before.

Only for a file on a local fixed drive, named by a drive-letter path: a
read through a mapping fails as an exception rather than an error, and a
network share or a removable drive can fail mid-file, where ReadFile
reports it and the check refuses cleanly. Those, and any mapping or view
that can't be made, are read as before, a failed view carrying on from
where the mapping stopped. LEGACY_WIN32 keeps reading (no
SetFilePointerEx or GetFileSizeEx before Windows 2000).

Elsewhere nothing changes. A POSIX mapping of a file another process can
shorten raises SIGBUS on the next page touched, and the files the check
knows nobody can write are the ones it never hashes.

tools/core_hash_bench measures the mapped hash 8-10% faster than the
buffered one with the file cached (on Linux and under wine; not yet
timed on Windows itself). The core_signature harness hashes a 40 MiB
file by its full path, mapped and across a view boundary, and by a
relative path, read, against the digest of its bytes; both pass under
wine as 64-bit and 32-bit builds.
2026-11-16 08:43:39 +01:00
LibretroAdmin 0c228a1d0d core signatures: poll a parked load only while one waits
core_load_check_iterate() ran every frame, a call into another
translation unit even in a build whose check is dormant (no signing key
compiled in) or with nothing parked. A park now raises a frame_work bit,
RUNLOOP_WORK_CORE_PARK, and its drop lowers it, so the frame loop skips
the call as it does Discord, cheats and the camera when they are idle.

Every way a park ends goes through core_load_park_drop(), so the bit
can't outlive it. The core_load_check harness now polls only under the
bit, as the frame loop does, and checks it rises with a park and falls
once the park has run.
2026-11-16 07:12:21 +01:00
davey bac280f9d2 core signatures: the load check on by default
HAVE_CORE_LOAD_CHECK now builds wherever HAVE_CORE_SIGNATURES does.
CI builds the tree once without it.
2026-11-16 07:12:21 +01:00
davey c591125458 core signatures: a harness for real loads through the load check
The shipping objects of a build with the load check and the public
test key load cores the way users do, one mode a run: a startup -L
checked in place and answered from the menu (Load Once, Always Trust,
a core outside the cores folder, there also with its probe cached by
an earlier session, with content, a core that needs content, and one
that changes before Load Once, which asks again) or, with no menu,
refused or waiting for the seed; staged loads with and without a task
worker, one whose core changes before the core stage opens it, and
one marked as a lobby join marks the load in flight, past its preload
stage, which isn't parked; a playlist Run, a parked subsystem load,
and subsystem loads from a playlist and from netplay, which say a
refused core wasn't loaded; netplay lobby joins of a refused core,
its probe cached or not and, uncached, from the dummy core too, which
say so and leave netplay off; a quiet probe and a parked Load Core,
one that fails to open after Load Once, which says so, and, with no
menu, one refused again on its re-run, which says only that it was
refused; the first run's seed, a subsystem load while it runs, which
says the seed is still checking, and a core the seed passes that
fails to open, which says so where a held back load doesn't;
run-ahead's copy, Load Once lasting through Close Content until
another core loads, another load ending a waiting park, a built-in
core's load, which checks no core and ends a park as another core's
load does, and, on Windows, a \\?\ core path ending in '.' given to
-L, Load Core or a playlist Run, which is refused as named and asks
nothing.

The companion UI's Load Core has modes of its own: a first Load Core
of an untrusted core asks and Load Once starts it; Load Core of the
running core, of a trusted core and of one that needs content; and
Load Once on a parked Load Core whose core changed since its check,
which asks again, for the companion UI's start and the menu's load
alike. Some answers press the Security Warning's buttons through the
menu, as a pad does.

build.sh links the harness on macOS too, with ui_cocoa.m's main()
renamed; the no-menu re-run mode, which forces the quick check's
answer through ld's --wrap, is skipped there. The menu-harness job
builds with the check and runs every mode.
2026-11-16 07:12:21 +01:00
davey def1005deb core signatures: fs-verity on a core after its first full check on Android
After a load check that passes in full, the check task turns fs-verity
on where the filesystem and the app allow it, then records the core's
identity again with its digest, so later loads hold only for the file
the kernel keeps unchanged. Where it can't, the identity record works
as before.

A refused enable can still move the file: with fs-verity's
require_signatures set, f2fs rolls the attempt back by truncating the
file, which moves its mtime and ctime. The core is then hashed again
and recorded as it is after the attempt, only if it didn't move again
while hashed, so its record still matches it on later loads.

On Linux the unit harness also builds core_load_check.c and
core_load_file.c as for Android, with ANDROID defined over the tree's
NDK stubs and a stand-in linker that reads the fd as Android 5's
does, and runs the fs-verity and load-by-fd tests on that build, so
they take the Android code paths.
2026-11-16 07:12:21 +01:00
davey 6259694cbf core signatures: run-ahead loads its copy only if it matches the running core
With a trust store, run-ahead gets its second instance back. The copy
task hashes the copy and compares it with the running core's hash:
from its check, or from its file, if that is still the file loaded. It
loads the copy from the file it hashed. A copy that doesn't match, or
won't load, is deleted and run-ahead keeps one instance.

A staged load's take now grants the stage's own quick pass even when a
probe's quick pass of another core took its place while the worker
opened the core, so that core keeps its record and run-ahead its
source.
2026-11-16 07:12:21 +01:00
davey 7092b43a2b core signatures: a startup load the check holds back asks from the menu
-L and launcher loads the check refuses fall back to the dummy core
and menu whatever --load-menu-on-error says, and run again as a menu
load after Load Once or Always Trust; with no menu they fail as
before, saying how to approve the core. A re-run of a core that starts
without content, refused again because the core changed since the user
was asked, asks again. On a first run, a core the pending seed covers
waits for the seed instead of a guess.

A load the check held back no longer also says "Failed to open
libretro core": the seed's wait, the Security Warning, the refusal
with no menu or a lobby join's own message says why. A core the check
passed that the loader can't open keeps the message.

A startup load that can only fail once the frame loop runs, such as a
seed wait with no menu, quits and RetroArch exits non-zero, as for one
that fails before. On macOS, where AppKit and the run loop observer
end a quit with exit(0), such a quit exits with 1.

A netplay lobby join whose core's probe is cached opens nothing at its
core push, so the load that opens the core is the one refused: the
join's own, or an unload's still in flight. The join marks that load.
Its refusal is said and netplay left off, as for a refused push,
before the dummy core's init probes the core for the menu, and the
load isn't parked, even when the mark lands after its preload stage.
2026-11-16 07:12:21 +01:00
davey 3bbec782cd core signatures: the load check parks a refused load and asks
core_load_check_park() holds a user-started load the check refused:
Load Once runs it again from the file the user was asked about and
lasts until another core loads, Always Trust records the core first,
Cancel drops it. With the trusted list full, Always Trust loads the
core this once and says so. A core the pending seed covers waits for
the seed. A park and a staged load of the same core share one check,
the stage's re-check of a file that changed included. Without a menu
to ask on, the core isn't loaded and RetroArch says how to approve it.

A re-run starts with no refusal recorded, so only its own open can
refuse it again: one that opens nothing, such as a load whose core's
probe is cached, isn't asked about again.

Any other load, built-in cores included, ends a waiting park, and a
newer park replaces it. A park whose warning another Security Warning
replaces is logged. Nothing parks yet.
2026-11-16 07:12:21 +01:00
davey 6944cbdb6e core signatures: a staged load's core is checked in its preload stage
With a trust store the preload stage is the core's check, with or
without a worker. A core the quick check doesn't pass is hashed by a
task; one the pending seed covers waits for it first. A worker then
opens the core from the file that passed, or the core stage opens it
from the slot. The core loaded last passes on its own record, as its
reload does: no second hash and no second open file. The stage
resolves the core path as load_dynamic_core() does, so on Windows it
too leaves a \\?\ path ending in '.' as given.

A pass whose file changed before the stage hands it over, or before
the worker opens it, is checked again instead of ending the stage with
neither a library nor a refusal. The first such re-check in a stage is
logged.
2026-11-16 07:12:21 +01:00
davey 349a3ae780 core signatures: the last loaded core passes its reload until another core loads
The core loaded last keeps its pass after the unload, so its reload
after Close Content and menu or driver init pass without another hash
or warning. Where a file's identity can't bind the pass (Windows, and
Linux filesystems that don't keep ctime), its checked file stays open
to bind it. Loading another core ends the pass. So do the Core
Updater, Core Manager delete and core restore: on the main thread,
before they replace or delete a core file, they close every core file
the check keeps open for a pass or a refusal.
2026-11-16 07:12:21 +01:00
davey f1675e7f4f core signatures: the load check's gate and check task
core_load_check.c checks a core before it is opened: the quick check
on the main thread, else a task hashes it in slices of the shared I/O
window and keeps the result for the load, bound to the file it
checked. A refusal tells whether it only waits for the first run's
seed. Built with HAVE_CORE_LOAD_CHECK; nothing calls it yet. Its unit
harness runs in the samples-tasks job, under ASan and UBSan, TSan and
mingw-w64.

On Windows the check reads the file LoadLibraryW will load: a name
with no '.' is read as <name>.dll, and a \\?\ path ending in '.' is
refused, since CreateFileW opens that name as written while
LoadLibraryW may drop the dot and map another file.
2026-11-16 07:12:21 +01:00
davey dfc440096f core signatures: load a core from the file that was checked
core_load_file() is the loader the load check will use, so that a file
swapped after the check is not the one loaded. On Android it loads from
the checked fd with android_dlopen_ext, named by the core's real path.
On Windows it loads by path while the check's handle, which shares only
reads, holds the file. Elsewhere it loads the path. On Apple,
core_load_framework_binary() names the binary dylib_load opens inside a
.framework, so the check can read that file. RetroArch doesn't build or
call either yet; the core_signature harness tests them.
2026-11-16 07:12:21 +01:00
davey 9b3ddf682a core signatures: fs-verity digests in the identity check
A record that carries an fs-verity digest holds only when the kernel
measures the same digest on the open file. Helpers to enable and
measure fs-verity, for the load check to use on Android; filesystems
and kernels without it, and files that aren't ours, are skipped.
2026-11-16 07:12:21 +01:00
davey 6d6c22d851 core signatures: trust cores inside RetroArch's own package
Whoever can change RetroArch's own .app bundle, or the read-only mount
its binary runs from (Flatpak, AppImage, Snap), can replace RetroArch
itself, so cores there are exempt like it. Linux compares mount ids,
not devices: a Flatpak user install's read-only view of the home shares
/app's device. Not on Windows, Android or the BSDs.

The bundle is looked up through CoreFoundation, which RetroArch and the
core_signature and core_install_check harnesses now link on macOS.
2026-11-16 07:12:21 +01:00
davey 9cbe001856 core signatures: Android's system account and APK-loaded library
/data and /data/app are system:system 0771, so Play cores in
nativeLibraryDir failed the exemption: uid and gid 1000 now count as
root on Android. A library loaded from inside its APK has an <apk>!/
path that stat refuses; RetroArch's device and owner come from the APK.

Android takes the 65534 fallback for the overflow uid: its SELinux
denies reading /proc/sys/kernel/overflowuid, which logged an audit
denial on every check.
2026-11-16 07:12:21 +01:00
davey 9a3d791dde core signatures: expose the checked file's fd
The load check loads a core from the file it checked; Android passes
the fd to android_dlopen_ext.
2026-11-16 07:12:21 +01:00
davey 670e274643 core signatures: let test-key builds hide their notice
Builds that trust the test signing key get a Test Signing Key toggle
in Notification Visibility. Off hides the on-screen reminder; the log
line saying the build trusts a test key stays on every launch.
Release builds have no such setting.
2026-11-16 07:12:20 +01:00
davey 046ed16734 core signatures: a .sig for a core already up to date
Update Installed Cores skips a core whose CRC matches the buildbot's,
so such a core never got a .sig. With checks on, the run now fetches
the .sig of an up-to-date core that has none and checks it against
the core in place on its own, never through the core's trusted hash.
One that checks out is placed and recorded; one that doesn't is only
logged, and the next run asks again. A .sig-only download that was
never hashed places nothing. Fetching a .sig changes no core file, so
it forces no core info rescan and no contentless cores reload.
2026-11-16 07:12:20 +01:00
davey 1d885f83ee core signatures: the core updater checks every download
The updater fetches <core>.sig into the core's staging folder before
the core itself; with checks on, a missing one refuses the update
there. Every download is then staged and checked under its install
name, and only a core that passes replaces the installed one, its .sig
beside it, its record made on the main thread. A refused core is named
in a message and the old core stays; Update Installed Cores carries on
with the rest. Builds without keys update as before.

Only a 404 or 410 for the .sig means the core is unsigned; any other
failure ends as a failed install, never as a bad signature. A checked
download that holds anything but the core and its .sig is refused.
The core's staging folder is cleared before a download and at every
end, a capped number of entries a tick, so a hostile archive can't
stall a frame. An update cancelled after the backup task moved the new
core in still places its .sig and records it.
2026-11-16 07:12:20 +01:00
davey c88283d7a3 core signatures: check a core before a restore installs it
Restoring a backup or using Install or Restore a Core now unpacks the
core under its own name beside the one it replaces and checks it with
the .sig kept beside what was picked. A restore from RetroArch's own
backup list may be an older build. Anything that doesn't pass goes to
the Security Warning; Install and Trust runs the restore again and
installs only when the core is still the one the warning showed.

On a Play Store build a core installed through Play Feature Delivery
is a link into the APK's read-only lib folder; a restore stages beside
the link and deletes it only once the core passes. Install and Trust
that can't run the restore again says so.
2026-11-16 07:12:20 +01:00
davey a7c00a8fcb core signatures: backups keep the core's .sig
A backup gets a copy of the core's .sig beside it, whether it is
written or moved into the backups before an update, so a restore can
check it. Pruning and Delete Backup remove it with the backup.

When an update's install move puts the new core in, the old .sig is
set aside as in core_install_commit(), and the backup's copy of it
goes if the move rolls back.
2026-11-16 07:12:20 +01:00
davey f1df7cf157 core signatures: check a core staged for install
Adds the check the install paths will use: a core is staged under
the name it is installed as, checked there and only then moved into
place. The check hashes the staged file even when a record or the
folder rule would pass the file in place: those vouch for the file,
not the download. A check reads as failed until it ends, so a cancel
is a failure.

The old .sig is set aside as <core>.sig.old while the core is renamed
in, then deleted, or renamed back when the rename fails; the new .sig
is placed and the identity read again after the rename. A crash in
between leaves a core without a .sig, never a new core beside the old
one's .sig, and a stray .sig.old is never put back. A core that passed
by its trusted hash keeps its staged .sig only if that .sig verifies
on its own.
2026-11-16 07:12:20 +01:00
davey b54fc15ea9 core signatures: Settings > Core > Check Core Signatures
The value lives in the trust store, not retroarch.cfg, so no config
file can turn the checks off. Turning them off always asks first with
the OK/Back confirm, even with confirmations off; turning them on asks
nothing. The row is hidden when the feature is inactive, and in a
session whose store couldn't be read it shows its value but says it
can't be changed.

The row is a switch like Core Lock's: Left and Right leave it alone
when it already sits on that side, and Start resets it to On.
2026-11-16 07:12:20 +01:00
davey 738584cd10 core signatures: the Security Warning
core_warning_push() holds one request, a copy of the check that failed,
and opens a screen built like Load Archive / Open Archive: the reason
and the full-access warning as rows above the choices, the line about
turning the checks off below, the cursor on Cancel. An install offers
Install and Trust, a load Load Once and Always Trust This Core, a core
that couldn't be read Cancel only. The text rows are wrapped short
because no menu driver wraps a label. The core updater's two refusal
messages are added with the rest.

The caller's callback gets the choice, or Cancel on Back, a newer
request or quit. Each request has a serial that its screen's rows
carry, so OK on rows built for an older request refreshes the screen
rather than answering the newer one. OK and Back take the screen off
the stack before the callback runs, so a callback that changes the
menu stack (a load starting content) isn't followed by a pop of the
wrong screen. A newer push runs the replaced request's callback with
Cancel inside itself, with the newer request already in the slot; a
choice made from there is ignored.

A request still pending when a stack flush (a tab switch, a menu
reinit) takes its screen away gets it back on the next frame; one
answered before its screen came up leaves none. Info on the screen
does nothing. core_warning_push() refuses during deinit's cancel and
when the menu driver shows no screens (null), so the caller keeps its
request instead of one nobody can answer.

samples/menu/core_warning drives the screen through the shipping
handlers, with core_signature.c rebuilt around the test key and a trust
store of its own.
2026-11-16 07:12:20 +01:00
davey e637d109f5 core signatures: trust the cores already installed, once
With the load check built in, the first run with a store that was never
seeded hashes every core in the platform's built-in cores folder, a
read or a folder entry at a time within the per-frame I/O window, and
trusts each one, up to the store's 256 trusted hashes. Only what
lstat() calls a regular file is seeded, so a symlink in the folder
can't bring in a file that lives elsewhere; a hardlink's bytes are the
folder's own. On Android the seed walks <ApplicationInfo.dataDir>/cores,
which no intent extra moves, rather than the default core folder, which
follows the DATADIR extra; when ApplicationInfo can't be read the seed
doesn't run that launch.

The store is marked seeded once the walk finishes or the folder doesn't
exist. A seed cut short at quit, or a folder that is there but can't be
opened, is seeded at a later start. If trust was recorded for at least
one core, a notice says once that cores are now checked.
2026-11-16 07:12:20 +01:00
davey 3e010f2ce6 core signatures: keep the trust store in RetroArch
core_trust_runtime owns the one store: loaded at startup before any
core is opened, saved by a task after each change with one write out at
a time, and written once more at quit, within the exit drain's limit,
if a change didn't go through. A store that can't be read is left alone
and the session's changes stay in memory. With no keys compiled in,
nothing is loaded and the feature acts as if it weren't built. A
test-key build says so at every launch.

Test-key builds keep their store in core_trust.testkey, so what they
record never reaches a release build's store on the same account. On
macOS the store always lives in ~/Library/Application Support/RetroArch,
whatever portable.txt, RAPortableInstall or a Steam build say about the
app's folder.
2026-11-16 07:12:20 +01:00
davey ce61e3d3a8 core signatures: compile the public test key in on request
HAVE_CORE_SIGNING_TEST_KEY appends RFC 6979 A.2.5's P-256 key, the
harness's test key 1, to the built-in keys. Its private half is public,
so such a build runs cores anyone can sign: it exists to test real
RetroArch before libretro has keys and is never on by default.
2026-11-16 07:12:19 +01:00
davey 948af61c31 core signatures: decide whether a core is trusted
The check, in order: off; an identity record of the file, for a build no
older than the newest seen in its folder; or, on POSIX, a core this user
can't have put there (the exemption below) answers without hashing.
Otherwise the core is hashed and a trusted hash, then a .sig signed by a
known key, decides. A signed build older than the newest seen for that
name in the same cores folder is refused, unless it is a restore of
RetroArch's own backup (CORE_CHECK_ALLOW_OLDER). The folder is keyed by
its canonical path, so ., .., repeated separators and symlinks (POSIX)
or case (Windows) don't change it. On Android every folder has the same
key, so the newest date is per core name whatever folder holds the
cores. The outcome goes back to the main thread to record.

An identity record answers only for a file whose filesystem keeps ctime
and that is on the store's filesystem or on RetroArch's own, which
loading the store finds through core_self_find. A core that can't be
opened, read or identified, or whose folder can't be keyed or whose
size changed while it was hashed, is CORE_CHECK_ERROR: never trusted,
and nothing is recorded. The .sig is read until its end or until a
buffer longer than any valid one is full.

The unsigned exemption needs the core on RetroArch's own filesystem, and
the file and every folder up to / not writable by this user, owned by
root or by the owner of RetroArch's binary, never by the overflow uid a
user namespace shows for accounts it doesn't map, and without group
write unless the folder is sticky or, on Linux and Android, the group
is root's; on macOS and the BSDs gid 0 is wheel, the admin users.
Read-only mounts skip the owner and group rules. When the overflow uid
can't be read only root's files qualify. Windows has no exemption. A
.sig that is a FIFO is refused without waiting for a writer.
2026-11-16 07:12:19 +01:00
davey 06ee72eb82 core signatures: load and save the trust store
The store is read whole, with a size cap. A file that exists but can't
be looked at or read, isn't a regular file, or was written by a newer
format version is left alone, and the store stays read-only for the
session, so nothing it holds is lost. A file that reads but is damaged
is renamed to core_trust.bad, replacing an older one, and the store
starts empty with every flag clear: CORE_TRUST_SEEDED too, so the
one-time trust of the cores already installed runs again. If it can't
be renamed it is treated as unreadable. Running out of memory is never
damage. Each load also takes the device of the store's folder:
identity records are kept only for files on that filesystem (the next
commit adds RetroArch's own), and none when it can't be read or on
Windows.

Another instance can share the file, so each save reads it again and
puts this store's changes since it was last loaded or saved over what is
there now: the newer build date wins and trusted hashes are the union.
Only newest entries this instance raised are merged, so a save at the
list's cap never brings back what another instance's save dropped. A
hash the file has no room for stays a change for a later save. One
write runs at a time, through a temporary of this instance's own and a
rename; a change while one is out writes again after. The file lives in
Android's internalDataPath and elsewhere in the platform's default
config folder.
2026-11-16 07:12:19 +01:00
davey 28ed309004 core signatures: trust store contents
Identity records, trusted hashes, the newest build time seen per core
name in each cores folder, and a few flags, serialised big-endian with a
SHA-256 trailer and parsed strictly. Only the main thread changes the
store; each change publishes a new reference-counted set and never
touches one already handed out, so a task reads its own set with no
lock. Identity records are a bounded cache and trusted hashes refuse
when full. The newest list holds 4096 entries; when it is full a new
one replaces the oldest build, ties going to the lower folder key and
then the lower name, so the list's order never decides. A record is not
kept for a build older than the newest seen in its folder, unless it
comes from Always Trust or a restore, and Always Trust refuses a check
that ended in CORE_CHECK_ERROR.

A record is made only of a file whose filesystem keeps ctime and that
is on the store's own filesystem or on RetroArch's, as
core_trust_set_device gives them: whoever can write either raw can
rewrite the store or RetroArch itself anyway. A core anywhere else is
hashed on every check, and a trusted hash still makes it OK. struct
core_check carries a check's outcome to the main thread to record; the
check that fills it follows.

From here the samples-tasks job also runs the harness under TSan, with
a worker reading a set while the main thread changes the store.
2026-11-16 07:12:19 +01:00
davey 6fbac3584e core signatures: identify and hash an open core
A core is opened once and both identified and hashed through that
handle, so what is hashed is the file that was identified: fstat's
device, inode, size and, where the libc has them, nanosecond times on
POSIX; volume serial, 128-bit file id, size, write and change time on
Windows, where GetFileInformationByHandleEx is looked up at run time
and the file is opened without write or delete sharing. A FIFO is
refused rather than waited on. Hashing goes a 64 KiB chunk per step so
a task can pace it.

The identity also says whether the file's filesystem keeps ctime
itself, from fstatfs on the same handle: ext2/3/4, xfs, btrfs, f2fs,
tmpfs, zfs and bcachefs on Linux and Android; apfs, hfs, ufs, ffs, zfs
and tmpfs on macOS, FreeBSD, OpenBSD and DragonFly. Only there does the
kernel keep ctime against every writer that goes through it, so only
there may an identity record stand in for a hash. Stacked and network
filesystems, FAT, exFAT and NTFS are not on the list, and Windows never
is: any writer can set ChangeTime.
2026-11-16 07:12:19 +01:00
davey acd64afe05 core signatures: parse and verify a .sig
A core's <core>.sig names its key, build time, SHA-256 and file name,
signed with ECDSA P-256. Parsing takes only an exact-length file and
refuses a build time of 0, which the rollback check would read as none;
the digest verified is our own SHA-256 of the signed bytes, and success
is p256_ecdsa_verify() == 0. libretro's keys go in core_signing_keys.h,
empty for now. Nothing calls this yet, and only the harness builds it
until the check is wired in.

The harness in samples/tasks/core_signature checks against fixtures that
gen_fixtures.py makes with tools/core_sign.py. The samples-tasks job
runs it under ASan and UBSan, and mingw-w64 with Wine. The CI local
runner job runs core_sign.py's self-test, with its RFC 6979 vector where
OpenSSL is 3.2 or newer, and checks the fixtures on any OpenSSL: each
signed header is rebuilt and each signature verified with openssl, and
on 3.2 or newer the fixtures are also signed again and compared.
2026-11-16 07:12:19 +01:00
LibretroAdmin 8756cdc136 core updater: a download's handle outlives its handler until it retires
The push's duplicate finder reads remote_filename through task->state,
from other threads than the worker, for as long as the task is
findable. The handler leaves task->state set; the last reference still
tears the download down where it is dropped, and the struct with
remote_filename is freed once that teardown and the task's cleanup
have both let go of it. A finished download does not count as a
duplicate, as before.

download_backup_wait_test gains a lane that runs the finder on the
main thread against forty downloads finishing on the worker; under
TSan it reports the race on task->state.
2026-11-13 02:30:07 +01:00
davey 93cc8b8fd2 tasks: a playlist thumbnail download keeps its handle until it retires
A finished task stays findable until it retires, and the push's
duplicate finder reads the handle's playlist_config, so the handle is
freed in cleanup, shared with the entry download. The playlist itself
is freed by the handler when the download finishes, on the worker, so
retirement on the main thread frees only the small handle.

The pl_thumbnail_wait_test "finished" lane pushes a second download of
a playlist whose first one has finished but not retired.

Closes #20075
2026-11-13 02:30:03 +01:00
LibretroAdmin fd17192acb formats: no file I/O - image_texture's path loaders go through streams/
formats/image_texture.c loaded images by path through the data_transfer
file adapter. Its four path loaders (image_texture_load, _load_ex,
_load_request, _load_request_ex) move to streams/image_texture_file.c,
declared in streams/image_texture_file.h, the same split data_transfer,
cdfs and the DVD reader got. The names and behaviour are unchanged;
callers include the new header.

formats/image_texture.c keeps the buffer decoders and makes
image_texture_load_buffer_probe public so the adapter can reach it.
image_texture_load_set stays in formats/image_texture_set.c: it does no
file I/O of its own, and gfx_surface_still tests it against a stubbed
load_request.

griffin, Makefile.common, the companion test scripts and the sample
Makefiles that build the loaders add streams/image_texture_file.c; the
overlay task sample, which stubs image loading, does not.
2026-11-12 22:27:29 +01:00
LibretroAdmin 68b07f6a1a formats: no file I/O - data_transfer, cdfs and the DVD file reader go through streams/
data_transfer reads only through its reader callback. The path entry
points keep their names, data_transfer_open_prefix and
data_transfer_open_window, in streams/data_transfer_file.c
(<streams/data_transfer_file.h>), which opens the file through
filestream, reads it at offsets and closes it with the transfer;
data_transfer_open_prefix_reader and data_transfer_set_release are the
core's side of that.

cdfs reads only through the stream a track holds. cdfs_open_track,
cdfs_open_data_track and cdfs_open_raw_track are in
streams/cdfs_file.c (<streams/cdfs_file.h>); the length-based sector
probe they use is cdfs_track_sector_size_from_length.

rdvd_vfs, which binds files to the DVD source, and rdvd_stream, which
drives it, are streams/rdvd_vfs.c and streams/rdvd_stream.c, their
headers under <streams/>.

cdfs_file_test covers the path openers: a cooked iso and a raw bin
sized by length, a cue sheet resolving its bin beside it, an INDEX 01
offset, the data track, refusals.
2026-11-12 19:22:20 +01:00
LibretroAdmin edeecb928d vfs: reads at offsets for chd, data_transfer, rdvd and RVZ; pread on every Unix
chd_stream's decode-ahead thread reads the reader's own file with
filestream_read_at instead of opening a second one, and both sides'
rchd pumps take each range in one call. data_transfer_read_at, the DVD
VFS service and the RVZ hashing reader do the same; each still seeks
and reads where read_at answers -1.

pread/pwrite are used on the Unix hosts by name rather than by
HAVE_MMAP, so Android and the other builds without a file mapping have
positional I/O. An offset a narrow off_t cannot hold is refused, so the
caller seeks, rather than cast to a lower one; 32-bit Android from API
21 takes pread64/pwrite64.

Lanes: vfs_positional_nommap_test (no mmap, positional I/O required),
vfs_positional_off32_test (32-bit offsets on a 64-bit host),
chd_stream_ahead_test counts one open per stream, rdvd_vfs_test runs
both paths; the I/O-counting tests count reads at offsets too.
2026-11-12 09:26:08 +01:00
LibretroAdmin 2a688d8f43 translation_reply_test: the point scaler's picks are the nearest to each centre
ab6a34d3 has the point scaler take the sample nearest each output
pixel's centre, and translation_reply_test still worked out its
expected pixels from the old start, half a sample short: a 128x96 reply
drawn on a 64x48 frame now starts at row 1, column 1 rather than 0, and
the 7x5 PNG reply's pixels on the other frame sizes moved with it -
105 checks failed. The scaled lane expects floor(in / (2 out)) at the
top left, and the PNG lane starts its picks at the centre.

translation_reply_test passes with and without RPNG, natively under
ASan and UBSan and as a Windows binary under Wine.
2026-11-12 04:43:25 +01:00
LibretroAdmin a86d86a22c HAVE_RGIF: GIF images through image_texture, image_transfer and the tasks
rgif now loads GIFs wherever RetroArch loads images: thumbnails and
backgrounds through task_image, the image viewer core, the file browser
and the image_texture/image_transfer layer underneath them all.

rgif:
- the image_transfer interface the other decoders have:
  rgif_set_buf_ptr, rgif_set_avail, rgif_header_ready and
  rgif_process_image, giving a 32-bit texture of its own, ARGB32 or
  ABGR32 in native byte order
- RGIF_ABGR, for ABGR32 on big-endian targets
- a file not all read yet gives IMAGE_PROCESS_WAIT and is not touched;
  the image is decoded in one call once it is all in

Wiring, as HAVE_RTGA is wired:
- IMAGE_TYPE_GIF (image.h) and NBIO_TYPE_GIF (task_file_transfer.h),
  both appended so no other value moves
- image_texture_get_type: .gif
- image_transfer: new, free, start, is_valid, set_buffer_ptr, process,
  set_avail; the support matrix gains a GIF column
- task_image and task_file_transfer: GIF is an image task
- FILE_TYPE_GIF ("gif", "GIF"): opened as image content
- the file browser's image extensions, the image viewer core's
  extensions, the System Information list ("GIF (RGIF)") and
  --features ("RGIF"); SUPPORTS_RGIF in config.features.h
- griffin.c, Makefile.common (rgif.o), configure (HAVE_RGIF=yes), and
  next to HAVE_RTGA in every platform Makefile, the Android, Apple,
  MSVC, UWP and QNX projects and the CI compile matrix
- tools/settings_check.py and tools/stack_budget.py check with it

Also: menu_displaylist's image viewer extension list wrote "tga"
without moving its length on, so "webp" and "dds" landed on top of it
and TGA dropped out of the list; it moves on now.

Tests: rgif_test checks the texture in both byte orders against
rgif_decode, the wait before the whole file is in, and a refused file;
image_decode_fuzz sweeps GIF too (every byte of a small GIF set to
edge values, and every truncation), under ASan and UBSan. The griffin
unity build with every codec, the touched objects in a configured
build, the MinGW/C89 syntax check, the overlap check and the stack
budget pass.
2026-11-10 20:00:24 +01:00
LibretroAdmin ad2e390196 database_scan_test: an unknown-kind SMB scan stats its path twice now
31215d5 took the directory flag from the task's config rather than
stat'ing the content path again on the main thread, so a database scan
of an smb:// path of unknown kind stats it twice before the push, in
set_menu_content_dir and get_task_config, not three times. The SMB
build's two checks that counted three ('unknown kind stats the path'
and 'one file with no database') failed, regular and threaded; they
count two. The TSan SMB build passes all 998 checks.
2026-11-09 20:36:12 +01:00
Davey Hughes 0f72bd97d5 scan: reuse known path kinds for local content (#20029)
Reuse the caller's known content kind for every path. CLI scans and
playlist refreshes already read it on a worker; asking again while
building their configuration can stall the main thread.

Keep the stat fallback when no kind is available. Reject an expected
folder that is no longer a directory on the worker before playlist
overwrite or validation.
2026-11-09 19:16:12 +01:00
JCorrêa e31d1c85de fix(replay): decode input event IDs on big-endian systems (#20035)
Convert little-endian event IDs before matching input queries.
This restores recorded inputs, including joypad masks, on PS3.
2026-11-09 18:55:56 +01:00
davey fa8870bc20 scan: preserve dots in playlist and database names
Append the playlist extension without trimming dotted suffixes.
Refreshing Tiger - Game.com then keeps using its original playlist
and database.
2026-11-09 17:10:45 +01:00