diff options
Diffstat (limited to 'contrib/llvm/lib/System')
-rw-r--r-- | contrib/llvm/lib/System/Disassembler.cpp | 16 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Path.cpp | 29 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Unix/Path.inc | 23 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Unix/Program.inc | 5 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Unix/Signals.inc | 17 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Win32/Path.inc | 6 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Win32/Signals.inc | 2 |
7 files changed, 46 insertions, 52 deletions
diff --git a/contrib/llvm/lib/System/Disassembler.cpp b/contrib/llvm/lib/System/Disassembler.cpp index bad427a..139e3be 100644 --- a/contrib/llvm/lib/System/Disassembler.cpp +++ b/contrib/llvm/lib/System/Disassembler.cpp @@ -44,33 +44,29 @@ std::string llvm::sys::disassembleBuffer(uint8_t* start, size_t length, uint64_t pc) { std::stringstream res; -#if defined (__i386__) || defined (__amd64__) || defined (__x86_64__) +#if (defined (__i386__) || defined (__amd64__) || defined (__x86_64__)) \ + && USE_UDIS86 unsigned bits; # if defined(__i386__) bits = 32; # else bits = 64; # endif - -# if USE_UDIS86 + ud_t ud_obj; - + ud_init(&ud_obj); ud_set_input_buffer(&ud_obj, start, length); ud_set_mode(&ud_obj, bits); ud_set_pc(&ud_obj, pc); ud_set_syntax(&ud_obj, UD_SYN_ATT); - + res << std::setbase(16) << std::setw(bits/4); - + while (ud_disassemble(&ud_obj)) { res << ud_insn_off(&ud_obj) << ":\t" << ud_insn_asm(&ud_obj) << "\n"; } -# else - res << "No disassembler available. See configure help for options.\n"; -# endif - #else res << "No disassembler available. See configure help for options.\n"; #endif diff --git a/contrib/llvm/lib/System/Path.cpp b/contrib/llvm/lib/System/Path.cpp index 6844530..1235257 100644 --- a/contrib/llvm/lib/System/Path.cpp +++ b/contrib/llvm/lib/System/Path.cpp @@ -136,26 +136,23 @@ sys::IdentifyFileType(const char *magic, unsigned length) { bool Path::isArchive() const { - if (canRead()) - return hasMagicNumber("!<arch>\012"); - return false; + return hasMagicNumber("!<arch>\012"); } bool Path::isDynamicLibrary() const { - if (canRead()) { - std::string Magic; - if (getMagicNumber(Magic, 64)) - switch (IdentifyFileType(Magic.c_str(), - static_cast<unsigned>(Magic.length()))) { - default: return false; - case Mach_O_FixedVirtualMemorySharedLib_FileType: - case Mach_O_DynamicallyLinkedSharedLib_FileType: - case Mach_O_DynamicallyLinkedSharedLibStub_FileType: - case ELF_SharedObject_FileType: - case COFF_FileType: return true; - } - } + std::string Magic; + if (getMagicNumber(Magic, 64)) + switch (IdentifyFileType(Magic.c_str(), + static_cast<unsigned>(Magic.length()))) { + default: return false; + case Mach_O_FixedVirtualMemorySharedLib_FileType: + case Mach_O_DynamicallyLinkedSharedLib_FileType: + case Mach_O_DynamicallyLinkedSharedLibStub_FileType: + case ELF_SharedObject_FileType: + case COFF_FileType: return true; + } + return false; } diff --git a/contrib/llvm/lib/System/Unix/Path.inc b/contrib/llvm/lib/System/Unix/Path.inc index 74596dc..bc104a3 100644 --- a/contrib/llvm/lib/System/Unix/Path.inc +++ b/contrib/llvm/lib/System/Unix/Path.inc @@ -421,10 +421,8 @@ bool Path::getMagicNumber(std::string &Magic, unsigned len) const { return false; ssize_t bytes_read = ::read(fd, Buf, len); ::close(fd); - if (ssize_t(len) != bytes_read) { - Magic.clear(); + if (ssize_t(len) != bytes_read) return false; - } Magic.assign(Buf, len); return true; } @@ -890,14 +888,19 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) { #else // Okay, looks like we have to do it all by our lonesome. static unsigned FCounter = 0; - unsigned offset = path.size() + 1; - while ( FCounter < 999999 && exists()) { - sprintf(FNBuffer+offset,"%06u",++FCounter); + // Try to initialize with unique value. + if (FCounter == 0) FCounter = ((unsigned)getpid() & 0xFFFF) << 8; + char* pos = strstr(FNBuffer, "XXXXXX"); + do { + if (++FCounter > 0xFFFFFF) { + return MakeErrMsg(ErrMsg, + path + ": can't make unique filename: too many files"); + } + sprintf(pos, "%06X", FCounter); path = FNBuffer; - } - if (FCounter > 999999) - return MakeErrMsg(ErrMsg, - path + ": can't make unique filename: too many files"); + } while (exists()); + // POSSIBLE SECURITY BUG: An attacker can easily guess the name and exploit + // LLVM. #endif return false; } diff --git a/contrib/llvm/lib/System/Unix/Program.inc b/contrib/llvm/lib/System/Unix/Program.inc index 358415f..0209f5a 100644 --- a/contrib/llvm/lib/System/Unix/Program.inc +++ b/contrib/llvm/lib/System/Unix/Program.inc @@ -310,12 +310,9 @@ Program::Wait(unsigned secondsToWait, // fact of having a handler at all causes the wait below to return with EINTR, // unlike if we used SIG_IGN. if (secondsToWait) { -#ifndef __HAIKU__ - Act.sa_sigaction = 0; -#endif + memset(&Act, 0, sizeof(Act)); Act.sa_handler = TimeOutHandler; sigemptyset(&Act.sa_mask); - Act.sa_flags = 0; sigaction(SIGALRM, &Act, &Old); alarm(secondsToWait); } diff --git a/contrib/llvm/lib/System/Unix/Signals.inc b/contrib/llvm/lib/System/Unix/Signals.inc index 9548816..1e74647 100644 --- a/contrib/llvm/lib/System/Unix/Signals.inc +++ b/contrib/llvm/lib/System/Unix/Signals.inc @@ -111,6 +111,14 @@ static void UnregisterHandlers() { } +/// RemoveFilesToRemove - Process the FilesToRemove list. This function +/// should be called with the SignalsMutex lock held. +static void RemoveFilesToRemove() { + while (!FilesToRemove.empty()) { + FilesToRemove.back().eraseFromDisk(true); + FilesToRemove.pop_back(); + } +} // SignalHandler - The signal handler that runs. static RETSIGTYPE SignalHandler(int Sig) { @@ -126,10 +134,7 @@ static RETSIGTYPE SignalHandler(int Sig) { sigprocmask(SIG_UNBLOCK, &SigMask, 0); SignalsMutex.acquire(); - while (!FilesToRemove.empty()) { - FilesToRemove.back().eraseFromDisk(true); - FilesToRemove.pop_back(); - } + RemoveFilesToRemove(); if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) { if (InterruptFunction) { @@ -153,7 +158,9 @@ static RETSIGTYPE SignalHandler(int Sig) { } void llvm::sys::RunInterruptHandlers() { - SignalHandler(SIGINT); + SignalsMutex.acquire(); + RemoveFilesToRemove(); + SignalsMutex.release(); } void llvm::sys::SetInterruptFunction(void (*IF)()) { diff --git a/contrib/llvm/lib/System/Win32/Path.inc b/contrib/llvm/lib/System/Win32/Path.inc index 5a0052f..379527d 100644 --- a/contrib/llvm/lib/System/Win32/Path.inc +++ b/contrib/llvm/lib/System/Win32/Path.inc @@ -281,12 +281,6 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { // FIXME: the above set of functions don't map to Windows very well. -bool -Path::isRootDirectory() const { - size_t len = path.size(); - return len > 0 && path[len-1] == '/'; -} - StringRef Path::getDirname() const { return getDirnameCharSep(path, "/"); } diff --git a/contrib/llvm/lib/System/Win32/Signals.inc b/contrib/llvm/lib/System/Win32/Signals.inc index a3a393c..d6db71b 100644 --- a/contrib/llvm/lib/System/Win32/Signals.inc +++ b/contrib/llvm/lib/System/Win32/Signals.inc @@ -283,7 +283,7 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) { #ifdef _MSC_VER if (ExitOnUnhandledExceptions) - _exit(-3); + _exit(-3); #endif // Allow dialog box to pop up allowing choice to start debugger. |