Commit Graph
2434 Commits
Author SHA1 Message Date
Dean Galvin 97f1d41a2c Revert "Merge pull request #10809 from frankea/fix/direct-memory-12gib"
This reverts commit 780b33aea3, restoring the 13824 MiB direct memory pool.

With the pool at 12288 MiB, Astro Bot (PPSA21564) can no longer load its
level: DirectMemoryAllocator asserts "Can't allocate direct memory" for a
64 MB VideoPlayerTexture with 12228 of 12288 MB in use, then the process
faults about 26 s in (2 of 2 runs, RTX 4090, Linux, main cccdaa2734).
The same tree with only this merge reverted runs the full 150 s with no
direct memory assert (2 of 2 runs).
2026-10-28 15:45:26 +13:00
Adrià b5873b4ce4 Merge pull request #11594 from milescoviello/test/read-tsc
test(libkernel): cover sceKernelReadTsc's rate against sceKernelGetTscFrequency
2026-10-28 03:35:23 +01:00
Dean 780b33aea3 Merge pull request #10809 from frankea/fix/direct-memory-12gib
fix(libkernel): report 12 GiB of direct memory, as a PS5 does
2026-10-28 13:49:57 +13:00
Dean b3b449cfe4 Merge pull request #8916 from Henryisdjfunkyho/fix/cancellable-timed-sleeps
fix(libkernel): wake timed sleeps for thread cancellation
2026-10-28 13:48:32 +13:00
Dean 1068cd6b76 Merge pull request #7780 from savvaniss/fix/savedata-ps4-modules
fix(savedata): build libSceSaveData and libSceSaveDataDialog from the native sources
2026-10-28 13:48:05 +13:00
Dean e778405b5b Merge pull request #11592 from alvaroelpob/fix/libkernel-condattr-getclock-einval
fix(libkernel): fail pthread_condattr_getclock with EINVAL for a null attribute
2026-10-28 13:04:04 +13:00
Dean a6816811f3 Merge pull request #10975 from xXPBSXx/fix/gettimeofday-itimer-efault
fix(libkernel): fail gettimeofday, getitimer, setitimer and the sceKernel time getters with EFAULT on an unusable pointer
2026-10-28 13:02:14 +13:00
Dean ba8845d2e7 Merge pull request #9442 from Gruzzberry/feat/lchflags
feat(libkernel_sys): implement lchflags
2026-10-28 13:00:19 +13:00
Dean d59cdd502b Merge pull request #11799 from xXPBSXx/test/pthread-specific-behavior
test(libkernel): cover pthread_setspecific and pthread_getspecific
2026-10-28 12:10:38 +13:00
Adrià 4a6005955f Merge pull request #10898 from imellag/feat/libkernel-memory-protection-macos
feat(libkernel): guest memory protection and VirtualQuery on macOS hosts
2026-10-27 21:42:24 +01:00
Adrià 225ebc5eee Merge pull request #11264 from Gruzzberry/fix/sysctl-faults
fix(libkernel): fail sysctl and sysctlbyname with EFAULT on an unreadable or unwritable pointer
2026-10-27 21:16:21 +01:00
Dean 5ad1c72e33 Merge pull request #11603 from milescoviello/test/apr-queries
test(libkernel): cover the APR prefixed resolve, file size and stat queries and the submission with a result
2026-10-28 06:01:07 +13:00
Adrià a1053d987b Merge pull request #11273 from Gruzzberry/fix/signal-pointer-faults
fix(libkernel): fail the signal action, mask, stack and pending calls with EFAULT on an unusable pointer
2026-10-27 17:55:35 +01:00
Adrià e2a5118839 Merge pull request #11047 from imellag/feat/libkernel-macho-tls
feat(libkernel): thread-local storage for Mach-O guests
2026-10-27 15:18:46 +01:00
Adrià a40ad89e2c Merge pull request #11236 from orezraey/fix/libkernel-kqueue-timer-readd-measured-ps5
fix(libkernel): accept EVFILT_TIMER re-adds with a time unit or on a disabled timer as measured on a PS5
2026-10-27 14:28:05 +01:00
Adrià 1089f2bbfd Merge pull request #11039 from orezraey/fix/libkernel-mutex-yieldloops-destroyed-measured-ps5
fix(libkernel): fail the yield loop setter on a destroyed mutex as measured on a PS5
2026-10-27 14:08:31 +01:00
Adrià 62b3ba2522 Merge pull request #11125 from MarcZX10/marc/fix-equeue-close-during-measure
fix(libkernel): wait for an in-flight file measurement before closing a watched descriptor
2026-10-27 13:30:54 +01:00
Adrià b71d5db752 Merge pull request #10855 from Felipebmaitan/feat/async-storage-engine
fix(libkernel): preserve AIO request ownership and identities
2026-10-27 13:30:47 +01: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
Dean c28cf99512 Merge pull request #11438 from p3n1cillin/claude/direct-map-refuses-execute
fix(libkernel): refuse to map direct memory with execute as the console does
2026-10-27 21:26:17 +13: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
Dean efed902d27 Merge pull request #10936 from AdnanKhan-ak47/fix/ampr-nop-encoding
fix(libSceAmpr): record Nop as n dwords with a one-dword header
2026-10-27 21:15:40 +13:00
Dean 699ffce388 Merge pull request #10550 from GitamarT045T3R/fix/libkernel-munmap-unaligned
fix(libkernel): round an unaligned munmap address down like FreeBSD
2026-10-27 21:11:19 +13:00
Adrià 12686b52de Merge pull request #11060 from pushkarreddyy/fix/libkernel-writev-append-efault
fix(libkernel): return EFAULT for unreadable append iovec buffers on Windows
2026-10-27 08:56:20 +01:00
xXPBSXxandClaude Sonnet 5.5 d6ec92312c test(libkernel): cover pthread_setspecific and pthread_getspecific
pthread_setspecific returns an errno value, unlike the Sce function it wraps,
and neither POSIX export had a test. Check the FreeBSD 11.4 results of
_pthread_setspecific and _pthread_getspecific (lib/libthr/thread/thr_spec.c
lines 165-194 and 196-222): a key outside the valid range or a deleted key
makes setspecific return EINVAL (22), getspecific returns NULL for such a key
and for a key never set, a stored value is read back, NULL can be stored, a
new key with a reused number starts empty, and another thread has its own
value.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 08:53:33 +01:00
Adrià FranchandClaude Sonnet 5.5 c8cac8e090 fix(libkernel): initialise the CPU model before reading AVX support for guest TLS
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 08:42:09 +01:00
Emanueleandmugurc 86cdfb8647 feat(libkernel): thread-local storage for Mach-O guests
FreeBSD code reaches its thread pointer through %fs and macOS cannot set
the fs base. The macOS relinker turns each %fs access of a guest image
into a stub that reads the thread pointer from a pthread key and calls
Aps5GuestTlsAllocate on a thread's first access, registers the TLS
descriptor of an image with Aps5GuestTlsRegister, and routes
__tls_get_addr to Aps5GuestTlsGetAddr. No library provided them, so a
relinked executable could not start.

