Skip to content

Commit b329330

Browse files
argentitetstellar
authored andcommitted
[Orc] Disable use of shared memory on Android
shm_open and shm_unlink are not available on Android. This commit disables SharedMemoryMapper on Android until a better solution is available. https://android.googlesource.com/platform/bionic/+/refs/heads/master/docs/status.md #56812 Differential Revision: https://reviews.llvm.org/D130814 (cherry picked from commit ac3cb4e)
1 parent 0154886 commit b329330

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ class ExecutorSharedMemoryMapperService final
6666
static llvm::orc::shared::CWrapperFunctionResult
6767
releaseWrapper(const char *ArgData, size_t ArgSize);
6868

69+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
6970
std::atomic<int> SharedMemoryCount{0};
71+
#endif
72+
7073
std::mutex Mutex;
7174
ReservationMap Reservations;
7275
AllocationMap Allocations;

llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
1212
#include "llvm/Support/WindowsError.h"
1313

14-
#if defined(LLVM_ON_UNIX)
14+
#if defined(LLVM_ON_UNIX) && !defined(__ANDROID__)
1515
#include <fcntl.h>
1616
#include <sys/mman.h>
1717
#include <unistd.h>
@@ -173,20 +173,30 @@ InProcessMemoryMapper::~InProcessMemoryMapper() {
173173

174174
SharedMemoryMapper::SharedMemoryMapper(ExecutorProcessControl &EPC,
175175
SymbolAddrs SAs, size_t PageSize)
176-
: EPC(EPC), SAs(SAs), PageSize(PageSize) {}
176+
: EPC(EPC), SAs(SAs), PageSize(PageSize) {
177+
#if (!defined(LLVM_ON_UNIX) || defined(__ANDROID__)) && !defined(_WIN32)
178+
llvm_unreachable("SharedMemoryMapper is not supported on this platform yet");
179+
#endif
180+
}
177181

178182
Expected<std::unique_ptr<SharedMemoryMapper>>
179183
SharedMemoryMapper::Create(ExecutorProcessControl &EPC, SymbolAddrs SAs) {
184+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
180185
auto PageSize = sys::Process::getPageSize();
181186
if (!PageSize)
182187
return PageSize.takeError();
183188

184189
return std::make_unique<SharedMemoryMapper>(EPC, SAs, *PageSize);
190+
#else
191+
return make_error<StringError>(
192+
"SharedMemoryMapper is not supported on this platform yet",
193+
inconvertibleErrorCode());
194+
#endif
185195
}
186196

187197
void SharedMemoryMapper::reserve(size_t NumBytes,
188198
OnReservedFunction OnReserved) {
189-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
199+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
190200

191201
EPC.callSPSWrapperAsync<
192202
rt::SPSExecutorSharedMemoryMapperServiceReserveSignature>(
@@ -334,7 +344,7 @@ void SharedMemoryMapper::deinitialize(
334344

335345
void SharedMemoryMapper::release(ArrayRef<ExecutorAddr> Bases,
336346
OnReleasedFunction OnReleased) {
337-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
347+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
338348
Error Err = Error::success();
339349

340350
{

llvm/lib/ExecutionEngine/Orc/TargetProcess/ExecutorSharedMemoryMapperService.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace rt_bootstrap {
5252

5353
Expected<std::pair<ExecutorAddr, std::string>>
5454
ExecutorSharedMemoryMapperService::reserve(uint64_t Size) {
55-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
55+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
5656

5757
#if defined(LLVM_ON_UNIX)
5858

@@ -125,7 +125,7 @@ ExecutorSharedMemoryMapperService::reserve(uint64_t Size) {
125125

126126
Expected<ExecutorAddr> ExecutorSharedMemoryMapperService::initialize(
127127
ExecutorAddr Reservation, tpctypes::SharedMemoryFinalizeRequest &FR) {
128-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
128+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
129129

130130
ExecutorAddr MinAddr(~0ULL);
131131

@@ -207,7 +207,7 @@ Error ExecutorSharedMemoryMapperService::deinitialize(
207207

208208
Error ExecutorSharedMemoryMapperService::release(
209209
const std::vector<ExecutorAddr> &Bases) {
210-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
210+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
211211
Error Err = Error::success();
212212

213213
for (auto Base : Bases) {

llvm/unittests/ExecutionEngine/Orc/SharedMemoryMapperTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace llvm::orc;
1818
using namespace llvm::orc::shared;
1919
using namespace llvm::orc::rt_bootstrap;
2020

21-
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
21+
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
2222

2323
// A basic function to be used as both initializer/deinitializer
2424
orc::shared::CWrapperFunctionResult incrementWrapper(const char *ArgData,

0 commit comments

Comments
 (0)