blob: 703b593fa94318658971d4352f7cd67c6fda598a [file] [log] [blame]
Jiyong Park7130e132017-05-11 02:15:24 +09001/*
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
24extern struct android_namespace_t* android_get_exported_namespace(const char*);
25
26void* 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 Yun17baed12017-05-22 14:31:56 +090033 if (!handle) {
34 ALOGE(
Justin Yun95600882017-07-31 15:18:32 +090035 "Could not load %s from sphal namespace: %s.",
Jiyong Park7130e132017-05-11 02:15:24 +090036 name, dlerror());
37 }
Justin Yun17baed12017-05-22 14:31:56 +090038 return handle;
Jiyong Park7130e132017-05-11 02:15:24 +090039 } else {
Justin Yun95600882017-07-31 15:18:32 +090040 ALOGD(
41 "Loading %s from current namespace instead of sphal namespace.",
Jiyong Park7130e132017-05-11 02:15:24 +090042 name);
Justin Yun17baed12017-05-22 14:31:56 +090043 return dlopen(name, flag);
Jiyong Park7130e132017-05-11 02:15:24 +090044 }
Jiyong Park7130e132017-05-11 02:15:24 +090045}
46
47int android_unload_sphal_library(void* handle) {
48 return dlclose(handle);
49}