-
-
Save cptwunderlich/423994070700f68557533ea90400d23b to your computer and use it in GitHub Desktop.
2nd OSMem.c fix for rlimit crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SYS_TIME_H) | |
struct rlimit asLimit; | |
/* rlim_t is signed on some platforms, including FreeBSD; | |
* explicitly cast to avoid sign compare error */ | |
if (!getrlimit(RLIMIT_AS, &asLimit) | |
&& asLimit.rlim_cur > 0 | |
&& *len > (W_) asLimit.rlim_cur) { | |
// TODO: get stack limit from pthread_attr_getstacksize | |
struct rlimit stackLimit; | |
if (getrlimit(RLIMIT_STACK, &stackLimit)) { | |
// Default stack size on Linux is 8MB | |
stackLimit.rlim_cur = 8388608; | |
debugBelch("Setting default stack limit\n"); | |
} else { | |
debugBelch("Stack limit is: %zu\n", stackLimit.rlim_cur); | |
} | |
size_t pageSize = getPageSize(); | |
// 2/3rds of limit, round down to multiple of PAGE_SIZE | |
W_ *len = ((asLimit.rlim_cur * ((double) 2/3)) / pageSize) * pageSize; | |
if (((W_) (asLimit.rlim_cur - *len )) < ((W_) (stackLimit.rlim_cur * 3))) { | |
sysErrorBelch("not enough available virtual memory! Please check your resource limits!"); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment