How do C signals interact with the stack?

We know how C functions work. The program maintains a call stack, which contains stack frames corresponding to nested function calls. Calling a function means pushing a new stack frame onto the stack, and returning from a function means popping its stack frame off the stack.

C signal handlers are functions, but the calling mechanism is clearly different. They don’t get called in a “normal” way, and they don’t get to “return” a value. So how do these functions work? And how do they interact with “normal” C functions?

The BSD manual for sigaction explains:

Normally, signal handlers execute on the current stack of the process. This may be changed, on a per-handler basis, so that signals are taken on a special signal stack.

So signal handlers do reuse the same stack, under normal conditions.

I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.