blob: 20f08d9f140ab40d1ff03a02b3606a3753e9466d [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
Mitch Phillipsa493fe42023-01-19 12:47:22 -080017#include <android/dlext.h>
Matt Fischere2a8b1f2009-12-31 12:17:40 -060018#include <dlfcn.h>
Elliott Hughes7ac97512014-01-14 17:25:13 -080019#include <link.h>
Mitch Phillipsa493fe42023-01-19 12:47:22 -080020#include <signal.h>
Elliott Hughesa4aafd12014-01-13 16:37:47 -080021#include <stdlib.h>
22
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080023// These functions are exported by the loader
24// TODO(dimitry): replace these with reference to libc.so
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080025
Josh Gaodfcc6e42017-10-13 11:56:55 -070026extern "C" {
27
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080028__attribute__((__weak__, visibility("default")))
dimitryce584e42019-03-29 05:34:33 +010029void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
30
31__attribute__((__weak__, visibility("default")))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080032void* __loader_dlopen(const char* filename, int flags, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080033
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080034__attribute__((__weak__, visibility("default")))
Josh Gaodfcc6e42017-10-13 11:56:55 -070035char* __loader_dlerror();
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080036
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080037__attribute__((__weak__, visibility("default")))
38void* __loader_dlsym(void* handle, const char* symbol, const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080039
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080040__attribute__((__weak__, visibility("default")))
41void* __loader_dlvsym(void* handle,
42 const char* symbol,
43 const char* version,
44 const void* caller_addr);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080045
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080046__attribute__((__weak__, visibility("default")))
47int __loader_dladdr(const void* addr, Dl_info* info);
Dimitry Ivanov9cf99cb2015-12-11 14:22:24 -080048
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080049__attribute__((__weak__, visibility("default")))
50int __loader_dlclose(void* handle);
Elliott Hughes7ac97512014-01-14 17:25:13 -080051
Elliott Hughes22d62922012-10-12 10:50:21 -070052#if defined(__arm__)
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080053__attribute__((__weak__, visibility("default")))
54_Unwind_Ptr __loader_dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
Christopher Ferris24053a42013-08-19 17:45:09 -070055#endif
Elliott Hughes22d62922012-10-12 10:50:21 -070056
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080057__attribute__((__weak__, visibility("default")))
58int __loader_dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data),
59 void* data);
60
61__attribute__((__weak__, visibility("default")))
62void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size);
63
64__attribute__((__weak__, visibility("default")))
65void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
66
67__attribute__((__weak__, visibility("default")))
68void* __loader_android_dlopen_ext(const char* filename,
69 int flag,
70 const android_dlextinfo* extinfo,
71 const void* caller_addr);
72
73__attribute__((__weak__, visibility("default")))
Elliott Hughesff1428a2018-11-12 16:01:37 -080074int __loader_android_get_application_target_sdk_version();
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080075
Mitch Phillipsa493fe42023-01-19 12:47:22 -080076__attribute__((__weak__, visibility("default"))) bool __loader_android_handle_signal(
77 int signal_number, siginfo_t* info, void* context);
78
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080079// Proxy calls to bionic loader
dimitryc5ea3eb2017-10-05 17:23:10 +020080__attribute__((__weak__))
dimitryce584e42019-03-29 05:34:33 +010081void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
82 __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
83}
84
85__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080086void* dlopen(const char* filename, int flag) {
87 const void* caller_addr = __builtin_return_address(0);
88 return __loader_dlopen(filename, flag, caller_addr);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070089}
Torne (Richard Coles)012cb452014-02-06 14:34:21 +000090
dimitryc5ea3eb2017-10-05 17:23:10 +020091__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080092char* dlerror() {
93 return __loader_dlerror();
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070094}
Dmitriy Ivanov79fd6682015-05-21 17:43:49 -070095
dimitryc5ea3eb2017-10-05 17:23:10 +020096__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -080097void* dlsym(void* handle, const char* symbol) {
98 const void* caller_addr = __builtin_return_address(0);
99 return __loader_dlsym(handle, symbol, caller_addr);
Dmitriy Ivanov1ffec1c2015-11-23 11:26:35 -0800100}
101
dimitryc5ea3eb2017-10-05 17:23:10 +0200102__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800103void* dlvsym(void* handle, const char* symbol, const char* version) {
104 const void* caller_addr = __builtin_return_address(0);
105 return __loader_dlvsym(handle, symbol, version, caller_addr);
106}
107
dimitryc5ea3eb2017-10-05 17:23:10 +0200108__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800109int dladdr(const void* addr, Dl_info* info) {
110 return __loader_dladdr(addr, info);
111}
112
dimitryc5ea3eb2017-10-05 17:23:10 +0200113__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800114int dlclose(void* handle) {
115 return __loader_dlclose(handle);
116}
117
118#if defined(__arm__)
dimitryc5ea3eb2017-10-05 17:23:10 +0200119__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800120_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
121 return __loader_dl_unwind_find_exidx(pc, pcount);
122}
123#endif
124
Dan Albertdb98fed2017-04-25 15:42:42 -0700125/*
126 * This needs to be defined as weak because it is also defined in libc.a.
127 * Without this, static executables will have a multiple definition error.
128 */
129__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800130int dl_iterate_phdr(int (*cb)(struct dl_phdr_info* info, size_t size, void* data), void* data) {
131 return __loader_dl_iterate_phdr(cb, data);
132}
133
dimitryc5ea3eb2017-10-05 17:23:10 +0200134__attribute__((__weak__))
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800135void* android_dlopen_ext(const char* filename, int flag, const android_dlextinfo* extinfo) {
136 const void* caller_addr = __builtin_return_address(0);
137 return __loader_android_dlopen_ext(filename, flag, extinfo, caller_addr);
138}
139
dimitryc5ea3eb2017-10-05 17:23:10 +0200140__attribute__((__weak__))
Elliott Hughesff1428a2018-11-12 16:01:37 -0800141int android_get_application_target_sdk_version() {
Dimitry Ivanovd9e427c2016-11-22 16:55:25 -0800142 return __loader_android_get_application_target_sdk_version();
143}
144
Mitch Phillipsa493fe42023-01-19 12:47:22 -0800145// Returns true if this function handled the signal, false if the caller should handle the signal
146// itself. This function returns true if the sigchain handler should immediately return, which
147// happens when the signal came from GWP-ASan, and we've dumped a debuggerd report and patched up
148// the GWP-ASan allocator to recover from the fault, and regular execution of the program can
149// continue.
150__attribute__((__weak__)) bool android_handle_signal(int signal_number, siginfo_t* info,
151 void* context) {
152 return __loader_android_handle_signal(signal_number, info, context);
153}
154
Josh Gaodfcc6e42017-10-13 11:56:55 -0700155} // extern "C"