Commit Graph

50 Commits

Author SHA1 Message Date
11b63a53b0 file_system: T:\ is a drive root for file calls; move and copy hold the folder lock
Three fixes to the GAME:/T: overlay shim:

- The T:\ root parses to its scratch folder's parts, not to an empty
  list, so the parts.empty() root checks in write_target, DeleteFileW,
  the copy destination and SetFileAttributesW let it through: a
  SetFileAttributesW(T:\) reached the host folder. They use
  drive_root(), as RemoveDirectory and MoveFileEx already do, with the
  error each gave for GAME:\.
- MoveFileEx and the CopyFile family did not hold the destination
  folder's lock from the "does the folder exist" check to the host
  move or copy, as a write-open and CreateDirectory do, so a concurrent
  RemoveDirectory of that folder could still be undone. A copy with a
  progress routine does not hold it across the copy, because the
  routine is the title's code.
- CreateDirectory removed a recreated folder's marker without
  win32_io_path(), so a marker beyond MAX_PATH could not be removed on a
  host without long path support, and the folder was not recreated.

Found by kevincommits (#1608).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:10:56 -06:00
00131bb85e main keeps its own runtime, tools and tests; the branch's variants stay on port/d3d12-nvidia
After the merge the tree held this branch's older states of files main maintains. Run against main's code,
tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have
been built from two generations of its sources. So that the merge cannot break what main builds and tests:

- runtime/ is main's, file for file (68 files only this branch had are not carried over);
- every file under tools/, tests/ and docs/ that both sides have is main's (80 files);
- ten translator tests only this branch has, which test rules main's translator does not have, and their
  fixtures are left out.

What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1,
play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven
notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and
the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia.

Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the
line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own.
Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the
branch's), CI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 17:58:38 -05:00
b87abdef57 Merge mandy's main into port/d3d12-nvidia
Brings the D3D12 runtime branch (d3d12/, its launcher scripts and notes, and the pull requests reviewed and applied
on it) together with mandy's main.

Conflicts (67 files, none under d3d12/): docs/, make_game.py, runtime/, scripts/build_runtime.ps1, tests/ and
tools/. Every one takes main's side: main is where that code is maintained, and this branch's copies were older
states of the same files or the same pull requests in another form. tests/test_fspx_unpack.py is main's too, as it
tests main's tools/fspx_unpack.py. Nothing under d3d12/ is changed by the merge.

Checked before pushing: python -m compileall over make_game.py, tools and tests; make_game.py --help;
scripts/check_no_game_data.py over the files this adds to main; tests/test_text_write_line_endings.py. The
translator suite, the C++ runtime build and CI have not run on the result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-27 17:50:37 -05:00
5ba3e05f23 file_system: GetDiskFreeSpace(Ex) and SetCurrentDirectory on console paths
Port VIctory's files.rs (GPL-3.0-or-later) for these path imports:
GetDiskFreeSpaceA/W/ExA/ExW and SetCurrentDirectoryA/W on GAME:, G: and
T: paths now ask the folder behind the path (the game folder or the
overlay), so a title checking its drive's free space no longer fails on a
drive letter the host lacks, or gets a host drive's answer. A path that
climbs out of the drive is refused as the other path calls refuse it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:24:11 -05:00
8564bb48bb Merge pull request #688 from aslan2142/game-rmdir-create-race
OLD-9215: restore old upstream PR 9215 - file_system: RemoveDirectory and a create inside the folder are ordered as on the host
2026-11-26 00:00:45 +01:00
5866d6974e Merge main into OLD-8161, T: overlay folder per process (#684)
Conflict in docs/boot.md, the --overlay switch: main now says the overlay defaults to
<game-dir>\overlay and the package is never written; this branch adds the per-process T: folder
inside the overlay. Kept main's sentence and appended the T: text after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 18:33:53 -05:00
5112ec1a84 file_system: a GAME: name inside a missing folder fails with ERROR_PATH_NOT_FOUND, as on the host
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-24 16:32:20 +03:00
de8cb53d54 file_system: RemoveDirectory and a create inside the folder are ordered as on the host
Restores old upstream PR 9215 in ItsNotRexed/Leonida (closed unmerged when that repository went private), ported
onto the current main: the write-open keeps main's long-path disk_path() for its overlay path, and the new race test
sits after main's tests that recreate a removed package folder.

A GAME: write-open checked that its folder exists, mirrored it into the overlay and then opened the file, and
RemoveDirectory checked that the folder was empty and wrote its marker, neither under a lock. A remove that ran
between the open's check and its host CreateFile succeeded on an empty folder, and the open then made the folder
and the file again: both calls succeeded and the removed folder was back. CreateDirectory of a folder inside it had
the same gap. On Windows one of the two fails: the create with ERROR_PATH_NOT_FOUND or the remove with
ERROR_DIR_NOT_EMPTY.

A striped lock keyed by the folder's upper-cased name (64 namespace-scope std::mutex, no function-local static):
write_target holds the lock of the folder it opens in from the parent check until the Target is gone, after the
host CreateFile/CreateFile2; CreateDirectory holds the parent's from its check to the host call; RemoveDirectory
holds the folder's from its view to the marker. Reads take no lock.

file_system_test races the two calls on two threads, 2,000 rounds each for a creating CreateFileW (CREATE_NEW,
CREATE_ALWAYS, OPEN_ALWAYS) and for CreateDirectoryW, and checks that they never both succeed, that the loser
fails with the host's error and that a removed folder stays removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 07:05:40 -05:00
1d37e033eb file_system: reserve T:'s folder with a create-only call, never reuse one
Xiiano's review of old upstream PR 8161: the folder name (start time to
the millisecond plus process id) is not guaranteed unique, and earlier
runs' folders are kept, so a reused id in the same millisecond would
land in a stale folder and bring ERROR_FILE_EXISTS back. Under Wine
every fresh run gets the same small ids (both run_tiny_game_dir runs
here were pid 32).

rt::fs::reserve_unique_dir(base, stem) makes base\stem with
CreateDirectoryW and takes success as ownership; on ERROR_ALREADY_EXISTS
it tries stem-2, stem-3, ... up to 1000 names, and fails with the Win32
error otherwise. T:'s folder is reserved once per overlay under a mutex
(the first T: call or rt::fs::scratch_dir(), which the startup line
calls), so concurrent first calls share it. A failed reservation is
printed once and T: paths fail with ERROR_INVALID_NAME.
rt::fs::scratch_stem() gives the first name tried.

file_system_test: with stem and stem-2 taken, reserve_unique_dir makes
stem-3, new and empty, then stem-4; a file with the next name counts as
taken; max_tries names taken fail with ERROR_ALREADY_EXISTS; a missing
base is made. T: with folders of this process's own stem and stem-2
already kept takes stem-3 and CREATE_NEW succeeds; eight threads making
their first T: call at once reserve one folder. The second-process test
stays.

Restored from old upstream PR 8161 and ported onto the new main: the
base folder and every candidate go through main's win32_io_path, like
the other creates in file_system.cpp, so a long overlay root keeps
working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 06:54:37 -05:00
297ad86854 file_system: T: is a folder of each process's own in the overlay
T:\ mapped to <overlay>\.gta6rt-temp, one folder shared by every run and
kept between runs. The title makes its crash dump and crash log there
with CREATE_NEW, and a name an earlier run (or a second process) had
left failed with ERROR_FILE_EXISTS (80), so no report landed (old
upstream issue 7913, measured by Spacecer2 under Wine 11.22).

T:\ now names <overlay>\.gta6rt-temp\<YYYYMMDD-HHMMSS-mmm>-pid<id>, the
process's start time in UTC and its id, made on the first T: call. The
start time keeps a reused process id (Wine hands each fresh prefix the
same small ids) out of an old run's folder. T:\.. cannot climb into the
shared folder, T:\ itself still cannot be removed or moved, and earlier
runs' folders are kept so their crash files can be read. GAME: and G:
are unchanged.

rt::fs::scratch_dir() returns the folder, and the startup line names it:
"console paths: GAME: -> ..., writes -> ..., T: -> ...". The two CMake
checks of that line (run_tiny_game_console_paths, run_tiny_game_dir)
and the synthetic test of the first now expect the T: part.

file_system_test: a CREATE_NEW of a name earlier runs left in
.gta6rt-temp succeeds and lands in the process's own folder; the folder
is stable for the process; a second process (the test started again)
creating the same name on the same overlay succeeds in a folder of its
own; GAME: reads and writes are unchanged. On main these fail with
ERROR_FILE_EXISTS (80), in this process and in the second one.

Restored from old upstream PR 8161 and ported onto the new main: the
folder is made through main's win32_io_path, so long overlay roots keep
working, and the scratch-folder check of the write-open path is kept.
Main's long-overlay T: check now finds scratch.bin in the process's own
folder below .gta6rt-temp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 06:54:36 -05:00
779f901084 fs, dstorage: a ReadFile into first-touch title memory commits the pages and reads again (RT-READFILE-NOACCESS)
xmem maps the title's physical pages as views of a reserve-only section and commits each page in a vectored handler
when user-mode code first faults on it. A kernel write raises no such fault: ReadFile into a page nobody touched yet
fails with ERROR_NOACCESS (998). The retail title's file reader treats any error but 6, 0x26 and 0x57 as transient
and calls Sleep(1) and ReadFile again forever, so the boot never leaves its first frame loop; DirectStorage reads
into the same memory came back as E_DSTORAGE_ACCESS_VIOLATION and the title stopped on an int3.

The ReadFile import of the file shims, and DirectStorage's read_file_range, now read one byte of every page of the
destination from user mode on ERROR_NOACCESS (the handler commits them) and read again once. file_system_test checks
it on a reserve-only section with a first-touch handler: the host ReadFile fails with ERROR_NOACCESS, the shimmed one
reads every byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 01:50:32 -06:00
e57a7558ac test: keep host fixtures unambiguous on G: and T: (TEST-FS-HOST-DRIVE) 2026-11-24 15:25:51 +11:00
bacf6f4e2a Merge remote-tracking branch 'origin/pr/8953' 2026-11-23 17:41:05 -05:00
dea8ce204d Merge PR #9567 2026-11-23 17:07:57 -05:00
6de6f5b2bb file_system: roll back directory when marker deletion fails 2026-11-23 22:27:43 +01:00
28716daea5 file_system: check CopyFile2 cancellation before preparing destination 2026-11-23 22:25:45 +01:00
68e20ecff8 file_system: clear marker when recreating directory 2026-11-23 22:24:36 +01:00
3101e317af Preserve trailing-dot DOS file search patterns on long paths 2026-11-23 16:50:23 -03:00
17f41ec69c Open long backing paths for guest file shims 2026-11-23 16:37:22 -03:00
26fdf4170b file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) (#3655)
Squash-merged after diff review of PR #3655
2026-11-23 10:04:42 -06:00
87c6c2b261 file_system_test: a refused delete keeps the host's attributes, not the ones set (#6861)
Squash-merged after diff review of PR #6861 - file_system_test: a refused delete keeps the host's attributes, not the ones set
2026-11-23 09:52:38 -06:00
b4adb75081 Startup trace: name failed guest file opens, and LEONIDA_SKIP_INT3 to follow a boot past soft asserts (#6937)
Squash-merged after diff review of PR #6937 - Startup trace: name failed guest file opens, and LEONIDA_SKIP_INT3 to follow a boot past soft asserts
2026-11-23 09:35:20 -06:00
6d55b156e3 file_system test: run to its summary under Wine (RT-451) (#6313)
Squash-merged after review of PR #6313 - file_system test: run to its summary under Wine (RT-451)
2026-11-23 08:15:23 -06:00
d582abc17f runtime: reject deleting read-only package files (#5946)
Squash-merged after review of PR #5946 - BUILD-1899: Respect read-only attributes when deleting package files
2026-11-23 08:07:54 -06:00
3c4974392b Merge pull request #4512 from sh1shu1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:26 -05:00
2800fa3bc6 Merge pull request #4328 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:13:36 -05:00
aa19ee37cf Merge pull request #3955 from ezbyDev
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:09:53 -05:00
9180103a7d Merge pull request #3655 from Claude
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:08:08 -05:00
0c1437dfd9 Merge pull request #3651 from kotorvr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:08:07 -05:00
be8570ace1 Merge remote-tracking branch 'origin/main' into triage-r43
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/xgameruntime.cpp
#	runtime/test/xmem_test.cpp
#	tools/rdna2spirv.py
2026-11-22 22:12:50 -05:00
39d748f250 file_system_test: probes for explicit GAME: paths into the overlay's reserved folders (RT-294)
The overlay's .gta6rt-deleted, .gta6rt-temp and .gta6rt-copy folders are hidden from GAME:\ listings but an explicit
GAME:\.gta6rt-*\... path still reaches them. These probes open, stat, list, create, mkdir and delete through such
paths in the spellings parse_console() normalises (case, forward slashes, ".", ".." and the G: alias), expect
ERROR_INVALID_NAME and no side effect, and keep T:\ and an ordinary dotted name working. They fail on main.

AI-assisted (Claude Code, Claude Fable 5.1).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GDgoLQVYG7p8mvxkwBroVz
2026-11-23 02:43:40 +01:00
844e650bfa file_system: only a T: path names the T:\ root, so GAME:\.gta6rt-temp is not refused as one
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 02:22:26 +01:00
2036d725c5 file_system: T:\ is a root: always a folder, never removed or moved
Signed-off-by: Maxime Mansiet <AirKyzzZ@users.noreply.github.com>
2026-11-23 01:42:59 +01:00
c49b5ec65f file_system: collect falls back to deleted() and dedupes by _wcsicmp (RT-257)
Review on #3955 (@pedro470), both reproduced here:

- A marker folder that cannot be listed (FILE_LIST_DIRECTORY denied, the
  markers still reachable by path) read as "no markers", so a deleted
  package file came back in the listing. Only ERROR_FILE_NOT_FOUND or
  ERROR_PATH_NOT_FOUND now means nothing is deleted; any other failure,
  an incomplete FindNextFileW scan or a marker that cannot be checked
  sends each entry through deleted().
- A _wcslwr_s key is not _wcsicmp in every locale: under .UTF-8 it folds
  U+00C9 and U+00E9, which _wcsicmp keeps apart, so a package entry was
  dropped. The names seen are now a std::set ordered by _wcsicmp, so two
  names are one entry exactly when same_name says so. Same timing.

Tests: the listing-denied marker folder (through the ACL API, restored
after), and a .UTF-8 merged listing checked against _wcsicmp itself. The
previous head fails both; each single fix removed fails its own check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 00:31:35 +01:00
0f3d467f0a file_system: read the folder's deletion markers once, also when it has some (RT-257)
Review on #3955 (@Parakeet-Wheat, @shdann): the fast path only held while
the folder had no marker folder. One DeleteFileW creates it, and every
package entry was probed with deleted() again: 1,073 ms for 16,000 files
after two deletes, against 27 ms now.

collect() lists the marker folder once and keeps the deleted names in a
set, with deleted()'s rule: a marker file, or a marker folder holding
kRemovedDirMarker. The lookup folds ASCII letters only, which is exactly
the file system's case-insensitive compare when both names are ASCII. A
non-ASCII entry, or a marker that is not plain ASCII or is a reparse
point, still goes through deleted(), so the file system's Unicode case
rule decides (deleting éclair.txt hides the package's Éclair.txt, as on
main).

Tests: a delete under another ASCII case in a 300-file folder hides only
that file; the Éclair case above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 00:16:25 +01:00
8518626c1b file_system: list a GAME: folder in linear time (RT-257)
collect() probed the overlay for a deletion marker twice per package entry
(two is_regular_file calls), also when the folder has no marker folder at
all, and de-duplicated names by comparing each one with every name kept so
far. Listing 16,000 package files took 3.7 s against 9 ms on the host.

Every marker for an entry of the listed folder lives inside that folder's
marker folder, so probe it once and skip the per-entry checks when it is
missing. Keep the names seen in an unordered_set, folded with _wcslwr_s,
which follows the same locale rule as the _wcsicmp that same_name uses.

Tests: names that differ only in case are one entry with the overlay's
spelling, and a 300-file folder without a marker folder lists every file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:40:31 +01:00
f46e90310d file_system: a listing directly below a file is ERROR_DIRECTORY, as on the host
collect answered ERROR_PATH_NOT_FOUND for any folder that is not one in the title's
view. The host tells a missing folder (3) from a file in the folder's place (267);
view() already knows which. Reported in review by shdann, with the host table.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 22:05:06 +00:00
95f023f62b file_system: a folder has to exist in the title's view; same-name moves succeed
Three places where the shim disagreed with the host about GAME: paths:

- write_target created the parent folders before checking anything. A failed
  OPEN_EXISTING left the missing folders behind, and a create succeeded in a
  folder that was never made, below a package file (which then read as a folder)
  and inside a folder the title had removed. The parent now has to be a folder in
  the title's view, as CreateDirectory, MoveFile and CopyFile already require;
  otherwise ERROR_PATH_NOT_FOUND and nothing is created.
- FindFirstFile inside a removed package folder returned "." and "..", and inside
  a folder that never existed reported ERROR_FILE_NOT_FOUND. Both are now
  ERROR_PATH_NOT_FOUND.
- MoveFile onto the same name, or to the same name in another case, failed with
  ERROR_ALREADY_EXISTS. The first now succeeds and changes nothing; the second
  renames the overlay entry (a package file gets an overlay copy under the new
  spelling; a package folder is refused like any other move of one).

Two existing checks encoded the old answers and are changed: the test that made
GAME:\save\slot1.bin without making GAME:\save first, and the one that expected
ERROR_FILE_NOT_FOUND for a listing inside a missing folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 22:05:06 +00:00
edbaf7c585 Merge pull request #3602 from kotorvr 2026-11-22 17:02:56 -05:00
4c52ce27a6 Seven fixes from an outside contributor (sent as patches, applied without the author's name)
- rdna2spirv: declare each packed vertex input register once; a register whose elements disagree on the component
  type is refused (SHADER-644).
- runtime: a title's VirtualAlloc drops the console's MEM_GRAPHICS / MEM_TITLE type bits the host rejects (RT-217).
- runtime: XPersistentLocalStorageImpl is served from <overlay>\persistent with the package's 2048 MB quota
  (RT-219; layout from the public docs, not measured in a caller).
- runtime: G:\ names the package and T:\ a scratch folder in the overlay; paths under the configured folders and
  every path with no folders configured stay host paths (RT-218).
- winhttp_offline: header blocks and timeouts the host WinHTTP rejects are rejected the same way.
- cfg_structure.run: a limit of zero or less runs no blocks.
- shader_meta: an s_movk_i32 with a register operand and a float immediate beyond float32 are left unknown instead
  of raising.

Each comes with a test that fails on the old code. Conflicts with main resolved here (internal_dir() hides T:'s
folder; both file_system_test blocks kept).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:55:46 -05:00
c0b821cda7 file_system: CopyFile2 checks its parameter block before the destination
Review on #3655 (kacper-serewis, daemosofchaos, on Windows 11):

- A parameter block shorter than COPYFILE2_EXTENDED_PARAMETERS (dwSize
  0, 4, 31) made the fallback copy and return S_OK, where the host's
  CopyFile2 returns E_INVALIDARG and writes nothing. Both paths now
  check it first, before copy_paths prepares the destination.
- The fallback silently dropped COPY_FILE_SKIP_ALTERNATE_STREAMS and
  copied the stream. Its flags are now sorted: passed on (the ones both
  calls define), dropped (requests that leave the contents as
  CopyFileExW writes them: no offload, compressed traffic, sparse copy,
  ...), or refused with ERROR_NOT_SUPPORTED before anything is written
  (SKIP_ALTERNATE_STREAMS, DIRECTORY, OPEN_AND_COPY_REPARSE_POINT,
  IGNORE_SOURCE_ENCRYPTION, unknown bits, a longer V2 block).
- A cancel flag already set is answered by the fallback itself, since
  Wine 9's CopyFileExW doesn't read it.

rt::fs::force_copy_file2_fallback lets the test run the fallback on
Windows, where the host has CopyFile2 (Maraco91 noted it couldn't be
reached there). file_system_test runs its CopyFile2 checks both ways:
no block, short blocks, fail-if-exists with a hint flag, a set cancel
flag, and in the fallback the refused flags and block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GN11jcpJWD4phrXJyDgED6
2026-11-22 21:54:00 +00:00
75f1351a07 file_system_test: the MAXIMUM_ALLOWED write is shorter than the file
A two-byte write leaves the rest of the file to compare, so the test also shows the
overlay copy began as the package file's bytes (suggested in review).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 21:19:55 +00:00
0977b5dc7e file_system: a MAXIMUM_ALLOWED open is a write-open, so it cannot write the package
writes() did not count MAXIMUM_ALLOWED as write access. CreateFileW/A and CreateFile2
then opened the package file itself, and a WriteFile through the handle changed the
package, which docs/runtime_imports.md says is never written. Such an open now gets
the overlay copy like any other write-open.

file_system_test: the three entry points, with the package bytes and the overlay
copy checked after a write; a plain read still makes no overlay copy.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 20:48:04 +00:00
fc1e0058e0 file_system: copy-up through a staging name, one at a time
A write-open of a package file copied it straight to its overlay name with
no lock. A process killed mid-copy left a truncated file there that every
later read preferred over the package; two threads write-opening the same
package file both copied, and the second copy_file failed on the taken name,
so that open failed.

write_target now copies into <overlay>\.gta6rt-copy under a private name and
renames it into place, under a mutex that only copy-ups take. Listings hide
the staging folder like .gta6rt-deleted. Without the mutex, copy-then-rename
alone still failed about 2 in 100 runs: a losing rename onto the existing
name briefly holds it, and the winner's open got ERROR_SHARING_VIOLATION.

file_system_test: two threads write-open one 256 KiB package file, 50 rounds;
both opens succeed and the overlay copy matches (fails 3 of 3 runs on the
old code, passes 200 of 200 with this); no staging file is left; a crash
leftover is hidden from a GAME: listing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 14:15:36 -05:00
7360583abd Merge pull request #2122 from jaybeebabageyus 2026-11-22 11:41:59 -05:00
403d59060e runtime: shim CreateFile2 and FindFirstFileExA/W for GAME: paths and overlay 2026-11-22 17:01:52 +01:00
c9fbc9d07e gta6rt: GAME: paths for folders, moves, copies and attributes (RT-97 follow-up)
The calls docs/runtime_imports.md listed as not mapped now follow the RT-97
rules, under kernel32, kernelbase and the api-ms-win-core-file-* sets:

- CreateDirectory/CreateDirectoryEx make the folder in the overlay; a name the
  title can already see, package-only folders included, is ERROR_ALREADY_EXISTS.
- RemoveDirectory needs the folder empty in the title's view. An overlay folder
  is removed; a package folder is hidden by a .gta6rt-dir marker file inside its
  marker folder and stays on disk (deleted() now also checks that file, on top
  of the regular-file rule from 3f26a95a).
- MoveFile/MoveFileEx write the destination in the overlay; a moved package file
  is copied there and its old name deleted by a marker. MOVEFILE_WRITE_THROUGH
  flushes that copy and the marker before returning (review on #1742). Package
  folders are not moved (ERROR_ACCESS_DENIED), GAME: <-> host is
  ERROR_NOT_SAME_DEVICE and MOVEFILE_DELAY_UNTIL_REBOOT is ERROR_INVALID_PARAMETER.
- CopyFile/CopyFileEx/CopyFile2 read like a read and write a GAME: destination
  in the overlay; fail-if-exists counts names only the package has.
- SetFileAttributes sets the overlay copy (copy-up or folder mirror first).

file_system: 123/123 checks. No game files.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 18:42:08 +03:00
3f26a95a10 fix(file_system): check is_regular_file for deletion markers so nested deletes do not hide parent directories 2026-11-22 10:41:32 -03:00
c5fb25f734 gta6rt: a failed write-open no longer revives a deleted GAME: name (RT-97)
write_target cleared the delete marker before the host CreateFileW ran, and copied a package file up
without looking at the marker, so a write-open of a deleted name could make it readable again: an
OPEN_EXISTING open succeeded on the copy-up, and one that failed left the marker gone with the package
file visible behind it.

The marker is now never removed, and a tombstoned name is never copied up. Reads and listings prefer an
overlay copy, so a re-created file is visible without clearing anything, while an open that keeps the
contents (OPEN_EXISTING, TRUNCATE_EXISTING) fails with ERROR_FILE_NOT_FOUND and leaves the name deleted.
file_system asserts that sequence: the failed write-open, no overlay copy, and the name still gone.

Review pass over the rest of the shim: Target loses the two fields nothing read, FindFirstFile no longer
parses its pattern twice, collect drops its unreachable non-console branch, and the enumeration states are
unique_ptr entries looked up under the lock instead of raw pointers handed out of it.
2026-11-22 13:29:20 +01:00
a98f9925b0 gta6rt: map GAME: console paths, and send writes to an overlay (RT-97)
A mapped title names its files on the console's drives, but nothing mapped them: the file calls went
straight to the host and --game-dir was only used to find modules, so the first file a title opens at boot
would fail. New shims for CreateFile*, FindFirstFile*/FindNextFile*/FindClose, GetFileAttributes*/
GetFileAttributesEx* and DeleteFile* (kernel32, kernelbase and the api-ms-win-core-file sets) map a GAME:
path under --game-dir, and send every open that can write and every delete to --overlay (default
<game-dir>\overlay), which reads and listings prefer. A write-open copies the package file into the overlay
first, so OPEN_EXISTING keeps its bytes, and a delete of a package file leaves a marker instead of removing
it, so the package is never modified. A path that climbs above GAME: with ".." or names another drive is
refused with ERROR_INVALID_NAME. A path without the prefix is still a host path.

The prefixes and the overlay come from ivall/xcl (GPL-2.0-only), as facts only, no code.

file_system ctest: 43 checks over folders in %TEMP%, covering mapping and case, copy-up and read
preference, a new file in folders the package lacks, delete and re-create, the merged listing, host-path
passthrough, the escape refusal and the narrow variants.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-22 13:11:57 +01:00