feat(libkernel): implement sceKernelFcntl #1108

Closed
nicolasabosch wants to merge 1 commit from upstream-pr/1108 into main
nicolasabosch commented 2026-10-07 12:33:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-07T12:33:43Z.


What

sceKernelFcntl was a throwing stub; PPSA14632 (LEGO Horizon Adventures) imports it. This implements it with the (fd, cmd, arg) signature, command numbers and flag masks of FreeBSD 11 fcntl.h and kern_fcntl in kern_descrip.c.

  • Descriptors opened through sceKernelOpen and open: F_GETFD, F_SETFD, F_GETFL, F_SETFL. The status flags open keeps (FMASK) and O_CLOEXEC are recorded beside the host descriptor at open and forgotten at close, since the Windows CRT cannot report them for a descriptor.
  • F_SETFL replaces the FCNTLFLAGS bits like kern_fcntl and ignores the rest. Only O_NONBLOCK and O_DIRECT may change, as they do nothing to a regular host file; a change of O_APPEND, O_ASYNC, O_FSYNC or the read-ahead flag throws, because the open host file cannot follow it.
  • Socket descriptors take the existing fcntl path (F_GETFL, F_SETFL) and its errno is returned as an SCE error.
  • Pipes, the standard streams, closed descriptors and every other command (duplication, locks, owner) throw. This is recorded in TechnicalDebt.

Which commands the title passes is not known: it imports the function, and I have no log of a call. POSIX fcntl is unchanged and still handles sockets only; Socket/src/Udp.cpp is left alone because #1088 and #1091 change it.

Tested

Windows 11, WinLibs GCC 15.2.0: full build, libs target and ctest (384 passed; agc_driver_sdwa_float_selectors, shader_clock, vop1_float_unary, vop3_mad_i64 and vopc_compare excluded, they fail on this machine's Intel Arc GPU without this change). New guest_fcntl test covers files, O_CLOEXEC, POSIX open/close, a directory, a pipe and a UDP socket. Not tested on Linux and not tested with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4772678354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1108). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-07T12:33:43Z. --- ### What `sceKernelFcntl` was a throwing stub; PPSA14632 (LEGO Horizon Adventures) imports it. This implements it with the `(fd, cmd, arg)` signature, command numbers and flag masks of FreeBSD 11 [`fcntl.h`](https://github.com/freebsd/freebsd-src/blob/stable/11/sys/sys/fcntl.h) and `kern_fcntl` in [`kern_descrip.c`](https://github.com/freebsd/freebsd-src/blob/stable/11/sys/kern/kern_descrip.c). - Descriptors opened through `sceKernelOpen` and `open`: `F_GETFD`, `F_SETFD`, `F_GETFL`, `F_SETFL`. The status flags `open` keeps (`FMASK`) and `O_CLOEXEC` are recorded beside the host descriptor at open and forgotten at close, since the Windows CRT cannot report them for a descriptor. - `F_SETFL` replaces the `FCNTLFLAGS` bits like `kern_fcntl` and ignores the rest. Only `O_NONBLOCK` and `O_DIRECT` may change, as they do nothing to a regular host file; a change of `O_APPEND`, `O_ASYNC`, `O_FSYNC` or the read-ahead flag throws, because the open host file cannot follow it. - Socket descriptors take the existing `fcntl` path (`F_GETFL`, `F_SETFL`) and its errno is returned as an SCE error. - Pipes, the standard streams, closed descriptors and every other command (duplication, locks, owner) throw. This is recorded in TechnicalDebt. Which commands the title passes is not known: it imports the function, and I have no log of a call. POSIX `fcntl` is unchanged and still handles sockets only; `Socket/src/Udp.cpp` is left alone because #1088 and #1091 change it. ### Tested Windows 11, WinLibs GCC 15.2.0: full build, `libs` target and `ctest` (384 passed; `agc_driver_sdwa_float_selectors`, `shader_clock`, `vop1_float_unary`, `vop3_mad_i64` and `vopc_compare` excluded, they fail on this machine's Intel Arc GPU without this change). New `guest_fcntl` test covers files, `O_CLOEXEC`, POSIX `open`/`close`, a directory, a pipe and a UDP socket. Not tested on Linux and not tested with a title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-07 12:34:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T12:34:17Z.


Progress report (62ffd1e → c6ebb64)

📈 System libraries: 86.64% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sceKernelFcntl
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038003360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1108#issuecomment-6038003360). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T12:34:17Z. --- <!-- progress-report --> ### Progress report (62ffd1e → c6ebb64) 📈 **System libraries**: 86.64% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelFcntl` | </details>
github-actions[bot] commented 2026-10-07 12:35:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T12:35:07Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1093 core/libs/prx/libkernel/File/src/Open.cpp L118
#1128 __error_nid_postfix
#1205 docs/dev/TechnicalDebt.md L101
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6038017882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1108#issuecomment-6038017882). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T12:35:07Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1093 | `core/libs/prx/libkernel/File/src/Open.cpp` [L118](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/core/libs/prx/libkernel/File/src/Open.cpp#L118) | | | | #1128 | | `__error_nid_postfix` | | | #1205 | `docs/dev/TechnicalDebt.md` [L101](https://github.com/boykopovar/AnyPS5/blob/df16c4c256be3c44e03eb9149a6ce5f8e8a038b2/docs/dev/TechnicalDebt.md#L101) | | |
oneandonlydean commented 2026-10-08 03:25:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:25:44Z.


Does PPSA14632 call sceKernelFcntl on main? Main already exports a throwing stub, so the import alone doesn't stop it. With the log line where it stops at this call (and the command it passes) this can go in; otherwise I'll close it until a title does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051539137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1108#issuecomment-6051539137). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T03:25:44Z. --- Does PPSA14632 call `sceKernelFcntl` on main? Main already exports a throwing stub, so the import alone doesn't stop it. With the log line where it stops at this call (and the command it passes) this can go in; otherwise I'll close it until a title does.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1108
No description provided.