@@ -688,37 +688,38 @@ static void setup_trampoline(void) {
688688#ifdef __ANDROID__
689689// REF: https://gist.github.com/khanhduytran0/faee2be9c8fd1282783b936156a03e1c
690690static void * _libdl_handle = NULL ;
691- static struct android_namespace_t * ( * _create_namespace )(
692- const char * , const char * , const char * , uint64_t , const char * ,
693- struct android_namespace_t * ) = NULL ;
691+ static void * _libc_handle = NULL ;
692+ static struct android_namespace_t * ( * _get_exported_namespace )( const char * ) =
693+ NULL ;
694694static void * (* _dlopen_ext )(const char * , int ,
695695 const android_dlextinfo * ) = NULL ;
696696
697697static void * get_libdl_handle (void ) {
698698 return _libdl_handle ? _libdl_handle : dlopen ("libdl.so" , RTLD_NOW );
699699}
700700
701- static void * create_namespace (const char * name , const char * ld_library_path ,
702- const char * default_library_path , uint64_t type ,
703- const char * permitted_when_isolated_path ,
704- struct android_namespace_t * parent_namespace ) {
705- if (!_create_namespace ) {
706- void * handle = get_libdl_handle ();
701+ static void * get_libc_handle (void ) {
702+ return _libc_handle ? _libc_handle
703+ : dlopen ("/system/lib64/libc.so" , RTLD_NOW );
704+ }
705+
706+ static struct android_namespace_t * get_exported_namespace (const char * name ) {
707+ if (!_get_exported_namespace ) {
708+ void * handle = get_libc_handle ();
707709 if (!handle ) {
710+ fprintf (stderr , "dlopen failed: %s\n" , dlerror ());
708711 goto fallback ;
709712 }
710713
711- _create_namespace = (struct android_namespace_t *
712- (* )(const char * , const char * , const char * , uint64_t ,
713- const char * , struct android_namespace_t * ))
714- dlsym (handle , "android_create_namespace" );
715- if (!_create_namespace ) {
714+ _get_exported_namespace = (struct android_namespace_t * (* )(const char * ))
715+ dlsym (handle , "__loader_android_get_exported_namespace" );
716+ if (!_get_exported_namespace ) {
717+ fprintf (stderr , "dlsym failed: %s\n" , dlerror ());
716718 goto fallback ;
717719 }
718720 }
719721
720- return _create_namespace (name , ld_library_path , default_library_path , type ,
721- permitted_when_isolated_path , parent_namespace );
722+ return _get_exported_namespace (name );
722723
723724fallback :
724725 return NULL ;
@@ -765,11 +766,7 @@ static void load_hook_lib(void) {
765766#if defined(__GLIBC__ )
766767 handle = dlmopen (LM_ID_NEWLM , filename , RTLD_NOW | RTLD_LOCAL );
767768#elif defined(__ANDROID__ )
768- struct android_namespace_t * ns = create_namespace (
769- "hook-namespace" , NULL ,
770- "/system/lib:/vendor/lib:/system/vendor/lib/hw/:/vendor/lib/hw" ,
771- 0 /* ANDROID_NAMESPACE_TYPE_REGULAR */ , NULL , NULL );
772-
769+ struct android_namespace_t * ns = get_exported_namespace ("default" );
773770 android_dlextinfo extinfo = {
774771 .flags = ANDROID_DLEXT_USE_NAMESPACE ,
775772 .library_namespace = ns ,
0 commit comments