Implement sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58) #2027

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

@⁠Ekt0re on GitHub · 2026-10-31 18:12 UTC · original
Ekt0re:RCCY01Xd+58 → main · +747 −207 · 5 files · 3 commits · closed without merging

Implement sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58)

Summary

This PR implements the missing libSceNet export RCCY01Xd+58 (sceNetResolverStartNtoaMultipleRecords). It performs a DNS name-to-address lookup and returns all IPv4 records found for a hostname (up to 10), instead of a single address like sceNetResolverStartNtoa.

To support it, the resolver code was reworked: sceNetResolverStartNtoa and the new export now share one internal implementation, and sceNetResolverAbort is no longer a no-op.

Background

HOT WHEELS™ Infinite Rush (PPSA22408) calls this function and currently stops at the logo screen:

Unresolved import stub called [0]: patch_vaddr=0x000000090b1c3da8 jmprela_index=308
symbol=RCCY01Xd+58[Net_v1][Net_v1.1][Func] type=Func bind=Global program=.../eboot.bin

Changes

Export and registration (src/libs/libNet.cpp)

  • Added LibNet::NetResolverStartNtoaMultipleRecords(rid, hostname, info, timeout, retry, flags), wrapped with FinishNetCall.
  • Registered NID RCCY01Xd+58 in InitNet_1_Net.

Public types and declarations (src/libs/network.h)

  • Added NetResolverAddress (36 bytes) and NetResolverInfo (384 bytes, up to 10 addresses), both guarded by static_assert on their size.
  • Declared NetResolverStartNtoaMultipleRecords.

Resolver state (src/libs/network.cpp)

The Resolver struct gained running, abort_requested, last_error and generation. Four new Network methods manage it:

Method Purpose
ResolverAbort Marks an abort (NET_ERROR_EINTR), bumps the generation and clears running.
ResolverBeginLookup Rejects invalid ids (EBADF), a busy resolver (NET_ERROR_RESOLVER_EBUSY) and a queued abort (EINTR, consumed). Otherwise marks the resolver running and returns a new generation.
ResolverEndLookup Stores the result, only if the generation still matches.
ResolverCheckValidForDelivery Tells an async lookup whether the resolver still exists, was not aborted and has the same generation.

ResolverDestroy now carries the generation forward so a late async lookup cannot match a recycled slot.

Lookup logic (src/libs/network.cpp)

NetResolverStartNtoa and the new export both call ResolverStartNtoaInternal:

  1. Validation, in this order: unknown resolver id → NET_ERROR_EBADF; null hostname or no output buffer → NET_ERROR_EINVAL; empty hostname or longer than 255 characters → NET_ERROR_EINVAL.
  2. Begin lookup (see above).
  3. Resolution:
    • A trailing . is stripped.
    • A hostname starting with localhost resolves to 127.0.0.1.
    • A literal IPv4 address is returned as is, unless ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS (0x00010000) is set.
    • Otherwise getaddrinfo runs with AF_INET / SOCK_STREAM. Results are deduplicated and capped at 10.
  4. Delivery: for the multiple-records export, the whole NetResolverInfo is zeroed, then records and recordsv4 are set to the address count and each entry gets af = 2 (AF_INET). For sceNetResolverStartNtoa, only the first address is written.
  5. Async (ORBIS_NET_RESOLVER_ASYNC, 0x00000001): the work runs on a detached thread and the call returns 0 immediately. The result is written only if ResolverCheckValidForDelivery still holds.
    Error translation from getaddrinfo (including the Windows WSA* equivalents):
Host error Net error
EAI_NONAME, EAI_NODATA NET_ERROR_RESOLVER_ENOHOST
EAI_AGAIN NET_ERROR_RESOLVER_ETIMEDOUT
EAI_FAIL NET_ERROR_RESOLVER_ESERVERFAILURE
empty result NET_ERROR_RESOLVER_ENORECORD
anything else NET_ERROR_RESOLVER_EINTERNAL

sceNetResolverAbort

Previously it only logged and returned OK. It now returns NET_ERROR_EBADF for an unknown resolver, and otherwise aborts the running lookup or queues the abort for the next one.

Tests

  • Added tests/NetResolverTests.cpp and the net_resolver_tests target in CMakeLists.txt.
  • Covered: NID registration, parameter validation, localhost (including trailing dot), literal IP with and without DISABLE_IPADDRESS, abort followed by a successful lookup, an async lookup, and a real resolution of google.com.

Behavior changes to existing code

These affect sceNetResolverStartNtoa as well, because it now uses the shared path:

  • The resolver id is checked before the argument checks, so an invalid id with a null hostname now returns EBADF instead of EINVAL.
  • The flags argument is no longer rejected when it contains bits other than 0x00010000. ORBIS_NET_RESOLVER_ASYNC is now honored.
  • When the socket backend cannot be initialized, the error is now NET_ERROR_RESOLVER_ENODNS instead of NET_ERROR_ENETDOWN.
  • localhost handling and the 10-record cap apply to sceNetResolverStartNtoa as well.

Known limitations

  • timeout and retry are only logged, not enforced.
  • Only IPv4 is resolved; recordsv6 stays 0.
  • Async lookups update the resolver state but do not signal a completion event. Guests that wait on one will not be notified.
  • Between the validity check and the write to the guest buffer, an async lookup is not protected against a concurrent destroy or abort.
  • sceNetResolverStartNtoaMultipleRecordsEx, ResolverGetError and ResolverStartAton are not part of this PR.
  • Any hostname that begins with localhost (for example localhost.example.com) resolves to 127.0.0.1.

Formatting

The diff also contains whitespace-only changes in libNet.cpp and network.cpp (alignment and line wrapping from the formatter). They do not change behavior.

Testing

  • net_resolver_tests builds and passes
  • TestResolveGoogle needs working DNS and network access; run it on a machine that is online
  • HOT WHEELS™ Infinite Rush (PPSA22408) no longer stops on the unresolved RCCY01Xd+58 import

AI use:
AI was used to analyze the problem and explore possible solutions.
I performed the testing manually.

**@⁠Ekt0re** on GitHub · 2026-10-31 18:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027) `Ekt0re:RCCY01Xd+58` → `main` · +747 −207 · 5 files · 3 commits · closed without merging # Implement `sceNetResolverStartNtoaMultipleRecords` (`RCCY01Xd+58`) ## Summary This PR implements the missing `libSceNet` export `RCCY01Xd+58` (`sceNetResolverStartNtoaMultipleRecords`). It performs a DNS name-to-address lookup and returns **all** IPv4 records found for a hostname (up to 10), instead of a single address like `sceNetResolverStartNtoa`. To support it, the resolver code was reworked: `sceNetResolverStartNtoa` and the new export now share one internal implementation, and `sceNetResolverAbort` is no longer a no-op. ## Background **HOT WHEELS™ Infinite Rush** (PPSA22408) calls this function and currently stops at the logo screen: ``` Unresolved import stub called [0]: patch_vaddr=0x000000090b1c3da8 jmprela_index=308 symbol=RCCY01Xd+58[Net_v1][Net_v1.1][Func] type=Func bind=Global program=.../eboot.bin ``` - Build: KytyPS5-2026-10-27-ffc8137 (0.3.0) - Reference log: #1954 The behavior was modeled on the shadPS4 implementation (`net.cpp`, `net_resolver.cpp`, `net_resolver.h`) and adapted to KytyPS5's existing `Network` class. [https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1960](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1960) ## Changes ### Export and registration (`src/libs/libNet.cpp`) - Added `LibNet::NetResolverStartNtoaMultipleRecords(rid, hostname, info, timeout, retry, flags)`, wrapped with `FinishNetCall`. - Registered NID `RCCY01Xd+58` in `InitNet_1_Net`. ### Public types and declarations (`src/libs/network.h`) - Added `NetResolverAddress` (36 bytes) and `NetResolverInfo` (384 bytes, up to 10 addresses), both guarded by `static_assert` on their size. - Declared `NetResolverStartNtoaMultipleRecords`. ### Resolver state (`src/libs/network.cpp`) The `Resolver` struct gained `running`, `abort_requested`, `last_error` and `generation`. Four new `Network` methods manage it: | Method | Purpose | |--------|---------| | `ResolverAbort` | Marks an abort (`NET_ERROR_EINTR`), bumps the generation and clears `running`. | | `ResolverBeginLookup` | Rejects invalid ids (`EBADF`), a busy resolver (`NET_ERROR_RESOLVER_EBUSY`) and a queued abort (`EINTR`, consumed). Otherwise marks the resolver running and returns a new generation. | | `ResolverEndLookup` | Stores the result, only if the generation still matches. | | `ResolverCheckValidForDelivery` | Tells an async lookup whether the resolver still exists, was not aborted and has the same generation. | `ResolverDestroy` now carries the generation forward so a late async lookup cannot match a recycled slot. ### Lookup logic (`src/libs/network.cpp`) `NetResolverStartNtoa` and the new export both call `ResolverStartNtoaInternal`: 1. **Validation, in this order:** unknown resolver id → `NET_ERROR_EBADF`; null hostname or no output buffer → `NET_ERROR_EINVAL`; empty hostname or longer than 255 characters → `NET_ERROR_EINVAL`. 2. **Begin lookup** (see above). 3. **Resolution:** - A trailing `.` is stripped. - A hostname starting with `localhost` resolves to `127.0.0.1`. - A literal IPv4 address is returned as is, unless `ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS` (`0x00010000`) is set. - Otherwise `getaddrinfo` runs with `AF_INET` / `SOCK_STREAM`. Results are deduplicated and capped at 10. 4. **Delivery:** for the multiple-records export, the whole `NetResolverInfo` is zeroed, then `records` and `recordsv4` are set to the address count and each entry gets `af = 2` (`AF_INET`). For `sceNetResolverStartNtoa`, only the first address is written. 5. **Async** (`ORBIS_NET_RESOLVER_ASYNC`, `0x00000001`): the work runs on a detached thread and the call returns `0` immediately. The result is written only if `ResolverCheckValidForDelivery` still holds. Error translation from `getaddrinfo` (including the Windows `WSA*` equivalents): | Host error | Net error | |------------|-----------| | `EAI_NONAME`, `EAI_NODATA` | `NET_ERROR_RESOLVER_ENOHOST` | | `EAI_AGAIN` | `NET_ERROR_RESOLVER_ETIMEDOUT` | | `EAI_FAIL` | `NET_ERROR_RESOLVER_ESERVERFAILURE` | | empty result | `NET_ERROR_RESOLVER_ENORECORD` | | anything else | `NET_ERROR_RESOLVER_EINTERNAL` | ### `sceNetResolverAbort` Previously it only logged and returned `OK`. It now returns `NET_ERROR_EBADF` for an unknown resolver, and otherwise aborts the running lookup or queues the abort for the next one. ### Tests - Added `tests/NetResolverTests.cpp` and the `net_resolver_tests` target in `CMakeLists.txt`. - Covered: NID registration, parameter validation, `localhost` (including trailing dot), literal IP with and without `DISABLE_IPADDRESS`, abort followed by a successful lookup, an async lookup, and a real resolution of `google.com`. ## Behavior changes to existing code These affect `sceNetResolverStartNtoa` as well, because it now uses the shared path: - The resolver id is checked **before** the argument checks, so an invalid id with a null hostname now returns `EBADF` instead of `EINVAL`. - The `flags` argument is no longer rejected when it contains bits other than `0x00010000`. `ORBIS_NET_RESOLVER_ASYNC` is now honored. - When the socket backend cannot be initialized, the error is now `NET_ERROR_RESOLVER_ENODNS` instead of `NET_ERROR_ENETDOWN`. - `localhost` handling and the 10-record cap apply to `sceNetResolverStartNtoa` as well. ## Known limitations - `timeout` and `retry` are only logged, not enforced. - Only IPv4 is resolved; `recordsv6` stays `0`. - Async lookups update the resolver state but do **not** signal a completion event. Guests that wait on one will not be notified. - Between the validity check and the write to the guest buffer, an async lookup is not protected against a concurrent destroy or abort. - `sceNetResolverStartNtoaMultipleRecordsEx`, `ResolverGetError` and `ResolverStartAton` are not part of this PR. - Any hostname that begins with `localhost` (for example `localhost.example.com`) resolves to `127.0.0.1`. ## Formatting The diff also contains whitespace-only changes in `libNet.cpp` and `network.cpp` (alignment and line wrapping from the formatter). They do not change behavior. ## Testing - `net_resolver_tests` builds and passes - `TestResolveGoogle` needs working DNS and network access; run it on a machine that is online - HOT WHEELS™ Infinite Rush (PPSA22408) no longer stops on the unresolved `RCCY01Xd+58` import **AI use:** AI was used to analyze the problem and explore possible solutions. I performed the testing manually.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:12:09 +00:00
github-bot closed this pull request 2026-11-26 10:12:09 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 22:24 UTC

Review in Change Stack →

Walkthrough

The change adds a multiple-record resolver API with synchronous and asynchronous IPv4 lookup, hostname validation, and generation-based abort and delivery checks. Resolver results hold up to 10 addresses. Network, SSL, and HTTP entry points now use a mutex-protected shared Network instance. The change also includes formatting changes and a test executable for resolver behavior.

Suggested reviewers: nmzik

Change: Feature

Merge Risk: Low · up to 74e1c

The resolver test should synchronize result publication before reading asynchronous output; otherwise test results may be unreliable.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 1.28% 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 names the main change: adding the libSceNet export sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58). The changeset registers this export in libNet.cpp, declares it in network.h, and impl…
Description check Passed The description is directly related to the changeset. It names the new export, explains the shared resolver implementation, lists the public types and resolver state methods, describes the tests, and …
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: Title check

Explanation

The title names the main change: adding the libSceNet export sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58). The changeset registers this export in libNet.cpp, declares it in network.h, and implements it in network.cpp. The title is specific and matches the primary change.

