Skip to content

feat(libkernel): implement sceKernelFcntl - #1108

Closed
nicolasabosch wants to merge 1 commit into
boykopovar:mainfrom
nicolasabosch:feat/kernel-fcntl
Closed

nicolasabosch wants to merge 1 commit into
boykopovar:mainfrom
nicolasabosch:feat/kernel-fcntl

Conversation

@nicolasabosch

Copy link
Copy Markdown
Contributor

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

PPSA14632 imports sceKernelFcntl, which was a throwing stub. The
signature, command numbers and flag masks follow FreeBSD 11 fcntl.h
and kern_fcntl.

F_GETFD, F_SETFD, F_GETFL and F_SETFL work on descriptors opened
through sceKernelOpen and open: the status and descriptor flags are
recorded at open and forgotten at close. F_SETFL changes O_NONBLOCK and
O_DIRECT only; a change that the open host file cannot follow throws.
Socket descriptors take the existing fcntl path and return its errno as
an SCE error. Other descriptors and commands throw.
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Progress report (62ffd1e → c6ebb64)

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

✅ 1 implemented
Library Name
libkernel sceKernelFcntl

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants