libc: implement guest getenv and store setenv values #2452

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

@⁠yasaiiko on GitHub · 2026-11-20 12:11 UTC · original
yasaiiko:libc-guest-getenv → main · +178 −0 · 3 files · 1 commits · open

Summary

Implements guest getenv and makes setenv store its value, as the corrected analysis in #2000 suggests: the imports are missing implementations, not version aliases.

  • init_env seeds a guest-only environment from the entry envp (entries without = or with an empty name are skipped; the first of duplicate names wins).
  • getenv (smbQukfxYJM) returns the stored value, or nullptr. A null or empty name, or one starting with =, sets EINVAL; a name containing = is looked up by the part before it, as FreeBSD's getenv does.
  • setenv keeps its existing argument checks and now stores the value, replacing an existing one only when overwrite is nonzero. It still never touches the emulator's host environment.
  • A null init_env entry clears the guest environment.

Both homebrew eboots I checked import smbQukfxYJM: Syobon Action (PPSA47402, kvaps/syobon-action-ps5 01.001.000) and Apotris (PPSA98513, darkxex/Apotris-PS5 v1.0.0).

This supersedes the closed #2007 (bobrass), which took the same approach but was not built or tested.

Fixes the getenv part of #2000; the other unresolved symbols listed there are not addressed.

Testing

Windows 11 build 26300, Build Tools 2022 clang-cl 19.1.5, Release, -DKYTY_BUILD_LAUNCHER=OFF.

  • New libc_environment_tests (registered with add_test and in kyty_tests): resolves init_env, getenv and setenv by NID through InitLibC_1 and checks the entry environment, invalid names and EINVAL, overwrite 0 and 1, and that a null entry clears the environment.
    • with this change: exit 0
    • with src/libs/libC.cpp from main: exit 1 (getenv is not registered)
  • http_uri_parse_tests builds unchanged.
  • src/libs/libC.cpp formatted with clang-format 22.1.3 (the pre-commit hook's version).
  • Not run in a title: kyty_emulator stops before loading on this machine's Intel iGPU (shaderResourceMinLod is not supported, the same check as #2434), so the change is not verified on a running homebrew.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

**@⁠yasaiiko** on GitHub · 2026-11-20 12:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2452) `yasaiiko:libc-guest-getenv` → `main` · +178 −0 · 3 files · 1 commits · open ## Summary Implements guest `getenv` and makes `setenv` store its value, as the corrected analysis in #2000 suggests: the imports are missing implementations, not version aliases. - `init_env` seeds a guest-only environment from the entry `envp` (entries without `=` or with an empty name are skipped; the first of duplicate names wins). - `getenv` (`smbQukfxYJM`) returns the stored value, or `nullptr`. A null or empty name, or one starting with `=`, sets `EINVAL`; a name containing `=` is looked up by the part before it, as FreeBSD's `getenv` does. - `setenv` keeps its existing argument checks and now stores the value, replacing an existing one only when `overwrite` is nonzero. It still never touches the emulator's host environment. - A null `init_env` entry clears the guest environment. Both homebrew eboots I checked import `smbQukfxYJM`: Syobon Action (PPSA47402, kvaps/syobon-action-ps5 01.001.000) and Apotris (PPSA98513, darkxex/Apotris-PS5 v1.0.0). This supersedes the closed #2007 (bobrass), which took the same approach but was not built or tested. Fixes the `getenv` part of #2000; the other unresolved symbols listed there are not addressed. ## Testing Windows 11 build 26300, Build Tools 2022 clang-cl 19.1.5, Release, `-DKYTY_BUILD_LAUNCHER=OFF`. - New `libc_environment_tests` (registered with `add_test` and in `kyty_tests`): resolves `init_env`, `getenv` and `setenv` by NID through `InitLibC_1` and checks the entry environment, invalid names and `EINVAL`, `overwrite` 0 and 1, and that a null entry clears the environment. - with this change: exit 0 - with `src/libs/libC.cpp` from `main`: exit 1 (`getenv` is not registered) - `http_uri_parse_tests` builds unchanged. - `src/libs/libC.cpp` formatted with clang-format 22.1.3 (the pre-commit hook's version). - Not run in a title: `kyty_emulator` stops before loading on this machine's Intel iGPU (`shaderResourceMinLod is not supported`, the same check as #2434), so the change is not verified on a running homebrew. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
init_env now seeds a guest-only environment from the entry envp.
getenv (smbQukfxYJM) reads it and setenv writes it, honouring
overwrite, instead of returning 0 without storing anything. The host
environment of the emulator is not touched.