Full details: Description check

Explanation

The description is directly related to the changeset. It names the new export, explains the shared resolver implementation, lists the public types and resolver state methods, describes the tests, and documents behavior changes and known limitations. This matches the files in the raw summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 1.28% 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 78 functions across 4 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
**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#issuecomment-6547395522) · edited 2026-10-31 22:24 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/2027?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 --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> The change adds a multiple-record resolver API with synchronous and asynchronous IPv4 lookup, hostname validation, and generation-based abort and delivery checks. Resolver results hold up to 10 addresses. Network, SSL, and HTTP entry points now use a mutex-protected shared `Network` instance. The change also includes formatting changes and a test executable for resolver behavior. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"74e1c9b976a1007f46b2cf65f3267de09d727374" --> <!-- 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-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>74e1c</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `74e1c` --> <!-- final_review_risk_coverage:{"sourceCommitId":"74e1c9b976a1007f46b2cf65f3267de09d727374","coveredCommitId":"74e1c9b976a1007f46b2cf65f3267de09d727374","kind":"reviewed"} --> The resolver test should synchronize result publication before reading asynchronous output; otherwise test results may be unreliable. <!-- 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 1.28% 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 names the main change: adding the libSceNet export sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58). The changeset registers this export in libNet.cpp, declares it in network.h, and impl… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changeset. It names the new export, explains the shared resolver implementation, lists the public types and resolver state methods, describes the tests, and … | | 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. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> **Explanation** The title names the main change: adding the libSceNet export sceNetResolverStartNtoaMultipleRecords (RCCY01Xd+58). The changeset registers this export in libNet.cpp, declares it in network.h, and implements it in network.cpp. The title is specific and matches the primary change. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> **Explanation** The description is directly related to the changeset. It names the new export, explains the shared resolver implementation, lists the public types and resolver state methods, describes the tests, and documents behavior changes and known limitations. This matches the files in the raw summary. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 1.28% 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 78 functions across 4 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=2027)! 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> <!-- tips_end -->
@ -1461,0 +1611,4 @@
const int begin_ret = network->ResolverBeginLookup(rid, is_async, &generation);
if (begin_ret != 0) {
return begin_ret;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC

Minor · Functional Correctness · Quick win

Validate flags before delegating NetResolverStartNtoa.

NetResolverStartNtoa previously returned NET_ERROR_EINVAL for flags other than 0x00010000. It now delegates directly to ResolverStartNtoaInternal, where 0x00000001 enables asynchronous lookup. A reachable guest call with flags = 0x1 can therefore return OK and start a detached lookup instead of rejecting the invalid flags. Preserve async handling for the multiple-record API, but validate flags separately in NetResolverStartNtoa.

Suggested fix
 int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout,
                                        int retry, int flags) {
 	PRINT_NAME();

 	LOGF(...);

+	if ((flags & ~0x00010000) != 0) {
+		return NET_ERROR_EINVAL;
+	}
+
 	return ResolverStartNtoaInternal(rid, hostname, {addr, nullptr}, timeout, retry, flags);
 }

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796855) · edited 2026-10-31 21:45 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** · **Functional Correctness** · **Quick win** **Validate flags before delegating `NetResolverStartNtoa`.** `NetResolverStartNtoa` previously returned `NET_ERROR_EINVAL` for flags other than `0x00010000`. It now delegates directly to `ResolverStartNtoaInternal`, where `0x00000001` enables asynchronous lookup. A reachable guest call with `flags = 0x1` can therefore return `OK` and start a detached lookup instead of rejecting the invalid flags. Preserve async handling for the multiple-record API, but validate flags separately in `NetResolverStartNtoa`. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout, int retry, int flags) { PRINT_NAME(); LOGF(...); + if ((flags & ~0x00010000) != 0) { + return NET_ERROR_EINVAL; + } + return ResolverStartNtoaInternal(rid, hostname, {addr, nullptr}, timeout, retry, flags); } ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f2d3c388e90e502375d069bb --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC
On src/libs/network.cpp line 1591 (outdated):

@@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) {
 
 int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) {
 	PRINT_NAME();
-	LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags);
+	LOGF("	 rid = %d\n	 flags = 0x%08x\n", rid, flags);
+
+	EXIT_IF(g_net == nullptr);
+	if (!g_net->ResolverAbort(rid, flags)) {
+		return NET_ERROR_EBADF;
+	}
+
 	return OK;
 }
 
-int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout,
-                                       int retry, int flags) {
-	PRINT_NAME();
-
-	LOGF("\t rid      = %d\n"
-	     "\t hostname = %s\n"
-	     "\t timeout  = %d\n"
-	     "\t retry    = %d\n"
-	     "\t flags    = 0x%08x\n",
-	     rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags);
+struct ResolverOutput {
+	void*            addr = nullptr;
+	NetResolverInfo* info = nullptr;
+};
 
+static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output,
+                                     int timeout, int retry, int flags) {
 	(void)timeout;
 	(void)retry;
 
-	if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) {
-		return NET_ERROR_EINVAL;
-	}
-
 	EXIT_IF(g_net == nullptr);
 	if (!g_net->ResolverValid(rid)) {
 		return NET_ERROR_EBADF;
 	}
 
-	if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) {
-		return OK;
+	if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) {
+		return NET_ERROR_EINVAL;
 	}
 
-	if (!EnsureSocketBackend()) {
-		return NET_ERROR_ENETDOWN;
+	constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255;
+	const size_t     host_len                            = std::strlen(hostname);
+	if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) {
+		return NET_ERROR_EINVAL;
 	}
 
-	addrinfo hints {};
-	hints.ai_family   = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
+	constexpr int ORBIS_NET_RESOLVER_ASYNC                        = 0x00000001;
+	constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000;
+
+	const bool is_async          = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0;
+	const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0;
+
+	uint32_t  generation = 0;
+	const int begin_ret  = g_net->ResolverBeginLookup(rid, is_async, &generation);
+	if (begin_ret != 0) {
+		return begin_ret;
+	}
 
