2025-04-02 12:13:09 +02:00
/**
* 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 .
*/
2025-04-02 02:43:03 +02:00
# include <log/log.h>
2025-04-02 12:13:09 +02:00
# include <dlfcn.h>
// libcutils
void * ashmem_create_region ;
void * ashmem_set_prot_region ;
void * native_handle_create ;
void * native_handle_delete ;
void * native_handle_close ;
2025-04-02 12:57:25 +02:00
void logError ( ) {
ALOGD ( " _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE called " ) ;
}
void createEventFlag ( ) {
ALOGD ( " _ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ called " ) ;
}
2025-04-02 12:13:09 +02:00
// libfmq
void * _ZN7android8hardware7details5checkEbPKc ;
2025-04-02 12:57:25 +02:00
void * _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE = ( void * ) ( logError ) ; // ndk
void * _ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ = ( void * ) ( createEventFlag ) ; // ndk
2025-04-02 12:13:09 +02:00
void * _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ ;
2025-04-02 02:02:51 +02:00
2025-04-02 12:13:09 +02:00
static void init_libcutils ( ) {
void * libcutils = dlopen ( " libcutils.so " , RTLD_NOW ) ;
if ( libcutils = = nullptr ) {
ALOGE ( " Failed to load libcutils.so " ) ;
return ;
2025-04-02 02:02:51 +02:00
}
2025-04-02 12:13:09 +02:00
ashmem_create_region = dlsym ( libcutils , " ashmem_create_region " ) ;
2025-04-02 12:28:43 +02:00
if ( ashmem_create_region = = nullptr ) {
ALOGE ( " Failed to load symbol ashmem_create_region from libcutils.so " ) ;
goto exit ;
}
2025-04-02 12:13:09 +02:00
ashmem_set_prot_region = dlsym ( libcutils , " ashmem_set_prot_region " ) ;
2025-04-02 12:28:43 +02:00
if ( ashmem_set_prot_region = = nullptr ) {
ALOGE ( " Failed to load symbol ashmem_set_prot_region from libcutils.so " ) ;
goto exit ;
}
2025-04-02 12:13:09 +02:00
native_handle_create = dlsym ( libcutils , " native_handle_create " ) ;
2025-04-02 12:28:43 +02:00
if ( native_handle_create = = nullptr ) {
ALOGE ( " Failed to load symbol native_handle_create from libcutils.so " ) ;
goto exit ;
}
2025-04-02 12:13:09 +02:00
native_handle_close = dlsym ( libcutils , " native_handle_close " ) ;
2025-04-02 12:28:43 +02:00
if ( native_handle_close = = nullptr ) {
ALOGE ( " Failed to load symbol native_handle_close from libcutils.so " ) ;
goto exit ;
}
2025-04-02 12:13:09 +02:00
2025-04-02 12:28:43 +02:00
native_handle_delete = dlsym ( libcutils , " native_handle_delete " ) ;
if ( native_handle_delete = = nullptr ) {
ALOGE ( " Failed to load symbol native_handle_delete from libcutils.so " ) ;
goto exit ;
2025-04-02 02:02:51 +02:00
}
2025-04-02 12:28:43 +02:00
ALOGD ( " ashmem_create_region: %p " , ashmem_create_region ) ;
ALOGD ( " ashmem_set_prot_region: %p " , ashmem_set_prot_region ) ;
ALOGD ( " native_handle_create: %p " , native_handle_create ) ;
ALOGD ( " native_handle_close: %p " , native_handle_close ) ;
ALOGD ( " native_handle_delete: %p " , native_handle_delete ) ;
exit :
2025-04-02 12:13:09 +02:00
dlclose ( libcutils ) ;
}
static void init_libfmq ( ) {
void * libfmq = dlopen ( " libfmq.so " , RTLD_NOW ) ;
if ( libfmq = = nullptr ) {
ALOGE ( " Failed to load libfmq.so " ) ;
return ;
2025-04-02 02:02:51 +02:00
}
2025-04-02 12:13:09 +02:00
_ZN7android8hardware7details5checkEbPKc = dlsym ( libfmq , " _ZN7android8hardware7details5checkEbPKc " ) ;
2025-04-02 12:28:43 +02:00
if ( _ZN7android8hardware7details5checkEbPKc = = nullptr ) {
ALOGE ( " Failed to load symbol _ZN7android8hardware7details5checkEbPKc from libfmq.so " ) ;
goto exit ;
}
2025-04-02 12:13:09 +02:00
// ndk variant, real symbol: _ZN7android8hardware7details8logErrorERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE
2025-04-02 12:57:25 +02:00
// _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE = dlsym(libfmq, "_ZN7android8hardware7details8logErrorERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE");
// if (_ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE == nullptr) {
// ALOGE("Failed to load symbol _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE from libfmq.so");
// goto exit;
// }
2025-04-02 12:28:43 +02:00
2025-04-02 12:13:09 +02:00
// ndk variant, real symbol: _ZN7android8hardware9EventFlag15createEventFlagEPNSt3__16atomicIjEEPPS1_
2025-04-02 12:57:25 +02:00
// _ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ = dlsym(libfmq, "_ZN7android8hardware9EventFlag15createEventFlagEPNSt3__16atomicIjEEPPS1_");
// if (_ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ == nullptr) {
// ALOGE("Failed to load symbol _ZN7android8hardware9EventFlag15createEventFlagEPNSt3__16atomicIjEEPPS1_ from libfmq.so");
// goto exit;
// }
2025-04-02 12:13:09 +02:00
2025-04-02 12:28:43 +02:00
_ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ = dlsym ( libfmq , " _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ " ) ;
if ( _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ = = nullptr ) {
ALOGE ( " Failed to load symbol _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ from libfmq.so " ) ;
goto exit ;
2025-04-02 02:02:51 +02:00
}
2025-04-02 12:13:09 +02:00
2025-04-02 12:28:43 +02:00
ALOGD ( " _ZN7android8hardware7details5checkEbPKc: %p " , _ZN7android8hardware7details5checkEbPKc ) ;
ALOGD ( " _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE: %p " , _ZN7android8hardware7details8logErrorERKNSt6__ndk112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE ) ;
ALOGD ( " _ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_: %p " , _ZN7android8hardware9EventFlag15createEventFlagEPNSt6__ndk16atomicIjEEPPS1_ ) ;
ALOGD ( " _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_: %p " , _ZN7android8hardware9EventFlag15deleteEventFlagEPPS1_ ) ;
exit :
2025-04-02 12:13:09 +02:00
dlclose ( libfmq ) ;
}
__attribute__ ( ( constructor ) )
void shim_init ( ) {
init_libcutils ( ) ;
init_libfmq ( ) ;
}