I am looking for a way to port POSIX getrlimits/setrlimit functionality on Windows.
Our application sometimes run into a very deep recursion and the default stack limit is reached resulting in a stack overflow.
To prevent that we have written the following piece of code:
struct rlimit rl;
int error = getrlimit(RLIMIT_STACK, &rl);
if (!error)
{
rl.rlim_cur = rl.rlim_max;
error = setrlimit(RLIMIT_STACK, &rl);
}
Basically we are setting the stack limit to the maximum value here.
Now I am trying to port this code to Windows using minGW(cross compiled for Windows on Linux)
I searched around but I could not find a way to do it from within the code.
What I found was a linker flag "--stack" which can be used as:
mingw32-g++ -Wl,--stack, -o file.exe file.c
But I am not sure if I can run into some issues with this usage in long run(like setting stack limit for the whole application vs for a specific piece of code)
What I would prefer over this solution would be one of the following:
- A platform independent way to set stack limit or
- A way to set stack limit in Window from within the code.