Index: lldb/source/Core/Disassembler.cpp =================================================================== --- lldb/source/Core/Disassembler.cpp +++ lldb/source/Core/Disassembler.cpp @@ -43,6 +43,7 @@ #include "lldb/lldb-private-types.h" #include "llvm/ADT/Triple.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Errno.h" #include #include @@ -942,14 +943,14 @@ if (!fgets(buffer, 255, test_file)) { out_stream->Printf( "Instruction::TestEmulation: Error reading first line of test file.\n"); - fclose(test_file); + llvm::sys::RetryAfterSignal(EOF, fclose, test_file); return false; } if (strncmp(buffer, "InstructionEmulationState={", 27) != 0) { out_stream->Printf("Instructin::TestEmulation: Test file does not contain " "emulation state dictionary\n"); - fclose(test_file); + llvm::sys::RetryAfterSignal(EOF, fclose, test_file); return false; } @@ -960,11 +961,11 @@ if (!data_dictionary_sp) { out_stream->Printf( "Instruction::TestEmulation: Error reading Dictionary Object.\n"); - fclose(test_file); + llvm::sys::RetryAfterSignal(EOF, fclose, test_file); return false; } - fclose(test_file); + llvm::sys::RetryAfterSignal(EOF, fclose, test_file); OptionValueDictionary *data_dictionary = data_dictionary_sp->GetAsDictionary(); Index: lldb/source/Host/common/File.cpp =================================================================== --- lldb/source/Host/common/File.cpp +++ lldb/source/Host/common/File.cpp @@ -158,12 +158,12 @@ Status File::Close() { Status error; if (StreamIsValid() && m_own_stream) { - if (::fclose(m_stream) == EOF) + if (llvm::sys::RetryAfterSignal(EOF, ::fclose, m_stream) == EOF) error.SetErrorToErrno(); } if (DescriptorIsValid() && m_should_close_fd) { - if (::close(m_descriptor) != 0) + if (llvm::sys::RetryAfterSignal(-1, ::close, m_descriptor) != 0) error.SetErrorToErrno(); } m_descriptor = kInvalidDescriptor; Index: lldb/source/Host/common/MainLoop.cpp =================================================================== --- lldb/source/Host/common/MainLoop.cpp +++ lldb/source/Host/common/MainLoop.cpp @@ -11,6 +11,9 @@ #include "lldb/Host/MainLoop.h" #include "lldb/Host/PosixApi.h" #include "lldb/Utility/Status.h" + +#include "llvm/Support/Errno.h" + #include #include #include @@ -260,7 +263,7 @@ } MainLoop::~MainLoop() { #if HAVE_SYS_EVENT_H - close(m_kqueue); + llvm::sys::RetryAfterSignal(-1, close, m_kqueue); #endif assert(m_read_fds.size() == 0); assert(m_signals.size() == 0); Index: lldb/source/Host/common/PseudoTerminal.cpp =================================================================== --- lldb/source/Host/common/PseudoTerminal.cpp +++ lldb/source/Host/common/PseudoTerminal.cpp @@ -58,7 +58,7 @@ //---------------------------------------------------------------------- void PseudoTerminal::CloseMasterFileDescriptor() { if (m_master_fd >= 0) { - ::close(m_master_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_master_fd); m_master_fd = invalid_fd; } } @@ -68,7 +68,7 @@ //---------------------------------------------------------------------- void PseudoTerminal::CloseSlaveFileDescriptor() { if (m_slave_fd >= 0) { - ::close(m_slave_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_slave_fd); m_slave_fd = invalid_fd; } } Index: lldb/source/Host/common/Socket.cpp =================================================================== --- lldb/source/Host/common/Socket.cpp +++ lldb/source/Host/common/Socket.cpp @@ -18,6 +18,7 @@ #include "lldb/Utility/RegularExpression.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Errno.h" #ifndef LLDB_DISABLE_POSIX #include "lldb/Host/posix/DomainSocket.h" @@ -371,7 +372,7 @@ #if defined(_WIN32) bool success = !!closesocket(m_socket); #else - bool success = !!::close(m_socket); + bool success = !!llvm::sys::RetryAfterSignal(-1, ::close, m_socket); #endif // A reference to a FD was passed in, set it to an invalid value m_socket = kInvalidSocketValue; @@ -442,7 +443,7 @@ if (flags != -1 && ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC) != -1) return fd; SetLastError(error); - close(fd); + llvm::sys::RetryAfterSignal(-1, close, fd); } return fd; #elif defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4) @@ -450,9 +451,11 @@ if (!child_processes_inherit) { flags |= SOCK_CLOEXEC; } - NativeSocket fd = ::accept4(sockfd, addr, addrlen, flags); + NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept4, + sockfd, addr, addrlen, flags); #else - NativeSocket fd = ::accept(sockfd, addr, addrlen); + NativeSocket fd = llvm::sys::RetryAfterSignal(-1, ::accept, + sockfd, addr, addrlen); #endif if (fd == kInvalidSocketValue) SetLastError(error); Index: lldb/source/Host/common/TCPSocket.cpp =================================================================== --- lldb/source/Host/common/TCPSocket.cpp +++ lldb/source/Host/common/TCPSocket.cpp @@ -17,6 +17,7 @@ #include "lldb/Utility/Log.h" #include "llvm/Config/llvm-config.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/raw_ostream.h" #ifndef LLDB_DISABLE_POSIX @@ -150,8 +151,8 @@ address.SetPort(port); - if (-1 == ::connect(GetNativeSocket(), &address.sockaddr(), - address.GetLength())) { + if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect, + GetNativeSocket(), &address.sockaddr(), address.GetLength())) { CLOSE_SOCKET(GetNativeSocket()); continue; } Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp =================================================================== --- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -252,8 +252,10 @@ ::tcgetattr(fd, &options); // Set port speed to maximum - ::cfsetospeed(&options, B115200); - ::cfsetispeed(&options, B115200); + llvm::sys::RetryAfterSignal(-1, ::cfsetospeed, + &options, B115200); + llvm::sys::RetryAfterSignal(-1, ::cfsetispeed, + &options, B115200); // Raw input, disable echo and signals options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); Index: lldb/source/Host/posix/DomainSocket.cpp =================================================================== --- lldb/source/Host/posix/DomainSocket.cpp +++ lldb/source/Host/posix/DomainSocket.cpp @@ -8,6 +8,7 @@ #include "lldb/Host/posix/DomainSocket.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" #include @@ -81,8 +82,8 @@ m_socket = CreateSocket(kDomain, kType, 0, m_child_processes_inherit, error); if (error.Fail()) return error; - if (::connect(GetNativeSocket(), (struct sockaddr *)&saddr_un, saddr_un_len) < - 0) + if (llvm::sys::RetryAfterSignal(-1, ::connect, GetNativeSocket(), + (struct sockaddr *)&saddr_un, saddr_un_len) < 0) SetLastError(error); return error; Index: lldb/source/Host/posix/PipePosix.cpp =================================================================== --- lldb/source/Host/posix/PipePosix.cpp +++ lldb/source/Host/posix/PipePosix.cpp @@ -10,6 +10,7 @@ #include "lldb/Host/HostInfo.h" #include "lldb/Utility/SelectHelper.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) @@ -240,14 +241,14 @@ void PipePosix::CloseReadFileDescriptor() { if (CanRead()) { - close(m_fds[READ]); + llvm::sys::RetryAfterSignal(-1, close, m_fds[READ]); m_fds[READ] = PipePosix::kInvalidDescriptor; } } void PipePosix::CloseWriteFileDescriptor() { if (CanWrite()) { - close(m_fds[WRITE]); + llvm::sys::RetryAfterSignal(-1, close, m_fds[WRITE]); m_fds[WRITE] = PipePosix::kInvalidDescriptor; } } Index: lldb/source/Host/posix/ProcessLauncherPosixFork.cpp =================================================================== --- lldb/source/Host/posix/ProcessLauncherPosixFork.cpp +++ lldb/source/Host/posix/ProcessLauncherPosixFork.cpp @@ -83,7 +83,7 @@ if (::dup2(target_fd, fd) == -1) ExitWithError(error_fd, "DupDescriptor-dup2"); - ::close(target_fd); + llvm::sys::RetryAfterSignal(-1, ::close, target_fd); return; } @@ -98,7 +98,7 @@ const FileAction &action = *info.GetFileActionAtIndex(i); switch (action.GetAction()) { case FileAction::eFileActionClose: - if (close(action.GetFD()) != 0) + if (llvm::sys::RetryAfterSignal(-1, close, action.GetFD()) != 0) ExitWithError(error_fd, "close"); break; case FileAction::eFileActionDuplicate: @@ -144,7 +144,7 @@ // actually rely on passing open descriptors to child processes. for (int fd = 3; fd < sysconf(_SC_OPEN_MAX); ++fd) if (!info.GetFileActionForFD(fd) && fd != error_fd) - close(fd); + llvm::sys::RetryAfterSignal(-1, close, fd); // Start tracing this child that is about to exec. if (ptrace(PT_TRACE_ME, 0, nullptr, 0) == -1) Index: lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp =================================================================== --- lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp +++ lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp @@ -1395,7 +1395,7 @@ if (dup2(target_fd, fd) == -1) return false; - return (close(target_fd) == -1) ? false : true; + return (llvm::sys::RetryAfterSignal(-1, close, target_fd) == -1) ? false : true; } void ProcessMonitor::StopMonitoringChildProcess() { @@ -1412,7 +1412,7 @@ sem_destroy(&m_operation_pending); sem_destroy(&m_operation_done); if (m_terminal_fd >= 0) { - close(m_terminal_fd); + llvm::sys::RetryAfterSignal(-1, close, m_terminal_fd); m_terminal_fd = -1; } } Index: lldb/source/Plugins/Process/Linux/ProcessorTrace.h =================================================================== --- lldb/source/Plugins/Process/Linux/ProcessorTrace.h +++ lldb/source/Plugins/Process/Linux/ProcessorTrace.h @@ -14,6 +14,7 @@ #include "lldb/lldb-types.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/Support/Errno.h" #include #include @@ -63,7 +64,7 @@ return; if (*ptr == -1) return; - close(*ptr); + llvm::sys::RetryAfterSignal(-1, close, *ptr); std::default_delete()(ptr); } }; Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -21,6 +21,7 @@ #include "lldb/Utility/Stream.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errno.h" #include @@ -39,7 +40,7 @@ void PythonObject::Dump(Stream &strm) const { if (m_py_obj) { - FILE *file = ::tmpfile(); + FILE *file = llvm::sys::RetryAfterSignal(nullptr, ::tmpfile); if (file) { ::PyObject_Print(m_py_obj, file, 0); const long length = ftell(file); @@ -47,11 +48,12 @@ ::rewind(file); std::vector file_contents(length, '\0'); const size_t length_read = - ::fread(file_contents.data(), 1, file_contents.size(), file); + llvm::sys::RetryAfterSignal(0, ::fread, + file_contents.data(), 1, file_contents.size(), file); if (length_read > 0) strm.Write(file_contents.data(), length_read); } - ::fclose(file); + llvm::sys::RetryAfterSignal(EOF, ::fclose, file); } } else strm.PutCString("NULL"); Index: lldb/tools/darwin-debug/darwin-debug.cpp =================================================================== --- lldb/tools/darwin-debug/darwin-debug.cpp +++ lldb/tools/darwin-debug/darwin-debug.cpp @@ -39,6 +39,8 @@ #include +#include "llvm/Support/Errno.h" + #ifndef _POSIX_SPAWN_DISABLE_ASLR #define _POSIX_SPAWN_DISABLE_ASLR 0x0100 #endif @@ -287,7 +289,8 @@ saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; saddr_un.sun_len = SUN_LEN(&saddr_un); - if (::connect(s, (struct sockaddr *)&saddr_un, SUN_LEN(&saddr_un)) < 0) { + if (llvm::sys::RetryAfterSignal(-1, ::connect, s, + (struct sockaddr *)&saddr_un, SUN_LEN(&saddr_un)) < 0) { perror("error: connect (socket, &saddr_un, saddr_un_len)"); exit(1); } @@ -305,7 +308,7 @@ } // We are done with the socket - close(s); + llvm::sys::RetryAfterSignal(-1, close, s); system("clear"); printf("Launching: '%s'\n", argv[0]); Index: lldb/tools/debugserver/source/MacOSX/MachProcess.h =================================================================== --- lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ lldb/tools/debugserver/source/MacOSX/MachProcess.h @@ -36,6 +36,8 @@ #include "PThreadMutex.h" #include "ThreadInfo.h" +#include "llvm/Support/Errno.h" + class DNBThreadResumeActions; class MachProcess { @@ -318,15 +320,15 @@ size_t GetAvailableSTDERR(char *buf, size_t buf_size); void CloseChildFileDescriptors() { if (m_child_stdin >= 0) { - ::close(m_child_stdin); + llvm::sys::RetryAfterSignal(-1, ::close, m_child_stdin); m_child_stdin = -1; } if (m_child_stdout >= 0) { - ::close(m_child_stdout); + llvm::sys::RetryAfterSignal(-1, ::close, m_child_stdout); m_child_stdout = -1; } if (m_child_stderr >= 0) { - ::close(m_child_stderr); + llvm::sys::RetryAfterSignal(-1, ::close, m_child_stderr); m_child_stderr = -1; } } Index: lldb/tools/debugserver/source/PseudoTerminal.cpp =================================================================== --- lldb/tools/debugserver/source/PseudoTerminal.cpp +++ lldb/tools/debugserver/source/PseudoTerminal.cpp @@ -11,6 +11,9 @@ //===----------------------------------------------------------------------===// #include "PseudoTerminal.h" + +#include "llvm/Support/Errno.h" + #include #include #include @@ -38,7 +41,7 @@ //---------------------------------------------------------------------- void PseudoTerminal::CloseMaster() { if (m_master_fd > 0) { - ::close(m_master_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_master_fd); m_master_fd = invalid_fd; } } @@ -48,7 +51,7 @@ //---------------------------------------------------------------------- void PseudoTerminal::CloseSlave() { if (m_slave_fd > 0) { - ::close(m_slave_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_slave_fd); m_slave_fd = invalid_fd; } } Index: lldb/tools/debugserver/source/RNBSocket.cpp =================================================================== --- lldb/tools/debugserver/source/RNBSocket.cpp +++ lldb/tools/debugserver/source/RNBSocket.cpp @@ -25,6 +25,7 @@ #include #include "lldb/Host/SocketAddress.h" +#include "llvm/Support/Errno.h" #ifdef WITH_LOCKDOWN #include "lockdown.h" @@ -169,7 +170,8 @@ lldb_private::SocketAddress &addr_in = socket_pair->second; lldb_private::SocketAddress accept_addr; socklen_t sa_len = accept_addr.GetMaxLength(); - m_fd = ::accept(sock_fd, &accept_addr.sockaddr(), &sa_len); + m_fd = llvm::sys::RetryAfterSignal(-1, ::accept, + sock_fd, &accept_addr.sockaddr(), &sa_len); if (m_fd == -1) { err.SetError(errno, DNBError::POSIX); @@ -182,7 +184,7 @@ if (accept_addr == addr_in) accept_connection = true; else { - ::close(m_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_fd); m_fd = -1; ::fprintf( stderr, @@ -230,7 +232,8 @@ address.SetPort(port); - if (-1 == ::connect(m_fd, &address.sockaddr(), address.GetLength())) { + if (-1 == llvm::sys::RetryAfterSignal(-1, ::connect, m_fd, + &address.sockaddr(), address.GetLength())) { Disconnect(false); continue; } @@ -384,7 +387,7 @@ int close_err = 0; if (fd > 0) { errno = 0; - close_err = close(fd); + close_err = llvm::sys::RetryAfterSignal(-1, close, fd); fd = -1; } return close_err != 0 ? rnb_err : rnb_success; Index: lldb/tools/debugserver/source/debugserver.cpp =================================================================== --- lldb/tools/debugserver/source/debugserver.cpp +++ lldb/tools/debugserver/source/debugserver.cpp @@ -681,8 +681,9 @@ saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0'; saddr_un.sun_len = SUN_LEN(&saddr_un); - if (::connect(s, (struct sockaddr *)&saddr_un, - static_cast(SUN_LEN(&saddr_un))) < 0) { + if (llvm::sys::RetryAfterSignal(-1, ::connect, s, + (struct sockaddr *)&saddr_un, + static_cast(SUN_LEN(&saddr_un))) < 0) { perror("error: connect (socket, &saddr_un, saddr_un_len)"); exit(1); } @@ -705,7 +706,7 @@ //::printf ("send () sucess!!\n"); // We are done with the socket - close(s); + llvm::sys::RetryAfterSignal(-1, close, s); } } @@ -719,7 +720,7 @@ ::snprintf(port_str, sizeof(port_str), "%u", port); // Write the port number as a C string with the NULL terminator ::write(fd, port_str, port_str_len + 1); - close(fd); + llvm::sys::RetryAfterSignal(-1, close, fd); } } } Index: lldb/tools/driver/Driver.cpp =================================================================== --- lldb/tools/driver/Driver.cpp +++ lldb/tools/driver/Driver.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" @@ -500,7 +501,7 @@ _close(fds[WRITE]); fds[WRITE] = -1; #else - close(fds[WRITE]); + llvm::sys::RetryAfterSignal(-1, close, fds[WRITE]); fds[WRITE] = -1; #endif // Now open the read file descriptor in a FILE * that we can give to @@ -534,7 +535,7 @@ _close(fds[WRITE]); fds[WRITE] = -1; #else - close(fds[WRITE]); + llvm::sys::RetryAfterSignal(-1, close, fds[WRITE]); fds[WRITE] = -1; #endif } @@ -544,7 +545,7 @@ _close(fds[READ]); fds[READ] = -1; #else - close(fds[READ]); + llvm::sys::RetryAfterSignal(-1, close, fds[READ]); fds[READ] = -1; #endif } @@ -758,7 +759,7 @@ } reset_stdin_termios(); - fclose(stdin); + llvm::sys::RetryAfterSignal(EOF, fclose, stdin); int exit_code = sb_interpreter.GetQuitStatus(); SBDebugger::Destroy(m_debugger); Index: lldb/tools/lldb-mi/MIUtilFileStd.cpp =================================================================== --- lldb/tools/lldb-mi/MIUtilFileStd.cpp +++ lldb/tools/lldb-mi/MIUtilFileStd.cpp @@ -18,6 +18,7 @@ #include "lldb/Host/FileSystem.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errno.h" //++ //------------------------------------------------------------------------------------ @@ -195,7 +196,7 @@ if (m_pFileHandle == nullptr) return; - ::fclose(m_pFileHandle); + llvm::sys::RetryAfterSignal(EOF, ::fclose, m_pFileHandle); m_pFileHandle = nullptr; // m_bFileError = false; Do not reset as want to remain until next attempt at // open or create @@ -228,7 +229,7 @@ FILE *pTmp = nullptr; pTmp = ::fopen(vFileNamePath.c_str(), "wb"); if (pTmp != nullptr) { - ::fclose(pTmp); + llvm::sys::RetryAfterSignal(EOF, ::fclose, pTmp); return true; } Index: lldb/tools/lldb-perf/common/clang/lldb_perf_clang.cpp =================================================================== --- lldb/tools/lldb-perf/common/clang/lldb_perf_clang.cpp +++ lldb/tools/lldb-perf/common/clang/lldb_perf_clang.cpp @@ -13,6 +13,7 @@ #include "lldb-perf/lib/Timer.h" #include "lldb-perf/lib/Xcode.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/Support/Errno.h" #include #include #include @@ -124,7 +125,7 @@ } )"; write(fd, source_content, strlen(source_content)); - close(fd); + llvm::sys::RetryAfterSignal(-1, close, fd); } else { const char *error_cstr = strerror(errno); fprintf(stderr, Index: lldb/tools/lldb-vscode/IOStream.cpp =================================================================== --- lldb/tools/lldb-vscode/IOStream.cpp +++ lldb/tools/lldb-vscode/IOStream.cpp @@ -20,6 +20,8 @@ #include #include +#include "llvm/Support/Errno.h" + using namespace lldb_vscode; StreamDescriptor::StreamDescriptor() {} @@ -36,10 +38,10 @@ #if defined(_WIN32) ::closesocket(m_socket); #else - ::close(m_socket); + llvm::sys::RetryAfterSignal(-1, ::close, m_socket); #endif else - ::close(m_fd); + llvm::sys::RetryAfterSignal(-1, ::close, m_fd); } StreamDescriptor &StreamDescriptor::operator=(StreamDescriptor &&other) { Index: lldb/tools/lldb-vscode/lldb-vscode.cpp =================================================================== --- lldb/tools/lldb-vscode/lldb-vscode.cpp +++ lldb/tools/lldb-vscode/lldb-vscode.cpp @@ -41,6 +41,7 @@ #include #include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" @@ -90,7 +91,8 @@ } else { listen(sockfd, 5); socklen_t clilen = sizeof(cli_addr); - newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen); + newsockfd = llvm::sys::RetryAfterSignal(-1, accept, + sockfd, (struct sockaddr *)&cli_addr, &clilen); if (newsockfd < 0) if (g_vsc.log) *g_vsc.log << "error: accept (" << strerror(errno) << ")" @@ -99,7 +101,7 @@ #if defined(_WIN32) closesocket(sockfd); #else - close(sockfd); + llvm::sys::RetryAfterSignal(-1, close, sockfd); #endif } return newsockfd;