136 Commits
Author SHA1 Message Date
Dean 750cf6cf48 Merge pull request #11595 from alvaroelpob/fix/libkernel-sys-linkat-symlink-itself
fix(libkernel_sys): link a symbolic link itself in linkat without AT_SYMLINK_FOLLOW
2026-10-29 01:32:29 +13:00
Dean ba8990161b Merge pull request #12077 from JJenkx/windows/kernel-sys-link-cleanup
test(libkernel): remove test symbolic links with guest unlink on Windows
2026-10-28 22:46:24 +13:00
Adrià 241649ed7e Merge pull request #11296 from tablefrogpillow/fix/fpathconf-kqueue-shm-eopnotsupp
fix(libkernel_sys): fail fpathconf on a kqueue or shm descriptor with EOPNOTSUPP
2026-10-28 09:41:16 +01:00
Adrià d7fd416992 Merge pull request #11231 from Gruzzberry/feat/kldsym
feat(libkernel_sys): implement kldsym argument checks
2026-10-28 08:56:23 +01:00
tablefrogpillowandClaude Opus 4.8 90d0daedc9 test(libkernel_sys): use a named shm descriptor in the fpathconf check
An anonymous shm descriptor is recognised as shared memory only on
Linux, where the memfd link name is matched; on Windows the anonymous
%TEMP% object is not registered in the shared-descriptor table, so the
descriptor is not recognised and fpathconf never reaches the EOPNOTSUPP
branch. A named descriptor is recognised on both platforms, so the
check now opens a named object and unlinks it, keeping the same branch
coverage without a Linux-only assumption.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-10-28 08:43:15 +01:00
tablefrogpillowandClaude Opus 4.8 d8dfb7eab4 fix(libkernel_sys): fail fpathconf on a kqueue or shm descriptor with EOPNOTSUPP
_fpathconf_nid_postfix only treated FIFOs and sockets as descriptors without
a vnode, so a kqueue or shm_open descriptor fell through to the UFS constants
(LINK_MAX 32767, NAME_MAX 255, PIPE_BUF 512). FreeBSD 11.4 kern_fpathconf
(kern_descrip.c:1411-1429) answers _PC_ASYNC_IO for every descriptor and
returns EOPNOTSUPP for a no-vnode descriptor that is not a pipe or socket.
Return EOPNOTSUPP for kqueue and shared-memory descriptors.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-10-28 08:43:15 +01:00
GruzzberryandClaude Sonnet 5.5 762a280ee3 feat(libkernel_sys): implement kenv
Follow FreeBSD 11.4 sys_kenv: KENV_GET, KENV_SET, KENV_UNSET and KENV_DUMP over
an in-memory kernel environment of at most 512 variables, with the 128-byte
name and value limits, ENOENT, EINVAL, ENAMETOOLONG and EFAULT.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-28 07:50:01 +01:00
Dean ba8845d2e7 Merge pull request #9442 from Gruzzberry/feat/lchflags
feat(libkernel_sys): implement lchflags
2026-10-28 13:00:19 +13:00
JJenkxandClaude Opus 5.5 6135955c52 test(libkernel_sys): remove the test's symbolic links with guest unlink
With symbolic links allowed on Windows, guest_kernel_sys failed at its
cleanup: MinGW's std::filesystem::remove reads links through stat, so a
dangling link looks absent and is left in place, and the check expecting
true fails. The two links are now removed with unlink_nid_postfix, which
also checks that guest unlink removes a live and a dangling link.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 15:21:51 -04:00
Adrià eece5da035 Merge pull request #10838 from EagleBearerYS/feat/libkernel-sys-finish-calls-v2
feat(libkernel_sys): finish sched_setscheduler and sigreturn
2026-10-27 13:20:31 +01:00
Alvaro 58f12f318c test(libkernel_sys): drop the Windows linkat symbolic link throw assertion
The Windows branch only pinned that linkat throws for a symbolic link
without AT_SYMLINK_FOLLOW, an unsupported path. The POSIX checks of the
real behaviour and the argument and error checks stay.
2026-10-27 12:24:00 +01:00
Dean 7f02cb1802 Merge pull request #11402 from 00xDisaster/fix/libkernel-settime-efault
fix(libkernel): check settimeofday and clock_settime pointers
2026-10-27 21:25:30 +13:00
Adrià 13926067ac Merge pull request #11026 from Gruzzberry/feat/profil
feat(libkernel_sys): implement profil argument checks
2026-10-27 08:18:36 +01:00
GruzzberryandClaude Sonnet 5.5 6b6ec00fad feat(libkernel_sys): implement kldsym argument checks
Follow FreeBSD 11.4's sys_kldsym: EFAULT for an unreadable lookup
structure, EINVAL for a wrong version or command, EFAULT or
ENAMETOOLONG for the symbol name, ENOENT for a negative file id. Any
other lookup throws, as no kernel module is modelled. Adds
GuestCopyIn_nid_no_patch for the checked structure read.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 08:01:39 +01:00
Adrià FranchandClaude Sonnet 5.5 fb1474f032 test(libkernel_sys): drop assertions that valid sched_setscheduler and sigreturn calls throw
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 06:14:13 +01:00
Yunus Shaikh fb3841479b fix(libkernel_sys): keep the owner check of chown, lchown and fchownat unmodelled
oneandonlydean's review of #8457 settled that the guest is modelled as
root, and FreeBSD 11's root keeps the privilege to change a file's
owner, so EPERM for another owner has no source until a console
measurement shows it. chown, lchown and fchownat go back to
RequireGuestOwner after the path lookup, as fchown does, and their debt
entry is main's again. The EPERM assertions go without throw assertions
in their place; the lookup error checks stay.
2026-10-27 06:14:13 +01:00
Yunus Shaikh 8f007d234a feat(libkernel_sys): implement sigreturn
sigreturn applies FreeBSD 11's amd64 sys_sigreturn checks:
- EFAULT for a null context;
- EINVAL for unknown mc_flags, and for rflags bits outside
  PSL_USERCHANGE that differ from the current flags;
