From fc54427e76c89e567390dd4a1d64a65568f4ec26 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 1 Apr 2022 15:59:18 -0700 Subject: [lldb] Refactor DataBuffer so we can map files as read-only Currently, all data buffers are assumed to be writable. This is a problem on macOS where it's not allowed to load unsigned binaries in memory as writable. To be more precise, MAP_RESILIENT_CODESIGN and MAP_RESILIENT_MEDIA need to be set for mapped (unsigned) binaries on our platform. Binaries are mapped through FileSystem::CreateDataBuffer which returns a DataBufferLLVM. The latter is backed by a llvm::WritableMemoryBuffer because every DataBuffer in LLDB is considered to be writable. In order to use a read-only llvm::MemoryBuffer I had to split our abstraction around it. This patch distinguishes between a DataBuffer (read-only) and WritableDataBuffer (read-write) and updates LLDB to use the appropriate one. rdar://74890607 Differential revision: https://reviews.llvm.org/D122856 --- .../RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp') diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index 1d91fb8f4cd8..2cf166bc8a1d 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -2442,7 +2442,7 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, auto data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath()); // Cast start of buffer to FileHeader and use pointer to read metadata - void *file_buf = data_sp->GetBytes(); + const void *file_buf = data_sp->GetBytes(); if (file_buf == nullptr || data_sp->GetByteSize() < (sizeof(AllocationDetails::FileHeader) + sizeof(AllocationDetails::ElementHeader))) { @@ -2451,7 +2451,7 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, return false; } const AllocationDetails::FileHeader *file_header = - static_cast(file_buf); + static_cast(file_buf); // Check file starts with ascii characters "RSAD" if (memcmp(file_header->ident, "RSAD", 4)) { @@ -2463,8 +2463,9 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, // Look at the type of the root element in the header AllocationDetails::ElementHeader root_el_hdr; - memcpy(&root_el_hdr, static_cast(file_buf) + - sizeof(AllocationDetails::FileHeader), + memcpy(&root_el_hdr, + static_cast(file_buf) + + sizeof(AllocationDetails::FileHeader), sizeof(AllocationDetails::ElementHeader)); LLDB_LOGF(log, "%s - header type %" PRIu32 ", element size %" PRIu32, @@ -2515,7 +2516,7 @@ bool RenderScriptRuntime::LoadAllocation(Stream &strm, const uint32_t alloc_id, } // Advance buffer past header - file_buf = static_cast(file_buf) + file_header->hdr_size; + file_buf = static_cast(file_buf) + file_header->hdr_size; // Calculate size of allocation data in file size_t size = data_sp->GetByteSize() - file_header->hdr_size; -- cgit v1.2.3