Skip to content

Commit

Permalink
[MERGE #2990 @obastemur] xplat: protect CC from un-reasonable stack l…
Browse files Browse the repository at this point in the history
…imits

Merge pull request #2990 from obastemur:better_stack
  • Loading branch information
obastemur committed May 23, 2017
2 parents 36d1ef2 + 26f85e8 commit 4c0fcf1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pal/src/init/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c0fcf1

Please sign in to comment.