fix(libc): implement guest getenv and setenv #2007

Closed
github-bot wants to merge 2 commits from gh-pr/2007/head into gh-pr/2007/base
Owner

@⁠bobrass on GitHub · 2026-10-30 22:44 UTC · original
bobrass:codex/kytyps5-issue2000-getenv → main · +51 −2 · 1 files · 2 commits · closed without merging

Summary

  • Capture the guest environment passed to init_env in a guest-owned map.
  • Resolve the LibcInternal getenv import and return values from that map.
  • Make the existing setenv implementation update the same guest environment with the requested overwrite behavior, without changing the emulator host environment.

This follows the corrected analysis in issue #2000: NID fallback is already version-agnostic, and these reported imports are missing implementations rather than version aliases. This only implements guest getenv/setenv; it does not resolve the other missing symbols or claim that the affected homebrew titles will boot fully.

Validation

  • git show --check and git diff --check are clean.
  • No tests, build, or emulator/PS5 runtime validation were run. The host environment and the affected homebrew builds still need validation.
**@⁠bobrass** on GitHub · 2026-10-30 22:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007) `bobrass:codex/kytyps5-issue2000-getenv` → `main` · +51 −2 · 1 files · 2 commits · closed without merging ## Summary - Capture the guest environment passed to `init_env` in a guest-owned map. - Resolve the `LibcInternal` `getenv` import and return values from that map. - Make the existing `setenv` implementation update the same guest environment with the requested overwrite behavior, without changing the emulator host environment. This follows the corrected analysis in [issue #2000](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/2000): NID fallback is already version-agnostic, and these reported imports are missing implementations rather than version aliases. This only implements guest `getenv`/`setenv`; it does not resolve the other missing symbols or claim that the affected homebrew titles will boot fully. ## Validation - `git show --check` and `git diff --check` are clean. - No tests, build, or emulator/PS5 runtime validation were run. The host environment and the affected homebrew builds still need validation.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:11:16 +00:00
github-bot closed this pull request 2026-11-26 10:11:16 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 22:46 UTC · original · edited 2026-10-30 23:04 UTC

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d53e1705c6 and 4611ba7541.

Files selected for processing: 1
  • src/libs/libC.cpp
Files skipped from review as they are similar to previous changes: 1
  • src/libs/libC.cpp

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

Walkthrough

The change adds mutex-protected guest environment storage initialized from envp. init_env clears the stored values when it receives null parameters. Valid setenv calls now store values and apply the overwrite rule. The new getenv function looks up stored values and is registered in LibcInternal.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Minimal · up to 4611b