Adds libc_environment_tests, which resolves the three exports by NID
and covers the entry environment, invalid names, overwrite and a null
entry. It fails on main (getenv is not registered) and passes with
this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:39 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 12:16 UTC · original

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

LibC now stores guest environment variables in a mutex-protected map initialized from envp. setenv inserts or updates values according to the overwrite argument, and getenv looks up values in the guest map. The change registers getenv as a LibC symbol. A new test executable checks initialization, invalid inputs, overwrite behavior, and clearing the environment. CMake adds the executable to CTest and the aggregate test target.

Suggested reviewers: nmzik

Change: Feature

Merge Risk: Minimal · up to e03e5

This change adds guest getenv and makes setenv store values in a guest-only environment. No merge-blocking risk was identified, and the new tests cover the main behaviors.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: guest getenv is implemented and setenv stores values in the libc change. It matches the libC.cpp changes (GuestEnvironment map, getenv registration in InitLibC_1, sete…
Description check Passed The description states that it implements guest getenv and changes setenv to store values, and it lists the init_env seeding, EINVAL handling, overwrite rules, and the libc_environment_tests registrat…
Linked Issues check Passed The only directly linked issue, #2007, is closed. It is background only and does not supply coding requirements for this pull request. No active directly linked targets remain. Issue #2000 appears in …
Out of Scope Changes check Passed All changes relate to the stated purpose: implementing guest getenv and storing setenv values. In src/libs/libC.cpp, the change adds a guest-only environment map, seeds it in init_env from envp, adds …
Full details: Title check

Explanation

The title names the main change: guest getenv is implemented and setenv stores values in the libc change. It matches the libC.cpp changes (GuestEnvironment map, getenv registration in InitLibC_1, setenv storing values) and the new test. It is specific and concise.

Full details: Description check

Explanation

The description states that it implements guest getenv and changes setenv to store values, and it lists the init_env seeding, EINVAL handling, overwrite rules, and the libc_environment_tests registration. It matches the changeset in libC.cpp, CMakeLists.txt, and the new test file.

Full details: Linked Issues check

Explanation

The only directly linked issue, #2007, is closed. It is background only and does not supply coding requirements for this pull request. No active directly linked targets remain. Issue #2000 appears in the PR description and objectives, but it is not a linked target here. Because no active coding requirements apply, no requirement-level compliance check is needed.

Full details: Out of Scope Changes check

Explanation

All changes relate to the stated purpose: implementing guest getenv and storing setenv values. In src/libs/libC.cpp, the change adds a guest-only environment map, seeds it in init_env from envp, adds getenv (registered in InitLibC_1), and updates setenv to store values with overwrite handling. CMakeLists.txt adds the libc_environment_tests target and its CTest registration. tests/LibCEnvironmentTests.cpp covers these functions. The PR excludes other unresolved #2000 symbols, and the diff does not add them. The summary shows no unrelated changes. The summary was used as evidence; no repository inspection was needed to reach this result.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a1fc5ae438 and e03e5a71e7.

Files selected for processing: 3

  • CMakeLists.txt
  • src/libs/libC.cpp
  • tests/LibCEnvironmentTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 12:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2452#issuecomment-7039309841) <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2452?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> LibC now stores guest environment variables in a mutex-protected map initialized from `envp`. `setenv` inserts or updates values according to the overwrite argument, and `getenv` looks up values in the guest map. The change registers `getenv` as a LibC symbol. A new test executable checks initialization, invalid inputs, overwrite behavior, and clearing the environment. CMake adds the executable to CTest and the aggregate test target. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"e03e5a71e743f412688f476666c0361d11c200b9" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Feature <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>e03e5</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `e03e5` --> <!-- final_review_risk_coverage:{"sourceCommitId":"e03e5a71e743f412688f476666c0361d11c200b9","coveredCommitId":"e03e5a71e743f412688f476666c0361d11c200b9","kind":"reviewed"} --> This change adds guest getenv and makes setenv store values in a guest-only environment. No merge-blocking risk was identified, and the new tests cover the main behaviors. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the main change: guest getenv is implemented and setenv stores values in the libc change. It matches the libC.cpp changes (GuestEnvironment map, getenv registration in InitLibC_1, sete… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states that it implements guest getenv and changes setenv to store values, and it lists the init_env seeding, EINVAL handling, overwrite rules, and the libc_environment_tests registrat… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The only directly linked issue, `#2007`, is closed. It is background only and does not supply coding requirements for this pull request. No active directly linked targets remain. Issue `#2000` appears in … | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | All changes relate to the stated purpose: implementing guest getenv and storing setenv values. In src/libs/libC.cpp, the change adds a guest-only environment map, seeds it in init_env from envp, adds … | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: guest getenv is implemented and setenv stores values in the libc change. It matches the libC.cpp changes (GuestEnvironment map, getenv registration in InitLibC_1, setenv storing values) and the new test. It is specific and concise. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states that it implements guest getenv and changes setenv to store values, and it lists the init_env seeding, EINVAL handling, overwrite rules, and the libc_environment_tests registration. It matches the changeset in libC.cpp, CMakeLists.txt, and the new test file. </dd> </dl> </details> <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> <br> **Explanation** The only directly linked issue, `#2007`, is closed. It is background only and does not supply coding requirements for this pull request. No active directly linked targets remain. Issue `#2000` appears in the PR description and objectives, but it is not a linked target here. Because no active coding requirements apply, no requirement-level compliance check is needed. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> <br> **Explanation** All changes relate to the stated purpose: implementing guest getenv and storing setenv values. In src/libs/libC.cpp, the change adds a guest-only environment map, seeds it in init_env from envp, adds getenv (registered in InitLibC_1), and updates setenv to store values with overwrite handling. CMakeLists.txt adds the libc_environment_tests target and its CTest registration. tests/LibCEnvironmentTests.cpp covers these functions. The PR excludes other unresolved `#2000` symbols, and the diff does not add them. The summary shows no unrelated changes. The summary was used as evidence; no repository inspection was needed to reach this result. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2452)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/a1fc5ae438ea343480c9850f585d8c0afed06241/.coderabbit.yaml>) - **Commit**: [a1fc5ae](<https://github.com/KytyPS5/KytyPS5/commit/a1fc5ae438ea343480c9850f585d8c0afed06241>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0f0fefa1-09a0-49fe-9e16-d4185fe025c8` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between a1fc5ae438ea343480c9850f585d8c0afed06241 and e03e5a71e743f412688f476666c0361d11c200b9. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary> <dl> <dd> <br> * `CMakeLists.txt` * `src/libs/libC.cpp` * `tests/LibCEnvironmentTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠zearkreast on GitHub · 2026-11-23 18:31 UTC · original · approved these changes

**@⁠zearkreast** on GitHub · 2026-11-23 18:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2452#pullrequestreview-6027269852) · **approved these changes**
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/2452/head:github-bot/gh-2452'
git switch 'github-bot/gh-2452'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2452'
git switch 'github-bot/gh-2452'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2452'
git switch 'github-bot/gh-2452'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2452'
git switch 'main'
git merge --squash 'github-bot/gh-2452'
git switch 'main'
git merge --ff-only 'github-bot/gh-2452'
git switch 'main'
git merge 'github-bot/gh-2452'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.