Jiyong Park | 7130e13 | 2017-05-11 02:15:24 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "linker.h" |
| 17 | |
| 18 | #include <android/dlext.h> |
| 19 | #include <dlfcn.h> |
| 20 | |
| 21 | #define LOG_TAG "vndksupport" |
| 22 | #include <log/log.h> |
| 23 | |
| 24 | extern struct android_namespace_t* android_get_exported_namespace(const char*); |
| 25 | |
| 26 | void* android_load_sphal_library(const char* name, int flag) { |
| 27 | struct android_namespace_t* sphal_namespace = android_get_exported_namespace("sphal"); |
| 28 | if (sphal_namespace != NULL) { |
| 29 | const android_dlextinfo dlextinfo = { |
| 30 | .flags = ANDROID_DLEXT_USE_NAMESPACE, .library_namespace = sphal_namespace, |
| 31 | }; |
| 32 | void* handle = android_dlopen_ext(name, flag, &dlextinfo); |
| 33 | if (handle) { |
| 34 | return handle; |
| 35 | } else { |
| 36 | ALOGW( |
| 37 | "Could not load %s from sphal namespace: %s. " |
| 38 | "Falling back to loading it from the current namespace,", |
| 39 | name, dlerror()); |
| 40 | } |
| 41 | } else { |
| 42 | ALOGI( |
| 43 | "sphal namespace is not configured for this process. " |
| 44 | "Loading %s from the current namespace instead.", |
| 45 | name); |
| 46 | } |
| 47 | return dlopen(name, flag); |
| 48 | } |
| 49 | |
| 50 | int android_unload_sphal_library(void* handle) { |
| 51 | return dlclose(handle); |
| 52 | } |