static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo) { ScopedPthreadMutexLocker locker(&g_dl_mutex); soinfo* result = do_dlopen(filename, flags, extinfo); if (result == nullptr) { __bionic_format_dlerror("dlopen failed", linker_get_error_buffer()); return nullptr; } return result; }
void* dlopen(const char* filename, int flags) { ScopedPthreadMutexLocker locker(&gDlMutex); soinfo* result = do_dlopen(filename, flags); if (result == NULL) { __bionic_format_dlerror("dlopen failed", linker_get_error_buffer()); return NULL; } return result; }
static void* dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo, const void* caller_addr) { ScopedPthreadMutexLocker locker(&g_dl_mutex); soinfo* caller_soinfo = find_containing_library(caller_addr); soinfo* result = do_dlopen(filename, flags, caller_soinfo, extinfo); if (result == NULL) { __bionic_format_dlerror("dlopen failed", linker_get_error_buffer()); return NULL; } return result; }
libearly_init(void) { char *s; int k; s = getenv("EARLY"); if (s == NULL) { printf("%s: EARLY = %s\n", __func__, "(not set)"); return; } printf("%s: EARLY = %s\n", __func__, s); for (k = 0; s[k] != 0; k++) { switch (s[k]) { case 'C': case 'c': do_dlclose(); break; case 'E': case 'e': do_exit(); break; case 'F': case 'f': do_fork(); break; case 'O': case 'o': do_dlopen(); break; case 'T': case 't': do_thread(); break; default: printf("%s: unknown char: %c\n", __func__, s[k]); break; } } }
static int dlopen_open(const char *fname, bool use_ext, bool private_namespace, opal_dl_handle_t **handle, char **err_msg) { assert(fname); assert(handle); *handle = NULL; /* Setup the dlopen flags */ int flags = RTLD_LAZY; if (private_namespace) { flags |= RTLD_LOCAL; } else { flags |= RTLD_GLOBAL; } /* If the caller wants to use filename extensions, loop through them */ void *local_handle = NULL; if (use_ext) { int i; char *ext; for (i = 0, ext = mca_dl_dlopen_component.filename_suffixes[i]; NULL != ext; ext = mca_dl_dlopen_component.filename_suffixes[++i]) { char *name; asprintf(&name, "%s%s", fname, ext); if (NULL == name) { return OPAL_ERR_IN_ERRNO; } /* Does the file exist? */ struct stat buf; if (stat(name, &buf) < 0) { free(name); if (NULL != err_msg) { *err_msg = "File not found"; } continue; } /* Yes, the file exists -- try to dlopen it. If we can't dlopen it, bail. */ do_dlopen(name, flags, &local_handle, err_msg); free(name); break; } } /* Otherwise, the caller does not want to use filename extensions, so just use the single filename that the caller provided */ else { do_dlopen(fname, flags, &local_handle, err_msg); } if (NULL != local_handle) { *handle = calloc(1, sizeof(opal_dl_handle_t)); (*handle)->dlopen_handle = local_handle; #if OPAL_ENABLE_DEBUG (*handle)->filename = strdup(fname); #endif } return (NULL != local_handle) ? OPAL_SUCCESS : OPAL_ERROR; }