blob: 4c2415f1f69da66a926cafbc0088fe3d64bd40d9 [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001/*
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 Fischere2a8b1f2009-12-31 12:17:40 -060017#include <dlfcn.h>
Elliott Hughes7ac97512014-01-14 17:25:13 -080018#include <link.h>
Elliott Hughesa4aafd12014-01-13 16:37:47 -080019#include <stdlib.h>
Torne (Richard Coles)012cb452014-02-06 14:34:21 +000020#include <android/dlext.h>
Elliott Hughesa4aafd12014-01-13 16:37:47 -080021
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080022// These functions are exported by the loader
23// TODO(dimitry): replace these with reference to libc.so
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080024
Josh Gaodfcc6e42017-10-13 11:56:55 -070025extern "C" {
26
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080027__attribute__((__weak__, visibility("default")))
28void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080029
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080030__attribute__((__weak__, visibility("default")))
Josh Gaodfcc6e42017-10-13 11:56:55 -070031char* __loader_dlerror();
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080032
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080033__attribute__((__weak__, visibility("default")))
34void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080035
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080036__attribute__((__weak__, visibility("default")))
37void* __loader_dlvsym(void* handle,
38 const char* symbol,
39 const char* version,
40 const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080041
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080042__attribute__((__weak__, visibility("default")))
43int __loader_dladdr(const void* addr, Dl_info* info);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080044
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080045__attribute__((__weak__, visibility("default")))
46int __loader_dlclose(void* handle);
Elliott Hughes7ac97512014-01-14 17:25:13 -080047
Elliott Hughes22d62922012-10-12 10:50:21 -070048#if defined(__arm__)
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080049__attribute__((__weak__, visibility("default")))
50_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
Christopher Ferris24053a42013-08-19 17:45:09 -070051#endif
Elliott Hughes22d62922012-10-12 10:50:21 -070052
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080053__attribute__((__weak__, visibility("default")))
54int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data),
55 void* data);
56
57__attribute__((__weak__, visibility("default")))
58void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
59
60__attribute__((__weak__, visibility("default")))
61void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
62
63__attribute__((__weak__, visibility("default")))
64void* __loader_android_dlopen_ext(const char* filename,
65 int flag,
66 const android_dlextinfo* extinfo,
67 const void* caller_addr);
68
69__attribute__((__weak__, visibility("default")))
70void __loader_android_set_application_target_sdk_version(uint32_t target);
71
72__attribute__((__weak__, visibility("default")))
73uint32_t __loader_android_get_application_target_sdk_version();
74
75__attribute__((__weak__, visibility("default")))
Dimitry Ivanov7a34b9d2017-02-03 14:07:34 -080076bool __loader_android_init_anonymous_namespace(const char* shared_libs_sonames,
77 const char* library_search_path);
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080078
79__attribute__((__weak__, visibility("default")))
80struct android_namespace_t* __loader_android_create_namespace(
81 const char* name,
82 const char* ld_library_path,
83 const char* default_library_path,
84 uint64_t type,
85 const char* permitted_when_isolated_path,
86 struct android_namespace_t* parent,
87 const void* caller_addr);
88
Dimitry Ivanov4e84d5e2016-12-12 16:21:46 -080089__attribute__((__weak__, visibility("default")))
Dimitry Ivanov7a34b9d2017-02-03 14:07:34 -080090bool __loader_android_link_namespaces(
91 struct android_namespace_t* namespace_from,
92 struct android_namespace_t* namespace_to,
93 const char* shared_libs_sonames);
94
95__attribute__((__weak__, visibility("default")))
Logan Chien9ee45912018-01-18 12:05:09 +080096bool __loader_android_link_namespaces_all_libs(
97 struct android_namespace_t* namespace_from,
98 struct android_namespace_t* namespace_to);
99
100__attribute__((__weak__, visibility("default")))
Dimitry Ivanov4e84d5e2016-12-12 16:21:46 -0800101void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*));
102
Jiyong Parkd7c48322017-04-03 23:10:37 +0900103__attribute__((__weak__, visibility("default")))
104struct android_namespace_t* __loader_android_get_exported_namespace(const char* name);
105
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800106// Proxy calls to bionic loader
dimitryc5ea3eb2017-10-05 17:23:10 +0200107__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800108void* dlopen(const char* filename, int flag) {
109 const void* caller_addr = __builtin_return_address(0);
110 return __loader_dlopen(filename, flag, caller_addr);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700111}
Torne (Richard Coles)012cb452014-02-06 14:34:21 +0000112
dimitryc5ea3eb2017-10-05 17:23:10 +0200113__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800114char* dlerror() {
115 return __loader_dlerror();
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700116}
Dmitriy Ivanov79fd6682015-05-21 17:43:49 -0700117
dimitryc5ea3eb2017-10-05 17:23:10 +0200118__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800119void* dlsym(void* handle, const char* symbol) {
120 const void* caller_addr = __builtin_return_address(0);
121 return __loader_dlsym(handle, symbol, caller_addr);
Dmitriy Ivanov1ffec1c2015-11-23 11:26:35 -0800122}
123
dimitryc5ea3eb2017-10-05 17:23:10 +0200124__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800125void* dlvsym(void* handle, const char* symbol, const char* version) {
126 const void* caller_addr = __builtin_return_address(0);
127 return __loader_dlvsym(handle, symbol, version, caller_addr);
128}
129
dimitryc5ea3eb2017-10-05 17:23:10 +0200130__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800131int dladdr(const void* addr, Dl_info* info) {
132 return __loader_dladdr(addr, info);
133}
134
dimitryc5ea3eb2017-10-05 17:23:10 +0200135__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800136int dlclose(void* handle) {
137 return __loader_dlclose(handle);
138}
139
140#if defined(__arm__)
dimitryc5ea3eb2017-10-05 17:23:10 +0200141__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800142_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
143 return __loader_dl_unwind_find_exidx(pc, pcount);
144}
145#endif
146
Dan Albertdb98fed2017-04-25 15:42:42 -0700147/*
148 * This needs to be defined as weak because it is also defined in libc.a.
149 * Without this, static executables will have a multiple definition error.
150 */
151__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800152int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
153 return __loader_dl_iterate_phdr(cb, data);
154}
155
dimitryc5ea3eb2017-10-05 17:23:10 +0200156__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800157void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
158 __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
159}
160
dimitryc5ea3eb2017-10-05 17:23:10 +0200161__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800162void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
163 __loader_android_update_LD_LIBRARY_PATH(ld_library_path);
164}
165
dimitryc5ea3eb2017-10-05 17:23:10 +0200166__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800167void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
168 const void* caller_addr = __builtin_return_address(0);
169 return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
170}
171
dimitryc5ea3eb2017-10-05 17:23:10 +0200172__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800173void android_set_application_target_sdk_version(uint32_t target) {
174 __loader_android_set_application_target_sdk_version(target);
175}
dimitryc5ea3eb2017-10-05 17:23:10 +0200176
177__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800178uint32_t android_get_application_target_sdk_version() {
179 return __loader_android_get_application_target_sdk_version();
180}
181
dimitryc5ea3eb2017-10-05 17:23:10 +0200182__attribute__((__weak__))
Dimitry Ivanov7a34b9d2017-02-03 14:07:34 -0800183bool android_init_anonymous_namespace(const char* shared_libs_sonames,
184 const char* library_search_path) {
185 return __loader_android_init_anonymous_namespace(shared_libs_sonames, library_search_path);
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800186}
187
dimitryc5ea3eb2017-10-05 17:23:10 +0200188__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800189struct android_namespace_t* android_create_namespace(const char* name,
190 const char* ld_library_path,
191 const char* default_library_path,
192 uint64_t type,
193 const char* permitted_when_isolated_path,
194 struct android_namespace_t* parent) {
195 const void* caller_addr = __builtin_return_address(0);
196 return __loader_android_create_namespace(name,
197 ld_library_path,
198 default_library_path,
199 type,
200 permitted_when_isolated_path,
201 parent,
202 caller_addr);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700203}
Dimitry Ivanov769b33f2016-07-21 11:33:40 -0700204
dimitryc5ea3eb2017-10-05 17:23:10 +0200205__attribute__((__weak__))
Dimitry Ivanov7a34b9d2017-02-03 14:07:34 -0800206bool android_link_namespaces(struct android_namespace_t* namespace_from,
207 struct android_namespace_t* namespace_to,
208 const char* shared_libs_sonames) {
209 return __loader_android_link_namespaces(namespace_from, namespace_to, shared_libs_sonames);
210}
211
dimitryc5ea3eb2017-10-05 17:23:10 +0200212__attribute__((__weak__))
Logan Chien9ee45912018-01-18 12:05:09 +0800213bool android_link_namespaces_all_libs(struct android_namespace_t* namespace_from,
214 struct android_namespace_t* namespace_to) {
215 return __loader_android_link_namespaces_all_libs(namespace_from, namespace_to);
216}
217
218__attribute__((__weak__))
Dimitry Ivanov4e84d5e2016-12-12 16:21:46 -0800219void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
220 __loader_android_dlwarning(obj, f);
221}
Jiyong Parkd7c48322017-04-03 23:10:37 +0900222
dimitryc5ea3eb2017-10-05 17:23:10 +0200223__attribute__((__weak__))
Jiyong Parkd7c48322017-04-03 23:10:37 +0900224struct android_namespace_t* android_get_exported_namespace(const char* name) {
225 return __loader_android_get_exported_namespace(name);
226}
Josh Gaodfcc6e42017-10-13 11:56:55 -0700227
228} // extern "C"