No concrete merge-blocking issue remains. Build and runtime validation are still outstanding.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: implementing guest libc getenv and setenv support.
Description check Passed The description directly explains the guest environment map, getenv and setenv behavior, scope, issue context, and validation status.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-30 22:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007#issuecomment-6535100818) · edited 2026-10-30 23:04 UTC <!-- 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/2007?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-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <!-- 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> - **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/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f/.coderabbit.yaml>) - **Commit**: [4919fdb](<https://github.com/KytyPS5/KytyPS5/commit/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `eadb7f93-a1f6-4a73-9b37-cbbe9c059026` </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> Reviewing files that changed from the base of the PR and between d53e1705c69fc024d7da1bdcccec09123b560bfe and 4611ba7541aa72d54305acd51e5a09e279e2dea4. </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: 1</strong></summary> <dl> <dd> * `src/libs/libC.cpp` </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-similar-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files skipped from review as they are similar to previous changes: 1</strong></summary> <dl> <dd> * src/libs/libC.cpp </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> The change adds mutex-protected guest environment storage initialized from `envp`. `init_env` clears the stored values when it receives null parameters. Valid `setenv` calls now store values and apply the `overwrite` rule. The new `getenv` function looks up stored values and is registered in `LibcInternal`. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"4611ba7541aa72d54305acd51e5a09e279e2dea4" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- 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>4611b</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `4611b` --> <!-- final_review_risk_coverage:{"sourceCommitId":"4611ba7541aa72d54305acd51e5a09e279e2dea4","coveredCommitId":"4611ba7541aa72d54305acd51e5a09e279e2dea4","kind":"reviewed"} --> No concrete merge-blocking issue remains. Build and runtime validation are still outstanding. <!-- 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 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><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> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely identifies the main change: implementing guest libc getenv and setenv support. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the guest environment map, getenv and setenv behavior, scope, issue context, and validation status. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files. **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </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=2007)! 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> - [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> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -62,0 +90,4 @@
std::lock_guard lock(g_environment_mutex);
auto variable = g_environment.find(name);
if (variable == g_environment.end()) {
g_environment.emplace(name, value);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 22:52 UTC · original · edited 2026-10-30 23:04 UTC

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '55,105p;340,375p;640,665p;795,820p' src/libs/libC.cpp
rg -n 'ENOMEM|bad_alloc|catch.*exception|setenv|GetErrno' src/libs/libC.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4512


Script executed:

rg -n -F --glob '*.{h,hpp,cpp,inl}' -e '#define LIB_FUNC' -e 'LIB_FUNC(' -e 'GetErrorAddr' -e 'bad_alloc' -e 'catch' src include 2>/dev/null || true
printf '\n-- macro and registration definitions --\n'
rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'LIB_FUNC' -e 'Register' -e 'Invoke' -e 'Call' src include 2>/dev/null | head -n 240
printf '\n-- setenv and surrounding registration --\n'
nl -ba src/libs/libC.cpp | sed -n '335,365p;850,870p'

Repository: KytyPS5/KytyPS5

Length of output: 41222


Script executed:

pwd
rg -n -F -- 'define LIB_FUNC' .
rg -n -F -- 'LIB_FUNC(' src | head -n 120
rg -n -F -- 'GetErrorAddr' src | head -n 80
rg -n -F -- 'bad_alloc' . | head -n 80

Repository: KytyPS5/KytyPS5

Length of output: 16968


Script executed:

rg -n -F --glob '*.{h,hpp,cpp,inl}' -e '#define LIB_ADD' -e 'LIB_ADD(' -e 'AddFunction' -e 'SymbolType::Func' src include 2>/dev/null || true
printf '\n-- exception handling near loader/emulator dispatch --\n'
rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'std::exception' -e 'std::bad_alloc' -e 'catch (...)' -e 'catch (const' src include 2>/dev/null | rg -v 'updater|3rdparty' | head -n 240
printf '\n-- relevant macro definitions --\n'
rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'LIB_ADD' -e 'struct LibInitState' -e 'class LibInitState' src include 2>/dev/null | head -n 160

Repository: KytyPS5/KytyPS5

Length of output: 40884


Script executed:

nl -ba src/libs/libs.h | sed -n '20,55p'
printf '\n-- library symbol registration and address storage --\n'
rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'AddSymbol' -e 'AddFunction' -e 'FindByNid' -e 'FindByName' -e 'SymbolType::Func' src/loader src/libs src/kernel 2>/dev/null | head -n 240
printf '\n-- likely function-pointer invocation sites --\n'
rg -n --glob '*.{h,hpp,cpp,inl}' 'reinterpret_cast<.*\\(.*\\)|record->address|symbol->address|\\.address\\)|Function.*address|Call.*address' src/loader src/kernel src/emulator src/core src 2>/dev/null | head -n 240

Repository: KytyPS5/KytyPS5

Length of output: 5230


Script executed:

printf '%s\n' '-- symbol record definitions --'
rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'struct SymbolRecord' -e 'class SymbolRecord' -e 'struct SymbolResolve' -e 'class SymbolResolve' -e 'uint64_t address' -e 'address;' src/loader src/libs 2>/dev/null | head -n 160
printf '%s\n' '-- runtime references to resolved function addresses --'
rg -n -i --glob '*.{h,hpp,cpp,inl}' 'symbol.*address|address.*symbol|resolve.*func|func.*resolve|host.*call|call.*host|call.*function|function.*call|GetProcAddress|FindByNid' src/loader src/kernel src/libs src/emulator src/core 2>/dev/null | head -n 260

Repository: KytyPS5/KytyPS5

Length of output: 6540


Return ENOMEM when setenv allocation fails.

LIB_ADD stores the raw LibC::setenv address. It does not add an exception-translating wrapper. LibC::setenv calls SetGuestEnvironmentVariable without catching std::bad_alloc. An allocation failure can therefore escape the export instead of returning -1 with guest errno set to ENOMEM. This is a narrow memory-pressure failure, not evidence of a broad outage.

Suggested fix
-	return SetGuestEnvironmentVariable(name, value, overwrite);
+	try {
+		return SetGuestEnvironmentVariable(name, value, overwrite);
+	} catch (const std::bad_alloc&) {
+		*Posix::GetErrorAddr() = Posix::POSIX_ENOMEM;
+		return -1;
+	}

✅ Addressed in commit 4611ba7

**@⁠coderabbitai[bot]** on GitHub · 2026-10-30 22:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007#discussion_r4429152239) · edited 2026-10-30 23:04 UTC <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Stability & Availability** · **Quick win** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> Script executed: ```bash sed -n '55,105p;340,375p;640,665p;795,820p' src/libs/libC.cpp rg -n 'ENOMEM|bad_alloc|catch.*exception|setenv|GetErrno' src/libs/libC.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4512 --- Script executed: ```bash rg -n -F --glob '*.{h,hpp,cpp,inl}' -e '#define LIB_FUNC' -e 'LIB_FUNC(' -e 'GetErrorAddr' -e 'bad_alloc' -e 'catch' src include 2>/dev/null || true printf '\n-- macro and registration definitions --\n' rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'LIB_FUNC' -e 'Register' -e 'Invoke' -e 'Call' src include 2>/dev/null | head -n 240 printf '\n-- setenv and surrounding registration --\n' nl -ba src/libs/libC.cpp | sed -n '335,365p;850,870p' ``` Repository: KytyPS5/KytyPS5 Length of output: 41222 --- Script executed: ```bash pwd rg -n -F -- 'define LIB_FUNC' . rg -n -F -- 'LIB_FUNC(' src | head -n 120 rg -n -F -- 'GetErrorAddr' src | head -n 80 rg -n -F -- 'bad_alloc' . | head -n 80 ``` Repository: KytyPS5/KytyPS5 Length of output: 16968 --- Script executed: ```bash rg -n -F --glob '*.{h,hpp,cpp,inl}' -e '#define LIB_ADD' -e 'LIB_ADD(' -e 'AddFunction' -e 'SymbolType::Func' src include 2>/dev/null || true printf '\n-- exception handling near loader/emulator dispatch --\n' rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'std::exception' -e 'std::bad_alloc' -e 'catch (...)' -e 'catch (const' src include 2>/dev/null | rg -v 'updater|3rdparty' | head -n 240 printf '\n-- relevant macro definitions --\n' rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'LIB_ADD' -e 'struct LibInitState' -e 'class LibInitState' src include 2>/dev/null | head -n 160 ``` Repository: KytyPS5/KytyPS5 Length of output: 40884 --- Script executed: ```bash nl -ba src/libs/libs.h | sed -n '20,55p' printf '\n-- library symbol registration and address storage --\n' rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'AddSymbol' -e 'AddFunction' -e 'FindByNid' -e 'FindByName' -e 'SymbolType::Func' src/loader src/libs src/kernel 2>/dev/null | head -n 240 printf '\n-- likely function-pointer invocation sites --\n' rg -n --glob '*.{h,hpp,cpp,inl}' 'reinterpret_cast<.*\\(.*\\)|record->address|symbol->address|\\.address\\)|Function.*address|Call.*address' src/loader src/kernel src/emulator src/core src 2>/dev/null | head -n 240 ``` Repository: KytyPS5/KytyPS5 Length of output: 5230 --- Script executed: ```bash printf '%s\n' '-- symbol record definitions --' rg -n -F --glob '*.{h,hpp,cpp,inl}' -e 'struct SymbolRecord' -e 'class SymbolRecord' -e 'struct SymbolResolve' -e 'class SymbolResolve' -e 'uint64_t address' -e 'address;' src/loader src/libs 2>/dev/null | head -n 160 printf '%s\n' '-- runtime references to resolved function addresses --' rg -n -i --glob '*.{h,hpp,cpp,inl}' 'symbol.*address|address.*symbol|resolve.*func|func.*resolve|host.*call|call.*host|call.*function|function.*call|GetProcAddress|FindByNid' src/loader src/kernel src/libs src/emulator src/core 2>/dev/null | head -n 260 ``` Repository: KytyPS5/KytyPS5 Length of output: 6540 --- </dd> </dl> </details> **Return `ENOMEM` when `setenv` allocation fails.** `LIB_ADD` stores the raw `LibC::setenv` address. It does not add an exception-translating wrapper. `LibC::setenv` calls `SetGuestEnvironmentVariable` without catching `std::bad_alloc`. An allocation failure can therefore escape the export instead of returning `-1` with guest `errno` set to `ENOMEM`. This is a narrow memory-pressure failure, not evidence of a broad outage. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff - return SetGuestEnvironmentVariable(name, value, overwrite); + try { + return SetGuestEnvironmentVariable(name, value, overwrite); + } catch (const std::bad_alloc&) { + *Posix::GetErrorAddr() = Posix::POSIX_ENOMEM; + return -1; + } ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:72cd6688f1bcc7914105c3bf --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 4611ba7
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 22:52 UTC · original · reviewed

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4919fdb6e6 and d53e1705c6.

Files selected for processing: 1
  • src/libs/libC.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-10-30 22:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007#pullrequestreview-5719528817) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><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</summary> <dl> <dd> - **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/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f/.coderabbit.yaml>) - **Commit**: [4919fdb](<https://github.com/KytyPS5/KytyPS5/commit/4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `079fb8b0-0f43-4bc5-94dc-6349c70f733b` </dd> </dl> </details> <details> <summary><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</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 4919fdb6e6e28f46f1f5df8cf931a7a0823cb93f and d53e1705c69fc024d7da1bdcccec09123b560bfe. </dd> </dl> </details> <details> <summary><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: 1</summary> <dl> <dd> * `src/libs/libC.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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=cc221d39-28db-4034-a687-1b13531db83d attempt=ff185967-4dc4-41f0-9df8-676fbae00af3 batch=1/1 -->
@ -62,0 +90,4 @@
std::lock_guard lock(g_environment_mutex);
auto variable = g_environment.find(name);
if (variable == g_environment.end()) {
g_environment.emplace(name, value);
Author
Owner

@⁠bobrass on GitHub · 2026-10-30 23:00 UTC · original

Implemented in commit 4611ba75: setenv now catches std::bad_alloc, sets the guest errno to ENOMEM, and returns -1. git diff --check is clean. I did not run tests or a build; host runtime validation remains needed.

**@⁠bobrass** on GitHub · 2026-10-30 23:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007#discussion_r4429193718) Implemented in commit `4611ba75`: `setenv` now catches `std::bad_alloc`, sets the guest `errno` to `ENOMEM`, and returns `-1`. `git diff --check` is clean. I did not run tests or a build; host runtime validation remains needed.
@ -62,0 +90,4 @@
std::lock_guard lock(g_environment_mutex);
auto variable = g_environment.find(name);
if (variable == g_environment.end()) {
g_environment.emplace(name, value);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-30 23:04 UTC · original

@⁠bobrass The supplied src/libs/libC.cpp confirms the fix: setenv catches std::bad_alloc, sets guest errno to POSIX_ENOMEM, and returns -1. This addresses the finding.

Build, test, and host runtime validation remain pending.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-30 23:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2007#discussion_r4429214719) <!-- coderabbit-ai-generated:v1 --> @⁠bobrass The supplied `src/libs/libC.cpp` confirms the fix: `setenv` catches `std::bad_alloc`, sets guest `errno` to `POSIX_ENOMEM`, and returns `-1`. This addresses the finding. Build, test, and host runtime validation remain pending. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=CodeRabbit%20caught%20a%20subtle%20%60setenv%60%20failure%3A%20%60bad_alloc%60%20now%20returns%20%60-1%60%20with%20guest%20%60ENOMEM%60%20instead%20of%20escaping.%20Try%20%40coderabbitai%20for%20actionable%20code%20reviews%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F2007%23discussion_r4429152239)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.