-	addrinfo* result = nullptr;
-	const int ret    = getaddrinfo(hostname, nullptr, &hints, &result);
-	if (ret != 0 || result == nullptr) {
-		if (result != nullptr) {
-			freeaddrinfo(result);
+	auto do_lookup = [disable_ipaddress](const std::string&     host_str,
+	                                     std::vector<uint32_t>& out_addrs) -> int {
+		std::string host = host_str;
+		while (!host.empty() && host.back() == '.') {
+			host.pop_back();
 		}
-		if (ret == EAI_NONAME) {
+		if (host.empty()) {
 			return NET_ERROR_RESOLVER_ENOHOST;
 		}
-		if (ret == EAI_NODATA) {
+
+		if (host.rfind("localhost", 0) == 0) {
+			out_addrs.push_back(htonl(0x7f000001));
+			return OK;
+		}

Minor · Functional Correctness · Quick win

Fix the localhost match. It currently matches any hostname that starts with localhost.

host.rfind("localhost", 0) == 0 is a prefix test. Hostnames such as localhost.example.com or localhost-api.example.com resolve to 127.0.0.1 and skip DNS. The check also ignores case, so LOCALHOST goes to DNS. Use a case-insensitive equality test.

🐛 Proposed fix
--- "a/src/libs/network.cpp"
+++ "b/src/libs/network.cpp"
@@ -1585,10 +1585,13 @@
 			return NET_ERROR_RESOLVER_ENOHOST;
 		}
 
-		if (host.rfind("localhost", 0) == 0) {
+		std::string lowered = host;
+		std::transform(lowered.begin(), lowered.end(), lowered.begin(),
+		               [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
+		if (lowered == "localhost") {
 			out_addrs.push_back(htonl(0x7f000001));
 			return OK;
 		}
 
 		if (!disable_ipaddress) {
 			in_addr in {};

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796858) · edited 2026-10-31 21:45 UTC On `src/libs/network.cpp` line 1591 (outdated): ```diff @@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) { int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) { PRINT_NAME(); - LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags); + LOGF(" rid = %d\n flags = 0x%08x\n", rid, flags); + + EXIT_IF(g_net == nullptr); + if (!g_net->ResolverAbort(rid, flags)) { + return NET_ERROR_EBADF; + } + return OK; } -int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout, - int retry, int flags) { - PRINT_NAME(); - - LOGF("\t rid = %d\n" - "\t hostname = %s\n" - "\t timeout = %d\n" - "\t retry = %d\n" - "\t flags = 0x%08x\n", - rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags); +struct ResolverOutput { + void* addr = nullptr; + NetResolverInfo* info = nullptr; +}; +static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output, + int timeout, int retry, int flags) { (void)timeout; (void)retry; - if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) { - return NET_ERROR_EINVAL; - } - EXIT_IF(g_net == nullptr); if (!g_net->ResolverValid(rid)) { return NET_ERROR_EBADF; } - if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) { - return OK; + if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) { + return NET_ERROR_EINVAL; } - if (!EnsureSocketBackend()) { - return NET_ERROR_ENETDOWN; + constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255; + const size_t host_len = std::strlen(hostname); + if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) { + return NET_ERROR_EINVAL; } - addrinfo hints {}; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; + constexpr int ORBIS_NET_RESOLVER_ASYNC = 0x00000001; + constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000; + + const bool is_async = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0; + const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0; + + uint32_t generation = 0; + const int begin_ret = g_net->ResolverBeginLookup(rid, is_async, &generation); + if (begin_ret != 0) { + return begin_ret; + } - addrinfo* result = nullptr; - const int ret = getaddrinfo(hostname, nullptr, &hints, &result); - if (ret != 0 || result == nullptr) { - if (result != nullptr) { - freeaddrinfo(result); + auto do_lookup = [disable_ipaddress](const std::string& host_str, + std::vector<uint32_t>& out_addrs) -> int { + std::string host = host_str; + while (!host.empty() && host.back() == '.') { + host.pop_back(); } - if (ret == EAI_NONAME) { + if (host.empty()) { return NET_ERROR_RESOLVER_ENOHOST; } - if (ret == EAI_NODATA) { + + if (host.rfind("localhost", 0) == 0) { + out_addrs.push_back(htonl(0x7f000001)); + return OK; + } ``` <!-- 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** · **Functional Correctness** · **Quick win** **Fix the `localhost` match. It currently matches any hostname that starts with `localhost`.** `host.rfind("localhost", 0) == 0` is a prefix test. Hostnames such as `localhost.example.com` or `localhost-api.example.com` resolve to `127.0.0.1` and skip DNS. The check also ignores case, so `LOCALHOST` goes to DNS. Use a case-insensitive equality test. <details> <summary>🐛 Proposed fix</summary> <dl> <dd> ```diff --- "a/src/libs/network.cpp" +++ "b/src/libs/network.cpp" @@ -1585,10 +1585,13 @@ return NET_ERROR_RESOLVER_ENOHOST; } - if (host.rfind("localhost", 0) == 0) { + std::string lowered = host; + std::transform(lowered.begin(), lowered.end(), lowered.begin(), + [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); + if (lowered == "localhost") { out_addrs.push_back(htonl(0x7f000001)); return OK; } if (!disable_ipaddress) { in_addr in {}; ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:6fa0ecbbcd708d0b826ec3f6 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
@ -1461,0 +1718,4 @@
for (size_t i = 0; i < count; ++i) {
out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET
out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '1530,1745p' src/libs/network.cpp
sed -n '100,145p' tests/NetResolverTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8034


Script executed:

set -o pipefail
printf '%s\n' '--- resolver types and references ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'struct NetResolverInfo' -e 'class NetResolverInfo' -e 'NetResolverInfo' -e 'TestLocalhostAndLiteralIp' -e 'ResolverCheckValidForDelivery' -e 'deliver_result' src tests || test "$?" -eq 1
printf '%s\n' '--- guest-memory synchronization and async publication primitives ---'
rg -n --glob '*.{cpp,h,hpp}' -e 'atomic_thread_fence|memory_order_(acquire|release|seq_cst)|Guest.*(Read|Write|Buffer|Memory)|guest.*(read|write|buffer|memory)|SceKernel.*Event|event.*signal|Notify|Invalidate|Flush' src tests || test "$?" -eq 1
printf '%s\n' '--- resolver test body ---'
sed -n '1,230p' tests/NetResolverTests.cpp
printf '%s\n' '--- relevant declarations and implementations ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'ResolverStartNtoaInternal' -e 'NetResolverStartNtoaMultipleRecords' -e 'NetResolverStartNtoa' -e 'NetResolverCreate' -e 'NetResolverDestroy' src tests || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 41540


Script executed:

set -o pipefail
printf '%s\n' '--- resolver type and wrapper ---'
nl -ba src/libs/network.h | sed -n '45,82p'
nl -ba src/libs/libNet.cpp | sed -n '110,150p'
printf '%s\n' '--- guest pointer and call boundary references ---'
rg -n --glob '*.{cpp,h,hpp}' -e 'KYTY_SYSV_ABI.*NetResolverStartNtoa' -e 'NetResolverStartNtoaMultipleRecords' -e 'Guest.*Pointer' -e 'Guest.*Address' -e 'GuestRange' -e 'reinterpret_cast<.*guest' src/loader src/libs src/kernel | head -240
printf '%s\n' '--- synchronization tests and guest-memory atomics ---'
nl -ba tests/SyncOnAddressTests.cpp | sed -n '1,210p'
rg -n --glob '*.{cpp,h,hpp}' -e 'atomic_ref' -e 'SyncOnAddress' -e 'sync on address' -e 'guest.*atomic' -e 'Atomic.*Guest' src tests | head -240
printf '%s\n' '--- guest load/store implementation candidates ---'
rg -n --glob '*.{cpp,h,hpp}' -e 'ReadMemory' -e 'WriteMemory' -e 'MemoryRead' -e 'MemoryWrite' -e 'Load.*Memory' -e 'Store.*Memory' -e 'DataCacheInvalidate' -e 'Acquire' -e 'Release' src/loader src/kernel src/common | head -300

Repository: KytyPS5/KytyPS5

Length of output: 26300


Publish the address records before the counts.

deliver_result writes records and recordsv4 before addrs[]. The async test polls records and then reads addrs[0], so it can observe an incomplete result.

Reorder the writes. A release fence alone is not a synchronization protocol because the reader has no matching acquire operation.

♻️ Suggested reorder
--- "a/src/libs/network.cpp"
+++ "b/src/libs/network.cpp"
@@ -1672,14 +1672,14 @@
 
 	auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) {
 		if (out.info != nullptr) {
 			std::memset(out.info, 0, sizeof(NetResolverInfo));
 			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
-			out.info->records    = count;
-			out.info->recordsv4  = count;
 			for (size_t i = 0; i < count; ++i) {
 				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
 				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
 			}
+			out.info->recordsv4 = count;
+			out.info->records   = count;
 		} else if (out.addr != nullptr && !addrs.empty()) {
 			std::memcpy(out.addr, &addrs[0], sizeof(uint32_t));
 		}

If the guest contract requires a formal cross-thread guarantee, add a completion mechanism with a matching acquire operation. Do not rely on the release fence alone.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
			for (size_t i = 0; i < count; ++i) {
				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
			}
			out.info->recordsv4 = count;
			out.info->records   = count;

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796864) · edited 2026-10-31 21:45 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 '1530,1745p' src/libs/network.cpp sed -n '100,145p' tests/NetResolverTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8034 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- resolver types and references ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'struct NetResolverInfo' -e 'class NetResolverInfo' -e 'NetResolverInfo' -e 'TestLocalhostAndLiteralIp' -e 'ResolverCheckValidForDelivery' -e 'deliver_result' src tests || test "$?" -eq 1 printf '%s\n' '--- guest-memory synchronization and async publication primitives ---' rg -n --glob '*.{cpp,h,hpp}' -e 'atomic_thread_fence|memory_order_(acquire|release|seq_cst)|Guest.*(Read|Write|Buffer|Memory)|guest.*(read|write|buffer|memory)|SceKernel.*Event|event.*signal|Notify|Invalidate|Flush' src tests || test "$?" -eq 1 printf '%s\n' '--- resolver test body ---' sed -n '1,230p' tests/NetResolverTests.cpp printf '%s\n' '--- relevant declarations and implementations ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'ResolverStartNtoaInternal' -e 'NetResolverStartNtoaMultipleRecords' -e 'NetResolverStartNtoa' -e 'NetResolverCreate' -e 'NetResolverDestroy' src tests || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 41540 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- resolver type and wrapper ---' nl -ba src/libs/network.h | sed -n '45,82p' nl -ba src/libs/libNet.cpp | sed -n '110,150p' printf '%s\n' '--- guest pointer and call boundary references ---' rg -n --glob '*.{cpp,h,hpp}' -e 'KYTY_SYSV_ABI.*NetResolverStartNtoa' -e 'NetResolverStartNtoaMultipleRecords' -e 'Guest.*Pointer' -e 'Guest.*Address' -e 'GuestRange' -e 'reinterpret_cast<.*guest' src/loader src/libs src/kernel | head -240 printf '%s\n' '--- synchronization tests and guest-memory atomics ---' nl -ba tests/SyncOnAddressTests.cpp | sed -n '1,210p' rg -n --glob '*.{cpp,h,hpp}' -e 'atomic_ref' -e 'SyncOnAddress' -e 'sync on address' -e 'guest.*atomic' -e 'Atomic.*Guest' src tests | head -240 printf '%s\n' '--- guest load/store implementation candidates ---' rg -n --glob '*.{cpp,h,hpp}' -e 'ReadMemory' -e 'WriteMemory' -e 'MemoryRead' -e 'MemoryWrite' -e 'Load.*Memory' -e 'Store.*Memory' -e 'DataCacheInvalidate' -e 'Acquire' -e 'Release' src/loader src/kernel src/common | head -300 ``` Repository: KytyPS5/KytyPS5 Length of output: 26300 --- </dd> </dl> </details> **Publish the address records before the counts.** `deliver_result` writes `records` and `recordsv4` before `addrs[]`. The async test polls `records` and then reads `addrs[0]`, so it can observe an incomplete result. Reorder the writes. A release fence alone is not a synchronization protocol because the reader has no matching acquire operation. <details> <summary>♻️ Suggested reorder</summary> <dl> <dd> ```diff --- "a/src/libs/network.cpp" +++ "b/src/libs/network.cpp" @@ -1672,14 +1672,14 @@ auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) { if (out.info != nullptr) { std::memset(out.info, 0, sizeof(NetResolverInfo)); const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); - out.info->records = count; - out.info->recordsv4 = count; for (size_t i = 0; i < count; ++i) { out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; } + out.info->recordsv4 = count; + out.info->records = count; } else if (out.addr != nullptr && !addrs.empty()) { std::memcpy(out.addr, &addrs[0], sizeof(uint32_t)); } ``` </dd> </dl> </details> If the guest contract requires a formal cross-thread guarantee, add a completion mechanism with a matching acquire operation. Do not rely on the release fence alone. <!-- suggestion_start --> <details> <summary>Committable suggestion</summary> <dl> <dd> > <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg" width="20" height="20" align="absmiddle" alt=""></picture> **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); for (size_t i = 0; i < count; ++i) { out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; } out.info->recordsv4 = count; out.info->records = count; ``` </dd> </dl> </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:146970ee9ac4aec792b13942 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
@ -1461,0 +1741,4 @@
return res;
}
return NET_ERROR_EINTR;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

nl -ba src/libs/network.cpp | sed -n '300,420p;1625,1735p'

Repository: KytyPS5/KytyPS5

Length of output: 7980


Script executed:

rg -n -F -- 'ResolverStartNtoaInternal' 'NetResolverAbort' 'ResolverOutput' src/libs/network.cpp
nl -ba src/libs/network.cpp | sed -n '1480,1585p;1710,1785p'

Repository: KytyPS5/KytyPS5

Length of output: 6566


Serialize synchronous delivery with generation validation.

NetResolverAbort can invalidate the generation while do_lookup runs. The synchronous branch then calls deliver_result without validation and returns the original res, so an aborted successful lookup can write stale records and return OK.

Do not add a separate ResolverCheckValidForDelivery call before deliver_result; that method releases m_mutex before the write. Add a Network helper that holds m_mutex while it validates the resolver generation and invokes deliver_result. Skip the write and return NET_ERROR_EINTR when the generation is invalid. Pass that result to ResolverEndLookup and return it. Keep this correction limited to the synchronous branch.

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796869) · edited 2026-10-31 21:45 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 nl -ba src/libs/network.cpp | sed -n '300,420p;1625,1735p' ``` Repository: KytyPS5/KytyPS5 Length of output: 7980 --- Script executed: ```bash rg -n -F -- 'ResolverStartNtoaInternal' 'NetResolverAbort' 'ResolverOutput' src/libs/network.cpp nl -ba src/libs/network.cpp | sed -n '1480,1585p;1710,1785p' ``` Repository: KytyPS5/KytyPS5 Length of output: 6566 --- </dd> </dl> </details> **Serialize synchronous delivery with generation validation.** `NetResolverAbort` can invalidate the generation while `do_lookup` runs. The synchronous branch then calls `deliver_result` without validation and returns the original `res`, so an aborted successful lookup can write stale records and return `OK`. Do not add a separate `ResolverCheckValidForDelivery` call before `deliver_result`; that method releases `m_mutex` before the write. Add a `Network` helper that holds `m_mutex` while it validates the resolver generation and invokes `deliver_result`. Skip the write and return `NET_ERROR_EINTR` when the generation is invalid. Pass that result to `ResolverEndLookup` and return it. Keep this correction limited to the synchronous branch. <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:fa001816d73f09a5759f6e0e --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:46 UTC
On src/libs/network.cpp line 1710 (outdated):

@@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) {
 
 int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) {
 	PRINT_NAME();
-	LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags);
+	LOGF("	 rid = %d\n	 flags = 0x%08x\n", rid, flags);
+
+	EXIT_IF(g_net == nullptr);
+	if (!g_net->ResolverAbort(rid, flags)) {
+		return NET_ERROR_EBADF;
+	}
+
 	return OK;
 }
 
-int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout,
-                                       int retry, int flags) {
-	PRINT_NAME();
-
-	LOGF("\t rid      = %d\n"
-	     "\t hostname = %s\n"
-	     "\t timeout  = %d\n"
-	     "\t retry    = %d\n"
-	     "\t flags    = 0x%08x\n",
-	     rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags);
+struct ResolverOutput {
+	void*            addr = nullptr;
+	NetResolverInfo* info = nullptr;
+};
 
+static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output,
+                                     int timeout, int retry, int flags) {
 	(void)timeout;
 	(void)retry;
 
-	if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) {
-		return NET_ERROR_EINVAL;
-	}
-
 	EXIT_IF(g_net == nullptr);
 	if (!g_net->ResolverValid(rid)) {
 		return NET_ERROR_EBADF;
 	}
 
-	if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) {
-		return OK;
+	if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) {
+		return NET_ERROR_EINVAL;
 	}
 
-	if (!EnsureSocketBackend()) {
-		return NET_ERROR_ENETDOWN;
+	constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255;
+	const size_t     host_len                            = std::strlen(hostname);
+	if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) {
+		return NET_ERROR_EINVAL;
 	}
 
-	addrinfo hints {};
-	hints.ai_family   = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
+	constexpr int ORBIS_NET_RESOLVER_ASYNC                        = 0x00000001;
+	constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000;
+
+	const bool is_async          = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0;
+	const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0;
+
+	uint32_t  generation = 0;
+	const int begin_ret  = g_net->ResolverBeginLookup(rid, is_async, &generation);
+	if (begin_ret != 0) {
+		return begin_ret;
+	}
 
-	addrinfo* result = nullptr;
-	const int ret    = getaddrinfo(hostname, nullptr, &hints, &result);
-	if (ret != 0 || result == nullptr) {
-		if (result != nullptr) {
-			freeaddrinfo(result);
+	auto do_lookup = [disable_ipaddress](const std::string&     host_str,
+	                                     std::vector<uint32_t>& out_addrs) -> int {
+		std::string host = host_str;
+		while (!host.empty() && host.back() == '.') {
+			host.pop_back();
 		}
-		if (ret == EAI_NONAME) {
+		if (host.empty()) {
 			return NET_ERROR_RESOLVER_ENOHOST;
 		}
-		if (ret == EAI_NODATA) {
+
+		if (host.rfind("localhost", 0) == 0) {
+			out_addrs.push_back(htonl(0x7f000001));
+			return OK;
+		}
+
+		if (!disable_ipaddress) {
+			in_addr in {};
+#if defined(_WIN32)
+			if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) {
+#else
+			if (::inet_pton(AF_INET, host.c_str(), &in) == 1) {
+#endif
+				uint32_t ip = 0;
+				std::memcpy(&ip, &in, sizeof(ip));
+				out_addrs.push_back(ip);
+				return OK;
+			}
+		}
+
+		if (!EnsureSocketBackend()) {
+			return NET_ERROR_RESOLVER_ENODNS;
+		}
+
+		addrinfo hints {};
+		hints.ai_family   = AF_INET;
+		hints.ai_socktype = SOCK_STREAM;
+
+		addrinfo* result = nullptr;
+		const int ret    = getaddrinfo(host.c_str(), nullptr, &hints, &result);
+		if (ret != 0 || result == nullptr) {
+			if (result != nullptr) {
+				freeaddrinfo(result);
+			}
+#if defined(_WIN32)
+			if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+			if (ret == WSATRY_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == WSANO_RECOVERY) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+#endif
+			if (ret == EAI_NONAME) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#ifdef EAI_NODATA
+			if (ret == EAI_NODATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#endif
+			if (ret == EAI_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == EAI_FAIL) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+			return NET_ERROR_RESOLVER_EINTERNAL;
+		}
+
+		for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
+			if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
+			    ai->ai_addrlen >= sizeof(sockaddr_in)) {
+				const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
+				uint32_t    ip = 0;
+				std::memcpy(&ip, &in->sin_addr, sizeof(ip));
+				if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) {
+					out_addrs.push_back(ip);
+					if (out_addrs.size() >= 10) {
+						break;
+					}
+				}
+			}
+		}
+
+		freeaddrinfo(result);
+
+		if (out_addrs.empty()) {
 			return NET_ERROR_RESOLVER_ENORECORD;
 		}
-		return NET_ERROR_RESOLVER_EINTERNAL;
-	}
 
-	for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
-		if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
-		    ai->ai_addrlen >= sizeof(sockaddr_in)) {
-			const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
-			std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr));
-			freeaddrinfo(result);
-			return OK;
+		return OK;
+	};
+
+	auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) {
+		if (out.info != nullptr) {
+			std::memset(out.info, 0, sizeof(NetResolverInfo));
+			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
+			out.info->records    = count;
+			out.info->recordsv4  = count;
+			for (size_t i = 0; i < count; ++i) {
+				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
+				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
+			}
+		} else if (out.addr != nullptr && !addrs.empty()) {
+			std::memcpy(out.addr, &addrs[0], sizeof(uint32_t));
+		}
+	};
+
+	if (!is_async) {
+		std::vector<uint32_t> addrs;
+		const int             res = do_lookup(hostname, addrs);
+		if (res == OK) {
+			deliver_result(output, addrs);
 		}
+		g_net->ResolverEndLookup(rid, generation, res);
+		return res;
 	}
 
-	freeaddrinfo(result);
-	return NET_ERROR_RESOLVER_ENORECORD;
+	std::string host_copy = hostname;
+	std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() {
+		std::vector<uint32_t> addrs;
+		const int             res = do_lookup(host_copy, addrs);
+		if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) {
+			if (res == OK) {
+				deliver_result(output, addrs);
+			}
+			g_net->ResolverEndLookup(rid, generation, res);
+		}
+	}).detach();
+
+	return OK;

Major · Stability & Availability · Heavy lift

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- includes, global, Network lifecycle ---'
nl -ba src/libs/network.cpp | sed -n '1,145p'
nl -ba src/libs/network.cpp | sed -n '230,285p'
nl -ba src/libs/network.cpp | sed -n '1520,1765p'
printf '%s\n' '--- lifecycle and resolver call sites ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'Libs::Network::Initialize' -e 'Libs::Network::Shutdown' -e 'NetResolverStartNtoa' -e 'ResolverAbort' -e 'g_net' src tests || test "$?" -eq 1
printf '%s\n' '--- resolver test lifecycle ---'
nl -ba tests/NetResolverTests.cpp | sed -n '90,150p'

Repository: KytyPS5/KytyPS5

Length of output: 29085


Script executed:

set -eu
printf '%s\n' '--- resolver state methods ---'
nl -ba src/libs/network.cpp | sed -n '315,405p'
printf '%s\n' '--- mutex definitions and usages ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'class Mutex' -e 'struct Mutex' -e 'class LockGuard' -e 'using LockGuard' src common || test "$?" -eq 1
rg -n -F --glob '*.{h,hpp,cpp}' -e 'Common::Mutex' -e 'Common::LockGuard' src/common src/libs | head -80
printf '%s\n' '--- subsystem lifecycle ---'
nl -ba src/common/subsystems.cpp | sed -n '1,70p'
nl -ba src/emulator.cpp | sed -n '95,125p'

Repository: KytyPS5/KytyPS5

Length of output: 3314


Synchronize the shared-pointer handoff.

A plain const auto network = g_net still races Shutdown() resetting g_net. Protect the handoff with the existing mutex pattern, then capture the local owner in the worker. Apply the accessor to each g_net read that can overlap shutdown.

Suggested fix
-static Network* g_net = nullptr;
+static Common::Mutex             g_net_mutex;
+static std::shared_ptr<Network>  g_net;
+
+static std::shared_ptr<Network> GetNetwork() {
+	Common::LockGuard lock(g_net_mutex);
+	return g_net;
+}

 void Initialize() {
+	Common::LockGuard lock(g_net_mutex);
 	EXIT_IF(g_net != nullptr);

-	g_net = new Network;
+	g_net = std::make_shared<Network>();
 }

 void Shutdown() {
-	delete g_net;
-	g_net = nullptr;
+	std::shared_ptr<Network> network;
+	{
+		Common::LockGuard lock(g_net_mutex);
+		network = std::move(g_net);
+	}
 }

 static int ResolverStartNtoaInternal(...) {
-	EXIT_IF(g_net == nullptr);
-	if (!g_net->ResolverValid(rid)) {
+	const auto network = GetNetwork();
+	EXIT_IF(network == nullptr);
+	if (!network->ResolverValid(rid)) {
 		return NET_ERROR_EBADF;
 	}
 ...
-	const int begin_ret = g_net->ResolverBeginLookup(rid, is_async, &generation);
+	const int begin_ret = network->ResolverBeginLookup(rid, is_async, &generation);
 ...
-	std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() {
+	std::thread([network, rid, generation, output, host_copy, do_lookup, deliver_result]() {
 		...
-		if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) {
+		if (network->ResolverCheckValidForDelivery(rid, generation)) {
 			...
-			g_net->ResolverEndLookup(rid, generation, res);
+			network->ResolverEndLookup(rid, generation, res);
 		}
 	}).detach();

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796872) · edited 2026-10-31 21:46 UTC On `src/libs/network.cpp` line 1710 (outdated): ```diff @@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) { int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) { PRINT_NAME(); - LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags); + LOGF(" rid = %d\n flags = 0x%08x\n", rid, flags); + + EXIT_IF(g_net == nullptr); + if (!g_net->ResolverAbort(rid, flags)) { + return NET_ERROR_EBADF; + } + return OK; } -int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout, - int retry, int flags) { - PRINT_NAME(); - - LOGF("\t rid = %d\n" - "\t hostname = %s\n" - "\t timeout = %d\n" - "\t retry = %d\n" - "\t flags = 0x%08x\n", - rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags); +struct ResolverOutput { + void* addr = nullptr; + NetResolverInfo* info = nullptr; +}; +static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output, + int timeout, int retry, int flags) { (void)timeout; (void)retry; - if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) { - return NET_ERROR_EINVAL; - } - EXIT_IF(g_net == nullptr); if (!g_net->ResolverValid(rid)) { return NET_ERROR_EBADF; } - if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) { - return OK; + if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) { + return NET_ERROR_EINVAL; } - if (!EnsureSocketBackend()) { - return NET_ERROR_ENETDOWN; + constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255; + const size_t host_len = std::strlen(hostname); + if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) { + return NET_ERROR_EINVAL; } - addrinfo hints {}; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; + constexpr int ORBIS_NET_RESOLVER_ASYNC = 0x00000001; + constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000; + + const bool is_async = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0; + const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0; + + uint32_t generation = 0; + const int begin_ret = g_net->ResolverBeginLookup(rid, is_async, &generation); + if (begin_ret != 0) { + return begin_ret; + } - addrinfo* result = nullptr; - const int ret = getaddrinfo(hostname, nullptr, &hints, &result); - if (ret != 0 || result == nullptr) { - if (result != nullptr) { - freeaddrinfo(result); + auto do_lookup = [disable_ipaddress](const std::string& host_str, + std::vector<uint32_t>& out_addrs) -> int { + std::string host = host_str; + while (!host.empty() && host.back() == '.') { + host.pop_back(); } - if (ret == EAI_NONAME) { + if (host.empty()) { return NET_ERROR_RESOLVER_ENOHOST; } - if (ret == EAI_NODATA) { + + if (host.rfind("localhost", 0) == 0) { + out_addrs.push_back(htonl(0x7f000001)); + return OK; + } + + if (!disable_ipaddress) { + in_addr in {}; +#if defined(_WIN32) + if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) { +#else + if (::inet_pton(AF_INET, host.c_str(), &in) == 1) { +#endif + uint32_t ip = 0; + std::memcpy(&ip, &in, sizeof(ip)); + out_addrs.push_back(ip); + return OK; + } + } + + if (!EnsureSocketBackend()) { + return NET_ERROR_RESOLVER_ENODNS; + } + + addrinfo hints {}; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + + addrinfo* result = nullptr; + const int ret = getaddrinfo(host.c_str(), nullptr, &hints, &result); + if (ret != 0 || result == nullptr) { + if (result != nullptr) { + freeaddrinfo(result); + } +#if defined(_WIN32) + if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } + if (ret == WSATRY_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == WSANO_RECOVERY) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } +#endif + if (ret == EAI_NONAME) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#ifdef EAI_NODATA + if (ret == EAI_NODATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#endif + if (ret == EAI_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == EAI_FAIL) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } + return NET_ERROR_RESOLVER_EINTERNAL; + } + + for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { + if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && + ai->ai_addrlen >= sizeof(sockaddr_in)) { + const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); + uint32_t ip = 0; + std::memcpy(&ip, &in->sin_addr, sizeof(ip)); + if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) { + out_addrs.push_back(ip); + if (out_addrs.size() >= 10) { + break; + } + } + } + } + + freeaddrinfo(result); + + if (out_addrs.empty()) { return NET_ERROR_RESOLVER_ENORECORD; } - return NET_ERROR_RESOLVER_EINTERNAL; - } - for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { - if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && - ai->ai_addrlen >= sizeof(sockaddr_in)) { - const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); - std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr)); - freeaddrinfo(result); - return OK; + return OK; + }; + + auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) { + if (out.info != nullptr) { + std::memset(out.info, 0, sizeof(NetResolverInfo)); + const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); + out.info->records = count; + out.info->recordsv4 = count; + for (size_t i = 0; i < count; ++i) { + out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET + out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; + } + } else if (out.addr != nullptr && !addrs.empty()) { + std::memcpy(out.addr, &addrs[0], sizeof(uint32_t)); + } + }; + + if (!is_async) { + std::vector<uint32_t> addrs; + const int res = do_lookup(hostname, addrs); + if (res == OK) { + deliver_result(output, addrs); } + g_net->ResolverEndLookup(rid, generation, res); + return res; } - freeaddrinfo(result); - return NET_ERROR_RESOLVER_ENORECORD; + std::string host_copy = hostname; + std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() { + std::vector<uint32_t> addrs; + const int res = do_lookup(host_copy, addrs); + if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) { + if (res == OK) { + deliver_result(output, addrs); + } + g_net->ResolverEndLookup(rid, generation, res); + } + }).detach(); + + return OK; ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Stability & Availability** · **Heavy lift** <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 set -eu printf '%s\n' '--- includes, global, Network lifecycle ---' nl -ba src/libs/network.cpp | sed -n '1,145p' nl -ba src/libs/network.cpp | sed -n '230,285p' nl -ba src/libs/network.cpp | sed -n '1520,1765p' printf '%s\n' '--- lifecycle and resolver call sites ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'Libs::Network::Initialize' -e 'Libs::Network::Shutdown' -e 'NetResolverStartNtoa' -e 'ResolverAbort' -e 'g_net' src tests || test "$?" -eq 1 printf '%s\n' '--- resolver test lifecycle ---' nl -ba tests/NetResolverTests.cpp | sed -n '90,150p' ``` Repository: KytyPS5/KytyPS5 Length of output: 29085 --- Script executed: ```bash set -eu printf '%s\n' '--- resolver state methods ---' nl -ba src/libs/network.cpp | sed -n '315,405p' printf '%s\n' '--- mutex definitions and usages ---' rg -n -F --glob '*.{h,hpp,cpp}' -e 'class Mutex' -e 'struct Mutex' -e 'class LockGuard' -e 'using LockGuard' src common || test "$?" -eq 1 rg -n -F --glob '*.{h,hpp,cpp}' -e 'Common::Mutex' -e 'Common::LockGuard' src/common src/libs | head -80 printf '%s\n' '--- subsystem lifecycle ---' nl -ba src/common/subsystems.cpp | sed -n '1,70p' nl -ba src/emulator.cpp | sed -n '95,125p' ``` Repository: KytyPS5/KytyPS5 Length of output: 3314 --- </dd> </dl> </details> **Synchronize the shared-pointer handoff.** A plain `const auto network = g_net` still races `Shutdown()` resetting `g_net`. Protect the handoff with the existing mutex pattern, then capture the local owner in the worker. Apply the accessor to each `g_net` read that can overlap shutdown. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff -static Network* g_net = nullptr; +static Common::Mutex g_net_mutex; +static std::shared_ptr<Network> g_net; + +static std::shared_ptr<Network> GetNetwork() { + Common::LockGuard lock(g_net_mutex); + return g_net; +} void Initialize() { + Common::LockGuard lock(g_net_mutex); EXIT_IF(g_net != nullptr); - g_net = new Network; + g_net = std::make_shared<Network>(); } void Shutdown() { - delete g_net; - g_net = nullptr; + std::shared_ptr<Network> network; + { + Common::LockGuard lock(g_net_mutex); + network = std::move(g_net); + } } static int ResolverStartNtoaInternal(...) { - EXIT_IF(g_net == nullptr); - if (!g_net->ResolverValid(rid)) { + const auto network = GetNetwork(); + EXIT_IF(network == nullptr); + if (!network->ResolverValid(rid)) { return NET_ERROR_EBADF; } ... - const int begin_ret = g_net->ResolverBeginLookup(rid, is_async, &generation); + const int begin_ret = network->ResolverBeginLookup(rid, is_async, &generation); ... - std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() { + std::thread([network, rid, generation, output, host_copy, do_lookup, deliver_result]() { ... - if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) { + if (network->ResolverCheckValidForDelivery(rid, generation)) { ... - g_net->ResolverEndLookup(rid, generation, res); + network->ResolverEndLookup(rid, generation, res); } }).detach(); ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d66a63b9fcf4f472df432d60 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC
On src/libs/network.cpp line 1708 (outdated):

@@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) {
 
 int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) {
 	PRINT_NAME();
-	LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags);
+	LOGF("	 rid = %d\n	 flags = 0x%08x\n", rid, flags);
+
+	EXIT_IF(g_net == nullptr);
+	if (!g_net->ResolverAbort(rid, flags)) {
+		return NET_ERROR_EBADF;
+	}
+
 	return OK;
 }
 
-int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout,
-                                       int retry, int flags) {
-	PRINT_NAME();
-
-	LOGF("\t rid      = %d\n"
-	     "\t hostname = %s\n"
-	     "\t timeout  = %d\n"
-	     "\t retry    = %d\n"
-	     "\t flags    = 0x%08x\n",
-	     rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags);
+struct ResolverOutput {
+	void*            addr = nullptr;
+	NetResolverInfo* info = nullptr;
+};
 
+static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output,
+                                     int timeout, int retry, int flags) {
 	(void)timeout;
 	(void)retry;
 
-	if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) {
-		return NET_ERROR_EINVAL;
-	}
-
 	EXIT_IF(g_net == nullptr);
 	if (!g_net->ResolverValid(rid)) {
 		return NET_ERROR_EBADF;
 	}
 
-	if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) {
-		return OK;
+	if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) {
+		return NET_ERROR_EINVAL;
 	}
 
-	if (!EnsureSocketBackend()) {
-		return NET_ERROR_ENETDOWN;
+	constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255;
+	const size_t     host_len                            = std::strlen(hostname);
+	if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) {
+		return NET_ERROR_EINVAL;
 	}
 
-	addrinfo hints {};
-	hints.ai_family   = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
+	constexpr int ORBIS_NET_RESOLVER_ASYNC                        = 0x00000001;
+	constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000;
+
+	const bool is_async          = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0;
+	const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0;
+
+	uint32_t  generation = 0;
+	const int begin_ret  = g_net->ResolverBeginLookup(rid, is_async, &generation);
+	if (begin_ret != 0) {
+		return begin_ret;
+	}
 
-	addrinfo* result = nullptr;
-	const int ret    = getaddrinfo(hostname, nullptr, &hints, &result);
-	if (ret != 0 || result == nullptr) {
-		if (result != nullptr) {
-			freeaddrinfo(result);
+	auto do_lookup = [disable_ipaddress](const std::string&     host_str,
+	                                     std::vector<uint32_t>& out_addrs) -> int {
+		std::string host = host_str;
+		while (!host.empty() && host.back() == '.') {
+			host.pop_back();
 		}
-		if (ret == EAI_NONAME) {
+		if (host.empty()) {
 			return NET_ERROR_RESOLVER_ENOHOST;
 		}
-		if (ret == EAI_NODATA) {
+
+		if (host.rfind("localhost", 0) == 0) {
+			out_addrs.push_back(htonl(0x7f000001));
+			return OK;
+		}
+
+		if (!disable_ipaddress) {
+			in_addr in {};
+#if defined(_WIN32)
+			if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) {
+#else
+			if (::inet_pton(AF_INET, host.c_str(), &in) == 1) {
+#endif
+				uint32_t ip = 0;
+				std::memcpy(&ip, &in, sizeof(ip));
+				out_addrs.push_back(ip);
+				return OK;
+			}
+		}
+
+		if (!EnsureSocketBackend()) {
+			return NET_ERROR_RESOLVER_ENODNS;
+		}
+
+		addrinfo hints {};
+		hints.ai_family   = AF_INET;
+		hints.ai_socktype = SOCK_STREAM;
+
+		addrinfo* result = nullptr;
+		const int ret    = getaddrinfo(host.c_str(), nullptr, &hints, &result);
+		if (ret != 0 || result == nullptr) {
+			if (result != nullptr) {
+				freeaddrinfo(result);
+			}
+#if defined(_WIN32)
+			if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+			if (ret == WSATRY_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == WSANO_RECOVERY) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+#endif
+			if (ret == EAI_NONAME) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#ifdef EAI_NODATA
+			if (ret == EAI_NODATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#endif
+			if (ret == EAI_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == EAI_FAIL) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+			return NET_ERROR_RESOLVER_EINTERNAL;
+		}
+
+		for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
+			if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
+			    ai->ai_addrlen >= sizeof(sockaddr_in)) {
+				const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
+				uint32_t    ip = 0;
+				std::memcpy(&ip, &in->sin_addr, sizeof(ip));
+				if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) {
+					out_addrs.push_back(ip);
+					if (out_addrs.size() >= 10) {
+						break;
+					}
+				}
+			}
+		}
+
+		freeaddrinfo(result);
+
+		if (out_addrs.empty()) {
 			return NET_ERROR_RESOLVER_ENORECORD;
 		}
-		return NET_ERROR_RESOLVER_EINTERNAL;
-	}
 
-	for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
-		if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
-		    ai->ai_addrlen >= sizeof(sockaddr_in)) {
-			const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
-			std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr));
-			freeaddrinfo(result);
-			return OK;
+		return OK;
+	};
+
+	auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) {
+		if (out.info != nullptr) {
+			std::memset(out.info, 0, sizeof(NetResolverInfo));
+			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
+			out.info->records    = count;
+			out.info->recordsv4  = count;
+			for (size_t i = 0; i < count; ++i) {
+				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
+				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
+			}
+		} else if (out.addr != nullptr && !addrs.empty()) {
+			std::memcpy(out.addr, &addrs[0], sizeof(uint32_t));
+		}
+	};
+
+	if (!is_async) {
+		std::vector<uint32_t> addrs;
+		const int             res = do_lookup(hostname, addrs);
+		if (res == OK) {
+			deliver_result(output, addrs);
 		}
+		g_net->ResolverEndLookup(rid, generation, res);
+		return res;
 	}
 
-	freeaddrinfo(result);
-	return NET_ERROR_RESOLVER_ENORECORD;
+	std::string host_copy = hostname;
+	std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() {
+		std::vector<uint32_t> addrs;
+		const int             res = do_lookup(host_copy, addrs);
+		if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) {
+			if (res == OK) {
+				deliver_result(output, addrs);
+			}
+			g_net->ResolverEndLookup(rid, generation, res);
+		}
+	}).detach();

