mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2025-06-24 00:52:31 +08:00
Add shims for hidden API
This commit is contained in:
@ -7,13 +7,13 @@ add_compile_definitions(VIPER_VERSION=20240314)
|
|||||||
|
|
||||||
# External
|
# External
|
||||||
set(CORE_SRC
|
set(CORE_SRC
|
||||||
external/core/libcutils/ashmem-host.cpp
|
#[[external/core/libcutils/ashmem-host.cpp
|
||||||
external/core/libcutils/native_handle.cpp
|
external/core/libcutils/native_handle.cpp
|
||||||
external/core/libutils/SystemClock.cpp
|
external/core/libutils/SystemClock.cpp
|
||||||
external/core/libutils/Timers.cpp)
|
external/core/libutils/Timers.cpp]])
|
||||||
|
|
||||||
set(LIBFMQ_SRC
|
set(LIBFMQ_SRC
|
||||||
external/libfmq/EventFlag.cpp)
|
#[[external/libfmq/EventFlag.cpp]])
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
external/libbase/include
|
external/libbase/include
|
||||||
@ -223,5 +223,6 @@ add_library(v4a_re SHARED
|
|||||||
${FILES})
|
${FILES})
|
||||||
|
|
||||||
target_link_libraries(v4a_re log binder_ndk) # kissfft)
|
target_link_libraries(v4a_re log binder_ndk) # kissfft)
|
||||||
|
target_link_options(v4a_re PRIVATE "LINKER:--no-demangle")
|
||||||
target_compile_options(v4a_re PRIVATE -flto -O3 -DNDEBUG)
|
target_compile_options(v4a_re PRIVATE -flto -O3 -DNDEBUG)
|
||||||
#target_compile_options(v4afx_r PRIVATE -O2 -DNDEBUG -Wall -Wsign-conversion -Wno-unused-result -Wno-unneeded-internal-declaration -fstrict-aliasing -fvisibility=hidden -Wextra -Wno-unused-parameter)
|
#target_compile_options(v4afx_r PRIVATE -O2 -DNDEBUG -Wall -Wsign-conversion -Wno-unused-result -Wno-unneeded-internal-declaration -fstrict-aliasing -fvisibility=hidden -Wextra -Wno-unused-parameter)
|
||||||
|
81
src/shim.cpp
81
src/shim.cpp
@ -1,20 +1,79 @@
|
|||||||
#include <string>
|
/**
|
||||||
|
* Shims for the "hidden" api, not found in the Android NDK.
|
||||||
|
*
|
||||||
|
* The symbols are compiled with the NDK, but the real Android ones have
|
||||||
|
* a slightly different mangled name.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
namespace android::hardware::details {
|
// libcutils
|
||||||
void check(bool exp) {
|
void *ashmem_create_region;
|
||||||
ALOGE_IF(!exp, "Check failed");
|
void *ashmem_set_prot_region;
|
||||||
|
void *native_handle_create;
|
||||||
|
void *native_handle_delete;
|
||||||
|
void *native_handle_close;
|
||||||
|
|
||||||
|
// libfmq
|
||||||
|
void *_ZN7android8hardware7details5checkEbPKc;
|
||||||
|
void *_ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE; // ndk
|
||||||
|
void *_ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_; // ndk
|
||||||
|
void *_ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_;
|
||||||
|
|
||||||
|
static void init_libcutils() {
|
||||||
|
void *libcutils = dlopen("libcutils.so", RTLD_NOW);
|
||||||
|
if (libcutils == nullptr) {
|
||||||
|
ALOGE("Failed to load libcutils.so");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(bool exp, const char* message) {
|
ashmem_create_region = dlsym(libcutils, "ashmem_create_region");
|
||||||
ALOGE_IF(!exp, "%s", message);
|
ashmem_set_prot_region = dlsym(libcutils, "ashmem_set_prot_region");
|
||||||
|
|
||||||
|
native_handle_create = dlsym(libcutils, "native_handle_create");
|
||||||
|
native_handle_close = dlsym(libcutils, "native_handle_close");
|
||||||
|
native_handle_delete = dlsym(libcutils, "native_handle_delete");
|
||||||
|
|
||||||
|
if (ashmem_create_region == nullptr ||
|
||||||
|
ashmem_set_prot_region == nullptr ||
|
||||||
|
native_handle_create == nullptr ||
|
||||||
|
native_handle_close == nullptr ||
|
||||||
|
native_handle_delete == nullptr) {
|
||||||
|
ALOGE("Failed to load symbols from libcutils.so");
|
||||||
}
|
}
|
||||||
|
|
||||||
void logError(const std::string &message) {
|
dlclose(libcutils);
|
||||||
ALOGE("%s", message.c_str());
|
}
|
||||||
|
|
||||||
|
static void init_libfmq() {
|
||||||
|
void *libfmq = dlopen("libfmq.so", RTLD_NOW);
|
||||||
|
if (libfmq == nullptr) {
|
||||||
|
ALOGE("Failed to load libfmq.so");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void errorWriteLog(int tag, const char* info) {
|
_ZN7android8hardware7details5checkEbPKc = dlsym(libfmq, "_ZN7android8hardware7details5checkEbPKc");
|
||||||
ALOGE("%d: %s", tag, info);
|
// ndk variant, real symbol: _ZN7android8hardware7details8logErrorERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE
|
||||||
|
_ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE = dlsym(libfmq, "_ZN7android8hardware7details8logErrorERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE");
|
||||||
|
// ndk variant, real symbol: _ZN7android8hardware9EventFlag15createEventFlagEPNSt3__16atomicIjEEPPS1_
|
||||||
|
_ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ = dlsym(libfmq, "_ZN7android8hardware9EventFlag15createEventFlagEPNSt3__16atomicIjEEPPS1_");
|
||||||
|
_ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ = dlsym(libfmq, "_ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_");
|
||||||
|
|
||||||
|
if (_ZN7android8hardware7details5checkEbPKc == nullptr ||
|
||||||
|
_ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE == nullptr ||
|
||||||
|
_ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ == nullptr ||
|
||||||
|
_ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ == nullptr) {
|
||||||
|
ALOGE("Failed to load symbols from libfmq.so");
|
||||||
}
|
}
|
||||||
} // namespace android::hardware::details
|
|
||||||
|
dlclose(libfmq);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((constructor))
|
||||||
|
void shim_init() {
|
||||||
|
ALOGD("shim_init");
|
||||||
|
init_libcutils();
|
||||||
|
init_libfmq();
|
||||||
|
ALOGD("shim_init done");
|
||||||
|
}
|
@ -238,8 +238,11 @@ ndk::ScopedAStatus ViPER4AndroidAIDL::command(CommandId id) {
|
|||||||
stopThread();
|
stopThread();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
ALOGE("command: unknown command %d", static_cast<int>(id));
|
||||||
|
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
|
||||||
}
|
}
|
||||||
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
return ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk::ScopedAStatus ViPER4AndroidAIDL::getState(State *state) {
|
ndk::ScopedAStatus ViPER4AndroidAIDL::getState(State *state) {
|
||||||
|
Reference in New Issue
Block a user