From d87d0c707ed0f800a9b3e602d70ab034b8b24623 Mon Sep 17 00:00:00 2001 From: A_Wei Date: Mon, 22 Jul 2024 20:07:18 +0800 Subject: [PATCH 1/5] [LLDB] Added lldb to adapt to ohos platform's mmap Description: Adapt to the restrictions of mmap on ohos platform. Issue: https://gitee.com/openharmony/third_party_llvm-project/issues/IAESBY?from=project-issue Signed-off-by: A_Wei --- .../Plugins/Platform/OHOS/PlatformOHOS.cpp | 35 +++++++++++++++++++ .../Plugins/Platform/OHOS/PlatformOHOS.h | 5 +++ 2 files changed, 40 insertions(+) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index ea12bd656551..fecd4c9854c0 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -21,6 +21,23 @@ #include "PlatformOHOSRemoteGDBServer.h" #include "lldb/Target/Target.h" +#if LLDB_ENABLE_POSIX +#include +#else +// Define these constants from OHOS mman.h for use when targeting remote OHOS +// systems even when host has different values. +#define PROT_NONE 0 +#define PROT_READ 1 +#define PROT_WRITE 2 +#define PROT_EXEC 4 +#define MAP_PRIVATE 2 +#define MAP_ANON 0x20 +#endif + +#define MAP_ANON_MIPS 0x800 +// MAP_JIT allows to allocate anonymous memory with executable permissions. +#define MAP_JIT 0x1000 + using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_ohos; @@ -300,3 +317,21 @@ ConstString PlatformOHOS::GetMmapSymbolName(const ArchSpec &arch) { ? ConstString("__lldb_mmap") : PlatformLinux::GetMmapSymbolName(arch); } + +MmapArgList PlatformOHOS::GetMmapArgumentList(const ArchSpec &arch, + addr_t addr, addr_t length, + unsigned prot, unsigned flags, + addr_t fd, addr_t offset) { + uint64_t flags_platform = 0; + uint64_t map_anon = arch.IsMIPS() ? MAP_ANON_MIPS : MAP_ANON; + + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= map_anon; + if (flags & eMmapFlagsAnon && prot & PROT_EXEC) + flags_platform |= MAP_JIT; + + MmapArgList args({addr, length, prot, flags_platform, fd, offset}); + return args; +} \ No newline at end of file diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h index fdbd1d42535a..4ad5c4c23894 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h @@ -56,6 +56,11 @@ public: ConstString GetMmapSymbolName(const ArchSpec &arch) override; + MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr, + lldb::addr_t length, unsigned prot, + unsigned flags, lldb::addr_t fd, + lldb::addr_t offset) override; + protected: const char *GetCacheHostname() override; -- Gitee From e6a53bc8726fcace480a7cf715ab26d3117c4f64 Mon Sep 17 00:00:00 2001 From: A_Wei Date: Mon, 22 Jul 2024 13:11:00 +0000 Subject: [PATCH 2/5] update lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp. Signed-off-by: A_Wei --- lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index fecd4c9854c0..c6af890792cd 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -323,7 +323,7 @@ MmapArgList PlatformOHOS::GetMmapArgumentList(const ArchSpec &arch, unsigned prot, unsigned flags, addr_t fd, addr_t offset) { uint64_t flags_platform = 0; - uint64_t map_anon = arch.IsMIPS() ? MAP_ANON_MIPS : MAP_ANON; + const uint64_t map_anon = arch.IsMIPS() ? MAP_ANON_MIPS : MAP_ANON; if (flags & eMmapFlagsPrivate) flags_platform |= MAP_PRIVATE; -- Gitee From b1749f38cd39a40bd4289fb237fc3d59deee7837 Mon Sep 17 00:00:00 2001 From: A_Wei Date: Tue, 23 Jul 2024 01:50:33 +0000 Subject: [PATCH 3/5] update lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp. Signed-off-by: A_Wei --- lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index c6af890792cd..e28caf4db569 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -334,4 +334,4 @@ MmapArgList PlatformOHOS::GetMmapArgumentList(const ArchSpec &arch, MmapArgList args({addr, length, prot, flags_platform, fd, offset}); return args; -} \ No newline at end of file +} -- Gitee From 3ec775fe7a4a3ee18db9bd4305278e12083ed067 Mon Sep 17 00:00:00 2001 From: A_Wei Date: Tue, 23 Jul 2024 02:21:30 +0000 Subject: [PATCH 4/5] update lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp. Signed-off-by: A_Wei --- lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index e28caf4db569..b5dc501bc94b 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -21,7 +21,7 @@ #include "PlatformOHOSRemoteGDBServer.h" #include "lldb/Target/Target.h" -#if LLDB_ENABLE_POSIX +#if defined(__OHOS__) #include #else // Define these constants from OHOS mman.h for use when targeting remote OHOS -- Gitee From 440b0f5464d2cfeb14a1d8d0b411b661e17dcc35 Mon Sep 17 00:00:00 2001 From: A_Wei Date: Fri, 26 Jul 2024 07:27:06 +0000 Subject: [PATCH 5/5] update lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp. Signed-off-by: A_Wei --- lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index b5dc501bc94b..d7ea2897f377 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -317,7 +317,9 @@ ConstString PlatformOHOS::GetMmapSymbolName(const ArchSpec &arch) { ? ConstString("__lldb_mmap") : PlatformLinux::GetMmapSymbolName(arch); } - +//Customize mmap adaptation for OHOS platform. +//OHOS platform allows anonymous memory allocation with exec permission +//only when MAP_JIT parameter is specified. MmapArgList PlatformOHOS::GetMmapArgumentList(const ArchSpec &arch, addr_t addr, addr_t length, unsigned prot, unsigned flags, -- Gitee