Rust guarantees no segfaults with only safe code but it segfaults (stack overflow)

I'm at least not personally aware of a time where we ever treated a stack overflow as a panic, but I think this happened in the way way past, right? That is to say, at least when I've been working with std I believe that a stack overflow has always translated to some form of an immediate abort of the process.

The biggest roadblock I can think of in turning a stack overflow into a panic is that we don't know how much stack space the panic handler will take. Not only that, but we're also currently running on a global stack which has to be preallocated ahead of time, so there's not a lot of stack space itself to work within. Nowadays we also have custom panic handlers, so you're perhaps running arbitrary code when a panic happens.

Overall I've at least personally felt that stack overflows are so niche and difficult to recover from that it's basically not worth bending over backwards to support. I feel that we strike a good balance today between handling the error and being pragmatic about it.

2 Likes