Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fatal SBCL errors to be caught #54

Open
wants to merge 57 commits into
base: add-ci
Choose a base branch
from
Open

Conversation

kartik-s
Copy link
Contributor

@kartik-s kartik-s commented Apr 4, 2024

Problem

A call into Lisp may trigger a fatal error in SBCL, dropping the process unceremoniously into LDB and making it difficult for the user to gracefully terminate the process.

Solution

Use setjmp to save the execution context before calling into Lisp, and use longjmp to return to the pre-call execution context with a special error code if a fatal SBCL error was encountered.

Notes

  • This feature requires patching SBCL to make the lossage_handler function pointer non-static, setting sbcl-librarian::*non-static-lossage-handler* to T, and adding a fatal-error code to the error map.
  • DEFINE-ERROR-TYPE takes a new fatal-error argument specifying which value to return when a Lisp call triggers a fatal SBCL error.
  • The names of the function pointers in the generated C bindings are now prefixed with an underscore.
  • Each function pointer is wrapped by a function definition with the original callable name. The body of each function definition performs a setjmp before calling into Lisp through the associated function pointer.
  • If there is no error-map or no fatal-code is specified, then the fatal error handler just drops into LDB.

Copy link
Contributor

@macrologist macrologist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a first pass. I didn't try to understand what it is doing.

src/api.lisp Show resolved Hide resolved
src/api.lisp Show resolved Hide resolved
src/bindings.lisp Outdated Show resolved Hide resolved
src/function.lisp Show resolved Hide resolved
src/function.lisp Show resolved Hide resolved
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 5 times, most recently from 8d3f788 to 30991ab Compare April 18, 2024 20:41
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 4 times, most recently from 656f7a8 to c096346 Compare May 12, 2024 19:39
@kartik-s kartik-s changed the base branch from main to add-ci May 13, 2024 17:44
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 2 times, most recently from ff80900 to bda3d3c Compare June 12, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants