8000 Check if a fatal signal is from kernel · ruby/ruby@f928e60 · GitHub
[go: up one dir, main page]

Skip to content

Commit f928e60

Browse files
committed
Check if a fatal signal is from kernel
On Linux, `siginfo_t` uses a union for each `si_code`, and the field corresponding to `si_pid` does not belong to the `_sigfault` field for SIGSEGV. It actually overlaps the `si_addr` field, which is usually non-zero on stack overflow. #10201 (comment)
1 parent 4960a59 commit f928e60

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

signal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,16 +867,19 @@ check_stack_overflow(int sig, const void *addr)
867867
}
868868
}
869869
# endif
870+
870871
# ifdef _WIN32
871872
# define CHECK_STACK_OVERFLOW() check_stack_overflow(sig, 0)
872873
# else
873874
# define FAULT_ADDRESS info->si_addr
874875
# ifdef USE_UCONTEXT_REG
875-
# define CHECK_STACK_OVERFLOW() (info->si_pid ? (void)0 : check_stack_overflow(sig, (uintptr_t)FAULT_ADDRESS, ctx))
876+
# define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, (uintptr_t)FAULT_ADDRESS, ctx)
876877
# else
877-
# define CHECK_STACK_OVERFLOW() (info->si_pid ? (void)0 : check_stack_overflow(sig, FAULT_ADDRESS))
878+
# define CHECK_STACK_OVERFLOW_() check_stack_overflow(sig, FAULT_ADDRESS)
878879
# endif
879880
# define MESSAGE_FAULT_ADDRESS " at %p", FAULT_ADDRESS
881+
# define SIGNAL_FROM_USER_P() ((info)->si_code == SI_USER)
882+
# define CHECK_STACK_OVERFLOW() (SIGNAL_FROM_USER_P() ? (void)0 : CHECK_STACK_OVERFLOW_())
880883
# endif
881884
#else
882885
# define CHECK_STACK_OVERFLOW() (void)0

0 commit comments

Comments
 (0)
0