Why stack overflow causes segmentation fault instead of stack overflow in Linux? [duplicate]

你说的曾经没有我的故事 提交于 2019-12-01 02:47:48

A stack overflow can cause several different kinds of hardware errors.

  • It may lead to an attempt to access memory for which the program has no appropriate permissions → the kernel will raise a SIGSEGV (segmentation violation) signal for the process.
  • It may lead to an attempt to execute an illegal instruction (e.g: you overwrote the return address to point to an invalid instruction) → the kernel will raise a SIGILL (illegal instruction) signal.
  • Probably SIGBUS on some platforms (e.g: alignment exception).

All these errors occur after the stack overflow. An option is to add stack overflow protections (ProPolice, ...), so as to catch stack overflows before they cause more serious problems.

Edit:

You mean a "real stack overflow". Well, this case is covered by SEGV (trying to access memory for which the process has no permissions), so it gets a SEGV, instead of special-casing every single case of the more general SEGV.

Stackoverflow is not an error, it is a case, the error thrown from it changes from language to language and from platform to platform.

See more about segmentation fault in wiki

EDIT:

To make it clearer - in your case, the call stack is overflowed and the program tries to write the next call to an invalid address, causing a segmentation fault.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!