Skip to content

Commit

Permalink
Safely disable the alternate signal stack with sigaltstack(SS_DISABLE…
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Jan 11, 2025
1 parent 44ef955 commit 036d9b7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/crystal/system/unix/signal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module Crystal::System::Signal
LibC.sigaltstack(pointerof(altstack), nil)

at_exit {
LibC.free(altstack.ss_sp)
reset_signal_stack(pointerof(altstack))
}

action = LibC::Sigaction.new
Expand All @@ -239,6 +239,16 @@ module Crystal::System::Signal
LibC.sigaction(::Signal::SEGV, pointerof(action), nil)
LibC.sigaction(::Signal::BUS, pointerof(action), nil)
end

private def self.reset_signal_stack(altstack : Pointer(LibC::StackT))
default_stack = LibC::StackT.new
default_stack.ss_sp = nil
default_stack.ss_flags = 0x0004 # LibC::SS_DISABLE
default_stack.ss_size = 0
LibC.sigaltstack(pointerof(default_stack), nil)

LibC.free(altstack.value.ss_sp)
end
end

struct Crystal::System::Sigset
Expand Down

0 comments on commit 036d9b7

Please sign in to comment.