diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-20 14:16:56 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-20 14:16:56 +0000 |
commit | 2cab237b5dbfe1b3e9c7aa7a3c02d2b98fcf7462 (patch) | |
tree | 524fe828571f81358bba62fdb6d04c6e5e96a2a4 /contrib/llvm/lib/Support/Unix | |
parent | 6c7828a2807ea5e50c79ca42dbedf2b589ce63b2 (diff) | |
parent | 044eb2f6afba375a914ac9d8024f8f5142bb912e (diff) |
Notes
Diffstat (limited to 'contrib/llvm/lib/Support/Unix')
-rw-r--r-- | contrib/llvm/lib/Support/Unix/DynamicLibrary.inc | 2 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Memory.inc | 155 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Path.inc | 90 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Process.inc | 4 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Program.inc | 64 | ||||
-rw-r--r-- | contrib/llvm/lib/Support/Unix/Threading.inc | 10 |
6 files changed, 88 insertions, 237 deletions
diff --git a/contrib/llvm/lib/Support/Unix/DynamicLibrary.inc b/contrib/llvm/lib/Support/Unix/DynamicLibrary.inc index f05103ccd1eb..029451f347e8 100644 --- a/contrib/llvm/lib/Support/Unix/DynamicLibrary.inc +++ b/contrib/llvm/lib/Support/Unix/DynamicLibrary.inc @@ -71,7 +71,7 @@ void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) { // Must declare the symbols in the global namespace. static void *DoSearch(const char* SymbolName) { #define EXPLICIT_SYMBOL(SYM) \ - extern void *SYM; if (!strcmp(SymbolName, #SYM)) return &SYM + extern void *SYM; if (!strcmp(SymbolName, #SYM)) return (void*)&SYM // If this is darwin, it has some funky issues, try to solve them here. Some // important symbols are marked 'private external' which doesn't allow diff --git a/contrib/llvm/lib/Support/Unix/Memory.inc b/contrib/llvm/lib/Support/Unix/Memory.inc index dd39ef935bf9..848548d18177 100644 --- a/contrib/llvm/lib/Support/Unix/Memory.inc +++ b/contrib/llvm/lib/Support/Unix/Memory.inc @@ -27,7 +27,7 @@ #if defined(__mips__) # if defined(__OpenBSD__) # include <mips64/sysarch.h> -# else +# elif !defined(__FreeBSD__) # include <sys/cachectl.h> # endif #endif @@ -102,6 +102,10 @@ Memory::allocateMappedMemory(size_t NumBytes, int Protect = getPosixProtectionFlags(PFlags); +#if defined(__NetBSD__) && defined(PROT_MPROTECT) + Protect |= PROT_MPROTECT(PROT_READ | PROT_WRITE | PROT_EXEC); +#endif + // Use any near hint and the page size to set a page-aligned starting address uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) + NearBlock->size() : 0; @@ -122,8 +126,12 @@ Memory::allocateMappedMemory(size_t NumBytes, Result.Address = Addr; Result.Size = NumPages*PageSize; - if (PFlags & MF_EXEC) - Memory::InvalidateInstructionCache(Result.Address, Result.Size); + // Rely on protectMappedMemory to invalidate instruction cache. + if (PFlags & MF_EXEC) { + EC = Memory::protectMappedMemory (Result, PFlags); + if (EC != std::error_code()) + return MemoryBlock(); + } return Result; } @@ -152,141 +160,34 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { return std::error_code(EINVAL, std::generic_category()); int Protect = getPosixProtectionFlags(Flags); - uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize); uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize); - int Result = ::mprotect((void *)Start, End - Start, Protect); - - if (Result != 0) - return std::error_code(errno, std::generic_category()); - - if (Flags & MF_EXEC) - Memory::InvalidateInstructionCache(M.Address, M.Size); - - return std::error_code(); -} - -/// AllocateRWX - Allocate a slab of memory with read/write/execute -/// permissions. This is typically used for JIT applications where we want -/// to emit code to the memory then jump to it. Getting this type of memory -/// is very OS specific. -/// -MemoryBlock -Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock, - std::string *ErrMsg) { - if (NumBytes == 0) return MemoryBlock(); - - static const size_t PageSize = Process::getPageSize(); - size_t NumPages = (NumBytes+PageSize-1)/PageSize; - - int fd = -1; - - int flags = MAP_PRIVATE | -#ifdef MAP_ANONYMOUS - MAP_ANONYMOUS -#else - MAP_ANON -#endif - ; - - void* start = NearBlock ? (unsigned char*)NearBlock->base() + - NearBlock->size() : nullptr; - -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_EXEC, - flags, fd, 0); -#elif defined(__NetBSD__) && defined(PROT_MPROTECT) - void *pa = - ::mmap(start, PageSize * NumPages, - PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC), flags, fd, 0); -#else - void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, - flags, fd, 0); -#endif - if (pa == MAP_FAILED) { - if (NearBlock) //Try again without a near hint - return AllocateRWX(NumBytes, nullptr); - MakeErrMsg(ErrMsg, "Can't allocate RWX Memory"); - return MemoryBlock(); - } + bool InvalidateCache = (Flags & MF_EXEC); -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)pa, - (vm_size_t)(PageSize*NumPages), 0, - VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY); - if (KERN_SUCCESS != kr) { - MakeErrMsg(ErrMsg, "vm_protect max RX failed"); - return MemoryBlock(); - } +#if defined(__arm__) || defined(__aarch64__) + // Certain ARM implementations treat icache clear instruction as a memory read, + // and CPU segfaults on trying to clear cache on !PROT_READ page. Therefore we need + // to temporarily add PROT_READ for the sake of flushing the instruction caches. + if (InvalidateCache && !(Protect & PROT_READ)) { + int Result = ::mprotect((void *)Start, End - Start, Protect | PROT_READ); + if (Result != 0) + return std::error_code(errno, std::generic_category()); - kr = vm_protect(mach_task_self(), (vm_address_t)pa, - (vm_size_t)(PageSize*NumPages), 0, - VM_PROT_READ | VM_PROT_WRITE); - if (KERN_SUCCESS != kr) { - MakeErrMsg(ErrMsg, "vm_protect RW failed"); - return MemoryBlock(); + Memory::InvalidateInstructionCache(M.Address, M.Size); + InvalidateCache = false; } #endif - MemoryBlock result; - result.Address = pa; - result.Size = NumPages*PageSize; - - return result; -} - -bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) { - if (M.Address == nullptr || M.Size == 0) return false; - if (0 != ::munmap(M.Address, M.Size)) - return MakeErrMsg(ErrMsg, "Can't release RWX Memory"); - return false; -} - -bool Memory::setWritable (MemoryBlock &M, std::string *ErrMsg) { -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - if (M.Address == 0 || M.Size == 0) return false; - Memory::InvalidateInstructionCache(M.Address, M.Size); - kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address, - (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_WRITE); - return KERN_SUCCESS == kr; -#else - return true; -#endif -} + int Result = ::mprotect((void *)Start, End - Start, Protect); -bool Memory::setExecutable (MemoryBlock &M, std::string *ErrMsg) { - if (M.Address == nullptr || M.Size == 0) return false; - Memory::InvalidateInstructionCache(M.Address, M.Size); -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address, - (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY); - return KERN_SUCCESS == kr; -#else - return true; -#endif -} + if (Result != 0) + return std::error_code(errno, std::generic_category()); -bool Memory::setRangeWritable(const void *Addr, size_t Size) { -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)Addr, - (vm_size_t)Size, 0, - VM_PROT_READ | VM_PROT_WRITE); - return KERN_SUCCESS == kr; -#else - return true; -#endif -} + if (InvalidateCache) + Memory::InvalidateInstructionCache(M.Address, M.Size); -bool Memory::setRangeExecutable(const void *Addr, size_t Size) { -#if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) - kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)Addr, - (vm_size_t)Size, 0, - VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY); - return KERN_SUCCESS == kr; -#else - return true; -#endif + return std::error_code(); } /// InvalidateInstructionCache - Before the JIT can run a block of code diff --git a/contrib/llvm/lib/Support/Unix/Path.inc b/contrib/llvm/lib/Support/Unix/Path.inc index 67edb46f0025..2ecb97316c87 100644 --- a/contrib/llvm/lib/Support/Unix/Path.inc +++ b/contrib/llvm/lib/Support/Unix/Path.inc @@ -108,10 +108,9 @@ using namespace llvm; namespace llvm { namespace sys { namespace fs { -#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ - defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \ - defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) || \ - defined(_AIX) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ + defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ + defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { @@ -180,9 +179,9 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { if (realpath(exe_path, link_path)) return link_path; } -#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ - defined(__OpenBSD__) || defined(__minix) || defined(__DragonFly__) || \ - defined(__FreeBSD_kernel__) || defined(_AIX) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ + defined(__minix) || defined(__DragonFly__) || \ + defined(__FreeBSD_kernel__) || defined(_AIX) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL) @@ -218,11 +217,11 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) { return ""; } -TimePoint<> file_status::getLastAccessedTime() const { +TimePoint<> basic_file_status::getLastAccessedTime() const { return toTimePoint(fs_st_atime); } -TimePoint<> file_status::getLastModificationTime() const { +TimePoint<> basic_file_status::getLastModificationTime() const { return toTimePoint(fs_st_mtime); } @@ -642,15 +641,9 @@ std::error_code mapped_file_region::init(int FD, uint64_t Offset, return std::error_code(); } -mapped_file_region::mapped_file_region(int fd, mapmode mode, uint64_t length, +mapped_file_region::mapped_file_region(int fd, mapmode mode, size_t length, uint64_t offset, std::error_code &ec) : Size(length), Mapping() { - // Make sure that the requested size fits within SIZE_T. - if (length > std::numeric_limits<size_t>::max()) { - ec = make_error_code(errc::invalid_argument); - return; - } - ec = init(fd, offset, mode); if (ec) Mapping = nullptr; @@ -661,7 +654,7 @@ mapped_file_region::~mapped_file_region() { ::munmap(Mapping, Size); } -uint64_t mapped_file_region::size() const { +size_t mapped_file_region::size() const { assert(Mapping && "Mapping failed but used anyway!"); return Size; } @@ -720,6 +713,13 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &it) { return std::error_code(); } +ErrorOr<basic_file_status> directory_entry::status() const { + file_status s; + if (auto EC = fs::status(Path, s, FollowSymlinks)) + return EC; + return s; +} + #if !defined(F_GETPATH) static bool hasProcSelfFD() { // If we have a /proc filesystem mounted, we can quickly establish the @@ -808,53 +808,6 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD, return std::error_code(); } -std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) { - if (FD < 0) - return make_error_code(errc::bad_file_descriptor); - -#if defined(F_GETPATH) - // When F_GETPATH is availble, it is the quickest way to get - // the path from a file descriptor. - ResultPath.reserve(MAXPATHLEN); - if (::fcntl(FD, F_GETPATH, ResultPath.begin()) == -1) - return std::error_code(errno, std::generic_category()); - - ResultPath.set_size(strlen(ResultPath.begin())); -#else - // If we have a /proc filesystem mounted, we can quickly establish the - // real name of the file with readlink. Otherwise, we don't know how to - // get the filename from a file descriptor. Give up. - if (!fs::hasProcSelfFD()) - return make_error_code(errc::function_not_supported); - - ResultPath.reserve(PATH_MAX); - char ProcPath[64]; - snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", FD); - ssize_t CharCount = ::readlink(ProcPath, ResultPath.begin(), ResultPath.capacity()); - if (CharCount < 0) - return std::error_code(errno, std::generic_category()); - - // Was the filename truncated? - if (static_cast<size_t>(CharCount) == ResultPath.capacity()) { - // Use lstat to get the size of the filename - struct stat sb; - if (::lstat(ProcPath, &sb) < 0) - return std::error_code(errno, std::generic_category()); - - ResultPath.reserve(sb.st_size + 1); - CharCount = ::readlink(ProcPath, ResultPath.begin(), ResultPath.capacity()); - if (CharCount < 0) - return std::error_code(errno, std::generic_category()); - - // Test for race condition: did the link size change? - if (CharCount > sb.st_size) - return std::error_code(ENAMETOOLONG, std::generic_category()); - } - ResultPath.set_size(static_cast<size_t>(CharCount)); -#endif - return std::error_code(); -} - template <typename T> static std::error_code remove_directories_impl(const T &Entry, bool IgnoreErrors) { @@ -863,12 +816,11 @@ static std::error_code remove_directories_impl(const T &Entry, directory_iterator End; while (Begin != End) { auto &Item = *Begin; - file_status st; - EC = Item.status(st); - if (EC && !IgnoreErrors) - return EC; + ErrorOr<basic_file_status> st = Item.status(); + if (!st && !IgnoreErrors) + return st.getError(); - if (is_directory(st)) { + if (is_directory(*st)) { EC = remove_directories_impl(Item, IgnoreErrors); if (EC && !IgnoreErrors) return EC; diff --git a/contrib/llvm/lib/Support/Unix/Process.inc b/contrib/llvm/lib/Support/Unix/Process.inc index 2d4662094682..e43650d707e3 100644 --- a/contrib/llvm/lib/Support/Unix/Process.inc +++ b/contrib/llvm/lib/Support/Unix/Process.inc @@ -32,10 +32,10 @@ #if HAVE_SIGNAL_H #include <signal.h> #endif -// DragonFlyBSD, OpenBSD, and Bitrig have deprecated <malloc.h> for +// DragonFlyBSD, and OpenBSD have deprecated <malloc.h> for // <stdlib.h> instead. Unix.h includes this for us already. #if defined(HAVE_MALLOC_H) && !defined(__DragonFly__) && \ - !defined(__OpenBSD__) && !defined(__Bitrig__) + !defined(__OpenBSD__) #include <malloc.h> #endif #if defined(HAVE_MALLCTL) diff --git a/contrib/llvm/lib/Support/Unix/Program.inc b/contrib/llvm/lib/Support/Unix/Program.inc index c866d5b5a84e..4f791991f3e8 100644 --- a/contrib/llvm/lib/Support/Unix/Program.inc +++ b/contrib/llvm/lib/Support/Unix/Program.inc @@ -93,7 +93,7 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, return errc::no_such_file_or_directory; } -static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { +static bool RedirectIO(Optional<StringRef> Path, int FD, std::string* ErrMsg) { if (!Path) // Noop return false; std::string File; @@ -144,8 +144,7 @@ static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, static void TimeOutHandler(int Sig) { } -static void SetMemoryLimits (unsigned size) -{ +static void SetMemoryLimits(unsigned size) { #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT struct rlimit r; __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur)) (size) * 1048576; @@ -165,9 +164,9 @@ static void SetMemoryLimits (unsigned size) } -static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, - const char **envp, const StringRef **redirects, - unsigned memoryLimit, std::string *ErrMsg) { +static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, + const char **Envp, ArrayRef<Optional<StringRef>> Redirects, + unsigned MemoryLimit, std::string *ErrMsg) { if (!llvm::sys::fs::exists(Program)) { if (ErrMsg) *ErrMsg = std::string("Executable \"") + Program.str() + @@ -178,7 +177,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, // If this OS has posix_spawn and there is no memory limit being implied, use // posix_spawn. It is more efficient than fork/exec. #ifdef HAVE_POSIX_SPAWN - if (memoryLimit == 0) { + if (MemoryLimit == 0) { posix_spawn_file_actions_t FileActionsStore; posix_spawn_file_actions_t *FileActions = nullptr; @@ -187,11 +186,12 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, // so we copy any StringRefs into this variable. std::string RedirectsStorage[3]; - if (redirects) { + if (!Redirects.empty()) { + assert(Redirects.size() == 3); std::string *RedirectsStr[3] = {nullptr, nullptr, nullptr}; for (int I = 0; I < 3; ++I) { - if (redirects[I]) { - RedirectsStorage[I] = *redirects[I]; + if (Redirects[I]) { + RedirectsStorage[I] = *Redirects[I]; RedirectsStr[I] = &RedirectsStorage[I]; } } @@ -203,8 +203,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, if (RedirectIO_PS(RedirectsStr[0], 0, ErrMsg, FileActions) || RedirectIO_PS(RedirectsStr[1], 1, ErrMsg, FileActions)) return false; - if (redirects[1] == nullptr || redirects[2] == nullptr || - *redirects[1] != *redirects[2]) { + if (!Redirects[1] || !Redirects[2] || *Redirects[1] != *Redirects[2]) { // Just redirect stderr if (RedirectIO_PS(RedirectsStr[2], 2, ErrMsg, FileActions)) return false; @@ -216,20 +215,20 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, } } - if (!envp) + if (!Envp) #if !USE_NSGETENVIRON - envp = const_cast<const char **>(environ); + Envp = const_cast<const char **>(environ); #else // environ is missing in dylibs. - envp = const_cast<const char **>(*_NSGetEnviron()); + Envp = const_cast<const char **>(*_NSGetEnviron()); #endif // Explicitly initialized to prevent what appears to be a valgrind false // positive. pid_t PID = 0; int Err = posix_spawn(&PID, Program.str().c_str(), FileActions, - /*attrp*/nullptr, const_cast<char **>(args), - const_cast<char **>(envp)); + /*attrp*/nullptr, const_cast<char **>(Args), + const_cast<char **>(Envp)); if (FileActions) posix_spawn_file_actions_destroy(FileActions); @@ -254,13 +253,12 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, // Child process: Execute the program. case 0: { // Redirect file descriptors... - if (redirects) { + if (!Redirects.empty()) { // Redirect stdin - if (RedirectIO(redirects[0], 0, ErrMsg)) { return false; } + if (RedirectIO(Redirects[0], 0, ErrMsg)) { return false; } // Redirect stdout - if (RedirectIO(redirects[1], 1, ErrMsg)) { return false; } - if (redirects[1] && redirects[2] && - *(redirects[1]) == *(redirects[2])) { + if (RedirectIO(Redirects[1], 1, ErrMsg)) { return false; } + if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) { // If stdout and stderr should go to the same place, redirect stderr // to the FD already open for stdout. if (-1 == dup2(1,2)) { @@ -269,24 +267,24 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, } } else { // Just redirect stderr - if (RedirectIO(redirects[2], 2, ErrMsg)) { return false; } + if (RedirectIO(Redirects[2], 2, ErrMsg)) { return false; } } } // Set memory limits - if (memoryLimit!=0) { - SetMemoryLimits(memoryLimit); + if (MemoryLimit!=0) { + SetMemoryLimits(MemoryLimit); } // Execute! std::string PathStr = Program; - if (envp != nullptr) + if (Envp != nullptr) execve(PathStr.c_str(), - const_cast<char **>(args), - const_cast<char **>(envp)); + const_cast<char **>(Args), + const_cast<char **>(Envp)); else execv(PathStr.c_str(), - const_cast<char **>(args)); + const_cast<char **>(Args)); // If the execve() failed, we should exit. Follow Unix protocol and // return 127 if the executable was not found, and 126 otherwise. // Use _exit rather than exit so that atexit functions and static @@ -433,7 +431,8 @@ llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents, return EC; } -bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args) { +bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, + ArrayRef<const char *> Args) { static long ArgMax = sysconf(_SC_ARG_MAX); // System says no practical limit. @@ -444,9 +443,8 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<co long HalfArgMax = ArgMax / 2; size_t ArgLength = Program.size() + 1; - for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end(); - I != E; ++I) { - size_t length = strlen(*I); + for (const char* Arg : Args) { + size_t length = strlen(Arg); // Ensure that we do not exceed the MAX_ARG_STRLEN constant on Linux, which // does not have a constant unlike what the man pages would have you diff --git a/contrib/llvm/lib/Support/Unix/Threading.inc b/contrib/llvm/lib/Support/Unix/Threading.inc index 267af388ecdb..7369cff8466c 100644 --- a/contrib/llvm/lib/Support/Unix/Threading.inc +++ b/contrib/llvm/lib/Support/Unix/Threading.inc @@ -108,14 +108,14 @@ uint64_t llvm::get_threadid() { static constexpr uint32_t get_max_thread_name_length_impl() { #if defined(__NetBSD__) - return PTHREAD_MAX_NAMELEN_NP; + return PTHREAD_MAX_NAMELEN_NP; #elif defined(__APPLE__) - return 64; + return 64; #elif defined(__linux__) #if HAVE_PTHREAD_SETNAME_NP - return 16; + return 16; #else - return 0; + return 0; #endif #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) return 16; @@ -206,7 +206,7 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) { #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__) #if HAVE_PTHREAD_GETNAME_NP constexpr uint32_t len = get_max_thread_name_length_impl(); - char Buffer[len]; + char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive. if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len)) Name.append(Buffer, Buffer + strlen(Buffer)); #endif |