feat(libc): implement gethostname #1975

Closed
Pedroj-64 wants to merge 2 commits from upstream-pr/1975 into main
Pedroj-64 commented 2026-10-09 03:37:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pedroj-64 on 2026-10-09T03:37:26Z.


What

gethostname was not exported.

It writes the fixed name PS5 and returns 0. A buffer shorter than the name returns -1 with ENAMETOOLONG (63), following FreeBSD lib/libc/gen/gethostname.c. A null buffer returns -1 without setting errno. The name PS5 has no known source and the console's behaviour on a short buffer is unverified; both are recorded in technical debt. No title was run, so no log is attached.

  • core/libs/prx/libSceLibcInternal/Export.cpp: gethostname.
  • guest_thread_atexit test: full name, exact fit, short buffer, zero length and null buffer.
  • TechnicalDebt.md: entry under unknown function info.

Tested

Linux (CachyOS), GCC 16.2.1, Release.

  • guest_thread_atexit passes.
  • tools/check_conventions.py --base upstream/main passes.

Not tested on Windows or macOS.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4795662394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975). Originally posted by [Pedroj-64](https://github.com/Pedroj-64) on 2026-10-09T03:37:26Z. --- ### What `gethostname` was not exported. It writes the fixed name `PS5` and returns 0. A buffer shorter than the name returns -1 with `ENAMETOOLONG` (63), following [FreeBSD `lib/libc/gen/gethostname.c`](https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/gethostname.c). A null buffer returns -1 without setting `errno`. The name `PS5` has no known source and the console's behaviour on a short buffer is unverified; both are recorded in technical debt. No title was run, so no log is attached. - `core/libs/prx/libSceLibcInternal/Export.cpp`: `gethostname`. - `guest_thread_atexit` test: full name, exact fit, short buffer, zero length and null buffer. - `TechnicalDebt.md`: entry under unknown function info. ### Tested Linux (CachyOS), GCC 16.2.1, Release. - `guest_thread_atexit` passes. - `tools/check_conventions.py --base upstream/main` passes. Not tested on Windows or macOS. ### Checklist - [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
MarcZX10 commented 2026-10-09 04:08:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:08:31Z.


The tests cover the behavior this patch chose, but they do not establish that the guest behavior is correct. The body says two titles import gethostname, while CONTRIBUTING.md says an import list alone does not show that a title reaches the function; it also asks for a reproduced failure and its log. Could you add that evidence, and a source or hardware trace for returning the fixed string PS5 and truncating successfully on short buffers? These are the core semantics, and the TechnicalDebt entry currently says both are unverified. Until that is grounded, I cannot approve the implementation under the project rule that functions do what they are supposed to or throw.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074068956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975#issuecomment-6074068956). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T04:08:31Z. --- The tests cover the behavior this patch chose, but they do not establish that the guest behavior is correct. The body says two titles import `gethostname`, while CONTRIBUTING.md says an import list alone does not show that a title reaches the function; it also asks for a reproduced failure and its log. Could you add that evidence, and a source or hardware trace for returning the fixed string `PS5` and truncating successfully on short buffers? These are the core semantics, and the TechnicalDebt entry currently says both are unverified. Until that is grounded, I cannot approve the implementation under the project rule that functions do what they are supposed to or throw.
Pedroj-64 commented 2026-10-09 04:15:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pedroj-64 on 2026-10-09T04:15:48Z.


Thanks for the careful review, you're right on both points.

Short buffer. I checked FreeBSD's lib/libc/gen/gethostname.c, the base of the PS5 system software. It calls sysctl(CTL_KERN, KERN_HOSTNAME) and, on ENOMEM, sets errno = ENAMETOOLONG and returns -1. It does not truncate and succeed. I changed the implementation to match and updated the tests and the TechnicalDebt entry (Linux: full suite, 494 tests, and the conventions check pass; Windows is left to CI). It is a FreeBSD source, not a console trace, so it stays recorded as unverified on hardware.

The PS5 name. I don't have a source or trace for it and won't claim one. I found no host name in the other open-source implementations I checked (for example shadPS4's process.cpp). It stays a documented placeholder in TechnicalDebt. If you know a source, or someone can print gethostname on a console, I'll gladly use it.

Import evidence. You're right that an import list doesn't show the function is reached. I don't have PPSA99039 or PPSA99001 to run, so I can't provide a reproduced failure or log. I removed that claim from the PR body and the TechnicalDebt entry.

If you'd prefer this wait for a real trace, or be implemented differently, I'm open to that. Thanks again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074141806 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975#issuecomment-6074141806). Originally posted by [Pedroj-64](https://github.com/Pedroj-64) on 2026-10-09T04:15:48Z. --- Thanks for the careful review, you're right on both points. **Short buffer.** I checked FreeBSD's `lib/libc/gen/gethostname.c`, the base of the PS5 system software. It calls `sysctl(CTL_KERN, KERN_HOSTNAME)` and, on `ENOMEM`, sets `errno = ENAMETOOLONG` and returns -1. It does not truncate and succeed. I changed the implementation to match and updated the tests and the TechnicalDebt entry (Linux: full suite, 494 tests, and the conventions check pass; Windows is left to CI). It is a FreeBSD source, not a console trace, so it stays recorded as unverified on hardware. **The `PS5` name.** I don't have a source or trace for it and won't claim one. I found no host name in the other open-source implementations I checked (for example shadPS4's `process.cpp`). It stays a documented placeholder in TechnicalDebt. If you know a source, or someone can print `gethostname` on a console, I'll gladly use it. **Import evidence.** You're right that an import list doesn't show the function is reached. I don't have PPSA99039 or PPSA99001 to run, so I can't provide a reproduced failure or log. I removed that claim from the PR body and the TechnicalDebt entry. If you'd prefer this wait for a real trace, or be implemented differently, I'm open to that. Thanks again.
MarcZX10 commented 2026-10-09 04:17:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:17:23Z.


The FreeBSD source resolves the short-buffer behavior, and removing the import claim was the right correction. I still cannot approve: PS5 has no source or console trace, so the implementation returns a guessed hostname; the PR also has no demonstrated call/failure or other concrete use. TechnicalDebt records the uncertainty but does not make this behavior correct under the project rule. I recommend holding this export until the hostname can be grounded, rather than merging a placeholder that titles will observe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074157582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975#issuecomment-6074157582). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T04:17:23Z. --- The FreeBSD source resolves the short-buffer behavior, and removing the import claim was the right correction. I still cannot approve: `PS5` has no source or console trace, so the implementation returns a guessed hostname; the PR also has no demonstrated call/failure or other concrete use. TechnicalDebt records the uncertainty but does not make this behavior correct under the project rule. I recommend holding this export until the hostname can be grounded, rather than merging a placeholder that titles will observe.
Pedroj-64 commented 2026-10-09 04:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pedroj-64 on 2026-10-09T04:29:02Z.


Thanks for the review, Marc. Without a source or console trace for the host name, this would return a guessed value that titles can observe, so I'm closing it rather than merging a placeholder. The branch stays in my fork. If anyone can print gethostname on a console, or has a source for the value, I'll reopen it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6074276187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975#issuecomment-6074276187). Originally posted by [Pedroj-64](https://github.com/Pedroj-64) on 2026-10-09T04:29:02Z. --- Thanks for the review, Marc. Without a source or console trace for the host name, this would return a guessed value that titles can observe, so I'm closing it rather than merging a placeholder. The branch stays in my fork. If anyone can print `gethostname` on a console, or has a source for the value, I'll reopen it.
popcoder565 commented 2026-10-09 10:03:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:03:53Z.


First Windows run, since the description says it wasn't tested on Windows.

Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto main b7218b3c together with nine other small libc/libkernel PRs: #1976, #1977, #1859, #1685, #1676, #1675, #1641, #1656, #1807.

  • guest_thread_atexit passes.
  • Full ctest: 510/510 (one GPU test skipped for a device limit).

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078728127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1975#issuecomment-6078728127). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T10:03:53Z. --- First Windows run, since the description says it wasn't tested on Windows. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto `main` b7218b3c together with nine other small libc/libkernel PRs: #1976, #1977, #1859, #1685, #1676, #1675, #1641, #1656, #1807. - `guest_thread_atexit` passes. - Full ctest: 510/510 (one GPU test skipped for a device limit). _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_

Pull request closed

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!1975
No description provided.