summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2022-04-01 15:59:18 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2022-04-05 13:46:37 -0700
commitfc54427e76c89e567390dd4a1d64a65568f4ec26 (patch)
treed785373d3b04cb1cee280af9da4d7f510dbeaef0 /lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
parent4169650537622ef278b4d62ef5fb37aeb0ee9f4e (diff)
[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
Diffstat (limited to 'lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp')
-rw-r--r--lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp11
1 files changed, 6 insertions, 5 deletions
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<AllocationDetails::FileHeader *>(file_buf);
+ static_cast<const AllocationDetails::FileHeader *>(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<uint8_t *>(file_buf) +
- sizeof(AllocationDetails::FileHeader),
+ memcpy(&root_el_hdr,
+ static_cast<const uint8_t *>(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<uint8_t *>(file_buf) + file_header->hdr_size;
+ file_buf = static_cast<const uint8_t *>(file_buf) + file_header->hdr_size;
// Calculate size of allocation data in file
size_t size = data_sp->GetByteSize() - file_header->hdr_size;