From f5a2f8839a08d97df2d6e23f6b9fde252d6cc7c0 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Fri, 16 May 2025 07:04:52 +0000 Subject: [PATCH] Bug 1966311 - Use weak android symbol instead of dlopen/dlsym for android/Ashmem.cpp r=glandium Differential Revision: https://phabricator.services.mozilla.com/D249226 --- mozglue/android/Ashmem.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/mozglue/android/Ashmem.cpp b/mozglue/android/Ashmem.cpp index edfeb495dd9c..24fa31855f64 100644 --- a/mozglue/android/Ashmem.cpp +++ b/mozglue/android/Ashmem.cpp @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include -#include #include #include #include @@ -12,22 +11,16 @@ #include #include +#include + #include "Ashmem.h" namespace mozilla { namespace android { -static void* libhandle() { - static void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL); - return handle; -} - int ashmem_create(const char* name, size_t size) { - static auto fCreate = - (int (*)(const char*, size_t))dlsym(libhandle(), "ASharedMemory_create"); - - if (fCreate) { - return fCreate(name, size); + if (__builtin_available(android 26, *)) { + return ASharedMemory_create(name, size); } int fd = open("/" ASHMEM_NAME_DEF, O_RDWR); @@ -50,20 +43,16 @@ int ashmem_create(const char* name, size_t size) { } size_t ashmem_getSize(int fd) { - static auto fGetSize = - (size_t(*)(int))dlsym(libhandle(), "ASharedMemory_getSize"); - if (fGetSize) { - return fGetSize(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) { - static auto fSetProt = - (int (*)(int, int))dlsym(libhandle(), "ASharedMemory_setProt"); - if (fSetProt) { - return fSetProt(fd, prot); + if (__builtin_available(android 26, *)) { + return ASharedMemory_setProt(fd, prot); } return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);