blob: 289f153e7f7816722700d5a2a57dfa67e155e65c [file] [log] [blame]
Jiyong Park8902f752017-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 Yun7a1d8a12017-05-22 14:31:56 +090033 if (!handle) {
34 ALOGE("Could not load %s from sphal namespace: %s.", name, dlerror());
Jiyong Park8902f752017-05-11 02:15:24 +090035 }
Justin Yun7a1d8a12017-05-22 14:31:56 +090036 return handle;
Jiyong Park8902f752017-05-11 02:15:24 +090037 } else {
38 ALOGI(
39 "sphal namespace is not configured for this process. "
40 "Loading %s from the current namespace instead.",
41 name);
Justin Yun7a1d8a12017-05-22 14:31:56 +090042 return dlopen(name, flag);
Jiyong Park8902f752017-05-11 02:15:24 +090043 }
Jiyong Park8902f752017-05-11 02:15:24 +090044}
45
46int android_unload_sphal_library(void* handle) { return dlclose(handle); }