Hash :
38c01008
Author :
Date :
2022-09-13T15:11:54
Vulkan: Fix a cornercase bug when dynamically loading AHB APIs. The commit 122a1cc583f0 enabled dynamic loading of AHB APIs but did not handle the cornercase where some Android system services load "libnativewindow.so" with the RTLD_LOCAL flag. In such cases AHB APIs would not be resolvable through dlsym lookup. Explicitly dlopen "libnativewindow.so" in such cases. Bug: angleproject:7656 Change-Id: Ie74140ad816b756e1afc325d370f26bcb09428ca Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3894658 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Peng Huang <penghuang@chromium.org> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "libANGLE/renderer/vulkan/android/AHBFunctions.h"
#include "common/debug.h"
#include <dlfcn.h>
namespace rx
{
namespace
{
template <class T>
void AssignFn(void *handle, const char *name, T &fn)
{
fn = reinterpret_cast<T>(dlsym(handle, name));
}
constexpr char kNativeWindowLibraryName[] = "libnativewindow.so";
constexpr char kAhbAcquireFunctionName[] = "AHardwareBuffer_acquire";
constexpr char kAhbDescribeFunctionName[] = "AHardwareBuffer_describe";
constexpr char kAhbReleaseFunctionName[] = "AHardwareBuffer_release";
} // namespace
AHBFunctions::AHBFunctions() : mLibNativeWindowHandle(nullptr)
{
void *handle = dlopen(nullptr, RTLD_NOW);
getAhbProcAddresses(handle);
// Some services load "libnativewindow.so" with RTLD_LOCAL flag resulting in AHB function
// symbols being unresolvable through dlsym. Account for such cases and explicitly dlopen the
// library.
if (!valid())
{
mLibNativeWindowHandle = dlopen(kNativeWindowLibraryName, RTLD_NOW);
ASSERT(mLibNativeWindowHandle);
getAhbProcAddresses(mLibNativeWindowHandle);
}
}
AHBFunctions::~AHBFunctions()
{
if (mLibNativeWindowHandle)
{
dlclose(mLibNativeWindowHandle);
}
}
void AHBFunctions::getAhbProcAddresses(void *handle)
{
AssignFn(handle, kAhbAcquireFunctionName, mAcquireFn);
AssignFn(handle, kAhbDescribeFunctionName, mDescribeFn);
AssignFn(handle, kAhbReleaseFunctionName, mReleaseFn);
}
} // namespace rx