HLE: the narrow module path and argv are in the ANSI code page #4539

Open
github-bot wants to merge 1 commit from github-bot/gh-4538 into main AGit
Owner

@⁠breachato on GitHub · 2026-11-30 22:07 UTC · original
breachato:hle-narrow-paths-ansi → main · +36 −4 · 1 files · 1 commits · open

[pr-fix]

What it changes

GetModuleFileNameA gave a title image's path as UTF-8 bytes (path.as_bytes()), and the C runtime's narrow argv (__p___argv, built by title_argv with CString::new) was UTF-8 too. Windows gives both in the ANSI code page, and so does our own GetCommandLineA (through host::ansi). With a non-ASCII folder, for example C:\Téléchargements\jeu\game.exe or a user folder with an accent:

  • the title gets é for é from GetModuleFileNameA, and when it passes the path on to other narrow calls (CreateFileA, fopen, ...) they read it in the code page and do not find the file;
  • GetCommandLineA and argv[0] disagree on the program.

Both now go through host::ansi, as GetCommandLineA does (a character the code page lacks becomes its default character, as on Windows). GetCommandLineA's notes already said a NUL inside an argument ends it there "as in title_argv"; title_argv actually dropped such an argument, and now ends it there.

How it was tested

  • No GPU or game needed.
  • New test narrow_paths_and_arguments_are_in_the_ansi_code_page: a title image at C:\Téléchargements\jeu\game.exe, then GetModuleFileNameA and title_argv.
  • Before (main, code page 1252): GetModuleFileNameA wrote C:\T C3 A9 l C3 A9 chargements... (UTF-8). After: C:\T E9 l E9 chargements..., the bytes GetCommandLineA gives for the same text.
  • cargo test -p victory-hle --lib --locked modules::kernel: 19 passed, including the existing the_command_line_reads_back_as_the_title_arguments (argv still equals the split command line).
  • cargo test -p victory-hle --lib --locked: 469 passed; modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it failed in the full parallel run and passes alone, the known flake (#2420, #2439).
  • cargo clippy -p victory-hle --no-deps --all-targets: nothing in kernel.rs.
  • cargo test passed for the crates it touches: yes

How to try it

cargo test -p victory-hle --lib --locked narrow_paths_and_arguments. On main it fails with the UTF-8 bytes above (on any code page but UTF-8).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none for GetModuleFileNameA or __p___argv.

Assisted by Claude.

**@⁠breachato** on GitHub · 2026-11-30 22:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4538) `breachato:hle-narrow-paths-ansi` → `main` · +36 −4 · 1 files · 1 commits · open [pr-fix] ## What it changes `GetModuleFileNameA` gave a title image's path as UTF-8 bytes (`path.as_bytes()`), and the C runtime's narrow `argv` (`__p___argv`, built by `title_argv` with `CString::new`) was UTF-8 too. Windows gives both in the ANSI code page, and so does our own `GetCommandLineA` (through `host::ansi`). With a non-ASCII folder, for example `C:\Téléchargements\jeu\game.exe` or a user folder with an accent: - the title gets `é` for `é` from `GetModuleFileNameA`, and when it passes the path on to other narrow calls (`CreateFileA`, `fopen`, ...) they read it in the code page and do not find the file; - `GetCommandLineA` and `argv[0]` disagree on the program. Both now go through `host::ansi`, as `GetCommandLineA` does (a character the code page lacks becomes its default character, as on Windows). `GetCommandLineA`'s notes already said a NUL inside an argument ends it there "as in `title_argv`"; `title_argv` actually dropped such an argument, and now ends it there. ## How it was tested - No GPU or game needed. - New test `narrow_paths_and_arguments_are_in_the_ansi_code_page`: a title image at `C:\Téléchargements\jeu\game.exe`, then `GetModuleFileNameA` and `title_argv`. - Before (`main`, code page 1252): `GetModuleFileNameA` wrote `C:\T` `C3 A9` `l` `C3 A9` `chargements...` (UTF-8). After: `C:\T` `E9` `l` `E9` `chargements...`, the bytes `GetCommandLineA` gives for the same text. - `cargo test -p victory-hle --lib --locked modules::kernel`: 19 passed, including the existing `the_command_line_reads_back_as_the_title_arguments` (argv still equals the split command line). - `cargo test -p victory-hle --lib --locked`: 469 passed; `modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it` failed in the full parallel run and passes alone, the known flake (#2420, #2439). - `cargo clippy -p victory-hle --no-deps --all-targets`: nothing in `kernel.rs`. - `cargo test` passed for the crates it touches: yes ## How to try it `cargo test -p victory-hle --lib --locked narrow_paths_and_arguments`. On `main` it fails with the UTF-8 bytes above (on any code page but UTF-8). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none for `GetModuleFileNameA` or `__p___argv`. Assisted by Claude.
GetModuleFileNameA gave a title image's path as UTF-8 bytes, and the C
runtime's narrow argv (__p___argv) was made the same way, while
GetCommandLineA already gives the same line in the ANSI code page, as
Windows does. With a non-ASCII folder (C:\Téléchargements\..), the title
got "é" for "é" and passed that on to other narrow calls, which read it
in the code page; GetCommandLineA and argv disagreed on the program.

Both now go through host::ansi, like GetCommandLineA. A NUL inside an
argument now ends it there, as GetCommandLineA's notes already said of
title_argv (it used to drop such an argument).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 22:08:10 +00:00
github-bot force-pushed github-bot/gh-4538 from 380affaf0d to 77ae93ba77 2026-12-01 14:00:18 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/4539/head:github-bot/gh-4538'
git switch 'github-bot/gh-4538'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-4538'
git switch 'github-bot/gh-4538'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-4538'
git switch 'github-bot/gh-4538'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-4538'
git switch 'main'
git merge --squash 'github-bot/gh-4538'
git switch 'main'
git merge --ff-only 'github-bot/gh-4538'
git switch 'main'
git merge 'github-bot/gh-4538'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4539
No description provided.