Files
AnyPS5/docs/dev/debt/changes/fix-libkernel-socket-status-flags.md

5.4 KiB

libkernel

change a socket keeps the libSceNet path

  • fcntl (libkernel) follows FreeBSD 11.4's kern_fcntl and kern_dup on file, directory, pipe and character device descriptors; a socket keeps the libSceNet path (F_DUPFD, F_DUP2FD, F_DUP2FD_CLOEXEC, F_GETFL, F_SETFL, F_GETFD and F_SETFD, EINVAL for every other command, see the next entry). On Linux and macOS a host socket that is not a guest socket, such as a standard descriptor a service manager connected to its journal, takes the flag handling of a pipe end and FIONREAD asks the host for its queued bytes (for a datagram socket Linux counts only the next datagram, where FreeBSD's soo_ioctl counts every buffered byte); its record locks and read-ahead hints fail with EBADF, as FreeBSD fails them on a descriptor without a vnode, and O_ASYNC on it throws. The close-on-exec flag and the status flags live in a guest table, the status flags shared by dup, dup2 and F_DUPFD as in an open file description; a descriptor the table has not seen, such as 0 to 2, starts from the host's flags, since the console's are not known. F_DUPFD returns the lowest free host descriptor at or above the start, so the bound is the host table (EMFILE on Windows, EINVAL past RLIMIT_NOFILE on Linux), not the console's unknown RLIMIT_NOFILE and kern.maxfilesperproc. O_NONBLOCK switches a host pipe (PIPE_NOWAIT on Windows, where an empty read and a full write then report EAGAIN) and is only recorded on files, directories and the random device, as their reads never block; on a Windows console or other character device it throws. O_ASYNC on a pipe or character device (SIGIO is not delivered) and F_SETLK_REMOTE throw; F_GETOWN and F_SETOWN on a pipe store and return the owner, shared by dup, dup2 and F_DUPFD like the status flags, as a payload process on a PS5 (firmware 11.60) did (0, the pid set, 0 after setting 0) and signal nothing, and on any other descriptor they throw; O_FSYNC set by open or F_SETFL makes each write, pwrite, writev and pwritev on a file sync it before returning, as vn_write adds IO_SYNC; the sceKernelAioSubmitWriteCommands writes are not synced, as whether the console's AIO honours the flag is unknown; on Linux a file opened with it keeps the host O_SYNC after F_SETFL clears it. O_DIRECT, F_RDAHEAD and F_READAHEAD are recorded as the hints they are. Record locks (F_GETLK, F_SETLK, F_SETLKW and their forms without l_sysid) use the host's POSIX locks on Linux and macOS. F_GETLK with F_UNLCK asks the host with F_RDLCK: as in lf_blocks only another owner's overlapping write lock conflicts with either request. On Windows they follow kern_fcntl and lf_advlockasync for the one guest process, which owns every lock: EOVERFLOW for an SEEK_CUR start past OFF_MAX, then EBADF for F_RDLCK without read access or F_WRLCK without write access and EINVAL for another type, then EINVAL and EOVERFLOW for the range; as lf_blocks never lets locks of one owner conflict, whichever descriptor or thread asks, F_SETLK and F_SETLKW then succeed without waiting and F_GETLK reports F_UNLCK, so no lock list is kept and merging, splitting and the release on close have nothing to change. Nothing is held on the host, since Windows byte-range locks are mandatory and would fail the guest's own reads and writes through other descriptors, so other host processes neither see these locks nor are seen; a lock from the end of a directory throws. The return values and error codes are unverified on a console

add Functional

  • F_SETFL on a socket (libkernel) - O_NOFOLLOW fails with EOPNOTSUPP and changes nothing, though FreeBSD 11.4 keeps it as FPOSIXSHM in a kernel built with COMPAT_FREEBSD4 to COMPAT_FREEBSD7 (amd64 GENERIC has them) and ignores it otherwise; the console's options are unknown, and nothing here was measured on a console. On a guest socket or a libSceNet socket, F_SETFL keeps O_APPEND, O_ASYNC, O_FSYNC, O_DIRECT and the read-ahead bit besides O_NONBLOCK, ignores other bits and F_GETFL reports them, as in kern_fcntl; dup shares them and accept copies them. They change nothing: O_ASYNC raises SIGIO only for an owner (sowakeup), and no socket here can get one