diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -91,13 +91,26 @@ if (NumBytes == 0) return MemoryBlock(); - int fd = -1; + // on platforms that have it we can use MAP_ANONYMOUS to get a memory mapped + // page without file backing, but we need a fallback by opening /dev/zero + // for strictly POSIX platforms instead + int fd = +#if defined(MAP_ANONYMOUS) || defined(MAP_ANON) + -1; +#else + open("/dev/zero", O_RDWR); + if (fd ==-1) { + EC = std::error_code(errno, std::generic_category()); + return MemoryBlock(); + } +#endif + - int MMFlags = MAP_PRIVATE | + int MMFlags = MAP_PRIVATE #ifdef MAP_ANONYMOUS - MAP_ANONYMOUS -#else - MAP_ANON + | MAP_ANONYMOUS +#elif MAP_ANON + | MAP_ANON #endif ; // Ends statement above @@ -122,9 +135,17 @@ return allocateMappedMemory(NumBytes, nullptr, PFlags, EC); EC = std::error_code(errno, std::generic_category()); +#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON) + close(fd); +#endif return MemoryBlock(); } +#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON) + close(fd); +#endif + + MemoryBlock Result; Result.Address = Addr; Result.Size = NumBytes; diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -157,11 +157,14 @@ s = pv = strdup(pv); if (!pv) return nullptr; - while ((t = strsep(&s, ":")) != nullptr) { - if (test_dir(ret, t, bin) == 0) { - free(pv); - return ret; - } + char *state; + if ((t = strtok_r(s,":",&state)) != nullptr) { + do { + if (test_dir(ret, t, bin) == 0) { + free(pv); + return ret; + } + } while((t = strtok_r(nullptr,":",&state)) != nullptr); } free(pv); return nullptr; diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -288,7 +288,8 @@ unsigned Columns = 0; -#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H) +#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H) \ + && !(defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)) // Try to determine the width of the terminal. struct winsize ws; if (ioctl(FileID, TIOCGWINSZ, &ws) == 0)