- set_fpcontext's FPU format and ownership cases.
It then restores the context through the path setcontext uses, which
now lives in RestoreContext. A non-user %cs and an extended FPU state
still throw.
2026-10-27 06:14:13 +01:00
Yunus Shaikh 51849e7e41 feat(libkernel_sys): implement sched_setscheduler for the calling thread
FreeBSD 11's sys_sched_setscheduler checks: a null parameter is EFAULT,
another process is ESRCH and an unknown policy is EINVAL. Pid 0 sets the
calling thread through scePthreadSetschedparam. Values that call
rejects, and the guest's own pid, whose first thread is not tracked,
still throw.
2026-10-27 06:14:13 +01:00
Yunus Shaikh 788a87cb8e feat(libkernel_sys): fail chown, lchown and fchownat with EPERM for another owner
An owner or group other than the guest's (0) or the unchanged value
returns EPERM after the path lookup, as FreeBSD 11's chown(2) does for
a caller without the superuser privilege. That is the answer #8457
gives for fchown. A lookup error still comes first.
2026-10-27 06:14:13 +01:00
Dean 1075c38f07 Merge pull request #10799 from EagleBearerYS/feat/libkernel-sys-ampr-command-writers
feat(libkernel_sys): write the AMM commands and wait for their completion
2026-10-27 15:00:11 +13:00
Dean Galvin f733f7dc43 Merge branch 'main' into feat/lchflags 2026-10-27 11:58:22 +13:00
Alvaro 3507a7ae46 test(libkernel_sys): check that linkat links a symbolic link itself without AT_SYMLINK_FOLLOW
On Linux and macOS, linkat with flag 0 gives a symbolic link, a dangling
one and one naming a directory a second name: the new name reads the same
target, the link's own count is 2 and the target's is unchanged. With
AT_SYMLINK_FOLLOW the dangling link fails with ENOENT and the directory
link with EPERM. A taken destination fails with EEXIST, a missing parent
with ENOENT and a file parent with ENOTDIR. Windows still throws.
2026-10-26 23:08:33 +01:00
Dean e6b0b00261 Merge pull request #11268 from camezaro-intc/feat/libkernel-sys-kld-queries
feat(libkernel_sys): implement kldfind, kldfirstmod, kldnext and kldunload
2026-10-27 11:06:13 +13:00
Dean 26bbcd1b48 Merge pull request #11288 from Gruzzberry/fix/fchmodat-follow-links
fix(libkernel_sys): fchmodat follows a symbolic link like chmod
2026-10-27 10:40:54 +13:00
Dean fd75cc804d Merge pull request #9095 from mazen320/fix/unlinkat-windows-junction
fix(libkernel): treat Windows junctions in unlinkat like unlink and rmdir
2026-10-27 10:29:02 +13:00
Adrià 071552ef7f Merge pull request #10196 from orezraey/fix/libkernel-sys-pathconf-measured-ps5
fix(libkernel_sys): answer every pathconf name as the console's UFS mount does
2026-10-26 16:58:02 +01:00
Disaster 78571ca2fb fix(libkernel): check settimeofday and clock_settime pointers
Both read their caller's structures in place before validation, so an unreadable pointer crashed the host. Copy them in with a checked read first and return EFAULT, as FreeBSD 11.4 does.

