startup: persist game-save containers and blobs under the storage path #1239

Merged
tedin7 merged 8 commits from upstream-pr/1246 into main 2026-11-24 09:05:57 +00:00
tedin7 commented 2026-11-24 05:09:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:09:16Z.


What

  • Adds src/startup_stubs/save_store.h: a small standard-C++ store with one directory per container and one file per blob below <X2W_STORAGE_PATH>/x2w-gamesave. An existing container directory counts as success. Blob writes go through a side file and a rename. Names are one plain path component (no separators, :, .., control characters, device names or trailing dot/space), at most 128 bytes, blobs at most 64 MiB. Symlinks are never followed.
  • src/startup_stubs/runtime_proxy.cpp: the game-save slots use the store. Container and update handles keep their fixed base values, with the low bits indexing a small table. Persisted: create container (16), delete container (10, 11), create and close update (23, 24), blob write and blob delete through an open update (25, 26; applied at once, so submit stays a no-op).
  • Not changed, because their argument layout is not established by the code or docs: blob reads (20 to 22) still answer "blob not found", and the enumerations and queries (12 to 15, 18, 19) still report nothing. No new slots, no ABI change. Slots 10, 25 and 26 take the public-header argument shapes, which remains a hypothesis.
  • Adds tests/startup_gamesave_persist.cpp (CTest startup_gamesave_persist) and a "Game saves" section in docs/startup-runtime.md.

Why

Refs #1200. The first-run state most likely goes through the game-save API and the stand-in dropped it. This is the storage half. Reading the stored bytes back through slots 20 to 22 needs the blob record layout, which is a follow-up; the done-when condition (a startup run twice in a row skips first-run setup) is therefore not shown here.

Tested

Windows (not run by me, please run):

ctest --preset dev --no-tests=error -R '^startup_gamesave_persist$' -V
ctest --preset release --no-tests=error -R '^startup_gamesave_persist$' -V

The test writes a blob in one process, starts itself again to read it in a second process, and covers an existing container directory, a missing blob and container, 17 traversal-style names, the size cap, overwrite, blob delete and container delete. Negative controls: the reader finds nothing before the first write, and it rejects different bytes.

Run on Linux: save_store.h and the test compiled with g++ -std=c++17 and -std=c++20 (-Wall -Wextra, no warnings) and passed. Two mutations of the header (dropping the .. check; not renaming the side file) made it fail. Also run: python3 -B tests/docs_links_check.py and tests/bidi_controls_check.py, both pass.

