commit c4b5eb8ff0a3c8e52b13febd17e65fd55702ec66
parent f6ae20842de972d297270e7a145ec4b178586d50
Author: Ryan VanderMeulen <rvandermeulen@mozilla.com>
Date: Sat, 18 Oct 2025 00:53:10 +0000
Bug 1991644 - Use NDK ASharedMemory functions directly. r=glandium
We don't need shims around them now that our minimum SDK level is 26.
Differential Revision: https://phabricator.services.mozilla.com/D268816
Diffstat:
5 files changed, 6 insertions(+), 99 deletions(-)
diff --git a/ipc/glue/SharedMemoryPlatform_android.cpp b/ipc/glue/SharedMemoryPlatform_android.cpp
@@ -15,7 +15,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "mozilla/Ashmem.h"
+#include <android/sharedmem.h>
#ifdef MOZ_VALGRIND
# include <valgrind/valgrind.h>
@@ -31,7 +31,7 @@ namespace mozilla::ipc::shared_memory {
static Maybe<PlatformHandle> CreateImpl(size_t aSize, bool aFreezable) {
MOZ_ASSERT(aSize > 0);
- int fd = mozilla::android::ashmem_create(nullptr, aSize);
+ int fd = ASharedMemory_create(nullptr, aSize);
if (fd < 0) {
MOZ_LOG_FMT(gSharedMemoryLog, LogLevel::Warning, "failed to open shm: {}",
strerror(errno));
@@ -73,9 +73,9 @@ PlatformHandle Platform::CloneHandle(const PlatformHandle& aHandle) {
}
bool Platform::Freeze(FreezableHandle& aHandle) {
- if (mozilla::android::ashmem_setProt(aHandle.mHandle.get(), PROT_READ) != 0) {
+ if (ASharedMemory_setProt(aHandle.mHandle.get(), PROT_READ) != 0) {
MOZ_LOG_FMT(gSharedMemoryLog, LogLevel::Warning,
- "failed to set ashmem read-only: {}", strerror(errno));
+ "failed to set sharedmem read-only: {}", strerror(errno));
return false;
}
return true;
diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build
@@ -293,6 +293,8 @@ if CONFIG["TARGET_OS"] == "OSX":
OS_LIBS += ["bsm"] # for audit_token_to_pid
elif CONFIG["TARGET_OS"] == "iOS":
OS_LIBS += ["-framework BrowserEngineKit"]
+elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
+ OS_LIBS += ["android"]
for var in (
"MOZ_CHILD_PROCESS_NAME",
diff --git a/mozglue/static/android/Ashmem.cpp b/mozglue/static/android/Ashmem.cpp
@@ -1,62 +0,0 @@
-/* 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/. */
-
-#include <cstring>
-#include <fcntl.h>
-#include <linux/ashmem.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-
-#include <android/sharedmem.h>
-
-#include "Ashmem.h"
-
-namespace mozilla {
-namespace android {
-
-int ashmem_create(const char* name, size_t size) {
- if (__builtin_available(android 26, *)) {
- return ASharedMemory_create(name, size);
- }
-
- int fd = open("/" ASHMEM_NAME_DEF, O_RDWR);
- if (fd < 0) {
- return fd;
- }
-
- if (name) {
- char str[ASHMEM_NAME_LEN];
- strlcpy(str, name, sizeof(str));
- ioctl(fd, ASHMEM_SET_NAME, str);
- }
-
- if (ioctl(fd, ASHMEM_SET_SIZE, size) != 0) {
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-size_t ashmem_getSize(int fd) {
- if (__builtin_available(android 26, *)) {
- return ASharedMemory_getSize(fd);
- }
-
- return (size_t)ioctl(fd, ASHMEM_GET_SIZE, nullptr);
-}
-
-int ashmem_setProt(int fd, int prot) {
- if (__builtin_available(android 26, *)) {
- return ASharedMemory_setProt(fd, prot);
- }
-
- return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
-}
-
-} // namespace android
-} // namespace mozilla
diff --git a/mozglue/static/android/Ashmem.h b/mozglue/static/android/Ashmem.h
@@ -1,23 +0,0 @@
-/* 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/. */
-
-#ifndef Ashmem_h__
-#define Ashmem_h__
-
-#include <linux/ashmem.h>
-#include "mozilla/Types.h"
-
-namespace mozilla {
-namespace android {
-
-// Wrappers for the ASharedMemory function in the NDK
-// https://developer.android.com/ndk/reference/group/memory
-MFBT_API int ashmem_create(const char* name, size_t size);
-MFBT_API size_t ashmem_getSize(int fd);
-MFBT_API int ashmem_setProt(int fd, int prot);
-
-} // namespace android
-} // namespace mozilla
-
-#endif // Ashmem_h__
diff --git a/mozglue/static/moz.build b/mozglue/static/moz.build
@@ -6,16 +6,6 @@
EXPORTS.mozilla = ["Compression.h"]
-if CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":
- OS_LIBS += ["android"]
-
- EXPORTS.mozilla += ["android/Ashmem.h"]
-
- UNIFIED_SOURCES += [
- "android/Ashmem.cpp",
- ]
-
-
UNIFIED_SOURCES += [
"Compression.cpp",
]