Skip to content

feat(libkernel): record exception handlers - #724

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
merwie:feat/kernel-exception-handler-registration
Oct 6, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
merwie:feat/kernel-exception-handler-registration

Conversation

@merwie

@merwie merwie commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelInstallExceptionHandler and sceKernelRemoveExceptionHandler threw not implemented. They now keep one handler per allowed signal, with the checks of shadPS4's implementation:

  • allowed signals: SIGHUP (1), SIGILL (4), SIGFPE (8), SIGBUS (10), SIGSEGV (11), SIGUSR1 (30); any other signal, or a null handler, returns SCE_KERNEL_ERROR_EINVAL;
  • a second handler for a signal returns SCE_KERNEL_ERROR_EAGAIN;
  • removing clears the handler (also when none was installed).

Nothing delivers to the recorded handler yet: a host fault still ends the process with the crash report, and sceKernelRaiseException still throws. This is recorded under Functional in TechnicalDebt.

  • New test guest_exception_handler: rejected signals and null handler, install / duplicate / remove / reinstall for each allowed signal.

Why registration alone is useful, and what delivery needs: PPSA12544's Media/Modules/PS5Util.prx (Unity) installs a SIGUSR1 handler in its GC stop init (gc_stop_init failure 1 error:%x on failure). Its handler checks signum == 30 and calls the stored callback with the context and *(context + 0xf8), i.e. uc_mcontext.mc_rsp of the PS5 ucontext (16-byte uc_sigmask, 48 bytes, then uc_mcontext). To stop a thread for garbage collection it calls sceKernelRaiseException(thread, 30). Delivery therefore has to run the handler on the target thread with the interrupted state and resume it afterwards; on Windows the targets are typically blocked in host waits (seen: AssetGarbageCollectorHelper threads in ntdll waits). That design is a separate change, proposed in #727.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT.

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

🤖 Generated with Claude Code

sceKernelInstallExceptionHandler and sceKernelRemoveExceptionHandler threw.
They now keep one handler per allowed signal (SIGHUP, SIGILL, SIGFPE,
SIGBUS, SIGSEGV, SIGUSR1, as in shadPS4): another signal or a null handler
returns EINVAL, a second handler for a signal returns EAGAIN, and removing
clears it. Delivery is not implemented and is recorded in the technical
debt; sceKernelRaiseException still throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for this. It needs a one-line rebase: #796 added its Additional content (libSceAppContent) line to docs/dev/TechnicalDebt.md at the same place in the Functional list as your sceKernelInstallExceptionHandler line. Keeping both lines resolves it, and nothing else conflicts. #760 carries this commit, so it will need the same resolution.

…/kernel-exception-handler-registration

# Conflicts:
#	docs/dev/TechnicalDebt.md
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Progress report (481c85e → deddb10)

📈 System libraries: 82.37% (+0.06%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel sceKernelInstallExceptionHandler
libkernel sceKernelRemoveExceptionHandler

@merwie

merwie commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (a merge, not a rebase, so the review history stays) and kept both TechnicalDebt.md lines in the order you suggested. Nothing else changed.

@github-actions

github-actions Bot commented Oct 6, 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
#835 docs/dev/TechnicalDebt.md L138

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 6, 2026
@oneandonlydean
oneandonlydean merged commit 906b7f8 into boykopovar:main Oct 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants