diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-12 21:24:50 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-11-12 21:24:50 +0000 |
commit | 87e403aa4f62d7385999041abce5fdadb8741a47 (patch) | |
tree | 50a1ddaec65b06269d32c1455915f0fd4340f41e /lldb/source/Host/common/FileSystem.cpp | |
parent | e565e5a9621de42e7b82ad50803fe03beafa0334 (diff) | |
download | llvm-87e403aa4f62d7385999041abce5fdadb8741a47.zip llvm-87e403aa4f62d7385999041abce5fdadb8741a47.tar.gz llvm-87e403aa4f62d7385999041abce5fdadb8741a47.tar.bz2 |
Re-land "Extract construction of DataBufferLLVM into FileSystem"
This fixes some UB in isLocal detected by the sanitized bot.
llvm-svn: 346707
Diffstat (limited to 'lldb/source/Host/common/FileSystem.cpp')
-rw-r--r-- | lldb/source/Host/common/FileSystem.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lldb/source/Host/common/FileSystem.cpp b/lldb/source/Host/common/FileSystem.cpp index a9ed5bd..a010599 100644 --- a/lldb/source/Host/common/FileSystem.cpp +++ b/lldb/source/Host/common/FileSystem.cpp @@ -135,6 +135,16 @@ bool FileSystem::IsDirectory(const FileSpec &file_spec) const { return IsDirectory(file_spec.GetPath()); } +bool FileSystem::IsLocal(const Twine &path) const { + bool b = false; + m_fs->isLocal(path, b); + return b; +} + +bool FileSystem::IsLocal(const FileSpec &file_spec) const { + return IsLocal(file_spec.GetPath()); +} + void FileSystem::EnumerateDirectory(Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, @@ -218,6 +228,34 @@ void FileSystem::Resolve(FileSpec &file_spec) { file_spec.SetIsResolved(true); } +std::shared_ptr<DataBufferLLVM> +FileSystem::CreateDataBuffer(const llvm::Twine &path, uint64_t size, + uint64_t offset) { + const bool is_volatile = !IsLocal(path); + + std::unique_ptr<llvm::WritableMemoryBuffer> buffer; + if (size == 0) { + auto buffer_or_error = + llvm::WritableMemoryBuffer::getFile(path, -1, is_volatile); + if (!buffer_or_error) + return nullptr; + buffer = std::move(*buffer_or_error); + } else { + auto buffer_or_error = llvm::WritableMemoryBuffer::getFileSlice( + path, size, offset, is_volatile); + if (!buffer_or_error) + return nullptr; + buffer = std::move(*buffer_or_error); + } + return std::shared_ptr<DataBufferLLVM>(new DataBufferLLVM(std::move(buffer))); +} + +std::shared_ptr<DataBufferLLVM> +FileSystem::CreateDataBuffer(const FileSpec &file_spec, uint64_t size, + uint64_t offset) { + return CreateDataBuffer(file_spec.GetPath(), size, offset); +} + bool FileSystem::ResolveExecutableLocation(FileSpec &file_spec) { // If the directory is set there's nothing to do. const ConstString &directory = file_spec.GetDirectory(); |