| Jiyong Park | 8902f75 | 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); | 
| Justin Yun | 7a1d8a1 | 2017-05-22 14:31:56 +0900 | [diff] [blame] | 33 | if (!handle) { | 
|  | 34 | ALOGE("Could not load %s from sphal namespace: %s.", name, dlerror()); | 
| Jiyong Park | 8902f75 | 2017-05-11 02:15:24 +0900 | [diff] [blame] | 35 | } | 
| Justin Yun | 7a1d8a1 | 2017-05-22 14:31:56 +0900 | [diff] [blame] | 36 | return handle; | 
| Jiyong Park | 8902f75 | 2017-05-11 02:15:24 +0900 | [diff] [blame] | 37 | } else { | 
|  | 38 | ALOGI( | 
|  | 39 | "sphal namespace is not configured for this process. " | 
|  | 40 | "Loading %s from the current namespace instead.", | 
|  | 41 | name); | 
| Justin Yun | 7a1d8a1 | 2017-05-22 14:31:56 +0900 | [diff] [blame] | 42 | return dlopen(name, flag); | 
| Jiyong Park | 8902f75 | 2017-05-11 02:15:24 +0900 | [diff] [blame] | 43 | } | 
| Jiyong Park | 8902f75 | 2017-05-11 02:15:24 +0900 | [diff] [blame] | 44 | } | 
|  | 45 |  | 
|  | 46 | int android_unload_sphal_library(void* handle) { return dlclose(handle); } |