feat(libkernel): export environ as an empty environment #2090

Merged
LeandroLP23 merged 1 commit from upstream-pr/2090 into main 2026-10-10 04:43:45 +00:00
LeandroLP23 commented 2026-10-09 07:57:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T07:57:54Z.


What

PICO-8 for PS5 (PPSA99808 v0.1.2, RafaelNGP/pico8-ps5, GPL-3.0) stops at start-up on environ once __inet_aton (#1848) resolves:

FAIL: unresolved ELF import +2thxYZ4syk from libkernel.prx

+2thxYZ4syk is environ. FreeBSD's libc getenv reads it and setenv/putenv replace it, so the export is a writable char**.

It points to an empty, null-terminated array. A PS5 app starts with no environment variables: the payload SDK's elfldr (elfldr_set_environ in ps5-payload-dev/websrv) writes environ only when it has variables to pass, and shadPS4 exports the same NID as a pointer to an empty array (src/core/libraries/kernel/kernel.cpp).

Tested

Windows 11, MinGW-w64 GCC 15.2.0, Release, main f1451396:

  • PICO-8, with #1848 merged locally for its previous stop, gets past this import and stops at the next one, N2OjwJJGjeQ from libSceLibcInternal.prx (freeifaddrs, #1772).
  • guest_system_configuration checks that environ is non-null and empty.
  • tools/check_conventions.py passes.

Linux and Windows: fork CI https://github.com/LeandroLP23/AnyPS5/actions/runs/37899939325, all jobs pass.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4797721209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2090). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T07:57:54Z. --- ### What PICO-8 for PS5 (PPSA99808 v0.1.2, [RafaelNGP/pico8-ps5](https://github.com/RafaelNGP/pico8-ps5), GPL-3.0) stops at start-up on `environ` once `__inet_aton` (#1848) resolves: ``` FAIL: unresolved ELF import +2thxYZ4syk from libkernel.prx ``` `+2thxYZ4syk` is `environ`. FreeBSD's libc `getenv` reads it and `setenv`/`putenv` replace it, so the export is a writable `char**`. It points to an empty, null-terminated array. A PS5 app starts with no environment variables: the payload SDK's `elfldr` (`elfldr_set_environ` in [ps5-payload-dev/websrv](https://github.com/ps5-payload-dev/websrv/blob/master/src/ps5/elfldr.c)) writes `environ` only when it has variables to pass, and shadPS4 exports the same NID as a pointer to an empty array (`src/core/libraries/kernel/kernel.cpp`). ### Tested Windows 11, MinGW-w64 GCC 15.2.0, Release, `main` f1451396: - PICO-8, with #1848 merged locally for its previous stop, gets past this import and stops at the next one, `N2OjwJJGjeQ` from `libSceLibcInternal.prx` (`freeifaddrs`, #1772). - `guest_system_configuration` checks that `environ` is non-null and empty. - `tools/check_conventions.py` passes. Linux and Windows: fork CI https://github.com/LeandroLP23/AnyPS5/actions/runs/37899939325, all jobs pass. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
Amirtheshwaran commented 2026-10-10 04:40:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amirtheshwaran on 2026-10-10T04:40:18Z.


Tested on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7, same as CI), Release:

  • Merges cleanly onto current main.
  • guest_system_configuration builds and passes.
  • Patched libkernel.prx exports +2thxYZ4syk.

One question: libc's Environment.cpp seeds the guest environment from the host, so getenv("PATH") returns a value while environ stays empty, and setenv changes never show up in it. Is that intended for now? If so, it might be worth a line in TechnicalDebt.md under "Unknown function info", like __progname has.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093855746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2090#issuecomment-6093855746). Originally posted by [Amirtheshwaran](https://github.com/Amirtheshwaran) on 2026-10-10T04:40:18Z. --- Tested on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7, same as CI), Release: - Merges cleanly onto current `main`. - `guest_system_configuration` builds and passes. - Patched `libkernel.prx` exports `+2thxYZ4syk`. One question: libc's `Environment.cpp` seeds the guest environment from the host, so `getenv("PATH")` returns a value while `environ` stays empty, and `setenv` changes never show up in it. Is that intended for now? If so, it might be worth a line in `TechnicalDebt.md` under "Unknown function info", like `__progname` has.
LeandroLP23 commented 2026-10-10 07:16:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-10T07:16:53Z.


Thanks for testing it. Yes, that's how it is for now: environ is a fixed empty environment so titles that import it can load. It isn't linked to libc's environment, so it doesn't show the variables getenv sees, and setenv/putenv changes don't appear in it. You're right that it belongs in TechnicalDebt next to __progname; I missed that in this PR. I'll add the line in a follow-up as soon as I can open PRs again (the intake check closes new ones from my account for now); anyone who can open one is welcome to take it first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095034469 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2090#issuecomment-6095034469). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-10T07:16:53Z. --- Thanks for testing it. Yes, that's how it is for now: `environ` is a fixed empty environment so titles that import it can load. It isn't linked to libc's environment, so it doesn't show the variables `getenv` sees, and `setenv`/`putenv` changes don't appear in it. You're right that it belongs in TechnicalDebt next to `__progname`; I missed that in this PR. I'll add the line in a follow-up as soon as I can open PRs again (the intake check closes new ones from my account for now); anyone who can open one is welcome to take it first.
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!2090
No description provided.