diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index ea12bd6565511fda60d3398459ab48107fe1d924..d7ea2897f377a0b7a78441508fc3088807e1dbe6 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 defined(__OHOS__) +#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,23 @@ 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, + addr_t fd, addr_t offset) { + uint64_t flags_platform = 0; + const 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; +} diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.h index fdbd1d42535ace58eb6dfceb906c9a600dbb1f4b..4ad5c4c23894b1560dc5c023915b5a844ea8fa76 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;