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 wrote this because I felt like it. This post is my own, and not associated with my employer.

Jim. Friends.