From f61d10525d483653b608f89d80cb7f9ca9b1d186 Mon Sep 17 00:00:00 2001 From: chakrabot Date: Wed, 24 May 2017 21:00:36 -0700 Subject: [PATCH] [Merge Microsoft/Chakracore@4c0fcf1480] [MERGE #2990 @obastemur] xplat: protect CC from un-reasonable stack limits Merge pull request #2990 from obastemur:better_stack --- deps/chakrashim/core/pal/src/init/pal.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/deps/chakrashim/core/pal/src/init/pal.cpp b/deps/chakrashim/core/pal/src/init/pal.cpp index dd8d6365544..49be53296f0 100644 --- a/deps/chakrashim/core/pal/src/init/pal.cpp +++ b/deps/chakrashim/core/pal/src/init/pal.cpp @@ -130,6 +130,26 @@ Initialize() /*Firstly initiate a lastError */ SetLastError(ERROR_GEN_FAILURE); + // prevent un-reasonable stack limits. (otherwise affects mmap calls later) +#if !defined(__IOS__) && !defined(__ANDROID__) +#ifdef _AMD64_ + const rlim_t maxStackSize = 8 * 1024 * 1024; // CC Max stack size +#else + const rlim_t maxStackSize = 2 * 1024 * 1024; // CC Max stack size +#endif + struct rlimit rl; + int err = getrlimit(RLIMIT_STACK, &rl); + if (!err) + { + if (rl.rlim_cur > maxStackSize) + { + rl.rlim_cur = maxStackSize; + err = setrlimit(RLIMIT_STACK, &rl); + _ASSERTE(err == 0 && "Well, the environment has a strange stack limit \ + and setrlimit call failed to fix that"); + } + } +#endif // !__IOS__ && !__ANDROID__ CriticalSectionSubSysInitialize(); if(NULL == init_critsec)