Fixes #11370
2026-10-26 14:29:02 +03:00
camezaro-intc d4200caffc feat(libkernel_sys): implement kldfind, kldfirstmod, kldnext and kldunload 2026-10-25 23:58:13 -06:00
vaibhavindalia a385eee97c fix(libkernel_sys): validate descriptor first in fchown 2026-10-26 06:34:33 +05:30
Dean 10126f0c64 Merge pull request #9374 from cadenasynyster/test/windows-symlink-tests
test(libkernel): create the readlink and lutimes test links with CreateSymbolicLinkW on Windows
2026-10-26 13:30:41 +13:00
GruzzberryandClaude Sonnet 5.5 7322a3b9f8 fix(libkernel_sys): fchmodat follows a symbolic link like chmod
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-25 23:50:43 +00:00
GruzzberryandClaude Opus 5.5 33299ee554 feat(libkernel_sys): implement lchflags
lchflags is chflags without following a symbolic link in the last path
component, as FreeBSD 11.4's sys_lchflags calls kern_chflagsat with
AT_SYMLINK_NOFOLLOW. chflags now goes through a shared helper that takes
the follow choice; a link in the last component is accepted as the
target when not following, and the flag checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 22:14:40 +00:00
Maz 33f03f45eb fix(libkernel): guard unlinkat junction path with DIRECTORY
Match the AT_REMOVEDIR and rmdir sites so file reparse points stay on the old unlink path. Cover file symlink unlinkat on Windows and point the debt at the drive-target consumers.
2026-10-26 00:02:20 +04:00
Maz de84153592 fix(libkernel): treat Windows junctions in unlinkat like unlink and rmdir
Relative unlinkat skipped the junction path that absolute unlink and rmdir already use.
2026-10-26 00:02:20 +04:00
GruzzberryandClaude Opus 5.5 69ead78b5e feat(libkernel_sys): implement profil argument checks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 18:07:30 +00:00
GruzzberryandClaude Opus 5.5 e6b07323de feat(libkernel_sys): implement settimeofday
FreeBSD 11.4's kern_settimeofday rejects a timeval with a microsecond
field outside 0 to 999999 or a negative second field with EINVAL before
changing anything, sets the clock from a valid timeval, and then stores
the timezone, which gettimeofday reports. settimeofday now checks the
timeval the same way and throws for a valid one, as clock_settime does,
because the host clock is not changed. A timezone given without a
timeval is stored and gettimeofday reports it instead of 0 and 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 13:20:31 +00:00
ali zedan 2c5fcf6406 fix(kernel): safely copy guest path arguments 2026-10-25 08:28:09 +01:00
Dean 61fc572cee Merge pull request #10434 from Retr0G28/fix/linkat-directory-descriptor
fix(libkernel_sys): resolve linkat paths relative to a directory descriptor
2026-10-25 19:16:10 +13:00
Yunus Shaikh a666c83d20 fix(libkernel): accept every AMM id the queue has handed out in the completion wait
AmmSubmit_nid_no_patch stored the id _submit returned into lastSubmit
after _submit had released the queue's submit lock. Two submitters could
store out of order: the later id was stored first, then the earlier one
overwrote it, and a wait for the later, already submitted id failed with
ESRCH until the next submission.

