Commit Graph

3 Commits

Author SHA1 Message Date
Usif 46a7d3a446
[Kernel] Keep oversized reservations at the guest's hint and sign-extend user event ids (#1073)
* [Kernel] Keep an oversized reservation at the guest's hint instead of failing

A 768 GB sceKernelReserveVirtualRange with a hint at 0x1000000000 cannot use the
sparse aperture (it starts at 256 GB, and 256 GB plus 768 GB passes the 1008 GB
user limit), so it needed one contiguous host placeholder. When a host
allocation made before the startup reservation sits inside that window, the
call fails with 0x8002000C and the guest stops at boot.

Reserve such a range at the guest's own hint as a guest-only sparse range, as
smaller large reservations already are.

* [Kernel] Sign-extend the int id of user events into the event ident

sceKernelAddUserEvent, sceKernelAddUserEventEdge, sceKernelDeleteUserEvent and
sceKernelTriggerUserEvent take an int id, which the kernel stores in the
uintptr_t ident of the event. A negative id such as -1 therefore reads back from
sceKernelGetEventId as 0xFFFFFFFFFFFFFFFF. The exports used the zero-extended
register (0x00000000FFFFFFFF), so a guest that treats a negative id as a
wake-up event took its normal event path instead and never went back to wait.

Use the sign-extended id in all four exports.
2026-10-10 03:39:51 +03:00
kuba 816ec4ad27
Kernel: correct equeue event delivery and waiter lifetime (#723)
Ports the event-queue rework from the archived silent-hill-minimal branch
(968e9606, 9e3abb12, 2be9cfbf, f157a115) onto current upstream. The equeue
implementation had not been touched upstream since that branch forked, so
none of it had landed.

Behaviour fixed:

- Per-waiter event reservation. A blocked waiter used to wake on "the queue
  has any pending event" (TryWake => HasPendingEvents) and then re-read the
  queue on resume, so a woken waiter could find the event already drained by
  another waiter and park again with the wake consumed. Events are now
  reserved to the waiter they are delivered to.
- Level-triggered events are preserved instead of being cleared by an
  unrelated read; only events that declare clear-on-read reset their trigger
  state.
- Queued interrupts are bound to the registration generation that produced
  them, so an event registered after a queue was reused cannot consume an
  interrupt raised for the previous registration.
- Deleting an equeue now terminates its waiters instead of leaving them
  blocked on a handle that no longer resolves.
- sceKernelTriggerUserEvent stores its third argument in the event's udata
  (0x18) rather than its data word (0x10). The guest reads it back with
  sceKernelGetEventUserData, which loads 0x18, so every triggered user event
  previously read back as 0. This matches the reference behaviour in shadPS4,
  where TriggerEvent takes udata and sceKernelGetEventUserData returns
  ev->udata. The upstream test asserting the data word is updated, since it
  encoded the inconsistency rather than the ABI.

KernelPthreadState gains TryGetCurrentThreadIdentity and a new
KernelSyncTraceFormatter carries the shared, opt-in diagnostic formatting the
ported code calls; both are gated behind the existing trace flag and do no
work when it is off.

Tests: 662 pass, 0 fail (SharpEmu.Libs.Tests 588 -> 598).
2026-07-31 12:13:15 +03:00
kostyaff 6dda6589d0
test: add Kernel/Loader unit tests (22 tests) (#373)
- SelfLoader: reject unknown magic, truncated headers; parse PS5 SELF embedded ELF
- KernelMemory: MapNamedFlexibleMemory/mprotect/munmap argument validation
- KernelEventQueue: create/delete/add/trigger/wait lifecycle

Co-authored-by: OMP <omp@local>
2026-07-18 20:19:55 +03:00