Not run: MSVC. runtime_proxy.cpp was not compiled at all on Linux (Windows headers and intrinsics), and the slot code paths were not exercised. The test drives the storage code the slots call, not the slots through the runtime proxy; no existing test loads the proxy.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575098453 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:09:16Z. --- ## What - Adds `src/startup_stubs/save_store.h`: a small standard-C++ store with one directory per container and one file per blob below `<X2W_STORAGE_PATH>/x2w-gamesave`. An existing container directory counts as success. Blob writes go through a side file and a rename. Names are one plain path component (no separators, `:`, `..`, control characters, device names or trailing dot/space), at most 128 bytes, blobs at most 64 MiB. Symlinks are never followed. - `src/startup_stubs/runtime_proxy.cpp`: the game-save slots use the store. Container and update handles keep their fixed base values, with the low bits indexing a small table. Persisted: create container (16), delete container (10, 11), create and close update (23, 24), blob write and blob delete through an open update (25, 26; applied at once, so submit stays a no-op). - Not changed, because their argument layout is not established by the code or docs: blob reads (20 to 22) still answer "blob not found", and the enumerations and queries (12 to 15, 18, 19) still report nothing. No new slots, no ABI change. Slots 10, 25 and 26 take the public-header argument shapes, which remains a hypothesis. - Adds `tests/startup_gamesave_persist.cpp` (CTest `startup_gamesave_persist`) and a "Game saves" section in `docs/startup-runtime.md`. ## Why Refs #1200. The first-run state most likely goes through the game-save API and the stand-in dropped it. This is the storage half. Reading the stored bytes back through slots 20 to 22 needs the blob record layout, which is a follow-up; the done-when condition (a startup run twice in a row skips first-run setup) is therefore not shown here. ## Tested Windows (not run by me, please run): ```powershell ctest --preset dev --no-tests=error -R '^startup_gamesave_persist$' -V ctest --preset release --no-tests=error -R '^startup_gamesave_persist$' -V ``` The test writes a blob in one process, starts itself again to read it in a second process, and covers an existing container directory, a missing blob and container, 17 traversal-style names, the size cap, overwrite, blob delete and container delete. Negative controls: the reader finds nothing before the first write, and it rejects different bytes. Run on Linux: `save_store.h` and the test compiled with `g++ -std=c++17` and `-std=c++20` (-Wall -Wextra, no warnings) and passed. Two mutations of the header (dropping the `..` check; not renaming the side file) made it fail. Also run: `python3 -B tests/docs_links_check.py` and `tests/bidi_controls_check.py`, both pass. Not run: MSVC. `runtime_proxy.cpp` was not compiled at all on Linux (Windows headers and intrinsics), and the slot code paths were not exercised. The test drives the storage code the slots call, not the slots through the runtime proxy; no existing test loads the proxy.
chatgpt-codex-connector[bot commented 2026-11-24 06:47:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfb42a1f9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034203094 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034203094). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:33:43Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `cfb42a1f9c` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 06:47:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:26Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034231021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034231021). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:26Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:47:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:28Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034231298 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034231298). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:28Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:47:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:30Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034231527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034231527). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:30Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:47:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:32Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034231753 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034231753). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:32Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 06:50:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:44Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit cfb42a1f9c301c868d29d1650839fc2164f09700:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput -- -j 6): 4.85s (configure 1.97s)
    • Test (ctest --preset dev -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.19s, total CTest 0.27s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput -- -j 6): 3.63s (configure 1.9s)
    • Test (ctest --preset release -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.20s, total CTest 0.29s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122812823 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7122812823). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:17:44Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `cfb42a1f9c301c868d29d1650839fc2164f09700`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput -- -j 6`): `4.85s` (configure `1.97s`) - Test (`ctest --preset dev -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.19s`, total CTest `0.27s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput -- -j 6`): `3.63s` (configure `1.9s`) - Test (`ctest --preset release -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.20s`, total CTest `0.29s`)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:25:08Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T05:33:46.176228Z cfb42a1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122928640 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7122928640). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:25:08Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"cfb42a1f9c301c868d29d1650839fc2164f09700","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T05:33:46.176228Z">2026-11-24T05:33:46.176228Z</relative-time> | `cfb42a1` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-24 06:50:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:50:56Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit 0b2b078f57078c248ba499bdd31a14c136e472fa:

  • cmake --preset dev + cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput + ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$": 1/1 passed (startup_gamesave_persist, 0.21s)
  • cmake --preset release + cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput + ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$": 1/1 passed (startup_gamesave_persist, 0.19s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7123332074 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7123332074). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:50:56Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit `0b2b078f57078c248ba499bdd31a14c136e472fa`: - `cmake --preset dev` + `cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput` + `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"`: 1/1 passed (`startup_gamesave_persist`, 0.21s) - `cmake --preset release` + `cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput` + `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"`: 1/1 passed (`startup_gamesave_persist`, 0.19s)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.

Code review location: src/startup_stubs/save_store.h; line 89

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;
+    std::string stem(name.substr(0, name.find('.')));
+    for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
+    while (!stem.empty() && stem.back() == ' ') stem.pop_back();
+    for (const char* device : {"CON", "PRN", "AUX", "NUL"})
+        if (stem == device) return false;
+    if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false;
+    return true;
+}
+
+class Store {
+public:
+    explicit Store(fs::path root) : root_(std::move(root)) {}
+
+    // An existing container directory counts as success.
+    Status create_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name;
+        if (fs::is_directory(dir, ec)) return Status::ok;
+        fs::create_directories(dir, ec);
+        return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error;
+    }
+
+    Status delete_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        const fs::file_status state = fs::symlink_status(dir, ec);
+        if (!fs::exists(state)) return Status::not_found;
+        if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name;
+        fs::remove_all(dir, ec);
+        return ec ? Status::io_error : Status::ok;
+    }
+
+    // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes.
+    Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const
+    {
+        if (size > max_blob_bytes) return Status::too_large;
+        if (size && !data) return Status::io_error;
+        const fs::path file = blob_file(container, blob);
+        if (file.empty()) return Status::bad_name;
+        if (const Status made = create_container(container); made != Status::ok) return made;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name;
+        fs::path part = file;
+        part += std::string(part_suffix);
+        {
+            std::ofstream out(part, std::ios::binary | std::ios::trunc);

P1 Badge Refuse existing links when opening the staging file

If profile.dat.x2w-part already exists as a symlink to a writable file outside the store, this truncating ofstream follows the link before any rename happens. The symlink check above covers only the final blob path, so write_blob("slot-a", "profile.dat", ...) can return ok after overwriting an unrelated host file. A Linux helper probe reproduced this and left the final blob as a symlink. Create the staging file exclusively without following links instead of opening an existing predictable path.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675926998 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675926998). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:33:43Z. **Code review location:** `src/startup_stubs/save_store.h`; line 89 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; + std::string stem(name.substr(0, name.find('.'))); + for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + while (!stem.empty() && stem.back() == ' ') stem.pop_back(); + for (const char* device : {"CON", "PRN", "AUX", "NUL"}) + if (stem == device) return false; + if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false; + return true; +} + +class Store { +public: + explicit Store(fs::path root) : root_(std::move(root)) {} + + // An existing container directory counts as success. + Status create_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name; + if (fs::is_directory(dir, ec)) return Status::ok; + fs::create_directories(dir, ec); + return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error; + } + + Status delete_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + const fs::file_status state = fs::symlink_status(dir, ec); + if (!fs::exists(state)) return Status::not_found; + if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name; + fs::remove_all(dir, ec); + return ec ? Status::io_error : Status::ok; + } + + // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes. + Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const + { + if (size > max_blob_bytes) return Status::too_large; + if (size && !data) return Status::io_error; + const fs::path file = blob_file(container, blob); + if (file.empty()) return Status::bad_name; + if (const Status made = create_container(container); made != Status::ok) return made; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name; + fs::path part = file; + part += std::string(part_suffix); + { + std::ofstream out(part, std::ios::binary | std::ios::trunc); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Refuse existing links when opening the staging file** If `profile.dat.x2w-part` already exists as a symlink to a writable file outside the store, this truncating `ofstream` follows the link before any rename happens. The symlink check above covers only the final blob path, so `write_blob("slot-a", "profile.dat", ...)` can return `ok` after overwriting an unrelated host file. A Linux helper probe reproduced this and left the final blob as a symlink. Create the staging file exclusively without following links instead of opening an existing predictable path. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.

Code review location: src/startup_stubs/save_store.h; line 87

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;
+    std::string stem(name.substr(0, name.find('.')));
+    for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
+    while (!stem.empty() && stem.back() == ' ') stem.pop_back();
+    for (const char* device : {"CON", "PRN", "AUX", "NUL"})
+        if (stem == device) return false;
+    if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false;
+    return true;
+}
+
+class Store {
+public:
+    explicit Store(fs::path root) : root_(std::move(root)) {}
+
+    // An existing container directory counts as success.
+    Status create_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name;
+        if (fs::is_directory(dir, ec)) return Status::ok;
+        fs::create_directories(dir, ec);
+        return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error;
+    }
+
+    Status delete_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        const fs::file_status state = fs::symlink_status(dir, ec);
+        if (!fs::exists(state)) return Status::not_found;
+        if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name;
+        fs::remove_all(dir, ec);
+        return ec ? Status::io_error : Status::ok;
+    }
+
+    // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes.
+    Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const
+    {
+        if (size > max_blob_bytes) return Status::too_large;
+        if (size && !data) return Status::io_error;
+        const fs::path file = blob_file(container, blob);
+        if (file.empty()) return Status::bad_name;
+        if (const Status made = create_container(container); made != Status::ok) return made;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name;
+        fs::path part = file;
+        part += std::string(part_suffix);

P1 Badge Use a separate staging file for each concurrent write

When two open updates write the same container/blob concurrently, they share this single .x2w-part file; the runtime's save_lock protects the handle tables but is released before write_blob runs. One call can rename the staging file while the other continues writing to it and subsequently fails to rename. A two-thread Linux probe with distinct 16 MiB payloads repeatedly returned one ok and one io_error, but the final blob contained the failed writer's payload rather than the successful writer's. Use exclusively created per-write staging files or serialize the complete write/rename sequence across callers.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675927007 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927007). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:33:43Z. **Code review location:** `src/startup_stubs/save_store.h`; line 87 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; + std::string stem(name.substr(0, name.find('.'))); + for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + while (!stem.empty() && stem.back() == ' ') stem.pop_back(); + for (const char* device : {"CON", "PRN", "AUX", "NUL"}) + if (stem == device) return false; + if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false; + return true; +} + +class Store { +public: + explicit Store(fs::path root) : root_(std::move(root)) {} + + // An existing container directory counts as success. + Status create_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name; + if (fs::is_directory(dir, ec)) return Status::ok; + fs::create_directories(dir, ec); + return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error; + } + + Status delete_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + const fs::file_status state = fs::symlink_status(dir, ec); + if (!fs::exists(state)) return Status::not_found; + if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name; + fs::remove_all(dir, ec); + return ec ? Status::io_error : Status::ok; + } + + // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes. + Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const + { + if (size > max_blob_bytes) return Status::too_large; + if (size && !data) return Status::io_error; + const fs::path file = blob_file(container, blob); + if (file.empty()) return Status::bad_name; + if (const Status made = create_container(container); made != Status::ok) return made; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name; + fs::path part = file; + part += std::string(part_suffix); ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Use a separate staging file for each concurrent write** When two open updates write the same container/blob concurrently, they share this single `.x2w-part` file; the runtime's `save_lock` protects the handle tables but is released before `write_blob` runs. One call can rename the staging file while the other continues writing to it and subsequently fails to rename. A two-thread Linux probe with distinct 16 MiB payloads repeatedly returned one `ok` and one `io_error`, but the final blob contained the failed writer's payload rather than the successful writer's. Use exclusively created per-write staging files or serialize the complete write/rename sequence across callers. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.

Code review location: src/startup_stubs/save_store.h; line 38

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;

P2 Badge Reserve the staging suffix case-insensitively on Windows

On a normal case-insensitive Windows filesystem, valid_name("profile.X2W-PART") returns true even though that file aliases the staging name used for blob profile. Writing profile.X2W-PART and then profile therefore truncates and renames the first blob away, even though both names pass validation and both writes can succeed. Reserve the suffix case-insensitively on Windows, or move staging files outside the blob namespace.

AGENTS.md reference: AGENTS.md:L9-L10

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675927014 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927014). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:33:43Z. **Code review location:** `src/startup_stubs/save_store.h`; line 38 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reserve the staging suffix case-insensitively on Windows** On a normal case-insensitive Windows filesystem, `valid_name("profile.X2W-PART")` returns true even though that file aliases the staging name used for blob `profile`. Writing `profile.X2W-PART` and then `profile` therefore truncates and renames the first blob away, even though both names pass validation and both writes can succeed. Reserve the suffix case-insensitively on Windows, or move staging files outside the blob namespace. AGENTS.md reference: [AGENTS.md:L9-L10](https://github.com/R0Y00/Xbox2Windows/blob/cfb42a1f9c301c868d29d1650839fc2164f09700/AGENTS.md#L9-L10) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.

Code review location: src/startup_stubs/runtime_proxy.cpp; line 340

@@ -289,13 +292,67 @@ bool user_call(int slot, u64* args, u64* result)
 
 // ---- local game saves -----------------------------------------------------------------------
 // Slot numbers follow the order of the public XGameSave.h (hypothesis, checked against the logged
-// argument shapes). There are no stored saves: enumerations report nothing, reads find nothing,
-// writes are accepted and dropped. Asynchronous calls are completed by starting the real
+// argument shapes). Containers and blob writes are kept on disk (save_store.h, below
+// storage_path()/x2w-gamesave); enumerations and reads still report nothing and the calls whose
+// argument layout is not known are accepted and dropped. Asynchronous calls are completed by starting the real
 // "add default user silently" operation on the caller's async block: it fails quickly inside the
 // runtime and runs the caller's completion callback on its task queue; the matching Result call is
 // then answered here.
 constexpr u64 save_provider_handle = 0x58325753'00000001ull, save_container_handle = 0x58325743'00000001ull,
               save_update_handle = 0x58325755'50000001ull;
+// Container and update handles keep their fixed base; the low bits count from 1 and index these tables.
+// Reopening a container name returns the same handle, so the table stays small.
+constexpr std::size_t max_save_handles = 64;
+constexpr u64 e_invalidarg = 0x80070057, e_outofmemory = 0x8007000E, e_fail = 0x80004005;
+std::string save_containers[max_save_handles];
+std::size_t save_container_count;
+int save_updates[max_save_handles];  // container index + 1 of an open update, 0 = free
+SRWLOCK save_lock = SRWLOCK_INIT;
+x2w_save::Store save_store() { return x2w_save::Store(std::filesystem::path(storage_path()) / "x2w-gamesave"); }
+// A NUL-terminated name of at most x2w_save::max_name_bytes in readable memory.
+bool read_save_name(u64 pointer, std::string& name)
+{
+    const std::size_t readable = x2w_local::probe_readable(static_cast<std::uintptr_t>(pointer), x2w_save::max_name_bytes + 1);
+    const char* text = reinterpret_cast<const char*>(pointer);
+    const std::size_t length = readable ? strnlen(text, readable) : 0;
+    if (!readable || length == readable) return false;
+    name.assign(text, length);
+    return true;
+}
+u64 save_status(x2w_save::Status status)
+{
+    using x2w_save::Status;
+    switch (status) {
+    case Status::ok: return 0;
+    case Status::bad_name: case Status::too_large: return e_invalidarg;
+    case Status::not_found: return 0x80830008;
+    default: return e_fail;
+    }
+}
+u64 open_container(const std::string& name, u64* handle)
+{
+    const x2w_save::Status status = save_store().create_container(name);
+    if (status != x2w_save::Status::ok) return save_status(status);
+    AcquireSRWLockExclusive(&save_lock);
+    std::size_t index = 0;
+    while (index < save_container_count && save_containers[index] != name) ++index;
+    const bool full = index == save_container_count && save_container_count == max_save_handles;
+    if (index == save_container_count && !full) save_containers[save_container_count++] = name;

P2 Badge Reclaim closed container entries before exhausting the table

With the fake-user proxy enabled, opening and closing 64 distinct container names permanently exhausts this table: save_container_count only grows, while close-provider, close-container and delete-container never release entries. The 65th distinct container returns E_OUTOFMEMORY even if every earlier container and update was closed and deleted, so rotating save-container names eventually stop working until the process restarts. Reclaim entries when no live handle/update uses them, or avoid capping the handle table by all names ever opened.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675927021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927021). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T05:33:43Z. **Code review location:** `src/startup_stubs/runtime_proxy.cpp`; line 340 ~~~~diff @@ -289,13 +292,67 @@ bool user_call(int slot, u64* args, u64* result) // ---- local game saves ----------------------------------------------------------------------- // Slot numbers follow the order of the public XGameSave.h (hypothesis, checked against the logged -// argument shapes). There are no stored saves: enumerations report nothing, reads find nothing, -// writes are accepted and dropped. Asynchronous calls are completed by starting the real +// argument shapes). Containers and blob writes are kept on disk (save_store.h, below +// storage_path()/x2w-gamesave); enumerations and reads still report nothing and the calls whose +// argument layout is not known are accepted and dropped. Asynchronous calls are completed by starting the real // "add default user silently" operation on the caller's async block: it fails quickly inside the // runtime and runs the caller's completion callback on its task queue; the matching Result call is // then answered here. constexpr u64 save_provider_handle = 0x58325753'00000001ull, save_container_handle = 0x58325743'00000001ull, save_update_handle = 0x58325755'50000001ull; +// Container and update handles keep their fixed base; the low bits count from 1 and index these tables. +// Reopening a container name returns the same handle, so the table stays small. +constexpr std::size_t max_save_handles = 64; +constexpr u64 e_invalidarg = 0x80070057, e_outofmemory = 0x8007000E, e_fail = 0x80004005; +std::string save_containers[max_save_handles]; +std::size_t save_container_count; +int save_updates[max_save_handles]; // container index + 1 of an open update, 0 = free +SRWLOCK save_lock = SRWLOCK_INIT; +x2w_save::Store save_store() { return x2w_save::Store(std::filesystem::path(storage_path()) / "x2w-gamesave"); } +// A NUL-terminated name of at most x2w_save::max_name_bytes in readable memory. +bool read_save_name(u64 pointer, std::string& name) +{ + const std::size_t readable = x2w_local::probe_readable(static_cast<std::uintptr_t>(pointer), x2w_save::max_name_bytes + 1); + const char* text = reinterpret_cast<const char*>(pointer); + const std::size_t length = readable ? strnlen(text, readable) : 0; + if (!readable || length == readable) return false; + name.assign(text, length); + return true; +} +u64 save_status(x2w_save::Status status) +{ + using x2w_save::Status; + switch (status) { + case Status::ok: return 0; + case Status::bad_name: case Status::too_large: return e_invalidarg; + case Status::not_found: return 0x80830008; + default: return e_fail; + } +} +u64 open_container(const std::string& name, u64* handle) +{ + const x2w_save::Status status = save_store().create_container(name); + if (status != x2w_save::Status::ok) return save_status(status); + AcquireSRWLockExclusive(&save_lock); + std::size_t index = 0; + while (index < save_container_count && save_containers[index] != name) ++index; + const bool full = index == save_container_count && save_container_count == max_save_handles; + if (index == save_container_count && !full) save_containers[save_container_count++] = name; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reclaim closed container entries before exhausting the table** With the fake-user proxy enabled, opening and closing 64 distinct container names permanently exhausts this table: `save_container_count` only grows, while close-provider, close-container and delete-container never release entries. The 65th distinct container returns `E_OUTOFMEMORY` even if every earlier container and update was closed and deleted, so rotating save-container names eventually stop working until the process restarts. Reclaim entries when no live handle/update uses them, or avoid capping the handle table by all names ever opened. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:26Z.

Code review location: src/startup_stubs/save_store.h; line 89

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;
+    std::string stem(name.substr(0, name.find('.')));
+    for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
+    while (!stem.empty() && stem.back() == ' ') stem.pop_back();
+    for (const char* device : {"CON", "PRN", "AUX", "NUL"})
+        if (stem == device) return false;
+    if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false;
+    return true;
+}
+
+class Store {
+public:
+    explicit Store(fs::path root) : root_(std::move(root)) {}
+
+    // An existing container directory counts as success.
+    Status create_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name;
+        if (fs::is_directory(dir, ec)) return Status::ok;
+        fs::create_directories(dir, ec);
+        return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error;
+    }
+
+    Status delete_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        const fs::file_status state = fs::symlink_status(dir, ec);
+        if (!fs::exists(state)) return Status::not_found;
+        if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name;
+        fs::remove_all(dir, ec);
+        return ec ? Status::io_error : Status::ok;
+    }
+
+    // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes.
+    Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const
+    {
+        if (size > max_blob_bytes) return Status::too_large;
+        if (size && !data) return Status::io_error;
+        const fs::path file = blob_file(container, blob);
+        if (file.empty()) return Status::bad_name;
+        if (const Status made = create_container(container); made != Status::ok) return made;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name;
+        fs::path part = file;
+        part += std::string(part_suffix);
+        {
+            std::ofstream out(part, std::ios::binary | std::ios::trunc);

Fixed in eeda5404: the staging file is no longer a predictable name. Each write creates <blob>.<counter>-<clock>.x2w-part and refuses to open it if anything (a link included) already exists at that name. A link left at the old <blob>.x2w-part name is never opened: the test plants one and checks the outside file stays untouched (skipped where symlink creation is not permitted). Limit: this is an unguessable name plus a pre-check, not an exclusive-create open; the standard library offers none here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675950439 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950439). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:26Z. **Code review location:** `src/startup_stubs/save_store.h`; line 89 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; + std::string stem(name.substr(0, name.find('.'))); + for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + while (!stem.empty() && stem.back() == ' ') stem.pop_back(); + for (const char* device : {"CON", "PRN", "AUX", "NUL"}) + if (stem == device) return false; + if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false; + return true; +} + +class Store { +public: + explicit Store(fs::path root) : root_(std::move(root)) {} + + // An existing container directory counts as success. + Status create_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name; + if (fs::is_directory(dir, ec)) return Status::ok; + fs::create_directories(dir, ec); + return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error; + } + + Status delete_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + const fs::file_status state = fs::symlink_status(dir, ec); + if (!fs::exists(state)) return Status::not_found; + if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name; + fs::remove_all(dir, ec); + return ec ? Status::io_error : Status::ok; + } + + // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes. + Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const + { + if (size > max_blob_bytes) return Status::too_large; + if (size && !data) return Status::io_error; + const fs::path file = blob_file(container, blob); + if (file.empty()) return Status::bad_name; + if (const Status made = create_container(container); made != Status::ok) return made; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name; + fs::path part = file; + part += std::string(part_suffix); + { + std::ofstream out(part, std::ios::binary | std::ios::trunc); ~~~~ --- Fixed in eeda5404: the staging file is no longer a predictable name. Each write creates `<blob>.<counter>-<clock>.x2w-part` and refuses to open it if anything (a link included) already exists at that name. A link left at the old `<blob>.x2w-part` name is never opened: the test plants one and checks the outside file stays untouched (skipped where symlink creation is not permitted). Limit: this is an unguessable name plus a pre-check, not an exclusive-create open; the standard library offers none here.
tedin7 commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:28Z.

Code review location: src/startup_stubs/save_store.h; line 87

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;
+    std::string stem(name.substr(0, name.find('.')));
+    for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
+    while (!stem.empty() && stem.back() == ' ') stem.pop_back();
+    for (const char* device : {"CON", "PRN", "AUX", "NUL"})
+        if (stem == device) return false;
+    if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false;
+    return true;
+}
+
+class Store {
+public:
+    explicit Store(fs::path root) : root_(std::move(root)) {}
+
+    // An existing container directory counts as success.
+    Status create_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name;
+        if (fs::is_directory(dir, ec)) return Status::ok;
+        fs::create_directories(dir, ec);
+        return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error;
+    }
+
+    Status delete_container(std::string_view container) const
+    {
+        const fs::path dir = container_dir(container);
+        if (dir.empty()) return Status::bad_name;
+        std::error_code ec;
+        const fs::file_status state = fs::symlink_status(dir, ec);
+        if (!fs::exists(state)) return Status::not_found;
+        if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name;
+        fs::remove_all(dir, ec);
+        return ec ? Status::io_error : Status::ok;
+    }
+
+    // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes.
+    Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const
+    {
+        if (size > max_blob_bytes) return Status::too_large;
+        if (size && !data) return Status::io_error;
+        const fs::path file = blob_file(container, blob);
+        if (file.empty()) return Status::bad_name;
+        if (const Status made = create_container(container); made != Status::ok) return made;
+        std::error_code ec;
+        if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name;
+        fs::path part = file;
+        part += std::string(part_suffix);

Fixed in eeda5404: one staging file per write (unique counter + clock reading in the name), so two writers never share one. New test: two threads write 1 MiB payloads to the same blob 20 times; both always succeed, the blob holds one whole payload and no staging file is left. With the old fixed name the same test fails.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675950702 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950702). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:28Z. **Code review location:** `src/startup_stubs/save_store.h`; line 87 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; + std::string stem(name.substr(0, name.find('.'))); + for (char& c : stem) c = static_cast<char>(c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + while (!stem.empty() && stem.back() == ' ') stem.pop_back(); + for (const char* device : {"CON", "PRN", "AUX", "NUL"}) + if (stem == device) return false; + if (stem.size() == 4 && (stem.compare(0, 3, "COM") == 0 || stem.compare(0, 3, "LPT") == 0) && stem[3] >= '0' && stem[3] <= '9') return false; + return true; +} + +class Store { +public: + explicit Store(fs::path root) : root_(std::move(root)) {} + + // An existing container directory counts as success. + Status create_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(dir, ec))) return Status::bad_name; + if (fs::is_directory(dir, ec)) return Status::ok; + fs::create_directories(dir, ec); + return !ec && fs::is_directory(dir, ec) ? Status::ok : Status::io_error; + } + + Status delete_container(std::string_view container) const + { + const fs::path dir = container_dir(container); + if (dir.empty()) return Status::bad_name; + std::error_code ec; + const fs::file_status state = fs::symlink_status(dir, ec); + if (!fs::exists(state)) return Status::not_found; + if (!fs::is_directory(state) || fs::is_symlink(state)) return Status::bad_name; + fs::remove_all(dir, ec); + return ec ? Status::io_error : Status::ok; + } + + // Writes to a side file and renames it over the blob, so a reader sees the old or the new bytes. + Status write_blob(std::string_view container, std::string_view blob, const void* data, std::size_t size) const + { + if (size > max_blob_bytes) return Status::too_large; + if (size && !data) return Status::io_error; + const fs::path file = blob_file(container, blob); + if (file.empty()) return Status::bad_name; + if (const Status made = create_container(container); made != Status::ok) return made; + std::error_code ec; + if (fs::is_symlink(fs::symlink_status(file, ec))) return Status::bad_name; + fs::path part = file; + part += std::string(part_suffix); ~~~~ --- Fixed in eeda5404: one staging file per write (unique counter + clock reading in the name), so two writers never share one. New test: two threads write 1 MiB payloads to the same blob 20 times; both always succeed, the blob holds one whole payload and no staging file is left. With the old fixed name the same test fails.
tedin7 commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:30Z.

Code review location: src/startup_stubs/save_store.h; line 38

@@ -0,0 +1,152 @@
+// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in.
+// One directory per container, one file per blob, all below one root folder. Plain standard C++
+// with no Windows types, so the logic can be compiled and tested on its own.
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <string_view>
+#include <system_error>
+#include <vector>
+
+namespace x2w_save {
+
+namespace fs = std::filesystem;
+
+enum class Status { ok, bad_name, too_large, not_found, io_error };
+
+constexpr std::size_t max_name_bytes = 128;
+constexpr std::size_t max_blob_bytes = std::size_t{64} << 20;
+constexpr std::string_view part_suffix = ".x2w-part";
+
+// A name becomes one path component. Anything that could address another place is refused: empty,
+// too long, separators, drive letters and streams (':'), control characters, characters Windows
+// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the
+// store uses for files it is still writing.
+inline bool valid_name(std::string_view name) noexcept
+{
+    if (name.empty() || name.size() > max_name_bytes) return false;
+    for (const unsigned char c : name) {
+        if (c < 0x20 || c == 0x7f) return false;
+        if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false;
+    }
+    if (name.find("..") != std::string_view::npos) return false;
+    if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false;
+    if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false;

Fixed in eeda5404: valid_name now compares the staging suffix case-insensitively (.X2W-PART, .x2W-Part are refused on every OS). A near miss such as .x2w-par stays valid. Covered in the test.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675950919 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950919). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:30Z. **Code review location:** `src/startup_stubs/save_store.h`; line 38 ~~~~diff @@ -0,0 +1,152 @@ +// Experimental (docs/startup-runtime.md): on-disk store behind the local game-save stand-in. +// One directory per container, one file per blob, all below one root folder. Plain standard C++ +// with no Windows types, so the logic can be compiled and tested on its own. +#pragma once + +#include <cstddef> +#include <cstdint> +#include <filesystem> +#include <fstream> +#include <string> +#include <string_view> +#include <system_error> +#include <vector> + +namespace x2w_save { + +namespace fs = std::filesystem; + +enum class Status { ok, bad_name, too_large, not_found, io_error }; + +constexpr std::size_t max_name_bytes = 128; +constexpr std::size_t max_blob_bytes = std::size_t{64} << 20; +constexpr std::string_view part_suffix = ".x2w-part"; + +// A name becomes one path component. Anything that could address another place is refused: empty, +// too long, separators, drive letters and streams (':'), control characters, characters Windows +// does not allow in file names, "..", a trailing dot or space, device names, and the suffix the +// store uses for files it is still writing. +inline bool valid_name(std::string_view name) noexcept +{ + if (name.empty() || name.size() > max_name_bytes) return false; + for (const unsigned char c : name) { + if (c < 0x20 || c == 0x7f) return false; + if (std::string_view("/\\:*?\"<>|").find(static_cast<char>(c)) != std::string_view::npos) return false; + } + if (name.find("..") != std::string_view::npos) return false; + if (name.back() == '.' || name.back() == ' ' || name.front() == ' ') return false; + if (name.size() >= part_suffix.size() && name.substr(name.size() - part_suffix.size()) == part_suffix) return false; ~~~~ --- Fixed in eeda5404: `valid_name` now compares the staging suffix case-insensitively (`.X2W-PART`, `.x2W-Part` are refused on every OS). A near miss such as `.x2w-par` stays valid. Covered in the test.
tedin7 commented 2026-11-24 06:50:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:32Z.

Code review location: src/startup_stubs/runtime_proxy.cpp; line 340

@@ -289,13 +292,67 @@ bool user_call(int slot, u64* args, u64* result)
 
 // ---- local game saves -----------------------------------------------------------------------
 // Slot numbers follow the order of the public XGameSave.h (hypothesis, checked against the logged
-// argument shapes). There are no stored saves: enumerations report nothing, reads find nothing,
-// writes are accepted and dropped. Asynchronous calls are completed by starting the real
+// argument shapes). Containers and blob writes are kept on disk (save_store.h, below
+// storage_path()/x2w-gamesave); enumerations and reads still report nothing and the calls whose
+// argument layout is not known are accepted and dropped. Asynchronous calls are completed by starting the real
 // "add default user silently" operation on the caller's async block: it fails quickly inside the
 // runtime and runs the caller's completion callback on its task queue; the matching Result call is
 // then answered here.
 constexpr u64 save_provider_handle = 0x58325753'00000001ull, save_container_handle = 0x58325743'00000001ull,
               save_update_handle = 0x58325755'50000001ull;
+// Container and update handles keep their fixed base; the low bits count from 1 and index these tables.
+// Reopening a container name returns the same handle, so the table stays small.
+constexpr std::size_t max_save_handles = 64;
+constexpr u64 e_invalidarg = 0x80070057, e_outofmemory = 0x8007000E, e_fail = 0x80004005;
+std::string save_containers[max_save_handles];
+std::size_t save_container_count;
+int save_updates[max_save_handles];  // container index + 1 of an open update, 0 = free
+SRWLOCK save_lock = SRWLOCK_INIT;
+x2w_save::Store save_store() { return x2w_save::Store(std::filesystem::path(storage_path()) / "x2w-gamesave"); }
+// A NUL-terminated name of at most x2w_save::max_name_bytes in readable memory.
+bool read_save_name(u64 pointer, std::string& name)
+{
+    const std::size_t readable = x2w_local::probe_readable(static_cast<std::uintptr_t>(pointer), x2w_save::max_name_bytes + 1);
+    const char* text = reinterpret_cast<const char*>(pointer);
+    const std::size_t length = readable ? strnlen(text, readable) : 0;
+    if (!readable || length == readable) return false;
+    name.assign(text, length);
+    return true;
+}
+u64 save_status(x2w_save::Status status)
+{
+    using x2w_save::Status;
+    switch (status) {
+    case Status::ok: return 0;
+    case Status::bad_name: case Status::too_large: return e_invalidarg;
+    case Status::not_found: return 0x80830008;
+    default: return e_fail;
+    }
+}
+u64 open_container(const std::string& name, u64* handle)
+{
+    const x2w_save::Status status = save_store().create_container(name);
+    if (status != x2w_save::Status::ok) return save_status(status);
+    AcquireSRWLockExclusive(&save_lock);
+    std::size_t index = 0;
+    while (index < save_container_count && save_containers[index] != name) ++index;
+    const bool full = index == save_container_count && save_container_count == max_save_handles;
+    if (index == save_container_count && !full) save_containers[save_container_count++] = name;

Fixed in eeda5404: container handles now come from a small ContainerTable (in save_store.h) with a reference count per entry. Close-container releases it, and an entry with an open update is kept until CloseUpdate. The test runs 300 open/close rounds of distinct names without exhausting the table, and keeps the full-table refusal and the open-update case as controls. runtime_proxy.cpp only uses the table under save_lock; it was not compiled on Linux.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675951117 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675951117). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:37:32Z. **Code review location:** `src/startup_stubs/runtime_proxy.cpp`; line 340 ~~~~diff @@ -289,13 +292,67 @@ bool user_call(int slot, u64* args, u64* result) // ---- local game saves ----------------------------------------------------------------------- // Slot numbers follow the order of the public XGameSave.h (hypothesis, checked against the logged -// argument shapes). There are no stored saves: enumerations report nothing, reads find nothing, -// writes are accepted and dropped. Asynchronous calls are completed by starting the real +// argument shapes). Containers and blob writes are kept on disk (save_store.h, below +// storage_path()/x2w-gamesave); enumerations and reads still report nothing and the calls whose +// argument layout is not known are accepted and dropped. Asynchronous calls are completed by starting the real // "add default user silently" operation on the caller's async block: it fails quickly inside the // runtime and runs the caller's completion callback on its task queue; the matching Result call is // then answered here. constexpr u64 save_provider_handle = 0x58325753'00000001ull, save_container_handle = 0x58325743'00000001ull, save_update_handle = 0x58325755'50000001ull; +// Container and update handles keep their fixed base; the low bits count from 1 and index these tables. +// Reopening a container name returns the same handle, so the table stays small. +constexpr std::size_t max_save_handles = 64; +constexpr u64 e_invalidarg = 0x80070057, e_outofmemory = 0x8007000E, e_fail = 0x80004005; +std::string save_containers[max_save_handles]; +std::size_t save_container_count; +int save_updates[max_save_handles]; // container index + 1 of an open update, 0 = free +SRWLOCK save_lock = SRWLOCK_INIT; +x2w_save::Store save_store() { return x2w_save::Store(std::filesystem::path(storage_path()) / "x2w-gamesave"); } +// A NUL-terminated name of at most x2w_save::max_name_bytes in readable memory. +bool read_save_name(u64 pointer, std::string& name) +{ + const std::size_t readable = x2w_local::probe_readable(static_cast<std::uintptr_t>(pointer), x2w_save::max_name_bytes + 1); + const char* text = reinterpret_cast<const char*>(pointer); + const std::size_t length = readable ? strnlen(text, readable) : 0; + if (!readable || length == readable) return false; + name.assign(text, length); + return true; +} +u64 save_status(x2w_save::Status status) +{ + using x2w_save::Status; + switch (status) { + case Status::ok: return 0; + case Status::bad_name: case Status::too_large: return e_invalidarg; + case Status::not_found: return 0x80830008; + default: return e_fail; + } +} +u64 open_container(const std::string& name, u64* handle) +{ + const x2w_save::Status status = save_store().create_container(name); + if (status != x2w_save::Status::ok) return save_status(status); + AcquireSRWLockExclusive(&save_lock); + std::size_t index = 0; + while (index < save_container_count && save_containers[index] != name) ++index; + const bool full = index == save_container_count && save_container_count == max_save_handles; + if (index == save_container_count && !full) save_containers[save_container_count++] = name; ~~~~ --- Fixed in eeda5404: container handles now come from a small `ContainerTable` (in `save_store.h`) with a reference count per entry. Close-container releases it, and an entry with an open update is kept until `CloseUpdate`. The test runs 300 open/close rounds of distinct names without exhausting the table, and keeps the full-table refusal and the open-update case as controls. `runtime_proxy.cpp` only uses the table under `save_lock`; it was not compiled on Linux.
R0Y00 commented 2026-11-24 08:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:40:36Z.

Review: CHANGES_REQUESTED


The file-level rename tests are useful. The wrapped update has a different lifetime from the public API the implementation uses as its ABI reference. Writes and deletes currently reach disk before submit, so closing an update without submitting it can change a save. A failure on a later action can also leave the earlier action published. The GDK makes the whole update atomic at submit. Please stage actions until submit, or keep this PR at the storage-helper level until the wrapped transaction is ready. The most useful controls are close-without-submit, failure of the second action, and a second process observing only committed state.

There is also a gap in the documented path boundary: the blob read and delete methods check the leaf while traversal may already have passed through a redirected container directory. Refuse redirected containers consistently, or narrow and document the storage-root trust contract. Reference: https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-save/xgamesave?view=gdk-2610

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035385736 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6035385736). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:40:36Z. **Review:** CHANGES_REQUESTED --- The file-level rename tests are useful. The wrapped update has a different lifetime from the public API the implementation uses as its ABI reference. Writes and deletes currently reach disk before submit, so closing an update without submitting it can change a save. A failure on a later action can also leave the earlier action published. The GDK makes the whole update atomic at submit. Please stage actions until submit, or keep this PR at the storage-helper level until the wrapped transaction is ready. The most useful controls are close-without-submit, failure of the second action, and a second process observing only committed state. There is also a gap in the documented path boundary: the blob read and delete methods check the leaf while traversal may already have passed through a redirected container directory. Refuse redirected containers consistently, or narrow and document the storage-root trust contract. Reference: https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-save/xgamesave?view=gdk-2610
tedin7 commented 2026-11-24 08:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:08:18Z.


Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) after rebase at 5b05c67a:

  • Debug (--preset dev): ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.21s)
  • Release /O2 (--preset release): ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.18s, build 0.39s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124658982 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7124658982). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:08:18Z. --- Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) after rebase at `5b05c67a`: - Debug (`--preset dev`): `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.21s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.18s`, build `0.39s`)
tedin7 commented 2026-11-24 08:01:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:48:17Z.


Addressed both points in d4de15eb:

  1. Atomic update staging until submit: XGameSaveSubmitBlobWrite / XGameSaveSubmitBlobDelete now stage actions in memory and apply them atomically on XGameSaveSubmitUpdate, leaving disk state unchanged if closed without submit or if a later action fails. Added the three controls in tests/startup_gamesave_persist.cpp (close-without-submit, failure of a second action, and a second process observing only committed state).
  2. Consistent container path boundary: redirected container directories (reparse points / junctions) are refused consistently across read, write, delete, and enumeration, with a negative test covering a redirected container directory.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at d4de15eb:

  • Debug (--preset dev): ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.54s)
  • Release /O2 (--preset release): ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.49s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125390326 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7125390326). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:48:17Z. --- Addressed both points in `d4de15eb`: 1. **Atomic update staging until submit**: `XGameSaveSubmitBlobWrite` / `XGameSaveSubmitBlobDelete` now stage actions in memory and apply them atomically on `XGameSaveSubmitUpdate`, leaving disk state unchanged if closed without submit or if a later action fails. Added the three controls in `tests/startup_gamesave_persist.cpp` (close-without-submit, failure of a second action, and a second process observing only committed state). 2. **Consistent container path boundary**: redirected container directories (reparse points / junctions) are refused consistently across read, write, delete, and enumeration, with a negative test covering a redirected container directory. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `d4de15eb`: - Debug (`--preset dev`): `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.54s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.49s`)
R0Y00 commented 2026-11-24 09:04:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:19:18Z.

Review: CHANGES_REQUESTED


The new staging and close-without-submit paths address the earlier immediate-write problem. One acceptance case remains. The commit lock is process-local and read_blob does not take it. During publication a second reader can see a missing old blob or a mix of generations because the update renames each blob separately. Before merging a multi-blob contract, please make readers observe one complete generation through a shared publication point, or arrange compatible reader/writer coordination across processes. Add a deterministic two-process check paused at publication, with a two-blob update and the existing second-operation failure control. Keep the separate crash-recovery limitation explicit.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6035809624 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6035809624). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T08:19:18Z. **Review:** CHANGES_REQUESTED --- The new staging and close-without-submit paths address the earlier immediate-write problem. One acceptance case remains. The commit lock is process-local and read_blob does not take it. During publication a second reader can see a missing old blob or a mix of generations because the update renames each blob separately. Before merging a multi-blob contract, please make readers observe one complete generation through a shared publication point, or arrange compatible reader/writer coordination across processes. Add a deterministic two-process check paused at publication, with a two-blob update and the existing second-operation failure control. Keep the separate crash-recovery limitation explicit.
R0Y00 commented 2026-11-24 09:04:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:16:39Z.


@tedin7 I am taking the read-side follow-up to your staged store at d4de15eb. The source-built second process will start at container enumeration, use the returned container and blob names, then verify the synchronous read and short-buffer/missing-blob cases. I will keep your storage and submit work on this PR and send the follow-up separately. If you already have a read-side change, please link it here so we can reuse it.

The independent XCL table at 64b3f355 identifies slots 13 (exact container), 14 (all containers), 18 (blob metadata) and 20 (sync read) on the same provider. Microsoft documents the enumeration callback and read buffer contract.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125939148 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7125939148). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T08:16:39Z. --- @tedin7 I am taking the read-side follow-up to your staged store at d4de15eb. The source-built second process will start at container enumeration, use the returned container and blob names, then verify the synchronous read and short-buffer/missing-blob cases. I will keep your storage and submit work on this PR and send the follow-up separately. If you already have a read-side change, please link it here so we can reuse it. The independent [XCL table at 64b3f355](https://github.com/ivall/xcl/blob/64b3f35599bb7102f55d640e1a791e7d6dd3b175/crates/xcl/src/hle/xgameruntime/gdk_table.rs#L261-L270) identifies slots 13 (exact container), 14 (all containers), 18 (blob metadata) and 20 (sync read) on the same provider. Microsoft documents the [enumeration callback](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesave/functions/xgamesaveenumeratecontainerinfo) and [read buffer contract](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesave/functions/xgamesavereadblobdata).
R0Y00 commented 2026-11-24 09:04:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:31:59Z.


@tedin7 We reproduced a write-side ordering issue on d4de15eb: when slot 28 rejects the supplied async block, its staged bytes have already replaced the committed value. A second result can also overwrite the first block's status. I am preparing a focused fix on this PR for rejected starts, inline completion and independent results. I will keep the synchronous read follow-up (#1334) separate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126249856 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126249856). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T08:31:59Z. --- @tedin7 We reproduced a write-side ordering issue on d4de15eb: when slot 28 rejects the supplied async block, its staged bytes have already replaced the committed value. A second result can also overwrite the first block's status. I am preparing a focused fix on this PR for rejected starts, inline completion and independent results. I will keep the synchronous read follow-up (#1334) separate.
R0Y00 commented 2026-11-24 09:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:39:31Z.


@tedin7 I pushed 97a63a54 to this PR's existing branch using maintainer edits. A rejected asynchronous start now leaves the committed file and staged actions intact. Slots 28 and 29 use Windows XAsyncBegin/Complete/GetResult with the submit operation's identity. File publication still runs in slot 28, before its completion callback.

Debug and Release on Windows 11 build 26200.9974 each passed 3/3 (0 skips). The controlled scheduler rejected the first start, let the same update retry, and held one block pending while a second returned its own error. An inline callback read the committed file and its own result before slot 28 returned. The independent system case used the installed Gaming Runtime and an immediate queue: the callback read 0x77 and S_OK, while the other block returned 0x80830008.

cmake --build --preset release --target startup_stub_gameinput startup_gamesave_submit startup_gamesave_persist
ctest --preset release --no-tests=error --output-on-failure -R '^startup_gamesave_(submit|persist)'

#1334 now consumes this commit. Its separate two-process readback passes after either synchronous or asynchronous submit.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126402583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126402583). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T08:39:31Z. --- @tedin7 I pushed 97a63a54 to this PR's existing branch using maintainer edits. A rejected asynchronous start now leaves the committed file and staged actions intact. Slots 28 and 29 use Windows XAsyncBegin/Complete/GetResult with the submit operation's identity. File publication still runs in slot 28, before its completion callback. Debug and Release on Windows 11 build 26200.9974 each passed 3/3 (0 skips). The controlled scheduler rejected the first start, let the same update retry, and held one block pending while a second returned its own error. An inline callback read the committed file and its own result before slot 28 returned. The independent system case used the installed Gaming Runtime and an immediate queue: the callback read 0x77 and S_OK, while the other block returned 0x80830008. ```powershell cmake --build --preset release --target startup_stub_gameinput startup_gamesave_submit startup_gamesave_persist ctest --preset release --no-tests=error --output-on-failure -R '^startup_gamesave_(submit|persist)' ``` #1334 now consumes this commit. Its separate two-process readback passes after either synchronous or asynchronous submit.
tedin7 commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:46:03Z.


AI-assisted reply to the second review, in 8b82ced3 (one new commit on top of 97a63a54, no history change).

What changed

  • Readers and publication now share one cross-process lock per container: <container>.x2w-lock beside the container directory (LockFileEx on Windows, flock elsewhere; src/startup_stubs/file_lock.h). Publication holds it exclusively until the last blob is in place; read_blob takes it shared and the new read_blobs reads several blobs under one hold, so another process sees the whole previous generation or the whole new one. Blob and container deletes take it too.
  • Chosen over a manifest/generation directory because it keeps the layout the earlier commits of this PR already write (one directory per container, one file per blob). Staging files are written before the lock, so readers wait only for the renames.
  • The wait is bounded (5 s default, a Store parameter). On timeout the call returns the new busy status and changes nothing. A holder that dies is harmless: the system drops the lock when its handle closes.
  • tests/startup_gamesave_publish.cpp: a writer process pauses at each step of a two-blob publication (old blob moved aside, new blob in place, for each blob) through file handshakes with deadlines, no sleeps as synchronisation. A second process must be refused with busy while paused, never shown a mix or a missing blob, and a reader that waits sees the whole new generation. It also covers the existing failing-second-action control (previous generation whole for another process, lock free afterwards) and a lock holder that ends without unlocking.
  • Negative control: the same test is built from a generated copy of the headers whose lock does nothing (startup_gamesave_publish_unlocked); it must be caught, and is: the reader sees a mixed generation at pause points 0 to 2. The pause points exist only in the generated test copies, not in the production headers.

What remains (kept explicit in docs/startup-runtime.md)

  • Crash recovery is a separate limitation: if the writer is killed mid-replacement the lock is released but nothing rolls the update back or completes it, so a mixed state and .x2w-old/.x2w-part files can remain. No recovery pass yet.
  • A program that reads the files without this store is not covered by the lock.
  • #1334 adds reads; it should go through read_blobs/read_blob to stay under the lock.

Verified here (Linux, not the Windows node)

  • g++ native: startup_gamesave_persist ok; startup_gamesave_publish locked variant ok 5/5 runs, unlocked variant caught.
  • MinGW (x86_64-w64-mingw32-g++) binaries under Wine: persist ok, publish locked ok (3 runs), unlocked caught. Wine is not NTFS and MSVC was not used.
  • git diff --check, docs_links_check.py, bidi_controls_check.py pass; x2w_pipe preflight: WARN only (behind base, overlap with #1334 and docs edits by others).

To run on Windows Server 2025 / NTFS with MSVC: ctest --preset dev -R startup_gamesave (also --preset release).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126537390 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126537390). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:46:03Z. --- AI-assisted reply to the second review, in 8b82ced3 (one new commit on top of 97a63a54, no history change). What changed - Readers and publication now share one cross-process lock per container: `<container>.x2w-lock` beside the container directory (`LockFileEx` on Windows, `flock` elsewhere; `src/startup_stubs/file_lock.h`). Publication holds it exclusively until the last blob is in place; `read_blob` takes it shared and the new `read_blobs` reads several blobs under one hold, so another process sees the whole previous generation or the whole new one. Blob and container deletes take it too. - Chosen over a manifest/generation directory because it keeps the layout the earlier commits of this PR already write (one directory per container, one file per blob). Staging files are written before the lock, so readers wait only for the renames. - The wait is bounded (5 s default, a `Store` parameter). On timeout the call returns the new `busy` status and changes nothing. A holder that dies is harmless: the system drops the lock when its handle closes. - `tests/startup_gamesave_publish.cpp`: a writer process pauses at each step of a two-blob publication (old blob moved aside, new blob in place, for each blob) through file handshakes with deadlines, no sleeps as synchronisation. A second process must be refused with `busy` while paused, never shown a mix or a missing blob, and a reader that waits sees the whole new generation. It also covers the existing failing-second-action control (previous generation whole for another process, lock free afterwards) and a lock holder that ends without unlocking. - Negative control: the same test is built from a generated copy of the headers whose lock does nothing (`startup_gamesave_publish_unlocked`); it must be caught, and is: the reader sees a mixed generation at pause points 0 to 2. The pause points exist only in the generated test copies, not in the production headers. What remains (kept explicit in docs/startup-runtime.md) - Crash recovery is a separate limitation: if the writer is killed mid-replacement the lock is released but nothing rolls the update back or completes it, so a mixed state and `.x2w-old`/`.x2w-part` files can remain. No recovery pass yet. - A program that reads the files without this store is not covered by the lock. - #1334 adds reads; it should go through `read_blobs`/`read_blob` to stay under the lock. Verified here (Linux, not the Windows node) - g++ native: `startup_gamesave_persist` ok; `startup_gamesave_publish` locked variant ok 5/5 runs, unlocked variant caught. - MinGW (x86_64-w64-mingw32-g++) binaries under Wine: persist ok, publish locked ok (3 runs), unlocked caught. Wine is not NTFS and MSVC was not used. - `git diff --check`, docs_links_check.py, bidi_controls_check.py pass; x2w_pipe preflight: WARN only (behind base, overlap with #1334 and docs edits by others). To run on Windows Server 2025 / NTFS with MSVC: `ctest --preset dev -R startup_gamesave` (also `--preset release`).
tedin7 commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:52:56Z.


AI-assisted. Windows Server 2025 node (MSVC 14.44, Debug) on 8b82ced3: startup_gamesave_publish_locked failed 7 checks, all of them expecting Status::busy while another process holds the lock (4x reader at pause points 0..3, 3x commit/read/delete). The lock mapped only ERROR_LOCK_VIOLATION to "busy"; any other code from LockFileEx(LOCKFILE_FAIL_IMMEDIATELY) became Status::io_error. Fix in a43e9f8f: lock violation, sharing violation and ERROR_IO_PENDING all mean busy (a pending request is cancelled and awaited before the stack OVERLAPPED is released). The exact code the node returned is not known; it was not reproducible here (Linux and MinGW under Wine pass, and Wine is not NTFS). The test messages now print the real Status, the reader exit code and the system error of a zero-wait lock probe, and a new startup_gamesave_lock_errors test checks the mapping on every platform. To re-run on the Windows node: ctest -R startup_gamesave, Debug and release.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126680781 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126680781). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:52:56Z. --- AI-assisted. Windows Server 2025 node (MSVC 14.44, Debug) on 8b82ced3: startup_gamesave_publish_locked failed 7 checks, all of them expecting Status::busy while another process holds the lock (4x reader at pause points 0..3, 3x commit/read/delete). The lock mapped only ERROR_LOCK_VIOLATION to "busy"; any other code from LockFileEx(LOCKFILE_FAIL_IMMEDIATELY) became Status::io_error. Fix in a43e9f8f: lock violation, sharing violation and ERROR_IO_PENDING all mean busy (a pending request is cancelled and awaited before the stack OVERLAPPED is released). The exact code the node returned is not known; it was not reproducible here (Linux and MinGW under Wine pass, and Wine is not NTFS). The test messages now print the real Status, the reader exit code and the system error of a zero-wait lock probe, and a new startup_gamesave_lock_errors test checks the mapping on every platform. To re-run on the Windows node: ctest -R startup_gamesave, Debug and release.
tedin7 commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:59:00Z.


Found the cause of the remaining failure on the Windows node in startup_gamesave_publish_locked: both publish tests named their temp directory from std::rand() (constant when srand is not called on some runtimes) and time(nullptr), and ctest --parallel started the locked and unlocked runs in the same second, so they shared one directory and removed it under each other. 2f9c55d9 names the directory from the process id and a steady-clock reading (same change in startup_gamesave_persist). Locally two simultaneous locked runs pass 2/2 with 0 failures. Not run on MSVC or NTFS. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126805926 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126805926). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:59:00Z. --- Found the cause of the remaining failure on the Windows node in `startup_gamesave_publish_locked`: both publish tests named their temp directory from `std::rand()` (constant when `srand` is not called on some runtimes) and `time(nullptr)`, and `ctest --parallel` started the locked and unlocked runs in the same second, so they shared one directory and removed it under each other. `2f9c55d9` names the directory from the process id and a steady-clock reading (same change in `startup_gamesave_persist`). Locally two simultaneous locked runs pass 2/2 with 0 failures. Not run on MSVC or NTFS. AI-assisted.
tedin7 commented 2026-11-24 09:04:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:02:12Z.


@R0Y00 Addressed on top of 97a63a54 in 8b82ced3..2f9c55d9:

  • Added a cross-process container publication lock (src/startup_stubs/file_lock.h, LockFileEx on Windows / flock on POSIX) acquired shared by read_blob/read_blobs and exclusively by commit/delete_blob/delete_container, so readers in other processes observe one complete generation rather than mixed or missing blobs.
  • Added the deterministic two-process check paused at every publication step (tests/startup_gamesave_publish.cpp, built as startup_gamesave_publish_locked and the lock-disabled negative control startup_gamesave_publish_unlocked that verifies "reader saw a mixed generation"), covering a two-blob update, the second-operation failure control, and dead-holder lock release, plus startup_gamesave_lock_errors.
  • Kept the separate crash-recovery limitation explicit in docs/startup-runtime.md and save_store.h.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, NTFS) at 2f9c55d9f684c49ee737ccf99686aaaa677b5246:

  • Debug (--preset dev): ctest --preset dev -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist 0.66s, startup_gamesave_publish_locked 2.05s, startup_gamesave_publish_unlocked 0.96s, startup_gamesave_lock_errors 0.02s, startup_gamesave_submit_controlled 0.12s); skipped (capability): startup_gamesave_submit_system
  • Release /O2 (--preset release): ctest --preset release -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist 0.63s, startup_gamesave_publish_locked 2.03s, startup_gamesave_publish_unlocked 0.90s, startup_gamesave_lock_errors 0.02s, startup_gamesave_submit_controlled 0.11s); skipped (capability): startup_gamesave_submit_system
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126874410 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126874410). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:02:12Z. --- @R0Y00 Addressed on top of `97a63a54` in `8b82ced3`..`2f9c55d9`: - Added a cross-process container publication lock (`src/startup_stubs/file_lock.h`, `LockFileEx` on Windows / `flock` on POSIX) acquired shared by `read_blob`/`read_blobs` and exclusively by `commit`/`delete_blob`/`delete_container`, so readers in other processes observe one complete generation rather than mixed or missing blobs. - Added the deterministic two-process check paused at every publication step (`tests/startup_gamesave_publish.cpp`, built as `startup_gamesave_publish_locked` and the lock-disabled negative control `startup_gamesave_publish_unlocked` that verifies `"reader saw a mixed generation"`), covering a two-blob update, the second-operation failure control, and dead-holder lock release, plus `startup_gamesave_lock_errors`. - Kept the separate crash-recovery limitation explicit in `docs/startup-runtime.md` and `save_store.h`. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, NTFS) at `2f9c55d9f684c49ee737ccf99686aaaa677b5246`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure`: **5/6 passed** (`startup_gamesave_persist` `0.66s`, `startup_gamesave_publish_locked` `2.05s`, `startup_gamesave_publish_unlocked` `0.96s`, `startup_gamesave_lock_errors` `0.02s`, `startup_gamesave_submit_controlled` `0.12s`); skipped (capability): `startup_gamesave_submit_system` - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure`: **5/6 passed** (`startup_gamesave_persist` `0.63s`, `startup_gamesave_publish_locked` `2.03s`, `startup_gamesave_publish_unlocked` `0.90s`, `startup_gamesave_lock_errors` `0.02s`, `startup_gamesave_submit_controlled` `0.11s`); skipped (capability): `startup_gamesave_submit_system`
upstream-sync closed this pull request 2026-11-24 10:02:18 +00:00
R0Y00 commented 2026-11-24 10:02:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:05:02Z.

Review: APPROVED


Windows Release passed all six save tests, including the deterministic locked-reader publication case, the no-lock control, and both async schedulers. The new names keep parallel test runs isolated. This resolves the publication review for cooperating processes. Crash recovery during publication remains outside the documented scope.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036371069 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6036371069). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T09:05:02Z. **Review:** APPROVED --- Windows Release passed all six save tests, including the deterministic locked-reader publication case, the no-lock control, and both async schedulers. The new names keep parallel test runs isolated. This resolves the publication review for cooperating processes. Crash recovery during publication remains outside the documented scope.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1239
No description provided.