summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiyong Park2017-05-16 22:11:59 -0500
committerJiyong Park2017-05-17 00:29:44 -0500
commitc9c527f81f9e5cad429bdc74103c918aaf9c2a1b (patch)
tree3dbd746e0c93c1b2e7457b073599a54203253a02
parent1475ef280c02f42c680f034d16828544f166bf90 (diff)
parentfbe9427241623fa47d3d0113c089d0613f4ca5f5 (diff)
downloadplatform-system-core-c9c527f81f9e5cad429bdc74103c918aaf9c2a1b.tar.gz
platform-system-core-c9c527f81f9e5cad429bdc74103c918aaf9c2a1b.tar.xz
platform-system-core-c9c527f81f9e5cad429bdc74103c918aaf9c2a1b.zip
resolve merge conflicts of fbe942724 to oc-dev-plus-aosp
Test: I solemnly swear I tested this conflict resolution. Merged-In: I137c17d55940b783eab6d0125bc4d26b96bcc2f2 Change-Id: I90c3ff7c82a9b53ce00057fd87cf227d5faf0975
-rw-r--r--libvndksupport/Android.bp15
-rw-r--r--libvndksupport/include/vndksupport/linker.h31
-rw-r--r--libvndksupport/libvndksupport.map.txt7
-rw-r--r--libvndksupport/linker.c50
-rw-r--r--libvndksupport/tests/Android.bp26
-rw-r--r--libvndksupport/tests/linker_test.cpp60
-rw-r--r--rootdir/etc/ld.config.txt16
7 files changed, 192 insertions, 13 deletions
diff --git a/libvndksupport/Android.bp b/libvndksupport/Android.bp
new file mode 100644
index 000000000..ab9e26fe4
--- /dev/null
+++ b/libvndksupport/Android.bp
@@ -0,0 +1,15 @@
1subdirs = ["tests"]
2
3cc_library_shared {
4 name: "libvndksupport",
5 srcs: ["linker.c"],
6 local_include_dirs: ["include/vndksupport"],
7 export_include_dirs: ["include"],
8 shared_libs: ["liblog"],
9}
10
11llndk_library {
12 name: "libvndksupport",
13 symbol_file: "libvndksupport.map.txt",
14 export_include_dirs: ["include"],
15}
diff --git a/libvndksupport/include/vndksupport/linker.h b/libvndksupport/include/vndksupport/linker.h
new file mode 100644
index 000000000..f509564e1
--- /dev/null
+++ b/libvndksupport/include/vndksupport/linker.h
@@ -0,0 +1,31 @@
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#ifndef VNDKSUPPORT_LINKER_H_
17#define VNDKSUPPORT_LINKER_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23void* android_load_sphal_library(const char* name, int flag);
24
25int android_unload_sphal_library(void* handle);
26
27#ifdef __cplusplus
28}
29#endif
30
31#endif // VNDKSUPPORT_LINKER_H_
diff --git a/libvndksupport/libvndksupport.map.txt b/libvndksupport/libvndksupport.map.txt
new file mode 100644
index 000000000..16e38da1a
--- /dev/null
+++ b/libvndksupport/libvndksupport.map.txt
@@ -0,0 +1,7 @@
1LIBVNDKSUPPORT {
2 global:
3 android_load_sphal_library; # vndk
4 android_unload_sphal_library; # vndk
5 local:
6 *;
7};
diff --git a/libvndksupport/linker.c b/libvndksupport/linker.c
new file mode 100644
index 000000000..12aa3bec8
--- /dev/null
+++ b/libvndksupport/linker.c
@@ -0,0 +1,50 @@
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
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);
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
50int android_unload_sphal_library(void* handle) { return dlclose(handle); }
diff --git a/libvndksupport/tests/Android.bp b/libvndksupport/tests/Android.bp
new file mode 100644
index 000000000..3587cf88a
--- /dev/null
+++ b/libvndksupport/tests/Android.bp
@@ -0,0 +1,26 @@
1// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15cc_test {
16 name: "libvndksupport-tests",
17 srcs: [
18 "linker_test.cpp",
19 ],
20
21 host_supported: false,
22 shared_libs: [
23 "libvndksupport",
24 "libbase",
25 ]
26}
diff --git a/libvndksupport/tests/linker_test.cpp b/libvndksupport/tests/linker_test.cpp
new file mode 100644
index 000000000..7ce27d411
--- /dev/null
+++ b/libvndksupport/tests/linker_test.cpp
@@ -0,0 +1,60 @@
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 <gtest/gtest.h>
17
18#include <android-base/strings.h>
19#include <dirent.h>
20#include <dlfcn.h>
21#include <vndksupport/linker.h>
22#include <string>
23
24// Since the test executable will be in /data and ld.config.txt does not
25// configure sphal namespace for executables in /data, the call to
26// android_load_sphal_library will always fallback to the plain dlopen from the
27// default namespace.
28
29// Let's use libEGL_<chipset>.so as a SP-HAL in test
30static std::string find_sphal_lib() {
31 const char* path =
32#if defined(__LP64__)
33 "/vendor/lib64/egl";
34#else
35 "/vendor/lib/egl";
36#endif
37 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(path), closedir);
38
39 dirent* dp;
40 while ((dp = readdir(dir.get())) != nullptr) {
41 std::string name = dp->d_name;
42 if (android::base::StartsWith(name, "libEGL_")) {
43 return std::string(path) + "/" + name;
44 }
45 }
46 return "";
47}
48
49TEST(linker, load_existing_lib) {
50 std::string name = find_sphal_lib();
51 ASSERT_NE("", name);
52 void* handle = android_load_sphal_library(name.c_str(), RTLD_NOW | RTLD_LOCAL);
53 ASSERT_NE(nullptr, handle);
54 android_unload_sphal_library(handle);
55}
56
57TEST(linker, load_nonexisting_lib) {
58 void* handle = android_load_sphal_library("libNeverUseThisName.so", RTLD_NOW | RTLD_LOCAL);
59 ASSERT_EQ(nullptr, handle);
60}
diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index 3e23d9807..a4545afff 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -60,11 +60,7 @@ namespace.sphal.asan.permitted.paths = /data/asan/vendor/${LIB}:/vendor/${LIB}
60namespace.sphal.links = default,vndk,rs 60namespace.sphal.links = default,vndk,rs
61 61
62# WARNING: only NDK libs can be listed here. 62# WARNING: only NDK libs can be listed here.
63# However, this is commented out because some SP-HALs (gralloc.msm8996.so, etc) 63namespace.sphal.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libvndksupport.so
64# are currently using some non-stable libs such as libbacktrace.so. We will get back
65# to this list once the dependencies are fixed.
66#namespace.sphal.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libsync.so
67namespace.sphal.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libbacktrace.so:libGLESv1_CM.so:libGLESv2.so
68 64
69# WARNING: only VNDK-SP libs can be listed here. DO NOT EDIT this line. 65# WARNING: only VNDK-SP libs can be listed here. DO NOT EDIT this line.
70namespace.sphal.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so 66namespace.sphal.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so
@@ -85,7 +81,7 @@ namespace.rs.search.paths = /system/${LIB}/vndk-sp:/vendor/${LIB}
85namespace.rs.permitted.paths = /vendor/${LIB}:/data 81namespace.rs.permitted.paths = /vendor/${LIB}:/data
86 82
87namespace.rs.links = default,vndk 83namespace.rs.links = default,vndk
88namespace.rs.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libbacktrace.so:libGLESv1_CM.so:libGLESv2.so:libmediandk.so:libui.so 84namespace.rs.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libGLESv1_CM.so:libGLESv2.so:libmediandk.so:libui.so:libvndksupport.so
89namespace.rs.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so 85namespace.rs.link.vndk.shared_libs = android.hardware.renderscript@1.0.so:android.hardware.graphics.allocator@2.0.so:android.hardware.graphics.mapper@2.0.so:android.hardware.graphics.common@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so
90 86
91############################################################################### 87###############################################################################
@@ -104,13 +100,7 @@ namespace.vndk.asan.permitted.paths = /data/asan/vendor/${LIB}/hw:/vendor/${LIB}
104# to the default namespace. This is possible since their ABI is stable across 100# to the default namespace. This is possible since their ABI is stable across
105# Android releases. 101# Android releases.
106namespace.vndk.links = default 102namespace.vndk.links = default
107 103namespace.vndk.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libvndksupport.so
108# WARNING: only NDK libs can be listed here.
109# However, this is commented out because some SP-HALs (gralloc.msm8996.so, etc)
110# are currently using some non-stable libs such as libbacktrace.so. We will get back
111# to this list once the dependencies are fixed.
112#namespace.vndk.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libsync.so
113namespace.vndk.link.default.shared_libs = libc.so:libz.so:libm.so:libdl.so:libstdc++.so:liblog.so:libnativewindow.so:libEGL.so:libsync.so:libbacktrace.so
114 104
115 105
116[vendor] 106[vendor]