[issue46923] Implement stack overflow protection for supported platforms

Mark Shannon report at bugs.python.org
Fri Mar 4 11:54:19 EST 2022


New submission from Mark Shannon <mark at hotpy.org>:

https://github.com/python/steering-council/issues/102 (definitely not PEP 651 ;))

We should implement efficient stack checks on those platforms that allow us to introspect stack extents.
Windows and posix systems allow us to do this.

C allows addresses of stack variables to be taken. This means that C stacks cannot be moved.
In theory they might be discontinuous, although I suspect that they are always contiguous.

My plan is to maintain a per-thread "safe region" of 32or 64k. We can check if the current stack pointer (or near enough) is in that region cheaply.
If we are not in that region, we can ask the O/S for a stack limit to determine a new "safe region". If we cannot find a safe region, then we raise a MemoryError.

Personally I'd prefer a new exception `StackOverflow` to `MemoryError` but, thanks to stackoverflow.com, it is now impossible for new programmers to do a web search to determine what a "stack overflow" is.
So, I guess MemoryError will have to do.

----------
assignee: Mark.Shannon
messages: 414538
nosy: Mark.Shannon, gregory.p.smith
priority: normal
severity: normal
status: open
title: Implement stack overflow protection for supported platforms

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46923>
_______________________________________


More information about the Python-bugs-list mailing list