You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
STDERR.puts "Program exited because of a segmentation fault (11)"
when .int?
# OK, bubbled from the sub-program
else
STDERR.puts "Program received and didn't handle signal #{signal} (#{signal.value})"
end
else
STDERR.puts "Program exited abnormally, the cause is unknown"
end
exit1
end
status is a Process::Status. On Unix-like systems, if status.signal_exit? && status.exit_signal.segv?, then the process exited because of a segmentation fault. Windows executables do not communicate POSIX signals through the exit status, so that wouldn't work there. Nonetheless, we can still detect segmentation faults on Windows as follows:
libLibC# these constants are defined in `errhandlingapi.cr` but# they should actually be from `minwinbase.cr`EXCEPTION_ACCESS_VIOLATION=0xC0000005_u32EXCEPTION_STACK_OVERFLOW=0xC00000FD_u32
end
status.exit_status.in?(LibC::EXCEPTION_ACCESS_VIOLATION, LibC::EXCEPTION_STACK_OVERFLOW)
(Minor note: this won't work on Crystal programs at the moment, because currently the crash handler does not preserve those exit statuses.)
Neither exit_status nor exit_signal is platform-independent, so we would like some abstraction that uses the former on Windows, but the latter on Unix-like systems. Additionally, segmentation faults are not the only way a process could terminate, and there are other mutually exclusive reasons that could all be determined from the exit status. This calls for an enum:
enumProcess::ExitReasonNormalAbortedInterruptedAccessViolationBadMemoryAccessBadInstructionPosixSignal# any reasons not covered above; unused on windowsUnknowndefabnormal?
!normal? &&!unknown?
endend
And this enum is returned from a new method, Process::Status#exit_reason:
I would like to reach consensus on ExitReason and #exit_reason before moving on with a PR, because there might be subtle differences between the different POSIX signals that default to process termination.
#13052 defines ExitReason::Breakpoint and ExitReason::FloatException additional to the ones mentioned here.
I suppose it makes sense to have them and they seem to be clearly defined on all platforms.
Some programs need to determine how another process terminated. For example,
crystal run
does this after running the temporary executable:crystal/src/compiler/crystal/command.cr
Lines 277 to 295 in 994c70b
status
is aProcess::Status
. On Unix-like systems, ifstatus.signal_exit? && status.exit_signal.segv?
, then the process exited because of a segmentation fault. Windows executables do not communicate POSIX signals through the exit status, so that wouldn't work there. Nonetheless, we can still detect segmentation faults on Windows as follows:(Minor note: this won't work on Crystal programs at the moment, because currently the crash handler does not preserve those exit statuses.)
Neither
exit_status
norexit_signal
is platform-independent, so we would like some abstraction that uses the former on Windows, but the latter on Unix-like systems. Additionally, segmentation faults are not the only way a process could terminate, and there are other mutually exclusive reasons that could all be determined from the exit status. This calls for an enum:And this enum is returned from a new method,
Process::Status#exit_reason
:I would like to reach consensus on
ExitReason
and#exit_reason
before moving on with a PR, because there might be subtle differences between the different POSIX signals that default to process termination.See also #7339, #8381, and #9064.
The text was updated successfully, but these errors were encountered: