blob: 696e9781752b6f882ff2abd63d3e6e5295ddc1e6 [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(
35 "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 {
40 ALOGI(
41 "sphal namespace is not configured for this process. "
42 "Loading %s from the current namespace instead.",
43 name);
Justin Yun17baed12017-05-22 14:31:56 +090044 return dlopen(name, flag);
Jiyong Park7130e132017-05-11 02:15:24 +090045 }
Jiyong Park7130e132017-05-11 02:15:24 +090046}
47
48int android_unload_sphal_library(void* handle) {
49 return dlclose(handle);
50}