Is it possible to predict a stack overflow in C on Linux?

前端 未结 12 1531
遇见更好的自我
遇见更好的自我 2021-01-13 14:44

There are certain conditions that can cause stack overflows on an x86 Linux system:

  • struct my_big_object[HUGE_NUMBER] on the stack. Walking throu
12条回答
  •  -上瘾入骨i
    2021-01-13 15:43

    You can use GNU libsigsegv to handle a page fault, including cases where a stack overflow occurs (from its website):

    In some applications, the stack overflow handler performs some cleanup or notifies the user and then immediately terminates the application. In other applications, the stack overflow handler longjmps back to a central point in the application. This library supports both uses. In the second case, the handler must ensure to restore the normal signal mask (because many signals are blocked while the handler is executed), and must also call sigsegv_leave_handler() to transfer control; then only it can longjmp away.

提交回复
热议问题