- Aps5GuestTlsRegister validates the descriptor the relinker wrote and
  creates the key; its destructor frees the block of a thread.
- Aps5GuestTlsAllocateThreadPointer allocates the block (the TLS template
  followed by zeros, then a 0x100-byte thread control block whose first
  word points at itself, as on FreeBSD) and stores the thread pointer
  under the key.
- Aps5GuestTlsAllocate is the entry the stubs call: rax holds the
  descriptor and returns the thread pointer, every other register is
  preserved, the upper halves of the ymm registers only where AVX exists.
- Aps5GuestTlsGetAddr returns the block of the thread plus the offset.

Co-authored-by: mugurc <[email protected]>
2026-10-27 08:42:04 +01:00
GruzzberryandClaude Sonnet 5.5 4d8fa35a5e fix(libkernel): fail sysctl and sysctlbyname with EFAULT on an unreadable or unwritable pointer
FreeBSD 11.4's sys___sysctl and userland_sysctl copy the name and the
old length in, and copy the value and the length out, so a bad pointer
gives EFAULT in that order. sysctl dereferenced them directly, and
sysctlbyname read its name with strcmp.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-27 08:30:17 +01:00
Adrià 5c356f41c3 Merge pull request #11048 from imellag/feat/libkernel-macos-main-thread
feat(libkernel): start the guest off the main thread on macOS
2026-10-27 08:27:20 +01:00
Emanuele 896ae02ab5 fix(libkernel): address the macOS stack protection review 2026-10-27 08:16:36 +01:00
Emanuele 62d80b578f fix(libkernel): protect guest stack pages through the write watch on macOS 2026-10-27 08:16:36 +01:00
Emanuele f7f88a4886 fix(libkernel): wire a remapped locked range again on macOS
- mlock on macOS skipped every page the locked ranges recorded, but a
  mapping that replaces a locked range in place leaves the record behind
  without wires, so a later mlock returned 0 and wired nothing. Within a
  recorded range it now wires again the host regions whose wire count is
  0. The mlock test locks, remaps the range fixed and locks again.
- munlock and munlockall on macOS hold the locked-range lock across the
  host unwire and the record update, so a concurrent mlock cannot see a
  range as wired while it is being unwired.
- sceKernelVirtualQuery limits the host region it reports to the write
  watch run that holds the address, so the permissions it reports hold
  for the whole extent.
- The libc debt entry says what the mapping paths do: they register the
  range again, and GuestWriteWatchProtectionChanged has no caller yet.
2026-10-27 08:16:36 +01:00
Emanuele f2e8d5a3eb fix(libkernel): address the macOS memory protection review
- mlock on macOS wires only the pages libkernel has not wired yet. XNU
  counts each wire of a page, and the locked ranges merge overlapping
  locks, so a page locked twice stayed wired after munlock and
  munlockall. The mlock test checks the wire count on macOS.
- mprotect changes a watched page through GuestWriteWatchProtect, which
  applies the host protection and records it under the write watch's
  lock, so a collection on another thread cannot run between the two.
  The write watch test covers it.
