Revert "Bug 1966311 - Use weak android symbol instead of dlopen/dlsym for android/Ashmem.cpp r=glandium" for causing multiple Android failures.

This reverts commit f5a2f8839a.

This reverts commit 801ade11ce.

This reverts commit 5c575caf38.

This reverts commit 0336e618cb.
This commit is contained in:
Serban Stanca
2025-05-16 11:34:28 +03:00
committed by sstanca@mozilla.com
parent 20ad00a0fe
commit 0ae173924f
5 changed files with 112 additions and 65 deletions

View File

@@ -6,6 +6,8 @@
#include "AndroidHardwareBuffer.h"
#include <dlfcn.h>
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/ImageBridgeChild.h"
@@ -53,22 +55,41 @@ void AndroidHardwareBufferApi::Shutdown() { sInstance = nullptr; }
AndroidHardwareBufferApi::AndroidHardwareBufferApi() {}
bool AndroidHardwareBufferApi::Load() {
if (__builtin_available(android 26, *)) {
mAHardwareBuffer_allocate = AHardwareBuffer_allocate; // API 26
mAHardwareBuffer_acquire = AHardwareBuffer_acquire; // API 26
mAHardwareBuffer_release = AHardwareBuffer_release; // API 26
mAHardwareBuffer_describe = AHardwareBuffer_describe; // API 26
mAHardwareBuffer_lock = AHardwareBuffer_lock; // API 26
mAHardwareBuffer_unlock = AHardwareBuffer_unlock; // API 26
mAHardwareBuffer_sendHandleToUnixSocket =
AHardwareBuffer_sendHandleToUnixSocket; // API 26
mAHardwareBuffer_recvHandleFromUnixSocket =
AHardwareBuffer_recvHandleFromUnixSocket; // API 26
return true;
} else {
void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
MOZ_ASSERT(handle);
if (!handle) {
gfxCriticalNote << "Failed to load libandroid.so";
return false;
}
mAHardwareBuffer_allocate =
(_AHardwareBuffer_allocate)dlsym(handle, "AHardwareBuffer_allocate");
mAHardwareBuffer_acquire =
(_AHardwareBuffer_acquire)dlsym(handle, "AHardwareBuffer_acquire");
mAHardwareBuffer_release =
(_AHardwareBuffer_release)dlsym(handle, "AHardwareBuffer_release");
mAHardwareBuffer_describe =
(_AHardwareBuffer_describe)dlsym(handle, "AHardwareBuffer_describe");
mAHardwareBuffer_lock =
(_AHardwareBuffer_lock)dlsym(handle, "AHardwareBuffer_lock");
mAHardwareBuffer_unlock =
(_AHardwareBuffer_unlock)dlsym(handle, "AHardwareBuffer_unlock");
mAHardwareBuffer_sendHandleToUnixSocket =
(_AHardwareBuffer_sendHandleToUnixSocket)dlsym(
handle, "AHardwareBuffer_sendHandleToUnixSocket");
mAHardwareBuffer_recvHandleFromUnixSocket =
(_AHardwareBuffer_recvHandleFromUnixSocket)dlsym(
handle, "AHardwareBuffer_recvHandleFromUnixSocket");
if (!mAHardwareBuffer_allocate || !mAHardwareBuffer_acquire ||
!mAHardwareBuffer_release || !mAHardwareBuffer_describe ||
!mAHardwareBuffer_lock || !mAHardwareBuffer_unlock ||
!mAHardwareBuffer_sendHandleToUnixSocket ||
!mAHardwareBuffer_recvHandleFromUnixSocket) {
gfxCriticalNote << "Failed to load AHardwareBuffer";
return false;
}
return true;
}
void AndroidHardwareBufferApi::Allocate(const AHardwareBuffer_Desc* aDesc,

View File

@@ -8,7 +8,7 @@
#include "mozilla/Assertions.h"
#include "nsDebug.h"
#include <android/system_fonts.h>
#include <dlfcn.h>
namespace mozilla {
@@ -36,14 +36,26 @@ AndroidSystemFontIterator::~AndroidSystemFontIterator() {
bool AndroidSystemFontIterator::Init() {
if (!sSystemFontIterator_open) {
if (__builtin_available(android 29, *)) {
sSystemFontIterator_open = ASystemFontIterator_open;
sSystemFontIterator_next = ASystemFontIterator_next;
sSystemFontIterator_close = ASystemFontIterator_close;
AndroidFont::sFont_getFontFilePath = AFont_getFontFilePath;
AndroidFont::sFont_close = AFont_close;
} else {
return NS_WARN_IF(false);
void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
MOZ_ASSERT(handle);
sSystemFontIterator_open =
(_ASystemFontIterator_open)dlsym(handle, "ASystemFontIterator_open");
sSystemFontIterator_next =
(_ASystemFontIterator_next)dlsym(handle, "ASystemFontIterator_next");
sSystemFontIterator_close =
(_ASystemFontIterator_close)dlsym(handle, "ASystemFontIterator_close");
AndroidFont::sFont_getFontFilePath =
(_AFont_getFontFilePath)dlsym(handle, "AFont_getFontFilePath");
AndroidFont::sFont_close = (_AFont_close)dlsym(handle, "AFont_close");
if (NS_WARN_IF(!sSystemFontIterator_open) ||
NS_WARN_IF(!sSystemFontIterator_next) ||
NS_WARN_IF(!sSystemFontIterator_close) ||
NS_WARN_IF(!AndroidFont::sFont_getFontFilePath) ||
NS_WARN_IF(!AndroidFont::sFont_close)) {
sSystemFontIterator_open = nullptr;
return false;
}
}
@@ -61,7 +73,7 @@ Maybe<AndroidFont> AndroidSystemFontIterator::Next() {
return Nothing();
}
AFont* font = sSystemFontIterator_next(mIterator);
void* font = sSystemFontIterator_next(mIterator);
if (!font) {
sSystemFontIterator_close(mIterator);
mIterator = nullptr;

View File

@@ -7,23 +7,19 @@
#define AndroidSystemFontIterator_h__
#include "mozilla/Maybe.h"
#include <android/font.h>
#include <android/system_fonts.h>
namespace mozilla {
typedef ASystemFontIterator* _Nullable (*_ASystemFontIterator_open)();
typedef AFont* _Nullable (*_ASystemFontIterator_next)(
ASystemFontIterator* _Nonnull iterator);
typedef void (*_ASystemFontIterator_close)(
ASystemFontIterator* _Nullable iterator);
typedef const char* _Nonnull (*_AFont_getFontFilePath)(
const AFont* _Nonnull font);
typedef void (*_AFont_close)(AFont* _Nullable font);
typedef void* (*_ASystemFontIterator_open)();
typedef void* (*_ASystemFontIterator_next)(void*);
typedef void (*_ASystemFontIterator_close)(void*);
typedef const char* (*_AFont_getFontFilePath)(const void*);
typedef void (*_AFont_close)(void*);
class AndroidFont final {
public:
explicit AndroidFont(AFont* _Nullable aFont) : mFont(aFont) {};
explicit AndroidFont(void* aFont) : mFont(aFont) {};
AndroidFont() = delete;
AndroidFont(AndroidFont&) = delete;
@@ -35,13 +31,13 @@ class AndroidFont final {
~AndroidFont();
const char* _Nullable GetFontFilePath();
const char* GetFontFilePath();
private:
AFont* _Nullable mFont;
void* mFont;
static _AFont_getFontFilePath _Nullable sFont_getFontFilePath;
static _AFont_close _Nullable sFont_close;
static _AFont_getFontFilePath sFont_getFontFilePath;
static _AFont_close sFont_close;
friend class AndroidSystemFontIterator;
};
@@ -57,11 +53,11 @@ class AndroidSystemFontIterator final {
Maybe<AndroidFont> Next();
private:
ASystemFontIterator* _Nullable mIterator = nullptr;
void* mIterator = nullptr;
static _ASystemFontIterator_open _Nullable sSystemFontIterator_open;
static _ASystemFontIterator_next _Nullable sSystemFontIterator_next;
static _ASystemFontIterator_close _Nullable sSystemFontIterator_close;
static _ASystemFontIterator_open sSystemFontIterator_open;
static _ASystemFontIterator_next sSystemFontIterator_next;
static _ASystemFontIterator_close sSystemFontIterator_close;
};
} // namespace mozilla

View File

@@ -10,18 +10,26 @@
#include "AndroidBuild.h"
#include <dlfcn.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <android/performance_hint.h>
typedef struct APerformanceHintManager APerformanceHintManager;
typedef struct APerformanceHintSession APerformanceHintSession;
namespace mozilla {
namespace hal_impl {
#define LOAD_FN(api, lib, name) \
do { \
api->m##name = reinterpret_cast<Fn##name>(dlsym(handle, #name)); \
if (!api->m##name) { \
HAL_ERR("Failed to load %s", #name); \
return nullptr; \
} \
} while (false)
class PerformanceHintManagerApi final {
public:
static PerformanceHintManagerApi* Get() {
@@ -65,21 +73,20 @@ class PerformanceHintManagerApi final {
return nullptr;
}
if (__builtin_available(android 33, *)) {
auto api = WrapUnique(new PerformanceHintManagerApi());
api->mAPerformanceHint_getManager = ::APerformanceHint_getManager;
api->mAPerformanceHint_createSession = ::APerformanceHint_createSession;
api->mAPerformanceHint_updateTargetWorkDuration =
::APerformanceHint_updateTargetWorkDuration;
api->mAPerformanceHint_reportActualWorkDuration =
::APerformanceHint_reportActualWorkDuration;
api->mAPerformanceHint_closeSession = ::APerformanceHint_closeSession;
return api;
} else {
HAL_ERR("Failed to load PerformanceHintManager symbols");
void* const handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
if (!handle) {
HAL_ERR("Failed to open libandroid.so");
return nullptr;
}
auto api = WrapUnique(new PerformanceHintManagerApi());
LOAD_FN(api, handle, APerformanceHint_getManager);
LOAD_FN(api, handle, APerformanceHint_createSession);
LOAD_FN(api, handle, APerformanceHint_updateTargetWorkDuration);
LOAD_FN(api, handle, APerformanceHint_reportActualWorkDuration);
LOAD_FN(api, handle, APerformanceHint_closeSession);
return api;
}
using FnAPerformanceHint_getManager = APerformanceHintManager* (*)();

View File

@@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <cstring>
#include <dlfcn.h>
#include <fcntl.h>
#include <linux/ashmem.h>
#include <stdio.h>
@@ -11,16 +12,22 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <android/sharedmem.h>
#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) {
if (__builtin_available(android 26, *)) {
return ASharedMemory_create(name, size);
static auto fCreate =
(int (*)(const char*, size_t))dlsym(libhandle(), "ASharedMemory_create");
if (fCreate) {
return fCreate(name, size);
}
int fd = open("/" ASHMEM_NAME_DEF, O_RDWR);
@@ -43,16 +50,20 @@ int ashmem_create(const char* name, size_t size) {
}
size_t ashmem_getSize(int fd) {
if (__builtin_available(android 26, *)) {
return ASharedMemory_getSize(fd);
static auto fGetSize =
(size_t(*)(int))dlsym(libhandle(), "ASharedMemory_getSize");
if (fGetSize) {
return fGetSize(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);
static auto fSetProt =
(int (*)(int, int))dlsym(libhandle(), "ASharedMemory_setProt");
if (fSetProt) {
return fSetProt(fd, prot);
}
return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);