[PR #88] [CLOSED] runtime/shims: shim GetLogicalProcessorInformation and GlobalMemoryStatusEx #142

Closed
opened 2026-11-26 20:16:55 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/88
Author: @Andretuta
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: old-pr/9816


📝 Commits (1)

  • 793724f runtime/shims: shim GetLogicalProcessorInformation and GlobalMemoryStatusEx

📊 Changes

4 files changed (+489 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+14 -0)
➕ runtime/shims/sysinfo.cpp (+297 -0)
➕ runtime/test/sysinfo_test.cpp (+176 -0)
📝 scripts/build_runtime.ps1 (+2 -2)

📄 Description

Carried over from old PR 9816 by piyonchu in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9816, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
This branch conflicts with the current main and needs a rebase.
piyonchu: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Clean-room shim for api-ms-win-core-sysinfo-l1-1-0.dll, kernel32.dll, and kernelbase.dll exporting GetLogicalProcessorInformation and GlobalMemoryStatusEx.

Why

Static analysis of the retail executable (game_scarlett_master.exe, local inspection only — zero game bytes/RVAs included) shows:

  • GetLogicalProcessorInformation is called in a strict two-step pattern: (nullptr, &len) must return FALSE with GetLastError() == ERROR_INSUFFICIENT_BUFFER or the caller executes int3, and (buf, &len) must return TRUE or the caller executes int3; each 32-byte RelationProcessorCore record is then walked to count physical cores and __popcnt64(ProcessorMask) for logical processors.
  • GlobalMemoryStatusEx queries physical/available memory and load percentage via MEMORYSTATUSEX (dwLength == 64).

Changes

  • Added runtime/shims/sysinfo.cpp:
    • GetLogicalProcessorInformation: forwards to host by default while guarding against hosts/sandboxes that violate the ERROR_INSUFFICIENT_BUFFER probe contract or return an empty record buffer; supports deterministic topology overrides via LEONIDA_CPU_TOPOLOGY (xbox/scarlett = 8 physical cores / 16 logical SMT threads with per-core L1/L2 + shared 4-core L3 caches + NUMA/package records, or custom NxM / N up to 64 logical CPUs).
    • GlobalMemoryStatusEx: validates lpBuffer != nullptr && dwLength == sizeof(MEMORYSTATUSEX) (ERROR_INVALID_PARAMETER on invalid input), forwards to host by default, and supports LEONIDA_SYSTEM_MEMORY_MB (xbox/scarlett = 16384 MiB, or explicit MiB) while clamping available memory and recomputing load percentage.
    • Uses no function-local static initialization guards (0 _Init_thread_header symbols verified via dumpbin /symbols).
  • Added runtime/test/sysinfo_test.cpp covering validation contracts, host passthrough, "xbox" 8c/16t topology + SMT/L3 verification, "6x10" custom core distribution, invalid env fallback, and LEONIDA_SYSTEM_MEMORY_MB overrides.
  • Wired shims/sysinfo.cpp and sysinfo_test into runtime/CMakeLists.txt and scripts/build_runtime.ps1.

Verification

  • ctest -R '^sysinfo$': PASS (1/1) on a60e5eab5 (base only 1 README commit behind main).
  • Full CPU ctest suite (prior base): 113/113 CPU tests passed (8 skipped/disabled hardware/asset/SDL3 tests).
  • dumpbin /symbols on sysinfo.obj: 0 _Init_thread_header symbols.
  • gta6rt.exe --dry-run game_scarlett_master.exe: resolves both GetLogicalProcessorInformation and GlobalMemoryStatusEx via shim.
  • python scripts/check_no_game_data.py, python tests/test_ctest_registration.py (4/4 OK), git diff --check.
  • Claimed on #9677 (https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116628939).

AI-assisted: yes


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/88 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `old-pr/9816` --- ### 📝 Commits (1) - [`793724f`](https://github.com/ubiquitarianism/leonida/commit/793724fbf4b17d066a174c8ea1d9d374d8883575) runtime/shims: shim GetLogicalProcessorInformation and GlobalMemoryStatusEx ### 📊 Changes **4 files changed** (+489 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+14 -0) ➕ `runtime/shims/sysinfo.cpp` (+297 -0) ➕ `runtime/test/sysinfo_test.cpp` (+176 -0) 📝 `scripts/build_runtime.ps1` (+2 -2) </details> ### 📄 Description > Carried over from **old PR 9816** by `piyonchu` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9816`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > This branch conflicts with the current `main` and needs a rebase. > `piyonchu`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Clean-room shim for `api-ms-win-core-sysinfo-l1-1-0.dll`, `kernel32.dll`, and `kernelbase.dll` exporting `GetLogicalProcessorInformation` and `GlobalMemoryStatusEx`. ### Why Static analysis of the retail executable (`game_scarlett_master.exe`, local inspection only — zero game bytes/RVAs included) shows: - `GetLogicalProcessorInformation` is called in a strict two-step pattern: `(nullptr, &len)` must return `FALSE` with `GetLastError() == ERROR_INSUFFICIENT_BUFFER` or the caller executes `int3`, and `(buf, &len)` must return `TRUE` or the caller executes `int3`; each 32-byte `RelationProcessorCore` record is then walked to count physical cores and `__popcnt64(ProcessorMask)` for logical processors. - `GlobalMemoryStatusEx` queries physical/available memory and load percentage via `MEMORYSTATUSEX` (`dwLength == 64`). ### Changes - Added [`runtime/shims/sysinfo.cpp`](runtime/shims/sysinfo.cpp): - `GetLogicalProcessorInformation`: forwards to host by default while guarding against hosts/sandboxes that violate the `ERROR_INSUFFICIENT_BUFFER` probe contract or return an empty record buffer; supports deterministic topology overrides via `LEONIDA_CPU_TOPOLOGY` (`xbox`/`scarlett` = 8 physical cores / 16 logical SMT threads with per-core L1/L2 + shared 4-core L3 caches + NUMA/package records, or custom `NxM` / `N` up to 64 logical CPUs). - `GlobalMemoryStatusEx`: validates `lpBuffer != nullptr && dwLength == sizeof(MEMORYSTATUSEX)` (`ERROR_INVALID_PARAMETER` on invalid input), forwards to host by default, and supports `LEONIDA_SYSTEM_MEMORY_MB` (`xbox`/`scarlett` = 16384 MiB, or explicit MiB) while clamping available memory and recomputing load percentage. - Uses no function-local static initialization guards (`0` `_Init_thread_header` symbols verified via `dumpbin /symbols`). - Added [`runtime/test/sysinfo_test.cpp`](runtime/test/sysinfo_test.cpp) covering validation contracts, host passthrough, `"xbox"` 8c/16t topology + SMT/L3 verification, `"6x10"` custom core distribution, invalid env fallback, and `LEONIDA_SYSTEM_MEMORY_MB` overrides. - Wired `shims/sysinfo.cpp` and `sysinfo_test` into `runtime/CMakeLists.txt` and `scripts/build_runtime.ps1`. ### Verification - `ctest -R '^sysinfo$'`: `PASS (1/1)` on `a60e5eab5` (base only 1 README commit behind `main`). - Full CPU `ctest` suite (prior base): `113/113` CPU tests passed (8 skipped/disabled hardware/asset/SDL3 tests). - `dumpbin /symbols` on `sysinfo.obj`: `0` `_Init_thread_header` symbols. - `gta6rt.exe --dry-run game_scarlett_master.exe`: resolves both `GetLogicalProcessorInformation` and `GlobalMemoryStatusEx` via `shim`. - `python scripts/check_no_game_data.py`, `python tests/test_ctest_registration.py` (`4/4` OK), `git diff --check`. - Claimed on `#9677` (`https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116628939`). AI-assisted: yes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:16:55 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#142
No description provided.