- sceKernelVirtualQuery takes a watched page's write permission from the
  write watch for memory outside the guest allocation registry.
- GuestAllocationsGuestPages counts an image segment up to the end of
  its last host page, as the image page collection does.
- The macOS includes stay in main's include block, so the host code
  other pull requests add there still sees them; the unused Mach-O
  headers and the end trim, which never changed the protected spans,
  are gone, and the guest page size is passed in.
- The libc and libkernel debt entries describe what is wired now.
2026-10-27 08:16:36 +01:00
Emanueleandmugurc 190ed6c8fb feat(libkernel): guest memory protection and VirtualQuery on macOS hosts
- mprotect: the guest rounds a range to its 16 KiB pages. A Mach-O image
  is loaded at a multiple of the host page size only (4 KiB under
  Rosetta), so the pages are counted from where the ELF address 0 of the
  image holding the range was loaded, and a rounded edge smaller than a
  guest page that lies in the gap between two segments, where no host page
  exists, is left out. The write watch is told the new protection.
- sceKernelVirtualQuery reads the region with mach_vm_region.
- sceKernelMunlockall unlocks the ranges libkernel locked, one by one:
  macOS has no munlockall, which fails there with ENOSYS and would
  overwrite errno.
- The stack protect test reads page protections with mach_vm_region.

This is mugurc's f66a4df741 from his macOS series, without the mlock
check that #10889 adds.

Co-authored-by: mugurc <[email protected]>
2026-10-27 08:16:35 +01:00
Dean 81267b2204 Merge pull request #8725 from orezraey/fix/libkernel-sync-on-address-measured-ps5
fix(libkernel): follow sceKernelSyncOnAddressWait and Wake as measured on a PS5
2026-10-27 20:03:20 +13:00
Adrià 589799aa53 Merge pull request #10889 from krishalivaibhav/fix/macos-mlock-prot-none
fix(libkernel): refuse mlock on PROT_NONE ranges on macOS
2026-10-27 07:58:57 +01:00
Dean a8ff389dee Merge pull request #11462 from xXPBSXx/test/usleep-behavior
test(libkernel): cover the return value and duration of usleep
2026-10-27 18:39:37 +13:00
Dean 741bf89739 Merge pull request #9782 from DavidSamir/test/libkernel-pthread-posix-calls
test(libkernel): cover the POSIX pthread attribute and thread calls
2026-10-27 18:21:20 +13:00
Dean 5023cd5a25 Merge pull request #9263 from imellag/fix/libkernel-macos-guest-unwind-info
fix(libkernel): report unwind information for guest and host addresses on macOS
2026-10-27 18:19:28 +13:00
Adrià 22782795a9 Merge pull request #10853 from krishalivaibhav/fix/macos-open-create-directory
fix(libkernel): refuse O_CREAT on an existing directory with EISDIR on macOS
2026-10-27 06:18:28 +01:00
Adrià d093ea9ced Merge pull request #10767 from Ragbie/fix/recvmsg-after-shut-rd
fix(libkernel): drop the data a socket held before shutdown(SHUT_RD) in every receive path
2026-10-27 06:14:18 +01:00
Adrià FranchandClaude Sonnet 5.5 7554d2095c fix(libkernel): keep swapcontext's finish helper externally linked
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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
Adrià 0a570f617d Merge pull request #10660 from imellag/build/libkernel-elf-fixture-options-not-apple
build(libkernel): keep the ELF-only module fixture options off Apple
2026-10-27 05:51:03 +01:00
MarcZX10 ea4eaeae42 fix(libkernel): remove a watched descriptor's events before dup2 takes its positioned lock on Windows
dup2 called EqueueDescriptorClosed(to) while holding the positioned-transfer lock of the descriptor, and the in-flight measurement it waits for needs that lock for its sceKernelLseek, so dup2 onto a watched descriptor deadlocked. The events are removed first, before the lock is taken.
2026-10-27 04:46:00 +00:00
MarcZX10 9b9f9b4af8 fix(libkernel): retire an in-flight file measurement on every exit with a guard
MeasureFiles registered the descriptors it measures in m_measuring and removed them only on the normal path, so an exception between unlocking and relocking left them there and every later RemoveDescriptorEvents for one of them waited forever. Both vectors are reserved before anything is registered, and a guard owns the registration: on every exit it relocks if needed, removes the entries and notifies.
2026-10-27 04:46:00 +00:00
MarcZX10 de2b96d8bd fix(libkernel): wait for an in-flight file measurement before closing a watched descriptor 2026-10-27 04:46:00 +00:00
Adrià 50a28679c4 Merge pull request #10528 from akkadbakkad89/fix/direct-remap-block-index
fix(libkernel): walk direct-memory physical ranges by block, not page
2026-10-27 05:35:38 +01:00
Felipebmaitan 152155e484 fix(libkernel): isolate AIO controls in the registry test target 2026-10-27 01:30:11 -03:00
Felipebmaitan e44cc5d463 chore: merge current main for AIO review fixes 2026-10-27 01:23:42 -03:00