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

Merged
merged 1 commit into from
Jun 28, 2024
Merged

Allow fatal SBCL errors to be caught #54

merged 1 commit into from
Jun 28, 2024

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. set_lossage_handler exists and is exported by the runtime
  • 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 from c096346 to 551dae5 Compare May 13, 2024 17:45
@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
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 2 times, most recently from 12567c1 to 6f4ba4d Compare June 24, 2024 21:35
@kartik-s kartik-s changed the base branch from add-ci to add-python-ci June 24, 2024 21:37
@kartik-s kartik-s force-pushed the catch-fatal-errors branch from 6f4ba4d to 0381264 Compare June 24, 2024 21:38
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 4 times, most recently from ba8ed32 to 757be44 Compare June 24, 2024 22:39
@kartik-s kartik-s changed the base branch from add-python-ci to main June 25, 2024 19:29
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 6 times, most recently from 744a0bb to 9a23881 Compare June 25, 2024 20:17
@kartik-s kartik-s force-pushed the catch-fatal-errors branch 7 times, most recently from c6eab0c to 0c46ced Compare June 25, 2024 22:26
@eliaslfox
Copy link

This pr should gracefully handle calling into lisp after a fatal error. Doing so should repeat the fatal error behavior.

@kartik-s kartik-s force-pushed the catch-fatal-errors branch from 0c46ced to de02256 Compare June 26, 2024 21:00
@kartik-s kartik-s force-pushed the catch-fatal-errors branch from cd9c18e to 4981dcb Compare June 27, 2024 17:33
@kartik-s
Copy link
Contributor Author

This pr should gracefully handle calling into lisp after a fatal error. Doing so should repeat the fatal error behavior.

See implementation here and test here

Copy link

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

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

Ship it
ship

@kartik-s kartik-s merged commit aab8a5a into main Jun 28, 2024
3 checks passed
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.

3 participants