fix(libkernel): set and read SO_LINGER in seconds on macOS #19488

Merged
imellag merged 1 commit from upstream-pr/19488 into main 2026-11-13 14:51:35 +00:00
imellag commented 2026-11-13 12:13:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-11-13T12:13:50Z.


What

On macOS a guest SO_LINGER time was passed to the host's SO_LINGER, which XNU counts in 1/100 s, not in seconds as FreeBSD does. A title that asked to linger 5 seconds on close got 50 ms. XNU also keeps the time in a short, so above 32767 (ticks) the set failed with EDOM, which is why guest_sce_net_linger fails on macOS at the 65535 s case.

Measured on macOS 27.2 (x86-64 under Rosetta 2) with a small native program:

set value SO_LINGER reads SO_LINGER_SEC reads
SO_LINGER 5 5 0
SO_LINGER_SEC 5 500 5
SO_LINGER_SEC 327 32700 327
SO_LINGER_SEC 328 EDOM
SO_LINGER 32768 / 65535 EDOM

Changes:

  • On macOS, setsockopt and getsockopt of SO_LINGER (and sceNetSetsockopt/sceNetGetsockopt, which share the code) use SO_LINGER_SEC, which is in seconds. Linux and Windows are unchanged.
  • A time above 327 seconds cannot be held by macOS at all. It now goes through NotImplemented_nid_no_patch instead of setting a shorter time or failing with an error FreeBSD does not give. The existing checks are unchanged: a negative time or one above 65535 still fails with EDOM, a short value with EINVAL.
  • guest_sce_net_linger reads the native value with SO_LINGER_SEC on macOS, checks 327 s there, and checks that 65535 s throws; elsewhere it is unchanged.
  • New debt entry "SO_LINGER on macOS" in libkernel.md.

Tested

macOS 27.2, Apple M4 Pro, x86-64 build under Rosetta 2, main d4556df8a8:

  • guest_sce_net_linger: main fails (check failed at line 83, the 65535 s set); this PR passes.
  • guest_socket_options (its LingerFollowsFreeBsd sets 5 s and reads it back): on main and on this PR alone it stops earlier, at the refused reconnect that #17879 fixes. With #17879 applied on top of this PR it passes in full.
  • guest_ssl_transport_kernel, guest_ssl_transport_net, guest_http2_transport, guest_socket_options_multicast: pass.

Not run on Linux or Windows; their code paths are unchanged.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5295271339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19488). Originally posted by [imellag](https://github.com/imellag) on 2026-11-13T12:13:50Z. --- ### What On macOS a guest `SO_LINGER` time was passed to the host's `SO_LINGER`, which XNU counts in 1/100 s, not in seconds as FreeBSD does. A title that asked to linger 5 seconds on close got 50 ms. XNU also keeps the time in a `short`, so above 32767 (ticks) the set failed with `EDOM`, which is why `guest_sce_net_linger` fails on macOS at the 65535 s case. Measured on macOS 27.2 (x86-64 under Rosetta 2) with a small native program: | set | value | `SO_LINGER` reads | `SO_LINGER_SEC` reads | |---|---|---|---| | `SO_LINGER` | 5 | 5 | 0 | | `SO_LINGER_SEC` | 5 | 500 | 5 | | `SO_LINGER_SEC` | 327 | 32700 | 327 | | `SO_LINGER_SEC` | 328 | `EDOM` | | | `SO_LINGER` | 32768 / 65535 | `EDOM` | | Changes: - On macOS, `setsockopt` and `getsockopt` of `SO_LINGER` (and `sceNetSetsockopt`/`sceNetGetsockopt`, which share the code) use `SO_LINGER_SEC`, which is in seconds. Linux and Windows are unchanged. - A time above 327 seconds cannot be held by macOS at all. It now goes through `NotImplemented_nid_no_patch` instead of setting a shorter time or failing with an error FreeBSD does not give. The existing checks are unchanged: a negative time or one above 65535 still fails with `EDOM`, a short value with `EINVAL`. - `guest_sce_net_linger` reads the native value with `SO_LINGER_SEC` on macOS, checks 327 s there, and checks that 65535 s throws; elsewhere it is unchanged. - New debt entry "SO_LINGER on macOS" in `libkernel.md`. ### Tested macOS 27.2, Apple M4 Pro, x86-64 build under Rosetta 2, `main` d4556df8a8: - `guest_sce_net_linger`: `main` fails (`check failed at line 83`, the 65535 s set); this PR passes. - `guest_socket_options` (its `LingerFollowsFreeBsd` sets 5 s and reads it back): on `main` and on this PR alone it stops earlier, at the refused reconnect that #17879 fixes. With #17879 applied on top of this PR it passes in full. - `guest_ssl_transport_kernel`, `guest_ssl_transport_net`, `guest_http2_transport`, `guest_socket_options_multicast`: pass. Not run on Linux or Windows; their code paths are unchanged. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19488
No description provided.