The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Matt Fischer | e2a8b1f | 2009-12-31 12:17:40 -0600 | [diff] [blame] | 17 | #include <dlfcn.h> |
Elliott Hughes | 7ac9751 | 2014-01-14 17:25:13 -0800 | [diff] [blame] | 18 | #include <link.h> |
Elliott Hughes | a4aafd1 | 2014-01-13 16:37:47 -0800 | [diff] [blame] | 19 | #include <stdlib.h> |
Dmitriy Ivanov | 79fd668 | 2015-05-21 17:43:49 -0700 | [diff] [blame] | 20 | #include <stdbool.h> |
Torne (Richard Coles) | 012cb45 | 2014-02-06 14:34:21 +0000 | [diff] [blame] | 21 | #include <android/dlext.h> |
Elliott Hughes | a4aafd1 | 2014-01-13 16:37:47 -0800 | [diff] [blame] | 22 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 23 | // These functions are exported by the loader |
| 24 | // TODO(dimitry): replace these with reference to libc.so |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 25 | |
Josh Gao | dfcc6e4 | 2017-10-13 11:56:55 -0700 | [diff] [blame^] | 26 | extern "C" { |
| 27 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 28 | __attribute__((__weak__, visibility("default"))) |
| 29 | void* __loader_dlopen(const char* filename, int flags, const void* caller_addr); |
Dimitry Ivanov | 9cf99cb | 2015-12-11 14:22:24 -0800 | [diff] [blame] | 30 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 31 | __attribute__((__weak__, visibility("default"))) |
Josh Gao | dfcc6e4 | 2017-10-13 11:56:55 -0700 | [diff] [blame^] | 32 | char* __loader_dlerror(); |
Dimitry Ivanov | 9cf99cb | 2015-12-11 14:22:24 -0800 | [diff] [blame] | 33 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 34 | __attribute__((__weak__, visibility("default"))) |
| 35 | void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr); |
Dimitry Ivanov | 9cf99cb | 2015-12-11 14:22:24 -0800 | [diff] [blame] | 36 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 37 | __attribute__((__weak__, visibility("default"))) |
| 38 | void* __loader_dlvsym(void* handle, |
| 39 | const char* symbol, |
| 40 | const char* version, |
| 41 | const void* caller_addr); |
Dimitry Ivanov | 9cf99cb | 2015-12-11 14:22:24 -0800 | [diff] [blame] | 42 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 43 | __attribute__((__weak__, visibility("default"))) |
| 44 | int __loader_dladdr(const void* addr, Dl_info* info); |
Dimitry Ivanov | 9cf99cb | 2015-12-11 14:22:24 -0800 | [diff] [blame] | 45 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 46 | __attribute__((__weak__, visibility("default"))) |
| 47 | int __loader_dlclose(void* handle); |
Elliott Hughes | 7ac9751 | 2014-01-14 17:25:13 -0800 | [diff] [blame] | 48 | |
Elliott Hughes | 22d6292 | 2012-10-12 10:50:21 -0700 | [diff] [blame] | 49 | #if defined(__arm__) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 50 | __attribute__((__weak__, visibility("default"))) |
| 51 | _Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount); |
Christopher Ferris | 24053a4 | 2013-08-19 17:45:09 -0700 | [diff] [blame] | 52 | #endif |
Elliott Hughes | 22d6292 | 2012-10-12 10:50:21 -0700 | [diff] [blame] | 53 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 54 | __attribute__((__weak__, visibility("default"))) |
| 55 | int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), |
| 56 | void* data); |
| 57 | |
| 58 | __attribute__((__weak__, visibility("default"))) |
| 59 | void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size); |
| 60 | |
| 61 | __attribute__((__weak__, visibility("default"))) |
| 62 | void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path); |
| 63 | |
| 64 | __attribute__((__weak__, visibility("default"))) |
| 65 | void* __loader_android_dlopen_ext(const char* filename, |
| 66 | int flag, |
| 67 | const android_dlextinfo* extinfo, |
| 68 | const void* caller_addr); |
| 69 | |
| 70 | __attribute__((__weak__, visibility("default"))) |
| 71 | void __loader_android_set_application_target_sdk_version(uint32_t target); |
| 72 | |
| 73 | __attribute__((__weak__, visibility("default"))) |
| 74 | uint32_t __loader_android_get_application_target_sdk_version(); |
| 75 | |
| 76 | __attribute__((__weak__, visibility("default"))) |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 77 | bool __loader_android_init_anonymous_namespace(const char* shared_libs_sonames, |
| 78 | const char* library_search_path); |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 79 | |
| 80 | __attribute__((__weak__, visibility("default"))) |
| 81 | struct android_namespace_t* __loader_android_create_namespace( |
| 82 | const char* name, |
| 83 | const char* ld_library_path, |
| 84 | const char* default_library_path, |
| 85 | uint64_t type, |
| 86 | const char* permitted_when_isolated_path, |
| 87 | struct android_namespace_t* parent, |
| 88 | const void* caller_addr); |
| 89 | |
Dimitry Ivanov | 4e84d5e | 2016-12-12 16:21:46 -0800 | [diff] [blame] | 90 | __attribute__((__weak__, visibility("default"))) |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 91 | bool __loader_android_link_namespaces( |
| 92 | struct android_namespace_t* namespace_from, |
| 93 | struct android_namespace_t* namespace_to, |
| 94 | const char* shared_libs_sonames); |
| 95 | |
| 96 | __attribute__((__weak__, visibility("default"))) |
Dimitry Ivanov | 4e84d5e | 2016-12-12 16:21:46 -0800 | [diff] [blame] | 97 | void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*)); |
| 98 | |
Jiyong Park | d7c4832 | 2017-04-03 23:10:37 +0900 | [diff] [blame] | 99 | __attribute__((__weak__, visibility("default"))) |
| 100 | struct android_namespace_t* __loader_android_get_exported_namespace(const char* name); |
| 101 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 102 | // Proxy calls to bionic loader |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 103 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 104 | void* dlopen(const char* filename, int flag) { |
| 105 | const void* caller_addr = __builtin_return_address(0); |
| 106 | return __loader_dlopen(filename, flag, caller_addr); |
Dmitriy Ivanov | 42d5fcb | 2015-10-29 17:01:24 -0700 | [diff] [blame] | 107 | } |
Torne (Richard Coles) | 012cb45 | 2014-02-06 14:34:21 +0000 | [diff] [blame] | 108 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 109 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 110 | char* dlerror() { |
| 111 | return __loader_dlerror(); |
Dmitriy Ivanov | 42d5fcb | 2015-10-29 17:01:24 -0700 | [diff] [blame] | 112 | } |
Dmitriy Ivanov | 79fd668 | 2015-05-21 17:43:49 -0700 | [diff] [blame] | 113 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 114 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 115 | void* dlsym(void* handle, const char* symbol) { |
| 116 | const void* caller_addr = __builtin_return_address(0); |
| 117 | return __loader_dlsym(handle, symbol, caller_addr); |
Dmitriy Ivanov | 1ffec1c | 2015-11-23 11:26:35 -0800 | [diff] [blame] | 118 | } |
| 119 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 120 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 121 | void* dlvsym(void* handle, const char* symbol, const char* version) { |
| 122 | const void* caller_addr = __builtin_return_address(0); |
| 123 | return __loader_dlvsym(handle, symbol, version, caller_addr); |
| 124 | } |
| 125 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 126 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 127 | int dladdr(const void* addr, Dl_info* info) { |
| 128 | return __loader_dladdr(addr, info); |
| 129 | } |
| 130 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 131 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 132 | int dlclose(void* handle) { |
| 133 | return __loader_dlclose(handle); |
| 134 | } |
| 135 | |
| 136 | #if defined(__arm__) |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 137 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 138 | _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) { |
| 139 | return __loader_dl_unwind_find_exidx(pc, pcount); |
| 140 | } |
| 141 | #endif |
| 142 | |
Dan Albert | db98fed | 2017-04-25 15:42:42 -0700 | [diff] [blame] | 143 | /* |
| 144 | * This needs to be defined as weak because it is also defined in libc.a. |
| 145 | * Without this, static executables will have a multiple definition error. |
| 146 | */ |
| 147 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 148 | int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) { |
| 149 | return __loader_dl_iterate_phdr(cb, data); |
| 150 | } |
| 151 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 152 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 153 | void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) { |
| 154 | __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size); |
| 155 | } |
| 156 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 157 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 158 | void android_update_LD_LIBRARY_PATH(const char* ld_library_path) { |
| 159 | __loader_android_update_LD_LIBRARY_PATH(ld_library_path); |
| 160 | } |
| 161 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 162 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 163 | void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) { |
| 164 | const void* caller_addr = __builtin_return_address(0); |
| 165 | return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr); |
| 166 | } |
| 167 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 168 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 169 | void android_set_application_target_sdk_version(uint32_t target) { |
| 170 | __loader_android_set_application_target_sdk_version(target); |
| 171 | } |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 172 | |
| 173 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 174 | uint32_t android_get_application_target_sdk_version() { |
| 175 | return __loader_android_get_application_target_sdk_version(); |
| 176 | } |
| 177 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 178 | __attribute__((__weak__)) |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 179 | bool android_init_anonymous_namespace(const char* shared_libs_sonames, |
| 180 | const char* library_search_path) { |
| 181 | return __loader_android_init_anonymous_namespace(shared_libs_sonames, library_search_path); |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 182 | } |
| 183 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 184 | __attribute__((__weak__)) |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 185 | struct android_namespace_t* android_create_namespace(const char* name, |
| 186 | const char* ld_library_path, |
| 187 | const char* default_library_path, |
| 188 | uint64_t type, |
| 189 | const char* permitted_when_isolated_path, |
| 190 | struct android_namespace_t* parent) { |
| 191 | const void* caller_addr = __builtin_return_address(0); |
| 192 | return __loader_android_create_namespace(name, |
| 193 | ld_library_path, |
| 194 | default_library_path, |
| 195 | type, |
| 196 | permitted_when_isolated_path, |
| 197 | parent, |
| 198 | caller_addr); |
Dmitriy Ivanov | 42d5fcb | 2015-10-29 17:01:24 -0700 | [diff] [blame] | 199 | } |
Dimitry Ivanov | 769b33f | 2016-07-21 11:33:40 -0700 | [diff] [blame] | 200 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 201 | __attribute__((__weak__)) |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 202 | bool android_link_namespaces(struct android_namespace_t* namespace_from, |
| 203 | struct android_namespace_t* namespace_to, |
| 204 | const char* shared_libs_sonames) { |
| 205 | return __loader_android_link_namespaces(namespace_from, namespace_to, shared_libs_sonames); |
| 206 | } |
| 207 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 208 | __attribute__((__weak__)) |
Dimitry Ivanov | 4e84d5e | 2016-12-12 16:21:46 -0800 | [diff] [blame] | 209 | void android_dlwarning(void* obj, void (*f)(void*, const char*)) { |
| 210 | __loader_android_dlwarning(obj, f); |
| 211 | } |
Jiyong Park | d7c4832 | 2017-04-03 23:10:37 +0900 | [diff] [blame] | 212 | |
dimitry | c5ea3eb | 2017-10-05 17:23:10 +0200 | [diff] [blame] | 213 | __attribute__((__weak__)) |
Jiyong Park | d7c4832 | 2017-04-03 23:10:37 +0900 | [diff] [blame] | 214 | struct android_namespace_t* android_get_exported_namespace(const char* name) { |
| 215 | return __loader_android_get_exported_namespace(name); |
| 216 | } |
Josh Gao | dfcc6e4 | 2017-10-13 11:56:55 -0700 | [diff] [blame^] | 217 | |
| 218 | } // extern "C" |