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

Handle exceptions raised at __crystal_sigfault_handler #8743

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/signal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,17 @@ fun __crystal_sigfault_handler(sig : LibC::Int, addr : Void*)
# Determine if the SEGV was inside or 'near' the top of the stack
# to check for potential stack overflow. 'Near' is a small
# amount larger than a typical stack frame, 4096 bytes here.
stack_top = Pointer(Void).new([email protected] - 4096)
is_stack_overflow =
begin
stack_top = Pointer(Void).new([email protected] - 4096)
stack_bottom = Fiber.current.@stack_bottom
stack_top <= addr < stack_bottom
rescue e
LibC.dprintf 2, "Error while trying to determine if a stack overflow has occurred. Probable memory corrpution\n"
false
end

if stack_top <= addr < Fiber.current.@stack_bottom
if is_stack_overflow
LibC.dprintf 2, "Stack overflow (e.g., infinite or very deep recursion)\n"
else
LibC.dprintf 2, "Invalid memory access (signal %d) at address 0x%lx\n", sig, addr
Expand Down