Skip to content

Commit

Permalink
[Orc] Disable use of shared memory on Android
Browse files Browse the repository at this point in the history
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
  • Loading branch information
argentite committed Aug 1, 2022
1 parent 6b2fed3 commit ac3cb4e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class ExecutorSharedMemoryMapperService final
static llvm::orc::shared::CWrapperFunctionResult
releaseWrapper(const char *ArgData, size_t ArgSize);

#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
std::atomic<int> SharedMemoryCount{0};
#endif

std::mutex Mutex;
ReservationMap Reservations;
AllocationMap Allocations;
Expand Down
18 changes: 14 additions & 4 deletions llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
#include "llvm/Support/WindowsError.h"

#if defined(LLVM_ON_UNIX)
#if defined(LLVM_ON_UNIX) && !defined(__ANDROID__)
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
Expand Down Expand Up @@ -173,20 +173,30 @@ InProcessMemoryMapper::~InProcessMemoryMapper() {

SharedMemoryMapper::SharedMemoryMapper(ExecutorProcessControl &EPC,
SymbolAddrs SAs, size_t PageSize)
: EPC(EPC), SAs(SAs), PageSize(PageSize) {}
: EPC(EPC), SAs(SAs), PageSize(PageSize) {
#if (!defined(LLVM_ON_UNIX) || defined(__ANDROID__)) && !defined(_WIN32)
llvm_unreachable("SharedMemoryMapper is not supported on this platform yet");
#endif
}

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

return std::make_unique<SharedMemoryMapper>(EPC, SAs, *PageSize);
#else
return make_error<StringError>(
"SharedMemoryMapper is not supported on this platform yet",
inconvertibleErrorCode());
#endif
}

void SharedMemoryMapper::reserve(size_t NumBytes,
OnReservedFunction OnReserved) {
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)

EPC.callSPSWrapperAsync<
rt::SPSExecutorSharedMemoryMapperServiceReserveSignature>(
Expand Down Expand Up @@ -334,7 +344,7 @@ void SharedMemoryMapper::deinitialize(

void SharedMemoryMapper::release(ArrayRef<ExecutorAddr> Bases,
OnReleasedFunction OnReleased) {
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
Error Err = Error::success();

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace rt_bootstrap {

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

#if defined(LLVM_ON_UNIX)

Expand Down Expand Up @@ -125,7 +125,7 @@ ExecutorSharedMemoryMapperService::reserve(uint64_t Size) {

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

ExecutorAddr MinAddr(~0ULL);

Expand Down Expand Up @@ -207,7 +207,7 @@ Error ExecutorSharedMemoryMapperService::deinitialize(

Error ExecutorSharedMemoryMapperService::release(
const std::vector<ExecutorAddr> &Bases) {
#if defined(LLVM_ON_UNIX) || defined(_WIN32)
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
Error Err = Error::success();

for (auto Base : Bases) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace llvm::orc;
using namespace llvm::orc::shared;
using namespace llvm::orc::rt_bootstrap;

#if defined(LLVM_ON_UNIX) || defined(_WIN32)
#if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)

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

0 comments on commit ac3cb4e

Please sign in to comment.