diff options
| author | Xing Xue <xingxue@outlook.com> | 2019-05-16 14:02:13 +0000 |
|---|---|---|
| committer | Xing Xue <xingxue@outlook.com> | 2019-05-16 14:02:13 +0000 |
| commit | 2dee094a08ff4e244e8df046f3b1d6445e707b77 (patch) | |
| tree | 5057df3159cbbcba2a956540b430d43426b0df29 /llvm/lib/Support/Unix/Memory.inc | |
| parent | 3966b02cc82ac258f6696ff7ced5f58f1265021b (diff) | |
| download | bcm5719-llvm-2dee094a08ff4e244e8df046f3b1d6445e707b77.tar.gz bcm5719-llvm-2dee094a08ff4e244e8df046f3b1d6445e707b77.zip | |
Fixes for builds that require strict X/Open and POSIX compatiblity
Summary:
- Use alternative to MAP_ANONYMOUS for allocating mapped memory if it isn't available
- Use strtok_r instead of strsep as part of getting program path
- Don't try to find the width of a terminal using "struct winsize" and TIOCGWINSZ on POSIX builds. These aren't defined under POSIX (even though some platforms make them available when they shouldn't), so just check if we are doing a X/Open or POSIX compliant build first.
Author: daltenty
Reviewers: hubert.reinterpretcast, xingxue, andusy
Reviewed By: hubert.reinterpretcast
Subscribers: MaskRay, jsji, hiraditya, kristina, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61326
llvm-svn: 360898
Diffstat (limited to 'llvm/lib/Support/Unix/Memory.inc')
| -rw-r--r-- | llvm/lib/Support/Unix/Memory.inc | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc index affdb7e70d9..05c5ccbdb3d 100644 --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -91,9 +91,24 @@ Memory::allocateMappedMemory(size_t NumBytes, if (NumBytes == 0) return MemoryBlock(); - int fd = -1; + // On platforms that have it, we can use MAP_ANON to get a memory-mapped + // page without file backing, but we need a fallback of opening /dev/zero + // for strictly POSIX platforms instead. + int fd; +#if defined(MAP_ANON) + fd = -1; +#else + fd = open("/dev/zero", O_RDWR); + if (fd == -1) { + EC = std::error_code(errno, std::generic_category()); + return MemoryBlock(); + } +#endif - int MMFlags = MAP_PRIVATE | MAP_ANON; + int MMFlags = MAP_PRIVATE; +#if defined(MAP_ANON) + MMFlags |= MAP_ANON; +#endif int Protect = getPosixProtectionFlags(PFlags); #if defined(__NetBSD__) && defined(PROT_MPROTECT) @@ -111,13 +126,24 @@ Memory::allocateMappedMemory(size_t NumBytes, void *Addr = ::mmap(reinterpret_cast<void *>(Start), NumBytes, Protect, MMFlags, fd, 0); if (Addr == MAP_FAILED) { - if (NearBlock) //Try again without a near hint + if (NearBlock) { //Try again without a near hint +#if !defined(MAP_ANON) + close(fd); +#endif return allocateMappedMemory(NumBytes, nullptr, PFlags, EC); + } EC = std::error_code(errno, std::generic_category()); +#if !defined(MAP_ANON) + close(fd); +#endif return MemoryBlock(); } +#if !defined(MAP_ANON) + close(fd); +#endif + MemoryBlock Result; Result.Address = Addr; Result.Size = NumBytes; |

