[PD] What exactly is a "stack overflow" ?

Martin Peach martin.peach at sympatico.ca
Thu Dec 20 15:18:45 CET 2007

Mathieu Bouchard wrote:
> On Mon, 17 Dec 2007, Martin Peach wrote:
>>> With Pd, this is never what happens on its own. Instead, just before 
>>> processing each message, a check of the count of nested message 
>>> processings in made (messages sent that are still being processed, 
>>> not counting those scheduled by [delay] and stuff).
>> So it's not really a stack overflow, more like a buffer overrun.
> A stack is a buffer, and an overflow of addresses is an overrun... 
> what are you trying to say?
A stack is Last In First Out, like a stack of trays in a cafeteria, and 
a buffer is First In First Out, like a train in a tunnel. Pd processes 
messages in the order they are sent, it uses a buffer.

>> But if you don't have 512Meg of RAM then what?
> Then you have swap, and if you don't have swap, you necessarily get a 
> stack overflow, but it's assumed that if you didn't allocate on the 
> stack, you would allocate the same amount of memory on the heap, so it 
> shouldn't be much different.
I think the machine would not be useful with the stack on the hard 
drive, it would be much too slow.

>> You would need to modify the processor's interrupt table by replacing 
>> the stack overflow exception handler, which is likely to cause 
>> trouble elsewhere. The OS wouldn't let you do that anyway, because 
>> you'd be accessing memory outside of user space, which triggers 
>> another kind of exception, "segmentation fault", the same one 
>> triggered by accessing a null pointer.
> In theory, wouldn't you just register a signal-handler for SIGSTKFLT 
> instead?

SIGSTKFLT is thrown by the cpu when the stack overflows, and registering 
a handler amounts to modifying the interrupt table, so its the same thing.

> But either way (even if the other way was possible), I think that 
> you'd get in trouble because the interrupt/signal-handler would need 
> to push at least 3 words on a stack that is already full.
Well obviously you're supposed to do it before the stack is too big. If 
as you say the OS starts out with no stack and waits for trouble, it 
would have the same problem. I would have thought that a stack overflow 
requires a restart, unless the exception kicks in before the absolute 
end of the stack.


More information about the Pd-list mailing list