fix integer overflow on i686 with high phys memory
sizeof(long) is 4 bytes on i686 GCC. With ~32 GiB of memory and a page size of 4096, there are 7988420 pages. (7988420 * 4096) is bigger than INT32_MAX folks. This has gone unnoticed for 9 years, and only came up thanks to 94ea517db[1] adding integer overflow sensitization checks, which caused this broken code to emit an illegal instruction, crashing Lix the instant the buildsystem ran Lix to generate the docs files. [1]: 94ea517dbe729765b69638190f4bea3f6a632b40 Change-Id: I50bb9ea072aac11b449d79e5d55525887a6e5a99
This commit is contained in:
parent
4998699e1a
commit
99903f24eb
1 changed files with 6 additions and 5 deletions
|
@ -316,13 +316,14 @@ void initGC()
|
|||
(resident) memory to be allocated. This might be a problem on
|
||||
systems that don't overcommit. */
|
||||
if (!getEnv("GC_INITIAL_HEAP_SIZE")) {
|
||||
size_t size = 32 * 1024 * 1024;
|
||||
int64_t size = 32 * 1024 * 1024;
|
||||
#if HAVE_SYSCONF && defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
|
||||
size_t maxSize = 384 * 1024 * 1024;
|
||||
long pageSize = sysconf(_SC_PAGESIZE);
|
||||
long pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pageSize != -1)
|
||||
int64_t maxSize = 384 * 1024 * 1024;
|
||||
int64_t pageSize = sysconf(_SC_PAGESIZE);
|
||||
int64_t pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pageSize != -1) {
|
||||
size = (pageSize * pages) / 4; // 25% of RAM
|
||||
}
|
||||
if (size > maxSize) size = maxSize;
|
||||
#endif
|
||||
debug("setting initial heap size to %1% bytes", size);
|
||||
|
|
Loading…
Reference in a new issue