Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef __ANDROID_DLEXT_NAMESPACES_H__ |
| 18 | #define __ANDROID_DLEXT_NAMESPACES_H__ |
| 19 | |
| 20 | #include <android/dlext.h> |
| 21 | |
| 22 | __BEGIN_DECLS |
| 23 | |
| 24 | /* |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 25 | * Initializes anonymous namespaces. The shared_libs_sonames is the list of sonames |
| 26 | * to be shared by default namespace separated by colon. Example: "libc.so:libm.so:libdl.so". |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 27 | * |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 28 | * The library_search_path is the search path for anonymous namespace. The anonymous namespace |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 29 | * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens |
| 30 | * for the code not loaded by dynamic linker; for example calls from the mono-compiled code. |
| 31 | */ |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 32 | extern bool android_init_anonymous_namespace(const char* shared_libs_sonames, |
| 33 | const char* library_search_path); |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 34 | |
| 35 | |
| 36 | enum { |
| 37 | /* A regular namespace is the namespace with a custom search path that does |
| 38 | * not impose any restrictions on the location of native libraries. |
| 39 | */ |
| 40 | ANDROID_NAMESPACE_TYPE_REGULAR = 0, |
| 41 | |
| 42 | /* An isolated namespace requires all the libraries to be on the search path |
| 43 | * or under permitted_when_isolated_path. The search path is the union of |
| 44 | * ld_library_path and default_library_path. |
| 45 | */ |
| 46 | ANDROID_NAMESPACE_TYPE_ISOLATED = 1, |
| 47 | |
| 48 | /* The shared namespace clones the list of libraries of the caller namespace upon creation |
| 49 | * which means that they are shared between namespaces - the caller namespace and the new one |
| 50 | * will use the same copy of a library if it was loaded prior to android_create_namespace call. |
| 51 | * |
| 52 | * Note that libraries loaded after the namespace is created will not be shared. |
| 53 | * |
| 54 | * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor |
| 55 | * permitted_path from the caller's namespace. |
| 56 | */ |
| 57 | ANDROID_NAMESPACE_TYPE_SHARED = 2, |
Jiyong Park | e8ffe56 | 2017-05-05 22:07:05 +0900 | [diff] [blame] | 58 | |
Ryan Prichard | aff9a34 | 2020-08-03 15:29:12 -0700 | [diff] [blame] | 59 | /* This flag instructs linker to enable exempt-list workaround for the namespace. |
Jiyong Park | e8ffe56 | 2017-05-05 22:07:05 +0900 | [diff] [blame] | 60 | * See http://b/26394120 for details. |
| 61 | */ |
Ryan Prichard | aff9a34 | 2020-08-03 15:29:12 -0700 | [diff] [blame] | 62 | ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000, |
Jiyong Park | e8ffe56 | 2017-05-05 22:07:05 +0900 | [diff] [blame] | 63 | |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 64 | ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED | |
| 65 | ANDROID_NAMESPACE_TYPE_ISOLATED, |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * Creates new linker namespace. |
| 70 | * ld_library_path and default_library_path represent the search path |
| 71 | * for the libraries in the namespace. |
| 72 | * |
| 73 | * The libraries in the namespace are searched by folowing order: |
| 74 | * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH) |
| 75 | * 2. In directories specified by DT_RUNPATH of the "needed by" binary. |
| 76 | * 3. deault_library_path (This of this as namespace-local default library path) |
| 77 | * |
| 78 | * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of |
| 79 | * the libraries to be on the search path or under the permitted_when_isolated_path; |
| 80 | * the search_path is ld_library_path:default_library_path. Note that the |
| 81 | * permitted_when_isolated_path path is not part of the search_path and |
| 82 | * does not affect the search order. It is a way to allow loading libraries from specific |
| 83 | * locations when using absolute path. |
| 84 | * If a library or any of its dependencies are outside of the permitted_when_isolated_path |
| 85 | * and search_path, and it is not part of the public namespace dlopen will fail. |
| 86 | */ |
| 87 | extern struct android_namespace_t* android_create_namespace(const char* name, |
| 88 | const char* ld_library_path, |
| 89 | const char* default_library_path, |
| 90 | uint64_t type, |
Dimitry Ivanov | fc2da53 | 2016-05-12 15:20:21 -0700 | [diff] [blame] | 91 | const char* permitted_when_isolated_path, |
| 92 | android_namespace_t* parent); |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 93 | |
Dimitry Ivanov | 7a34b9d | 2017-02-03 14:07:34 -0800 | [diff] [blame] | 94 | extern bool android_link_namespaces(android_namespace_t* from, |
| 95 | android_namespace_t* to, |
| 96 | const char* shared_libs_sonames); |
| 97 | |
Logan Chien | 9ee4591 | 2018-01-18 12:05:09 +0800 | [diff] [blame] | 98 | extern bool android_link_namespaces_all_libs(android_namespace_t* from, |
| 99 | android_namespace_t* to); |
| 100 | |
Elliott Hughes | ff1428a | 2018-11-12 16:01:37 -0800 | [diff] [blame] | 101 | extern void android_set_application_target_sdk_version(int target); |
Dimitry Ivanov | 41fd295 | 2016-05-09 17:37:39 -0700 | [diff] [blame] | 102 | |
| 103 | __END_DECLS |
| 104 | |
| 105 | #endif /* __ANDROID_DLEXT_NAMESPACES_H__ */ |