diff options
author | TreeHugger Robot | 2017-05-16 20:53:55 -0500 |
---|---|---|
committer | Android (Google) Code Review | 2017-05-16 20:53:56 -0500 |
commit | fbe9427241623fa47d3d0113c089d0613f4ca5f5 (patch) | |
tree | 864c4a0b91e635dcf3f4f945dd58432b63b414f2 | |
parent | 15042c1e5e2717cf16e36b8b48a89d665757cdb9 (diff) | |
parent | 15d7483bb77158b5fe631454208cfb2e130572f7 (diff) | |
download | platform-system-core-fbe9427241623fa47d3d0113c089d0613f4ca5f5.tar.gz platform-system-core-fbe9427241623fa47d3d0113c089d0613f4ca5f5.tar.xz platform-system-core-fbe9427241623fa47d3d0113c089d0613f4ca5f5.zip |
Merge changes from topic 'synchronize_vndk-sp' into oc-dev
* changes:
add libvndksupport.so to ll-ndk
libbacktrace is VNDK-SP
add libvndksupport
-rw-r--r-- | libvndksupport/Android.bp | 15 | ||||
-rw-r--r-- | libvndksupport/include/vndksupport/linker.h | 31 | ||||
-rw-r--r-- | libvndksupport/libvndksupport.map.txt | 7 | ||||
-rw-r--r-- | libvndksupport/linker.c | 50 | ||||
-rw-r--r-- | libvndksupport/tests/Android.bp | 26 | ||||
-rw-r--r-- | libvndksupport/tests/linker_test.cpp | 60 | ||||
-rw-r--r-- | rootdir/etc/ld.config.txt | 16 |
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 @@ | |||
1 | subdirs = ["tests"] | ||
2 | |||
3 | cc_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 | |||
11 | llndk_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 | ||
20 | extern "C" { | ||
21 | #endif | ||
22 | |||
23 | void* android_load_sphal_library(const char* name, int flag); | ||
24 | |||
25 | int 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 @@ | |||
1 | LIBVNDKSUPPORT { | ||
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 | |||
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); | ||
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 | |||
50 | int 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 | |||
15 | cc_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 | ||
30 | static 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 | |||
49 | TEST(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 | |||
57 | TEST(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 e8a34bf3b..b4adf53f7 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} | |||
60 | namespace.sphal.links = default,vndk,rs | 60 | namespace.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) | 63 | namespace.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 | ||
67 | namespace.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. |
70 | namespace.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:android.hidl.base@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so | 66 | namespace.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:android.hidl.base@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} | |||
85 | namespace.rs.permitted.paths = /vendor/${LIB}:/data | 81 | namespace.rs.permitted.paths = /vendor/${LIB}:/data |
86 | 82 | ||
87 | namespace.rs.links = default,vndk | 83 | namespace.rs.links = default,vndk |
88 | namespace.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 | 84 | namespace.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 |
89 | namespace.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:android.hidl.base@1.0.so:libhwbinder.so:libbase.so:libcutils.so:libhardware.so:libhidlbase.so:libhidltransport.so:libutils.so:libc++.so | 85 | namespace.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:android.hidl.base@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. |
106 | namespace.vndk.links = default | 102 | namespace.vndk.links = default |
107 | 103 | namespace.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 | ||
113 | namespace.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] |