fix(libc): expand %VAR% mount tokens in guest paths #4565

Closed
ahmedhamouda78 wants to merge 1 commit from upstream-pr/4565 into main
ahmedhamouda78 commented 2026-10-12 15:47:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmedhamouda78 on 2026-10-12T15:47:12Z.


What

ASTRO BOT (PPSA21564) stops during start-up because its asset paths carry a
literal %ASOBI_ROOT% token that reaches the file API unresolved, so the sound
config XML never loads and its SoundManager asserts.

This expands %VAR% tokens at the /host path-translation layer. In Resolve()'s
existing per-segment loop, a path segment that is exactly %NAME% is replaced
by the value of guest environment variable NAME (via a new read-only
LookupGuestEnvironment_nid_no_patch over the same table getenv uses — no guest
ABI, no mutation). The variable's own directory separators split into components,
and a leading separator is stripped so an absolute value extends the guest path
rather than escaping the guest root.

Scope is deliberately narrow, matching the issue's guidance and avoiding the two
closed wrong-layer attempts (libc % expansion in #3959; a guest env var in #4274):
only a whole-segment token is touched, so a segment that merely contains % (a file
named 100%done.txt) is unchanged, and a token naming no set/empty variable is left
literal — behaviour is identical to today for every path without a resolvable token.

Tested

Linux, GCC 16.2.0, C++20. core/libs/tests/GuestPathCase.cpp (guest_path_case
target) is extended with a self-contained, cross-platform block asserting: a
%VAR% segment expands to a known variable's directory; a value with nested
directories splits into components; a backslash-separated value resolves; an
unset token stays literal (proven by a successful read of a real file named
%UNSET_TOKEN%); and empty-value and separator-only-value tokens stay literal.
The full guest_path_case target links the whole libc/libkernel build (needs
the graphics stack this headless host cannot build), so it runs in CI; locally the
same resolver logic was exercised directly against ResolvePath_nid_no_patch and
adversarial ../absolute values were confirmed to stay under the guest root.
Not run on hardware or against the title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source — N/A, no third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA21564 #3480
  • AI-assisted: yes

The in-band %VAR% substitution has no escape syntax (%% is not handled), so a
file whose name is exactly %NAME% for a set variable NAME would be expanded
rather than opened literally. No such collision is known on a PS5 title; this
tradeoff is recorded in docs/dev/TechnicalDebt.md.

Fixes #3480

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4831750898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4565). Originally posted by [ahmedhamouda78](https://github.com/ahmedhamouda78) on 2026-10-12T15:47:12Z. --- ### What ASTRO BOT (PPSA21564) stops during start-up because its asset paths carry a literal `%ASOBI_ROOT%` token that reaches the file API unresolved, so the sound config XML never loads and its `SoundManager` asserts. This expands `%VAR%` tokens at the `/host` path-translation layer. In `Resolve()`'s existing per-segment loop, a path segment that is **exactly** `%NAME%` is replaced by the value of guest environment variable `NAME` (via a new read-only `LookupGuestEnvironment_nid_no_patch` over the same table `getenv` uses — no guest ABI, no mutation). The variable's own directory separators split into components, and a leading separator is stripped so an absolute value extends the guest path rather than escaping the guest root. Scope is deliberately narrow, matching the issue's guidance and avoiding the two closed wrong-layer attempts (libc `%` expansion in #3959; a guest env var in #4274): only a whole-segment token is touched, so a segment that merely contains `%` (a file named `100%done.txt`) is unchanged, and a token naming no set/empty variable is left literal — behaviour is identical to today for every path without a resolvable token. ### Tested Linux, GCC 16.2.0, C++20. `core/libs/tests/GuestPathCase.cpp` (`guest_path_case` target) is extended with a self-contained, cross-platform block asserting: a `%VAR%` segment expands to a known variable's directory; a value with nested directories splits into components; a backslash-separated value resolves; an unset token stays literal (proven by a successful read of a real file named `%UNSET_TOKEN%`); and empty-value and separator-only-value tokens stay literal. The full `guest_path_case` target links the whole `libc`/`libkernel` build (needs the graphics stack this headless host cannot build), so it runs in CI; locally the same resolver logic was exercised directly against `ResolvePath_nid_no_patch` and adversarial `..`/absolute values were confirmed to stay under the guest root. Not run on hardware or against the title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source — N/A, no third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA21564 #3480 - [x] AI-assisted: yes The in-band `%VAR%` substitution has no escape syntax (`%%` is not handled), so a file whose name is exactly `%NAME%` for a set variable `NAME` would be expanded rather than opened literally. No such collision is known on a PS5 title; this tradeoff is recorded in `docs/dev/TechnicalDebt.md`. Fixes #3480
ahmedhamouda78 commented 2026-10-13 09:50:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmedhamouda78 on 2026-10-13T09:50:34Z.


Closing as a duplicate — %VAR% path-token expansion for #3480 already landed in aa3f7b7b9c (feat(libc): add %VAR% environment variable expansion in path resolution), which closed the issue. Thanks to @StarMrGamer for the fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142902210 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4565#issuecomment-6142902210). Originally posted by [ahmedhamouda78](https://github.com/ahmedhamouda78) on 2026-10-13T09:50:34Z. --- Closing as a duplicate — `%VAR%` path-token expansion for #3480 already landed in `aa3f7b7b9c` (`feat(libc): add %VAR% environment variable expansion in path resolution`), which closed the issue. Thanks to @StarMrGamer for the fix.

Pull request closed

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
boykopovar/AnyPS5!4565
No description provided.