The wait now checks the id against the AMM queue's own submitted count,
which _submit raises under the queue mutex before it returns, and
lastSubmit goes.

The test has four threads submit empty AMM buffers while another waits
on the newest id any of them has published, through
sceKernelWaitCommandBufferCompletion and
sceAmprAmmWaitCommandBufferCompletion, and requires every wait to
succeed.
2026-10-24 21:15:55 -07:00
Yunus Shaikh fe9d31edae test(libkernel_sys): pin the AMM writers' narrowing of a wide type
The map, map direct and mtype-protect writers take type as a 64-bit
value and store it in the record's 32-bit field. That matches
sceKernelWriteModifyMtypeProtectCommand and the libSceAmpr siblings,
whose type is 32 bits, but nothing checked it. A type with bit 32 set
now has to record the same bytes as the sibling given the low 32 bits,
and the debt entry says the console's handling of such a type is not
measured.
2026-10-24 19:49:48 -07:00
Yunus Shaikh afd5c4a20e feat(libkernel_sys): wait for AMM command buffer completion
sceKernelWaitCommandBufferCompletion waits for an AMM submission as
libSceAmpr's sceAmprAmmWaitCommandBufferCompletion does: 0 once the
submission has run, SCE_KERNEL_ERROR_ESRCH for an id that was never
submitted. The signature follows ampr_emu's libkernel hook targets,
where the libSceAmpr wait forwards to it.

guest_kernel_sys submits a map written by sceKernelWriteMapCommand,
waits for it and uses the mapped page, and checks ids 0 and past the
last submission.
2026-10-25 00:09:03 +00:00
Yunus Shaikh 92f7271cc6 feat(libkernel_sys): write the AMM map, unmap, remap and protection commands
The twelve AMM kernel writers record into a caller buffer the command
their libSceAmpr command buffer sibling appends, built with the shared
encoder: sceKernelWriteMapCommand, sceKernelWriteMapWithGpuMaskIdCommand,
sceKernelWriteMapDirectCommand, sceKernelWriteMapDirectWithGpuMaskIdCommand,
sceKernelWriteUnmapCommand, sceKernelWriteRemapCommand,
sceKernelWriteRemapWithGpuMaskIdCommand, sceKernelWriteMultiMapCommand,
sceKernelWriteMultiMapWithGpuMaskIdCommand,
sceKernelWriteModifyProtectCommand,
sceKernelWriteModifyProtectWithGpuMaskIdCommand and
sceKernelWriteModifyMtypeProtectWithGpuMaskIdCommand.

The signatures follow ampr_emu's libkernel hook targets: the sibling's
arguments as 64-bit values between the destination and the size output.
A null destination only reports the size and a null size output only
writes, as for sceKernelWriteModifyMtypeProtectCommand. Invalid ranges,
offsets and protections return the sibling's SCE_KERNEL_ERROR_EINVAL and
write nothing; protection or mask bits above 32 are rejected too.

guest_kernel_sys compares each writer with its sibling on valid and
invalid arguments, in both modes.
2026-10-25 00:07:53 +00:00
orezraeyandClaude Opus 5.5 88bf509e20 Merge main into fix/libkernel-sys-pathconf-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 20:04:44 -03:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Retr0 2d32e8bd85 fix(libkernel_sys): check the linkat source before resolving the target 2026-10-24 16:00:43 +03:00
Dean Galvin b0b291be0b Merge main into feat/libkernel-sys-underscore-openat 2026-10-24 21:42:59 +13:00
Dean dd04e33b38 Merge pull request #10363 from cadenasynyster/fix/windows-mkdirat-loop
fix(libkernel_sys): report ELOOP from mkdirat through a Windows symli…
2026-10-24 16:36:38 +13:00
Retr0 d44d5685eb fix(libkernel_sys): resolve linkat paths relative to a directory descriptor 2026-10-24 02:58:00 +03:00
Dean c675a415f2 Merge pull request #9103 from HQasper/claude/project-thread-w0s18y-chown
feat(libkernel_sys): implement chown, lchown, fchownat and linkat
2026-10-24 11:56:40 +13:00
orezraeyandClaude Opus 5.5 f32fd62397 Merge main into fix/libkernel-sys-pathconf-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 17:14:25 -03:00