Minor · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- resolver methods and async worker ---'
sed -n '320,410p;1680,1720p' src/libs/network.cpp
printf '%s\n' '--- mutex guard usage in network.cpp ---'
rg -n -F -- 'm_mutex' src/libs/network.cpp | head -40
printf '%s\n' '--- mutex type/declarations ---'
rg -n -F -e 'class Mutex' -e 'struct Mutex' -e 'LockGuard' -e 'ScopedLock' -e 'Common::Mutex' src | head -80

Repository: KytyPS5/KytyPS5

Length of output: 10958


Script executed:

set -eu
sed -n '220,270p;1500,1720p' src/libs/network.cpp

Repository: KytyPS5/KytyPS5

Length of output: 7399


Script executed:

set -eu
sed -n '1,120p;120,220p' src/libs/network.cpp
rg -n -F -e 'ResolverCheckValidForDelivery' -e '#include <functional>' src/libs/network.cpp src/libs/*.h src/common 2>/dev/null || true

Repository: KytyPS5/KytyPS5

Length of output: 7170


Serialize async delivery with resolver abort.

ResolverCheckValidForDelivery releases m_mutex before deliver_result. ResolverAbort can invalidate the generation and return before the worker writes to the guest buffer. Run the delivery callback while the validity check still holds m_mutex.

Suggested fix
+#include <functional>
+
-	bool ResolverCheckValidForDelivery(int rid, uint32_t gen);
+	bool ResolverCheckValidForDelivery(int rid, uint32_t gen,
+	                                   const std::function<void()>& deliver);
 
-bool Network::ResolverCheckValidForDelivery(int rid, uint32_t gen) {
+bool Network::ResolverCheckValidForDelivery(int rid, uint32_t gen,
+                                            const std::function<void()>& deliver) {
 	Common::LockGuard lock(m_mutex);
 
-	return (rid >= 0 && rid < RESOLVERS_MAX && m_resolvers[rid].used &&
-	        m_resolvers[rid].generation == gen && !m_resolvers[rid].abort_requested);
+	if (rid < 0 || rid >= RESOLVERS_MAX || !m_resolvers[rid].used ||
+	    m_resolvers[rid].generation != gen || m_resolvers[rid].abort_requested) {
+		return false;
+	}
+	deliver();
+	return true;
 }
 
-		if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) {
-			if (res == OK) {
-				deliver_result(output, addrs);
-			}
+		if (g_net != nullptr &&
+		    g_net->ResolverCheckValidForDelivery(rid, generation, [&] {
+			    if (res == OK) {
+				    deliver_result(output, addrs);
+			    }
+		    })) {
 			g_net->ResolverEndLookup(rid, generation, res);
 		}

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796877) · edited 2026-10-31 21:45 UTC On `src/libs/network.cpp` line 1708 (outdated): ```diff @@ -1457,72 +1528,215 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) { int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) { PRINT_NAME(); - LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags); + LOGF(" rid = %d\n flags = 0x%08x\n", rid, flags); + + EXIT_IF(g_net == nullptr); + if (!g_net->ResolverAbort(rid, flags)) { + return NET_ERROR_EBADF; + } + return OK; } -int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout, - int retry, int flags) { - PRINT_NAME(); - - LOGF("\t rid = %d\n" - "\t hostname = %s\n" - "\t timeout = %d\n" - "\t retry = %d\n" - "\t flags = 0x%08x\n", - rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags); +struct ResolverOutput { + void* addr = nullptr; + NetResolverInfo* info = nullptr; +}; +static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output, + int timeout, int retry, int flags) { (void)timeout; (void)retry; - if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) { - return NET_ERROR_EINVAL; - } - EXIT_IF(g_net == nullptr); if (!g_net->ResolverValid(rid)) { return NET_ERROR_EBADF; } - if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) { - return OK; + if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) { + return NET_ERROR_EINVAL; } - if (!EnsureSocketBackend()) { - return NET_ERROR_ENETDOWN; + constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255; + const size_t host_len = std::strlen(hostname); + if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) { + return NET_ERROR_EINVAL; } - addrinfo hints {}; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; + constexpr int ORBIS_NET_RESOLVER_ASYNC = 0x00000001; + constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000; + + const bool is_async = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0; + const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0; + + uint32_t generation = 0; + const int begin_ret = g_net->ResolverBeginLookup(rid, is_async, &generation); + if (begin_ret != 0) { + return begin_ret; + } - addrinfo* result = nullptr; - const int ret = getaddrinfo(hostname, nullptr, &hints, &result); - if (ret != 0 || result == nullptr) { - if (result != nullptr) { - freeaddrinfo(result); + auto do_lookup = [disable_ipaddress](const std::string& host_str, + std::vector<uint32_t>& out_addrs) -> int { + std::string host = host_str; + while (!host.empty() && host.back() == '.') { + host.pop_back(); } - if (ret == EAI_NONAME) { + if (host.empty()) { return NET_ERROR_RESOLVER_ENOHOST; } - if (ret == EAI_NODATA) { + + if (host.rfind("localhost", 0) == 0) { + out_addrs.push_back(htonl(0x7f000001)); + return OK; + } + + if (!disable_ipaddress) { + in_addr in {}; +#if defined(_WIN32) + if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) { +#else + if (::inet_pton(AF_INET, host.c_str(), &in) == 1) { +#endif + uint32_t ip = 0; + std::memcpy(&ip, &in, sizeof(ip)); + out_addrs.push_back(ip); + return OK; + } + } + + if (!EnsureSocketBackend()) { + return NET_ERROR_RESOLVER_ENODNS; + } + + addrinfo hints {}; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + + addrinfo* result = nullptr; + const int ret = getaddrinfo(host.c_str(), nullptr, &hints, &result); + if (ret != 0 || result == nullptr) { + if (result != nullptr) { + freeaddrinfo(result); + } +#if defined(_WIN32) + if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } + if (ret == WSATRY_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == WSANO_RECOVERY) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } +#endif + if (ret == EAI_NONAME) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#ifdef EAI_NODATA + if (ret == EAI_NODATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#endif + if (ret == EAI_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == EAI_FAIL) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } + return NET_ERROR_RESOLVER_EINTERNAL; + } + + for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { + if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && + ai->ai_addrlen >= sizeof(sockaddr_in)) { + const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); + uint32_t ip = 0; + std::memcpy(&ip, &in->sin_addr, sizeof(ip)); + if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) { + out_addrs.push_back(ip); + if (out_addrs.size() >= 10) { + break; + } + } + } + } + + freeaddrinfo(result); + + if (out_addrs.empty()) { return NET_ERROR_RESOLVER_ENORECORD; } - return NET_ERROR_RESOLVER_EINTERNAL; - } - for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { - if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && - ai->ai_addrlen >= sizeof(sockaddr_in)) { - const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); - std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr)); - freeaddrinfo(result); - return OK; + return OK; + }; + + auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) { + if (out.info != nullptr) { + std::memset(out.info, 0, sizeof(NetResolverInfo)); + const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); + out.info->records = count; + out.info->recordsv4 = count; + for (size_t i = 0; i < count; ++i) { + out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET + out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; + } + } else if (out.addr != nullptr && !addrs.empty()) { + std::memcpy(out.addr, &addrs[0], sizeof(uint32_t)); + } + }; + + if (!is_async) { + std::vector<uint32_t> addrs; + const int res = do_lookup(hostname, addrs); + if (res == OK) { + deliver_result(output, addrs); } + g_net->ResolverEndLookup(rid, generation, res); + return res; } - freeaddrinfo(result); - return NET_ERROR_RESOLVER_ENORECORD; + std::string host_copy = hostname; + std::thread([rid, generation, output, host_copy, do_lookup, deliver_result]() { + std::vector<uint32_t> addrs; + const int res = do_lookup(host_copy, addrs); + if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) { + if (res == OK) { + deliver_result(output, addrs); + } + g_net->ResolverEndLookup(rid, generation, res); + } + }).detach(); ``` <!-- 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** · **Data Integrity & Integration** · **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 set -eu printf '%s\n' '--- resolver methods and async worker ---' sed -n '320,410p;1680,1720p' src/libs/network.cpp printf '%s\n' '--- mutex guard usage in network.cpp ---' rg -n -F -- 'm_mutex' src/libs/network.cpp | head -40 printf '%s\n' '--- mutex type/declarations ---' rg -n -F -e 'class Mutex' -e 'struct Mutex' -e 'LockGuard' -e 'ScopedLock' -e 'Common::Mutex' src | head -80 ``` Repository: KytyPS5/KytyPS5 Length of output: 10958 --- Script executed: ```bash set -eu sed -n '220,270p;1500,1720p' src/libs/network.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 7399 --- Script executed: ```bash set -eu sed -n '1,120p;120,220p' src/libs/network.cpp rg -n -F -e 'ResolverCheckValidForDelivery' -e '#include <functional>' src/libs/network.cpp src/libs/*.h src/common 2>/dev/null || true ``` Repository: KytyPS5/KytyPS5 Length of output: 7170 --- </dd> </dl> </details> **Serialize async delivery with resolver abort.** `ResolverCheckValidForDelivery` releases `m_mutex` before `deliver_result`. `ResolverAbort` can invalidate the generation and return before the worker writes to the guest buffer. Run the delivery callback while the validity check still holds `m_mutex`. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff +#include <functional> + - bool ResolverCheckValidForDelivery(int rid, uint32_t gen); + bool ResolverCheckValidForDelivery(int rid, uint32_t gen, + const std::function<void()>& deliver); -bool Network::ResolverCheckValidForDelivery(int rid, uint32_t gen) { +bool Network::ResolverCheckValidForDelivery(int rid, uint32_t gen, + const std::function<void()>& deliver) { Common::LockGuard lock(m_mutex); - return (rid >= 0 && rid < RESOLVERS_MAX && m_resolvers[rid].used && - m_resolvers[rid].generation == gen && !m_resolvers[rid].abort_requested); + if (rid < 0 || rid >= RESOLVERS_MAX || !m_resolvers[rid].used || + m_resolvers[rid].generation != gen || m_resolvers[rid].abort_requested) { + return false; + } + deliver(); + return true; } - if (g_net != nullptr && g_net->ResolverCheckValidForDelivery(rid, generation)) { - if (res == OK) { - deliver_result(output, addrs); - } + if (g_net != nullptr && + g_net->ResolverCheckValidForDelivery(rid, generation, [&] { + if (res == OK) { + deliver_result(output, addrs); + } + })) { g_net->ResolverEndLookup(rid, generation, res); } ``` </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c80a565c7eaf812085678265 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · edited 2026-10-31 21:45 UTC
On tests/NetResolverTests.cpp line 130 (outdated):

@@ -0,0 +1,187 @@
+#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
+
+#include "common/abi.h"
+#include "libs/errno.h"
+#include "libs/network.h"
+#include "loader/symbolDatabase.h"
+
+#include <chrono>
+#include <cstdio>
+#include <cstring>
+#include <string>
+#include <thread>
+
+namespace Libs::LibNet {
+void InitNet_1_Net(Loader::SymbolDatabase* symbols);
+}
+
+namespace {
+
+int failures = 0;
+
+#define CHECK(condition)                                                                           \
+	do {                                                                                           \
+		if (!(condition)) {                                                                        \
+			std::fprintf(stderr, "NetResolverTests:%d: %s\n", __LINE__, #condition);               \
+			failures++;                                                                            \
+		}                                                                                          \
+	} while (false)
+
+using NetResolverStartNtoaMultipleRecordsFn = int(KYTY_SYSV_ABI*)(
+    int rid, const char* hostname, void* info, int timeout, int retry, int flags);
+
+template <typename T>
+T GetNetFunction(const Loader::SymbolDatabase& symbols, const char* nid) {
+	const auto* record = symbols.FindByNid(nid, Loader::SymbolType::Func);
+	CHECK(record != nullptr);
+	return record != nullptr ? reinterpret_cast<T>(record->vaddr) : nullptr;
+}
+
+void TestRegistration(const Loader::SymbolDatabase& symbols) {
+	const auto fn = GetNetFunction<NetResolverStartNtoaMultipleRecordsFn>(symbols, "RCCY01Xd+58");
+	CHECK(fn != nullptr);
+}
+
+void TestParameterValidation(NetResolverStartNtoaMultipleRecordsFn fn) {
+	using namespace Libs::Network;
+	Initialize();
+
+	const int pool = Net::NetPoolCreate("test_pool", 0x10000, 0);
+	CHECK(pool >= 0);
+	const int rid = Net::NetResolverCreate("test_res", pool, 0);
+	CHECK(rid >= 0);
+
+	Net::NetResolverInfo info {};
+
+	// 1. Invalid resolver ID
+	CHECK(fn(-1, "localhost", &info, 0, 0, 0) == NET_ERROR_EBADF);
+	CHECK(fn(999, "localhost", &info, 0, 0, 0) == NET_ERROR_EBADF);
+
+	// 2. Null hostname
+	CHECK(fn(rid, nullptr, &info, 0, 0, 0) == NET_ERROR_EINVAL);
+
+	// 3. Null info
+	CHECK(fn(rid, "localhost", nullptr, 0, 0, 0) == NET_ERROR_EINVAL);
+
+	// 4. Empty hostname
+	CHECK(fn(rid, "", &info, 0, 0, 0) == NET_ERROR_EINVAL);
+
+	// 5. Hostname > 255 chars
+	std::string too_long_host(256, 'a');
+	CHECK(fn(rid, too_long_host.c_str(), &info, 0, 0, 0) == NET_ERROR_EINVAL);
+
+	CHECK(Net::NetResolverDestroy(rid) == 0);
+	CHECK(Net::NetPoolDestroy(pool) == 0);
+	Shutdown();
+}
+
+void TestLocalhostAndLiteralIp(NetResolverStartNtoaMultipleRecordsFn fn) {
+	using namespace Libs::Network;
+	Initialize();
+
+	const int pool = Net::NetPoolCreate("test_pool2", 0x10000, 0);
+	CHECK(pool >= 0);
+	const int rid = Net::NetResolverCreate("test_res2", pool, 0);
+	CHECK(rid >= 0);
+
+	Net::NetResolverInfo info {};
+	uint32_t             expected_loopback = 0;
+	CHECK(Net::NetInetPton(2, "127.0.0.1", &expected_loopback) == 1);
+
+	// Test localhost (with trailing dot as well)
+	CHECK(fn(rid, "localhost.", &info, 0, 0, 0) == 0);
+	CHECK(info.records == 1);
+	CHECK(info.recordsv4 == 1);
+	CHECK(info.addrs[0].af == 2); // AF_INET
+	CHECK(info.addrs[0].u.addr.inaddr_addr == expected_loopback);
+
+	// Test literal IP address
+	std::memset(&info, 0, sizeof(info));
+	CHECK(fn(rid, "192.168.1.50", &info, 0, 0, 0) == 0);
+	CHECK(info.records == 1);
+	CHECK(info.recordsv4 == 1);
+	CHECK(info.addrs[0].af == 2);
+	uint32_t expected_ip = 0;
+	CHECK(Net::NetInetPton(2, "192.168.1.50", &expected_ip) == 1);
+	CHECK(info.addrs[0].u.addr.inaddr_addr == expected_ip);
+
+	// Test literal IP address with DISABLE_IPADDRESS flag (0x00010000)
+	std::memset(&info, 0, sizeof(info));
+	int ret_dis = fn(rid, "192.168.1.50", &info, 0, 0, 0x00010000);
+	CHECK(ret_dis == 0);
+	CHECK(info.records == 1);
+	CHECK(info.addrs[0].u.addr.inaddr_addr == expected_ip);
+
+	// Test Abort and queued abort
+	CHECK(Net::NetResolverAbort(rid, 0) == 0);
+	// Once aborted, next lookup should consume abort and return NET_ERROR_EINTR
+	CHECK(fn(rid, "localhost", &info, 0, 0, 0) == NET_ERROR_EINTR);
+	// Subsequent lookup should succeed again
+	CHECK(fn(rid, "localhost", &info, 0, 0, 0) == 0);
+
+	// Test Async lookup (flag 0x00000001)
+	std::memset(&info, 0, sizeof(info));
+	CHECK(fn(rid, "localhost", &info, 0, 0, 0x00000001) == 0);
+	// Wait a moment for background thread
+	for (int i = 0; i < 50 && info.records == 0; ++i) {
+		std::this_thread::sleep_for(std::chrono::milliseconds(10));
+	}
+	CHECK(info.records == 1);
+	CHECK(info.addrs[0].u.addr.inaddr_addr == expected_loopback);

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '570,605p' CMakeLists.txt
sed -n '1,195p' tests/NetResolverTests.cpp
rg -n 'add_kyty_full_emulator_test|void Shutdown|NetResolverStartNtoaMultipleRecords' CMakeLists.txt src/libs/network.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8459


Script executed:

sed -n '350,415p' CMakeLists.txt
sed -n '240,300p' src/libs/network.cpp
sed -n '1600,1785p' src/libs/network.cpp
rg -n -F -e 'std::thread' -e 'jthread' -e 'NetResolverDestroy' -e 'NetResolverAbort' -e 'resolver' src/libs/network.cpp | sed -n '1,220p'

Repository: KytyPS5/KytyPS5

Length of output: 11161


Script executed:

sed -n '1,130p' src/libs/network.cpp
sed -n '300,410p' src/libs/network.cpp
sed -n '1500,1550p' src/libs/network.cpp
rg -n -F -e 'net_resolver_tests' -e 'ctest' -e 'cmake --build' -e 'BUILD_TESTING' -e 'add_test' --glob '!third_party/**' --glob '!build/**' .

Repository: KytyPS5/KytyPS5

Length of output: 40701


Join the async resolver worker before releasing info.

The google.com lookup is not part of the default CTest workflow because net_resolver_tests is excluded from the default build and has no add_test entry. An explicit run of the executable still requires live DNS.

The async lookup uses a detached worker. The 500 ms poll does not join it, and Shutdown() does not wait for it. The worker can therefore write through info after TestLocalhostAndLiteralIp releases its stack frame. Wait for worker completion before teardown, or use storage that outlives the worker.

✅ Addressed in commit b086a5d

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4432796879) · edited 2026-10-31 21:45 UTC On `tests/NetResolverTests.cpp` line 130 (outdated): ```diff @@ -0,0 +1,187 @@ +#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING + +#include "common/abi.h" +#include "libs/errno.h" +#include "libs/network.h" +#include "loader/symbolDatabase.h" + +#include <chrono> +#include <cstdio> +#include <cstring> +#include <string> +#include <thread> + +namespace Libs::LibNet { +void InitNet_1_Net(Loader::SymbolDatabase* symbols); +} + +namespace { + +int failures = 0; + +#define CHECK(condition) \ + do { \ + if (!(condition)) { \ + std::fprintf(stderr, "NetResolverTests:%d: %s\n", __LINE__, #condition); \ + failures++; \ + } \ + } while (false) + +using NetResolverStartNtoaMultipleRecordsFn = int(KYTY_SYSV_ABI*)( + int rid, const char* hostname, void* info, int timeout, int retry, int flags); + +template <typename T> +T GetNetFunction(const Loader::SymbolDatabase& symbols, const char* nid) { + const auto* record = symbols.FindByNid(nid, Loader::SymbolType::Func); + CHECK(record != nullptr); + return record != nullptr ? reinterpret_cast<T>(record->vaddr) : nullptr; +} + +void TestRegistration(const Loader::SymbolDatabase& symbols) { + const auto fn = GetNetFunction<NetResolverStartNtoaMultipleRecordsFn>(symbols, "RCCY01Xd+58"); + CHECK(fn != nullptr); +} + +void TestParameterValidation(NetResolverStartNtoaMultipleRecordsFn fn) { + using namespace Libs::Network; + Initialize(); + + const int pool = Net::NetPoolCreate("test_pool", 0x10000, 0); + CHECK(pool >= 0); + const int rid = Net::NetResolverCreate("test_res", pool, 0); + CHECK(rid >= 0); + + Net::NetResolverInfo info {}; + + // 1. Invalid resolver ID + CHECK(fn(-1, "localhost", &info, 0, 0, 0) == NET_ERROR_EBADF); + CHECK(fn(999, "localhost", &info, 0, 0, 0) == NET_ERROR_EBADF); + + // 2. Null hostname + CHECK(fn(rid, nullptr, &info, 0, 0, 0) == NET_ERROR_EINVAL); + + // 3. Null info + CHECK(fn(rid, "localhost", nullptr, 0, 0, 0) == NET_ERROR_EINVAL); + + // 4. Empty hostname + CHECK(fn(rid, "", &info, 0, 0, 0) == NET_ERROR_EINVAL); + + // 5. Hostname > 255 chars + std::string too_long_host(256, 'a'); + CHECK(fn(rid, too_long_host.c_str(), &info, 0, 0, 0) == NET_ERROR_EINVAL); + + CHECK(Net::NetResolverDestroy(rid) == 0); + CHECK(Net::NetPoolDestroy(pool) == 0); + Shutdown(); +} + +void TestLocalhostAndLiteralIp(NetResolverStartNtoaMultipleRecordsFn fn) { + using namespace Libs::Network; + Initialize(); + + const int pool = Net::NetPoolCreate("test_pool2", 0x10000, 0); + CHECK(pool >= 0); + const int rid = Net::NetResolverCreate("test_res2", pool, 0); + CHECK(rid >= 0); + + Net::NetResolverInfo info {}; + uint32_t expected_loopback = 0; + CHECK(Net::NetInetPton(2, "127.0.0.1", &expected_loopback) == 1); + + // Test localhost (with trailing dot as well) + CHECK(fn(rid, "localhost.", &info, 0, 0, 0) == 0); + CHECK(info.records == 1); + CHECK(info.recordsv4 == 1); + CHECK(info.addrs[0].af == 2); // AF_INET + CHECK(info.addrs[0].u.addr.inaddr_addr == expected_loopback); + + // Test literal IP address + std::memset(&info, 0, sizeof(info)); + CHECK(fn(rid, "192.168.1.50", &info, 0, 0, 0) == 0); + CHECK(info.records == 1); + CHECK(info.recordsv4 == 1); + CHECK(info.addrs[0].af == 2); + uint32_t expected_ip = 0; + CHECK(Net::NetInetPton(2, "192.168.1.50", &expected_ip) == 1); + CHECK(info.addrs[0].u.addr.inaddr_addr == expected_ip); + + // Test literal IP address with DISABLE_IPADDRESS flag (0x00010000) + std::memset(&info, 0, sizeof(info)); + int ret_dis = fn(rid, "192.168.1.50", &info, 0, 0, 0x00010000); + CHECK(ret_dis == 0); + CHECK(info.records == 1); + CHECK(info.addrs[0].u.addr.inaddr_addr == expected_ip); + + // Test Abort and queued abort + CHECK(Net::NetResolverAbort(rid, 0) == 0); + // Once aborted, next lookup should consume abort and return NET_ERROR_EINTR + CHECK(fn(rid, "localhost", &info, 0, 0, 0) == NET_ERROR_EINTR); + // Subsequent lookup should succeed again + CHECK(fn(rid, "localhost", &info, 0, 0, 0) == 0); + + // Test Async lookup (flag 0x00000001) + std::memset(&info, 0, sizeof(info)); + CHECK(fn(rid, "localhost", &info, 0, 0, 0x00000001) == 0); + // Wait a moment for background thread + for (int i = 0; i < 50 && info.records == 0; ++i) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + CHECK(info.records == 1); + CHECK(info.addrs[0].u.addr.inaddr_addr == expected_loopback); ``` <!-- 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 '570,605p' CMakeLists.txt sed -n '1,195p' tests/NetResolverTests.cpp rg -n 'add_kyty_full_emulator_test|void Shutdown|NetResolverStartNtoaMultipleRecords' CMakeLists.txt src/libs/network.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8459 --- Script executed: ```bash sed -n '350,415p' CMakeLists.txt sed -n '240,300p' src/libs/network.cpp sed -n '1600,1785p' src/libs/network.cpp rg -n -F -e 'std::thread' -e 'jthread' -e 'NetResolverDestroy' -e 'NetResolverAbort' -e 'resolver' src/libs/network.cpp | sed -n '1,220p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11161 --- Script executed: ```bash sed -n '1,130p' src/libs/network.cpp sed -n '300,410p' src/libs/network.cpp sed -n '1500,1550p' src/libs/network.cpp rg -n -F -e 'net_resolver_tests' -e 'ctest' -e 'cmake --build' -e 'BUILD_TESTING' -e 'add_test' --glob '!third_party/**' --glob '!build/**' . ``` Repository: KytyPS5/KytyPS5 Length of output: 40701 --- </dd> </dl> </details> **Join the async resolver worker before releasing `info`.** The `google.com` lookup is not part of the default CTest workflow because `net_resolver_tests` is excluded from the default build and has no `add_test` entry. An explicit run of the executable still requires live DNS. The async lookup uses a detached worker. The 500 ms poll does not join it, and `Shutdown()` does not wait for it. The worker can therefore write through `info` after `TestLocalhostAndLiteralIp` releases its stack frame. Wait for worker completion before teardown, or use storage that outlives the worker. <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c018bc050fb2e11f37e06c78 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b086a5d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 18:24 UTC · original · reviewed

Actionable comments posted: 7


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 026189166f and b39bda218d.

Files selected for processing: 5
  • CMakeLists.txt
  • src/libs/libNet.cpp
  • src/libs/network.cpp
  • src/libs/network.h
  • tests/NetResolverTests.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-31 18:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#pullrequestreview-5724271206) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 7** --- <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/026189166f71cc1995f5851dee1ddad7d5826e99/.coderabbit.yaml>) - **Commit**: [0261891](<https://github.com/KytyPS5/KytyPS5/commit/026189166f71cc1995f5851dee1ddad7d5826e99>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `575e74c1-1e83-439a-b6e7-ba18c02de5fc` </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 026189166f71cc1995f5851dee1ddad7d5826e99 and b39bda218d7cd248ab5165ab5d623e45faaf8a03. </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: 5</summary> <dl> <dd> * `CMakeLists.txt` * `src/libs/libNet.cpp` * `src/libs/network.cpp` * `src/libs/network.h` * `tests/NetResolverTests.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=2165b68c-f2d7-4d3c-b605-c51d87bd0b87 attempt=88d447c4-235c-4cf8-9502-725f00d831df batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 21:49 UTC · original · edited 2026-10-31 22:14 UTC
On src/libs/network.cpp line 1739 (outdated):

@@ -1457,72 +1564,229 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) {
 
 int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) {
 	PRINT_NAME();
-	LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags);
+	LOGF("	 rid = %d\n	 flags = 0x%08x\n", rid, flags);
+
+	const auto network = GetNetwork();
+	EXIT_IF(network == nullptr);
+	if (!network->ResolverAbort(rid, flags)) {
+		return NET_ERROR_EBADF;
+	}
+
 	return OK;
 }
 
-int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout,
-                                       int retry, int flags) {
-	PRINT_NAME();
-
-	LOGF("\t rid      = %d\n"
-	     "\t hostname = %s\n"
-	     "\t timeout  = %d\n"
-	     "\t retry    = %d\n"
-	     "\t flags    = 0x%08x\n",
-	     rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags);
+struct ResolverOutput {
+	void*            addr = nullptr;
+	NetResolverInfo* info = nullptr;
+};
 
+static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output,
+                                     int timeout, int retry, int flags) {
 	(void)timeout;
 	(void)retry;
 
-	if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) {
-		return NET_ERROR_EINVAL;
-	}
-
-	EXIT_IF(g_net == nullptr);
-	if (!g_net->ResolverValid(rid)) {
+	const auto network = GetNetwork();
+	EXIT_IF(network == nullptr);
+	if (!network->ResolverValid(rid)) {
 		return NET_ERROR_EBADF;
 	}
 
-	if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) {
-		return OK;
+	if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) {
+		return NET_ERROR_EINVAL;
 	}
 
-	if (!EnsureSocketBackend()) {
-		return NET_ERROR_ENETDOWN;
+	constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255;
+	const size_t     host_len                            = std::strlen(hostname);
+	if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) {
+		return NET_ERROR_EINVAL;
 	}
 
-	addrinfo hints {};
-	hints.ai_family   = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
+	constexpr int ORBIS_NET_RESOLVER_ASYNC                        = 0x00000001;
+	constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000;
+
+	const bool is_async          = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0;
+	const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0;
+
+	uint32_t  generation = 0;
+	const int begin_ret  = network->ResolverBeginLookup(rid, is_async, &generation);
+	if (begin_ret != 0) {
+		return begin_ret;
+	}
 
-	addrinfo* result = nullptr;
-	const int ret    = getaddrinfo(hostname, nullptr, &hints, &result);
-	if (ret != 0 || result == nullptr) {
-		if (result != nullptr) {
-			freeaddrinfo(result);
+	auto do_lookup = [disable_ipaddress](const std::string&     host_str,
+	                                     std::vector<uint32_t>& out_addrs) -> int {
+		std::string host = host_str;
+		while (!host.empty() && host.back() == '.') {
+			host.pop_back();
 		}
-		if (ret == EAI_NONAME) {
+		if (host.empty()) {
 			return NET_ERROR_RESOLVER_ENOHOST;
 		}
-		if (ret == EAI_NODATA) {
+
+		std::string lowered = host;
+		std::transform(lowered.begin(), lowered.end(), lowered.begin(),
+		               [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
+		if (lowered == "localhost") {
+			out_addrs.push_back(htonl(0x7f000001));
+			return OK;
+		}
+
+		if (!disable_ipaddress) {
+			in_addr in {};
+#if defined(_WIN32)
+			if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) {
+#else
+			if (::inet_pton(AF_INET, host.c_str(), &in) == 1) {
+#endif
+				uint32_t ip = 0;
+				std::memcpy(&ip, &in, sizeof(ip));
+				out_addrs.push_back(ip);
+				return OK;
+			}
+		}
+
+		if (!EnsureSocketBackend()) {
+			return NET_ERROR_RESOLVER_ENODNS;
+		}
+
+		addrinfo hints {};
+		hints.ai_family   = AF_INET;
+		hints.ai_socktype = SOCK_STREAM;
+
+		addrinfo* result = nullptr;
+		const int ret    = getaddrinfo(host.c_str(), nullptr, &hints, &result);
+		if (ret != 0 || result == nullptr) {
+			if (result != nullptr) {
+				freeaddrinfo(result);
+			}
+#if defined(_WIN32)
+			if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+			if (ret == WSATRY_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == WSANO_RECOVERY) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+#endif
+			if (ret == EAI_NONAME) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#ifdef EAI_NODATA
+			if (ret == EAI_NODATA) {
+				return NET_ERROR_RESOLVER_ENOHOST;
+			}
+#endif
+			if (ret == EAI_AGAIN) {
+				return NET_ERROR_RESOLVER_ETIMEDOUT;
+			}
+			if (ret == EAI_FAIL) {
+				return NET_ERROR_RESOLVER_ESERVERFAILURE;
+			}
+			return NET_ERROR_RESOLVER_EINTERNAL;
+		}
+
+		for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
+			if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
+			    ai->ai_addrlen >= sizeof(sockaddr_in)) {
+				const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
+				uint32_t    ip = 0;
+				std::memcpy(&ip, &in->sin_addr, sizeof(ip));
+				if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) {
+					out_addrs.push_back(ip);
+					if (out_addrs.size() >= 10) {
+						break;
+					}
+				}
+			}
+		}
+
+		freeaddrinfo(result);
+
+		if (out_addrs.empty()) {
 			return NET_ERROR_RESOLVER_ENORECORD;
 		}
-		return NET_ERROR_RESOLVER_EINTERNAL;
-	}
 
-	for (auto* ai = result; ai != nullptr; ai = ai->ai_next) {
-		if (ai->ai_family == AF_INET && ai->ai_addr != nullptr &&
-		    ai->ai_addrlen >= sizeof(sockaddr_in)) {
-			const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr);
-			std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr));
-			freeaddrinfo(result);
-			return OK;
+		return OK;
+	};
+
+	auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) {
+		if (out.info != nullptr) {
+			std::memset(out.info, 0, sizeof(NetResolverInfo));
+			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
+			for (size_t i = 0; i < count; ++i) {
+				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
+				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
+			}
+			out.info->recordsv4 = count;
+			out.info->records   = count;
+		} else if (out.addr != nullptr && !addrs.empty()) {
+			std::memcpy(out.addr, &addrs[0], sizeof(uint32_t));
+		}
+	};
+
+	if (!is_async) {
+		std::vector<uint32_t> addrs;
+		const int             res = do_lookup(hostname, addrs);
+		if (res == OK) {
+			const int deliver_res = network->ResolverDeliverResultSync(rid, generation, [&] {
+				deliver_result(output, addrs);
+			});
+			network->ResolverEndLookup(rid, generation, deliver_res);
+			return deliver_res;
+		}
+		network->ResolverEndLookup(rid, generation, res);

Minor · Functional Correctness · Quick win

Check cancellation before returning a synchronous DNS error.

If NetResolverAbort invalidates a synchronous lookup while getaddrinfo is running, a failed DNS lookup reaches this branch. ResolverEndLookup ignores the stale generation, but the call still returns the DNS error instead of NET_ERROR_EINTR. Apply the generation check to failed lookups too, then end the lookup and return the resulting error. (raw.githubusercontent.com)

✅ Addressed in commit 74e1c9b

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 21:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#discussion_r4433421406) · edited 2026-10-31 22:14 UTC On `src/libs/network.cpp` line 1739 (outdated): ```diff @@ -1457,72 +1564,229 @@ int KYTY_SYSV_ABI NetResolverDestroy(int rid) { int KYTY_SYSV_ABI NetResolverAbort(int rid, int flags) { PRINT_NAME(); - LOGF("\t rid = %d\n\t flags = 0x%08x\n", rid, flags); + LOGF(" rid = %d\n flags = 0x%08x\n", rid, flags); + + const auto network = GetNetwork(); + EXIT_IF(network == nullptr); + if (!network->ResolverAbort(rid, flags)) { + return NET_ERROR_EBADF; + } + return OK; } -int KYTY_SYSV_ABI NetResolverStartNtoa(int rid, const char* hostname, void* addr, int timeout, - int retry, int flags) { - PRINT_NAME(); - - LOGF("\t rid = %d\n" - "\t hostname = %s\n" - "\t timeout = %d\n" - "\t retry = %d\n" - "\t flags = 0x%08x\n", - rid, hostname != nullptr ? hostname : "<null>", timeout, retry, flags); +struct ResolverOutput { + void* addr = nullptr; + NetResolverInfo* info = nullptr; +}; +static int ResolverStartNtoaInternal(int rid, const char* hostname, const ResolverOutput& output, + int timeout, int retry, int flags) { (void)timeout; (void)retry; - if (hostname == nullptr || addr == nullptr || (flags & ~0x00010000) != 0) { - return NET_ERROR_EINVAL; - } - - EXIT_IF(g_net == nullptr); - if (!g_net->ResolverValid(rid)) { + const auto network = GetNetwork(); + EXIT_IF(network == nullptr); + if (!network->ResolverValid(rid)) { return NET_ERROR_EBADF; } - if ((flags & 0x00010000) == 0 && NetInetPton(2, hostname, addr) == 1) { - return OK; + if (hostname == nullptr || (output.addr == nullptr && output.info == nullptr)) { + return NET_ERROR_EINVAL; } - if (!EnsureSocketBackend()) { - return NET_ERROR_ENETDOWN; + constexpr size_t ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX = 255; + const size_t host_len = std::strlen(hostname); + if (host_len == 0 || host_len > ORBIS_NET_RESOLVER_HOSTNAME_LEN_MAX) { + return NET_ERROR_EINVAL; } - addrinfo hints {}; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; + constexpr int ORBIS_NET_RESOLVER_ASYNC = 0x00000001; + constexpr int ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS = 0x00010000; + + const bool is_async = (flags & ORBIS_NET_RESOLVER_ASYNC) != 0; + const bool disable_ipaddress = (flags & ORBIS_NET_RESOLVER_START_NTOA_DISABLE_IPADDRESS) != 0; + + uint32_t generation = 0; + const int begin_ret = network->ResolverBeginLookup(rid, is_async, &generation); + if (begin_ret != 0) { + return begin_ret; + } - addrinfo* result = nullptr; - const int ret = getaddrinfo(hostname, nullptr, &hints, &result); - if (ret != 0 || result == nullptr) { - if (result != nullptr) { - freeaddrinfo(result); + auto do_lookup = [disable_ipaddress](const std::string& host_str, + std::vector<uint32_t>& out_addrs) -> int { + std::string host = host_str; + while (!host.empty() && host.back() == '.') { + host.pop_back(); } - if (ret == EAI_NONAME) { + if (host.empty()) { return NET_ERROR_RESOLVER_ENOHOST; } - if (ret == EAI_NODATA) { + + std::string lowered = host; + std::transform(lowered.begin(), lowered.end(), lowered.begin(), + [](unsigned char c) { return static_cast<char>(std::tolower(c)); }); + if (lowered == "localhost") { + out_addrs.push_back(htonl(0x7f000001)); + return OK; + } + + if (!disable_ipaddress) { + in_addr in {}; +#if defined(_WIN32) + if (::InetPtonA(AF_INET, host.c_str(), &in) == 1) { +#else + if (::inet_pton(AF_INET, host.c_str(), &in) == 1) { +#endif + uint32_t ip = 0; + std::memcpy(&ip, &in, sizeof(ip)); + out_addrs.push_back(ip); + return OK; + } + } + + if (!EnsureSocketBackend()) { + return NET_ERROR_RESOLVER_ENODNS; + } + + addrinfo hints {}; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + + addrinfo* result = nullptr; + const int ret = getaddrinfo(host.c_str(), nullptr, &hints, &result); + if (ret != 0 || result == nullptr) { + if (result != nullptr) { + freeaddrinfo(result); + } +#if defined(_WIN32) + if (ret == WSAHOST_NOT_FOUND || ret == WSANO_DATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } + if (ret == WSATRY_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == WSANO_RECOVERY) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } +#endif + if (ret == EAI_NONAME) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#ifdef EAI_NODATA + if (ret == EAI_NODATA) { + return NET_ERROR_RESOLVER_ENOHOST; + } +#endif + if (ret == EAI_AGAIN) { + return NET_ERROR_RESOLVER_ETIMEDOUT; + } + if (ret == EAI_FAIL) { + return NET_ERROR_RESOLVER_ESERVERFAILURE; + } + return NET_ERROR_RESOLVER_EINTERNAL; + } + + for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { + if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && + ai->ai_addrlen >= sizeof(sockaddr_in)) { + const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); + uint32_t ip = 0; + std::memcpy(&ip, &in->sin_addr, sizeof(ip)); + if (std::find(out_addrs.begin(), out_addrs.end(), ip) == out_addrs.end()) { + out_addrs.push_back(ip); + if (out_addrs.size() >= 10) { + break; + } + } + } + } + + freeaddrinfo(result); + + if (out_addrs.empty()) { return NET_ERROR_RESOLVER_ENORECORD; } - return NET_ERROR_RESOLVER_EINTERNAL; - } - for (auto* ai = result; ai != nullptr; ai = ai->ai_next) { - if (ai->ai_family == AF_INET && ai->ai_addr != nullptr && - ai->ai_addrlen >= sizeof(sockaddr_in)) { - const auto* in = reinterpret_cast<const sockaddr_in*>(ai->ai_addr); - std::memcpy(addr, &in->sin_addr, sizeof(in->sin_addr)); - freeaddrinfo(result); - return OK; + return OK; + }; + + auto deliver_result = [](const ResolverOutput& out, const std::vector<uint32_t>& addrs) { + if (out.info != nullptr) { + std::memset(out.info, 0, sizeof(NetResolverInfo)); + const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); + for (size_t i = 0; i < count; ++i) { + out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET + out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; + } + out.info->recordsv4 = count; + out.info->records = count; + } else if (out.addr != nullptr && !addrs.empty()) { + std::memcpy(out.addr, &addrs[0], sizeof(uint32_t)); + } + }; + + if (!is_async) { + std::vector<uint32_t> addrs; + const int res = do_lookup(hostname, addrs); + if (res == OK) { + const int deliver_res = network->ResolverDeliverResultSync(rid, generation, [&] { + deliver_result(output, addrs); + }); + network->ResolverEndLookup(rid, generation, deliver_res); + return deliver_res; + } + network->ResolverEndLookup(rid, generation, res); ``` <!-- 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** · **Functional Correctness** · **Quick win** **Check cancellation before returning a synchronous DNS error.** If `NetResolverAbort` invalidates a synchronous lookup while `getaddrinfo` is running, a failed DNS lookup reaches this branch. `ResolverEndLookup` ignores the stale generation, but the call still returns the DNS error instead of `NET_ERROR_EINTR`. Apply the generation check to failed lookups too, then end the lookup and return the resulting error. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/b086a5dbc86b287503e79d8efa8cd1b584f08271/src/libs/network.cpp)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:f00824cf3b4d3db1272723bc --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 74e1c9b
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-31 21:49 UTC · original · reviewed

Follow-up Comments

Outside diff Do not queue a second interrupt when aborting a running lookup.

356-359: Minor · Functional Correctness · Quick win

Do not queue a second interrupt when aborting a running lookup.

If NetResolverAbort runs during a lookup, it invalidates that lookup but also leaves abort_requested set. ResolverBeginLookup then returns NET_ERROR_EINTR for the next lookup. Queue an interrupt only when the resolver was idle; when it was running, invalidate that lookup without interrupting its replacement. This matches the stated distinction between aborting a running lookup and queueing an abort for the next lookup. (raw.githubusercontent.com)

Open the source location


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b39bda218d and b086a5dbc8.

Files selected for processing: 2
  • src/libs/network.cpp
  • tests/NetResolverTests.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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 21:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#pullrequestreview-5725066475) · **reviewed** <!-- coderabbit-ai-generated:v1 --> ## Follow-up Comments <details> <summary><sub><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/contrast-v2/outside-diff-dark.svg" /><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/outside-diff.svg" /><img width="120" height="16" alt="Outside diff" src="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/outside-diff.svg" /></picture></sub> Do not queue a second interrupt when aborting a running lookup.</summary><blockquote> <dl> <dd> `356-359`: **<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** · **Functional Correctness** · **Quick win** **Do not queue a second interrupt when aborting a running lookup.** If `NetResolverAbort` runs during a lookup, it invalidates that lookup but also leaves `abort_requested` set. `ResolverBeginLookup` then returns `NET_ERROR_EINTR` for the next lookup. Queue an interrupt only when the resolver was idle; when it was running, invalidate that lookup without interrupting its replacement. This matches the stated distinction between aborting a running lookup and queueing an abort for the next lookup. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/b086a5dbc86b287503e79d8efa8cd1b584f08271/src/libs/network.cpp)) <!-- cr-comment:v1:5062c9cf7e46e296ffc178bd --> [Open the source location](https://github.com/KytyPS5/KytyPS5/blob/b086a5dbc86b287503e79d8efa8cd1b584f08271/src/libs/network.cpp#L356-L359) </dd> </dl> </blockquote></details> --- <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/026189166f71cc1995f5851dee1ddad7d5826e99/.coderabbit.yaml>) - **Commit**: [0261891](<https://github.com/KytyPS5/KytyPS5/commit/026189166f71cc1995f5851dee1ddad7d5826e99>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f60a259b-4ed4-4b1c-83f7-b528e81008e0` </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 b39bda218d7cd248ab5165ab5d623e45faaf8a03 and b086a5dbc86b287503e79d8efa8cd1b584f08271. </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: 2</summary> <dl> <dd> * `src/libs/network.cpp` * `tests/NetResolverTests.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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=e7429e61-4f07-4221-8f86-8fddaf2703b0 attempt=a69c6318-0723-4d13-b779-984566de00cc batch=1/1 -->
Author
Owner

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

Follow-up Comments

Outside diff Publish the asynchronous result before the test reads it.

122-132: Minor · Stability & Availability · Quick win

Publish the asynchronous result before the test reads it.

async_info.records is read while the detached worker can clear and populate the same NetResolverInfo. The ordinary stores in deliver_result race with the test's reads, so the test has undefined behavior and can report flaky results. Publish records with release semantics after filling the structure, and load it with acquire semantics before checking addrs.

Suggested fix
diff --git a/src/libs/network.cpp b/src/libs/network.cpp
@@
 		if (out.info != nullptr) {
-			std::memset(out.info, 0, sizeof(NetResolverInfo));
+			std::atomic_ref<uint32_t> records(out.info->records);
+			records.store(0, std::memory_order_relaxed);
+			std::memset(reinterpret_cast<char*>(out.info) + sizeof(out.info->records), 0,
+			            sizeof(NetResolverInfo) - sizeof(out.info->records));
 			const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10));
 			for (size_t i = 0; i < count; ++i) {
 				out.info->addrs[i].af                 = 2; // ORBIS_NET_AF_INET
 				out.info->addrs[i].u.addr.inaddr_addr = addrs[i];
 			}
 			out.info->recordsv4 = count;
-			out.info->records   = count;
+			records.store(count, std::memory_order_release);
 		} else if (out.addr != nullptr && !addrs.empty()) {
diff --git a/tests/NetResolverTests.cpp b/tests/NetResolverTests.cpp
@@
 #include <chrono>
+#include <atomic>
 #include <cstdio>
@@
 	static Net::NetResolverInfo async_info;
+	std::atomic_ref<uint32_t> async_records(async_info.records);
 	std::memset(&async_info, 0, sizeof(async_info));
 	CHECK(fn(rid, "localhost", &async_info, 0, 0, 0x00000001) == 0);
 	// Wait a moment for background thread
-	for (int i = 0; i < 50 && async_info.records == 0; ++i) {
+	for (int i = 0; i < 50 && async_records.load(std::memory_order_acquire) == 0; ++i) {
 		std::this_thread::sleep_for(std::chrono::milliseconds(10));
 	}
-	CHECK(async_info.records == 1);
-	CHECK(async_info.addrs[0].u.addr.inaddr_addr == expected_loopback);
+	const uint32_t records = async_records.load(std::memory_order_acquire);
+	CHECK(records == 1);
+	if (records == 1) {
+		CHECK(async_info.addrs[0].u.addr.inaddr_addr == expected_loopback);
+	}

Open the source location


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b086a5dbc8 and 74e1c9b976.

Files selected for processing: 1
  • src/libs/network.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-31 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#pullrequestreview-5725248000) · **reviewed** <!-- coderabbit-ai-generated:v1 --> ## Follow-up Comments <details> <summary><sub><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/contrast-v2/outside-diff-dark.svg" /><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/outside-diff.svg" /><img width="120" height="16" alt="Outside diff" src="https://storage.googleapis.com/coderabbit_public_assets/review-finding-badges-v1/outside-diff.svg" /></picture></sub> Publish the asynchronous result before the test reads it.</summary><blockquote> <dl> <dd> `122-132`: **<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** **Publish the asynchronous result before the test reads it.** `async_info.records` is read while the detached worker can clear and populate the same `NetResolverInfo`. The ordinary stores in `deliver_result` race with the test's reads, so the test has undefined behavior and can report flaky results. Publish `records` with release semantics after filling the structure, and load it with acquire semantics before checking `addrs`. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff diff --git a/src/libs/network.cpp b/src/libs/network.cpp @@ if (out.info != nullptr) { - std::memset(out.info, 0, sizeof(NetResolverInfo)); + std::atomic_ref<uint32_t> records(out.info->records); + records.store(0, std::memory_order_relaxed); + std::memset(reinterpret_cast<char*>(out.info) + sizeof(out.info->records), 0, + sizeof(NetResolverInfo) - sizeof(out.info->records)); const uint32_t count = static_cast<uint32_t>(std::min<size_t>(addrs.size(), 10)); for (size_t i = 0; i < count; ++i) { out.info->addrs[i].af = 2; // ORBIS_NET_AF_INET out.info->addrs[i].u.addr.inaddr_addr = addrs[i]; } out.info->recordsv4 = count; - out.info->records = count; + records.store(count, std::memory_order_release); } else if (out.addr != nullptr && !addrs.empty()) { ``` ```diff diff --git a/tests/NetResolverTests.cpp b/tests/NetResolverTests.cpp @@ #include <chrono> +#include <atomic> #include <cstdio> @@ static Net::NetResolverInfo async_info; + std::atomic_ref<uint32_t> async_records(async_info.records); std::memset(&async_info, 0, sizeof(async_info)); CHECK(fn(rid, "localhost", &async_info, 0, 0, 0x00000001) == 0); // Wait a moment for background thread - for (int i = 0; i < 50 && async_info.records == 0; ++i) { + for (int i = 0; i < 50 && async_records.load(std::memory_order_acquire) == 0; ++i) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } - CHECK(async_info.records == 1); - CHECK(async_info.addrs[0].u.addr.inaddr_addr == expected_loopback); + const uint32_t records = async_records.load(std::memory_order_acquire); + CHECK(records == 1); + if (records == 1) { + CHECK(async_info.addrs[0].u.addr.inaddr_addr == expected_loopback); + } ``` </dd> </dl> </details> <!-- cr-comment:v1:90404093acb78c992d6789d2 --> [Open the source location](https://github.com/KytyPS5/KytyPS5/blob/74e1c9b976a1007f46b2cf65f3267de09d727374/tests/NetResolverTests.cpp#L122-L132) </dd> </dl> </blockquote></details> --- <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/026189166f71cc1995f5851dee1ddad7d5826e99/.coderabbit.yaml>) - **Commit**: [0261891](<https://github.com/KytyPS5/KytyPS5/commit/026189166f71cc1995f5851dee1ddad7d5826e99>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `a957bf2b-f7cd-451b-aa98-def517025b99` </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 b086a5dbc86b287503e79d8efa8cd1b584f08271 and 74e1c9b976a1007f46b2cf65f3267de09d727374. </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/network.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=deb27a3e-d064-4449-98c4-a5763e6589ad attempt=7c3cd922-8385-4aef-89ee-8108e515770b batch=1/1 -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-31 23:34 UTC · original

Credited

**@⁠Nmzik** on GitHub · 2026-10-31 23:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2027#issuecomment-6550642047) Credited

Pull request closed

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