feat(libScePosixForWebKit): implement gethostbyname_r #14157

Merged
danielhorngt merged 2 commits from upstream-pr/14157 into main 2026-11-06 22:28:56 +00:00
danielhorngt commented 2026-10-31 21:17:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by danielhorngt on 2026-10-31T21:17:58Z.


What

Implements gethostbyname_r in libScePosixForWebKit (scePosixForWebKit_gethostbyname_r, NID dt8ermYp-Wc), which threw until now. The signature and behaviour follow FreeBSD 11.4 gethostnamadr.c and gethostbydns.c:

  • The entry is copied into the caller's buffer with __copy_hostent's layout: aligned to 8 bytes, then the address and alias pointer lists, the addresses, the name and the aliases.
  • A buffer that is too small returns ERANGE with NETDB_INTERNAL and writes nothing to the entry or buffer.
  • A failed lookup returns -1 with the error in *h_errnop and *result null. A success leaves *h_errnop unwritten.

gethostbyname and gethostbyname_r now share ResolveHost, each with its own thread-local storage, so _r does not overwrite an earlier gethostbyname result.

One change reaches beyond the new export: numeric names are cut to MAXDNAME (1025) bytes, as fakeaddr does, and this also applies to gethostbyname.

The debt entry records what is unverified, including that FreeBSD retries a numeric name that does not fit through /etc/hosts and DNS where this returns ERANGE. The old entry said this export had no credible prototype; FreeBSD's public header and source supply one, though no console or WebKit caller was read to confirm it.

Tested

Windows 11, WinLibs GCC 15.2.0, Release, on the rebased branch. No title or homebrew was run; I found no title that calls this export.

  • ctest -R 'guest_(resolver|raw_resolver|service_database|posix_wrap)$': 4 of 4 pass. The new cases in guest_resolver pin the exact buffer layout, the exact fitting size, an unaligned buffer, ERANGE one byte short, the 1025-byte cut, a failed lookup, localhost, a preserved gethostbyname result and a null name.
  • ctest -R '^public_headers' (before the rebase): 65 of 65 pass.
  • Negative control: loosening the size check by one byte made guest_resolver fail. Reverted.
  • check_conventions.py --base upstream/main passes.

Not run: the full test suite, the libs target, Linux, macOS, or any comparison with a console.

pr_overlap.py exited non-zero, so I compared the two PRs it reported. #13141 (mkostemp) edits a neighbouring line of the debt file. #5021 (ARM64 AOT) touches Resolver.cpp only as a stale copy from an older base, and could not be compared automatically. Neither implements this function.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5101621616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14157). Originally posted by [danielhorngt](https://github.com/danielhorngt) on 2026-10-31T21:17:58Z. --- ### What Implements `gethostbyname_r` in libScePosixForWebKit (`scePosixForWebKit_gethostbyname_r`, NID `dt8ermYp-Wc`), which threw until now. The signature and behaviour follow FreeBSD 11.4 [gethostnamadr.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/net/gethostnamadr.c) and [gethostbydns.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/net/gethostbydns.c): - The entry is copied into the caller's buffer with `__copy_hostent`'s layout: aligned to 8 bytes, then the address and alias pointer lists, the addresses, the name and the aliases. - A buffer that is too small returns `ERANGE` with `NETDB_INTERNAL` and writes nothing to the entry or buffer. - A failed lookup returns -1 with the error in `*h_errnop` and `*result` null. A success leaves `*h_errnop` unwritten. `gethostbyname` and `gethostbyname_r` now share `ResolveHost`, each with its own thread-local storage, so `_r` does not overwrite an earlier `gethostbyname` result. One change reaches beyond the new export: numeric names are cut to `MAXDNAME` (1025) bytes, as `fakeaddr` does, and this also applies to `gethostbyname`. The debt entry records what is unverified, including that FreeBSD retries a numeric name that does not fit through `/etc/hosts` and DNS where this returns `ERANGE`. The old entry said this export had no credible prototype; FreeBSD's public header and source supply one, though no console or WebKit caller was read to confirm it. ### Tested Windows 11, WinLibs GCC 15.2.0, Release, on the rebased branch. No title or homebrew was run; I found no title that calls this export. - `ctest -R 'guest_(resolver|raw_resolver|service_database|posix_wrap)$'`: 4 of 4 pass. The new cases in `guest_resolver` pin the exact buffer layout, the exact fitting size, an unaligned buffer, `ERANGE` one byte short, the 1025-byte cut, a failed lookup, `localhost`, a preserved `gethostbyname` result and a null name. - `ctest -R '^public_headers'` (before the rebase): 65 of 65 pass. - Negative control: loosening the size check by one byte made `guest_resolver` fail. Reverted. - `check_conventions.py --base upstream/main` passes. Not run: the full test suite, the `libs` target, Linux, macOS, or any comparison with a console. `pr_overlap.py` exited non-zero, so I compared the two PRs it reported. #13141 (`mkostemp`) edits a neighbouring line of the debt file. #5021 (ARM64 AOT) touches `Resolver.cpp` only as a stale copy from an older base, and could not be compared automatically. Neither implements this function. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-31 21:21:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T21:21:26Z.

Review: COMMENTED


Reviewed — Linux verification pending

At head 6193262cfc6252e3bc1166ee55030c3a92259937, source inspection found no concrete defect, but approval is withheld until the changed Linux resolver branch is exercised.

The no-build precheck passed diff, conventions, and dependency/mergeability checks; the ABI audit passed with the expected explicit-export-alias warning, and I confirmed guest_resolver is registered in CMake. The author reports 4/4 focused tests on Windows and 65/65 public-header tests before the rebase; I did not run those tests. The current hosted checks are still queued, and Linux/macOS resolver tests are not reported. Please provide an exact-head Linux guest_resolver run (and macOS too if available). I did not build or run C++ tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5724975297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14157#pullrequestreview-5724975297). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T21:21:26Z. **Review:** COMMENTED --- # Reviewed — Linux verification pending At head `6193262cfc6252e3bc1166ee55030c3a92259937`, source inspection found no concrete defect, but approval is withheld until the changed Linux resolver branch is exercised. The no-build precheck passed diff, conventions, and dependency/mergeability checks; the ABI audit passed with the expected explicit-export-alias warning, and I confirmed `guest_resolver` is registered in CMake. The author reports 4/4 focused tests on Windows and 65/65 public-header tests before the rebase; I did not run those tests. The current hosted checks are still queued, and Linux/macOS resolver tests are not reported. Please provide an exact-head Linux `guest_resolver` run (and macOS too if available). I did not build or run C++ tests locally.
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!14157
No description provided.