| dimitry | 8868d9e | 2019-03-19 13:01:42 +0100 | [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 |  | 
|  | 17 | #include <dlfcn.h> | 
|  | 18 | #include <link.h> | 
|  | 19 | #include <stdlib.h> | 
|  | 20 | #include <android/dlext.h> | 
|  | 21 |  | 
|  | 22 | // These functions are exported by the loader | 
|  | 23 | // TODO(dimitry): replace these with reference to libc.so | 
|  | 24 |  | 
|  | 25 | extern "C" { | 
|  | 26 |  | 
|  | 27 | __attribute__((__weak__, visibility("default"))) | 
|  | 28 | void __loader_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size); | 
|  | 29 |  | 
|  | 30 | __attribute__((__weak__, visibility("default"))) | 
| dimitry | 4b8b849 | 2019-03-28 12:43:14 +0100 | [diff] [blame] | 31 | void __loader_android_update_LD_LIBRARY_PATH(const char* ld_library_path); | 
| dimitry | 8868d9e | 2019-03-19 13:01:42 +0100 | [diff] [blame] | 32 |  | 
|  | 33 | __attribute__((__weak__, visibility("default"))) | 
|  | 34 | void __loader_android_set_application_target_sdk_version(int target); | 
|  | 35 |  | 
|  | 36 | __attribute__((__weak__, visibility("default"))) | 
|  | 37 | bool __loader_android_init_anonymous_namespace(const char* shared_libs_sonames, | 
|  | 38 | const char* library_search_path); | 
|  | 39 |  | 
|  | 40 | __attribute__((__weak__, visibility("default"))) | 
|  | 41 | struct android_namespace_t* __loader_android_create_namespace( | 
|  | 42 | const char* name, | 
|  | 43 | const char* ld_library_path, | 
|  | 44 | const char* default_library_path, | 
|  | 45 | uint64_t type, | 
|  | 46 | const char* permitted_when_isolated_path, | 
|  | 47 | struct android_namespace_t* parent, | 
|  | 48 | const void* caller_addr); | 
|  | 49 |  | 
|  | 50 | __attribute__((__weak__, visibility("default"))) | 
|  | 51 | bool __loader_android_link_namespaces( | 
|  | 52 | struct android_namespace_t* namespace_from, | 
|  | 53 | struct android_namespace_t* namespace_to, | 
|  | 54 | const char* shared_libs_sonames); | 
|  | 55 |  | 
|  | 56 | __attribute__((__weak__, visibility("default"))) | 
|  | 57 | void __loader_android_dlwarning(void* obj, void (*f)(void*, const char*)); | 
|  | 58 |  | 
|  | 59 | __attribute__((__weak__, visibility("default"))) | 
|  | 60 | struct android_namespace_t* __loader_android_get_exported_namespace(const char* name); | 
|  | 61 |  | 
|  | 62 | // Proxy calls to bionic loader | 
|  | 63 | __attribute__((__weak__)) | 
|  | 64 | void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) { | 
|  | 65 | __loader_android_get_LD_LIBRARY_PATH(buffer, buffer_size); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | __attribute__((__weak__)) | 
|  | 69 | void android_update_LD_LIBRARY_PATH(const char* ld_library_path) { | 
|  | 70 | __loader_android_update_LD_LIBRARY_PATH(ld_library_path); | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | __attribute__((__weak__)) | 
|  | 74 | void android_set_application_target_sdk_version(int target) { | 
|  | 75 | __loader_android_set_application_target_sdk_version(target); | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | __attribute__((__weak__)) | 
|  | 79 | bool android_init_anonymous_namespace(const char* shared_libs_sonames, | 
|  | 80 | const char* library_search_path) { | 
|  | 81 | return __loader_android_init_anonymous_namespace(shared_libs_sonames, library_search_path); | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | __attribute__((__weak__)) | 
|  | 85 | struct android_namespace_t* android_create_namespace(const char* name, | 
|  | 86 | const char* ld_library_path, | 
|  | 87 | const char* default_library_path, | 
|  | 88 | uint64_t type, | 
|  | 89 | const char* permitted_when_isolated_path, | 
|  | 90 | struct android_namespace_t* parent) { | 
|  | 91 | const void* caller_addr = __builtin_return_address(0); | 
|  | 92 | return __loader_android_create_namespace(name, | 
|  | 93 | ld_library_path, | 
|  | 94 | default_library_path, | 
|  | 95 | type, | 
|  | 96 | permitted_when_isolated_path, | 
|  | 97 | parent, | 
|  | 98 | caller_addr); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | __attribute__((__weak__)) | 
|  | 102 | bool android_link_namespaces(struct android_namespace_t* namespace_from, | 
|  | 103 | struct android_namespace_t* namespace_to, | 
|  | 104 | const char* shared_libs_sonames) { | 
|  | 105 | return __loader_android_link_namespaces(namespace_from, namespace_to, shared_libs_sonames); | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | __attribute__((__weak__)) | 
|  | 109 | void android_dlwarning(void* obj, void (*f)(void*, const char*)) { | 
|  | 110 | __loader_android_dlwarning(obj, f); | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | __attribute__((__weak__)) | 
|  | 114 | struct android_namespace_t* android_get_exported_namespace(const char* name) { | 
|  | 115 | return __loader_android_get_exported_namespace(name); | 
|  | 116 | } | 
|  | 117 |  | 
| dimitry | 8868d9e | 2019-03-19 13:01:42 +0100 | [diff] [blame] | 118 | } // extern "C" |