8

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:

  1. A platform independent way to set stack limit or
  2. A way to set stack limit in Window from within the code.
  • 2
    [This](https://stackoverflow.com/questions/20744650/how-to-overcome-stack-size-issue-with-visual-studio-running-c-codes-with-big-ar) and [this](https://stackoverflow.com/questions/156510/increase-stack-size-on-windows-gcc) sounds like there is no way to set the stack size limit on Windows programatically; you need to do it in the actual binary either by editing the .exe or when compiling. – hlt Sep 21 '18 at 13:18
  • thanks, I will go the compile time flag way. – Deeptanshu Sekhri Sep 24 '18 at 06:33

0 Answers0