Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22171

Linux process stack overrun by local variables (stack guarding)

$
0
0

From What is the purpose of the _chkstk() function?:

At the end of the stack, there is one guard page mapped as inaccessible memory -- if the program accesses it (because it is trying to use more stack than is currently mapped), there's an access violation.

_chkstk() is a special compiler-helper function which

ensures that there is enough space for the local variables

i.e. it's doing some stack probing (here is an LLVM example).
This case is Windows-specific. So Windows has some solution to the problem.

Let's consider the similar conditions under Linux (or some other Unix-like): we have a lot of function's local variables. The first stack variable access is behind the stack segment (e.g. mov eax, [esp-LARGE_NUMBER], here esp-LARGE_NUMBER is something behind the stack segment). Is there any features to prevent possible page fault or whatever in Linux (perhaps other Unix-like) or development tools like , , etc? Does -fstack-check (GCC stack checking) somehow solve this problem? This answer states that it is something very similar to _chkstk().

P.S. These posts 1, 2 didn't help a lot.

P.P.S. In general, the question is about implementation differences between OSs (foremost Linux vs Windows) approaches of struggling with huge amount of stack variables, that climb behind the stack segment. Both C++ and C tags are added because it's about Linux native binary producing, but the assembly code is compiler-related.


Viewing all articles
Browse latest Browse all 22171


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>