Quelle SharedMemoryPlatform_android.cpp
Sprache: C
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This source code was derived from Chromium code, and as such is also subject
* to the [Chromium license](ipc/chromium/src/LICENSE). */
// Right now we do nothing different for freezable shared memory on Android. static Maybe<PlatformHandle> CreateImpl(size_t aSize, bool aFreezable) {
MOZ_ASSERT(aSize > 0);
int fd = mozilla::android::ashmem_create(nullptr, aSize); if (fd < 0) {
MOZ_LOG_FMT(gSharedMemoryLog, LogLevel::Warning, "failed to open shm: {}",
strerror(errno)); return Nothing();
}
bool Platform::Freeze(FreezableHandle& aHandle) { if (mozilla::android::ashmem_setProt(aHandle.mHandle.get(), PROT_READ) != 0) {
MOZ_LOG_FMT(gSharedMemoryLog, LogLevel::Warning, "failed to set ashmem read-only: {}", strerror(errno)); returnfalse;
} returntrue;
}
Maybe<void*> Platform::Map(const HandleBase& aHandle, void* aFixedAddress, bool aReadOnly) { // Don't use MAP_FIXED when a fixed_address was specified, since that can // replace pages that are alread mapped at that address. void* mem = mmap(aFixedAddress, aHandle.Size(),
PROT_READ | (aReadOnly ? 0 : PROT_WRITE), MAP_SHARED,
aHandle.mHandle.get(), 0);
if (mem == MAP_FAILED) {
MOZ_LOG_FMT(gSharedMemoryLog, LogLevel::Warning, "call to mmap failed: {}",
strerror(errno)); return Nothing();
}
if (aFixedAddress && mem != aFixedAddress) {
DebugOnly<bool> munmap_succeeded = munmap(mem, aHandle.Size()) == 0;
MOZ_ASSERT(munmap_succeeded, "call to munmap failed"); return Nothing();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.