xref: /aosp_15_r20/bionic/tests/dlext_private.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*
2*8d67ca89SAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*8d67ca89SAndroid Build Coastguard Worker  *
4*8d67ca89SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8d67ca89SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8d67ca89SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8d67ca89SAndroid Build Coastguard Worker  *
8*8d67ca89SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*8d67ca89SAndroid Build Coastguard Worker  *
10*8d67ca89SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8d67ca89SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8d67ca89SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8d67ca89SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8d67ca89SAndroid Build Coastguard Worker  * limitations under the License.
15*8d67ca89SAndroid Build Coastguard Worker  */
16*8d67ca89SAndroid Build Coastguard Worker 
17*8d67ca89SAndroid Build Coastguard Worker #ifndef __ANDROID_DLEXT_NAMESPACES_H__
18*8d67ca89SAndroid Build Coastguard Worker #define __ANDROID_DLEXT_NAMESPACES_H__
19*8d67ca89SAndroid Build Coastguard Worker 
20*8d67ca89SAndroid Build Coastguard Worker #include <android/dlext.h>
21*8d67ca89SAndroid Build Coastguard Worker 
22*8d67ca89SAndroid Build Coastguard Worker __BEGIN_DECLS
23*8d67ca89SAndroid Build Coastguard Worker 
24*8d67ca89SAndroid Build Coastguard Worker /*
25*8d67ca89SAndroid Build Coastguard Worker  * Initializes anonymous namespaces. The shared_libs_sonames is the list of sonames
26*8d67ca89SAndroid Build Coastguard Worker  * to be shared by default namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
27*8d67ca89SAndroid Build Coastguard Worker  *
28*8d67ca89SAndroid Build Coastguard Worker  * The library_search_path is the search path for anonymous namespace. The anonymous namespace
29*8d67ca89SAndroid Build Coastguard Worker  * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
30*8d67ca89SAndroid Build Coastguard Worker  * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
31*8d67ca89SAndroid Build Coastguard Worker  */
32*8d67ca89SAndroid Build Coastguard Worker extern bool android_init_anonymous_namespace(const char* shared_libs_sonames,
33*8d67ca89SAndroid Build Coastguard Worker                                              const char* library_search_path);
34*8d67ca89SAndroid Build Coastguard Worker 
35*8d67ca89SAndroid Build Coastguard Worker 
36*8d67ca89SAndroid Build Coastguard Worker enum {
37*8d67ca89SAndroid Build Coastguard Worker   /* A regular namespace is the namespace with a custom search path that does
38*8d67ca89SAndroid Build Coastguard Worker    * not impose any restrictions on the location of native libraries.
39*8d67ca89SAndroid Build Coastguard Worker    */
40*8d67ca89SAndroid Build Coastguard Worker   ANDROID_NAMESPACE_TYPE_REGULAR = 0,
41*8d67ca89SAndroid Build Coastguard Worker 
42*8d67ca89SAndroid Build Coastguard Worker   /* An isolated namespace requires all the libraries to be on the search path
43*8d67ca89SAndroid Build Coastguard Worker    * or under permitted_when_isolated_path. The search path is the union of
44*8d67ca89SAndroid Build Coastguard Worker    * ld_library_path and default_library_path.
45*8d67ca89SAndroid Build Coastguard Worker    */
46*8d67ca89SAndroid Build Coastguard Worker   ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
47*8d67ca89SAndroid Build Coastguard Worker 
48*8d67ca89SAndroid Build Coastguard Worker   /* The shared namespace clones the list of libraries of the caller namespace upon creation
49*8d67ca89SAndroid Build Coastguard Worker    * which means that they are shared between namespaces - the caller namespace and the new one
50*8d67ca89SAndroid Build Coastguard Worker    * will use the same copy of a library if it was loaded prior to android_create_namespace call.
51*8d67ca89SAndroid Build Coastguard Worker    *
52*8d67ca89SAndroid Build Coastguard Worker    * Note that libraries loaded after the namespace is created will not be shared.
53*8d67ca89SAndroid Build Coastguard Worker    *
54*8d67ca89SAndroid Build Coastguard Worker    * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
55*8d67ca89SAndroid Build Coastguard Worker    * permitted_path from the caller's namespace.
56*8d67ca89SAndroid Build Coastguard Worker    */
57*8d67ca89SAndroid Build Coastguard Worker   ANDROID_NAMESPACE_TYPE_SHARED = 2,
58*8d67ca89SAndroid Build Coastguard Worker 
59*8d67ca89SAndroid Build Coastguard Worker   /* This flag instructs linker to enable exempt-list workaround for the namespace.
60*8d67ca89SAndroid Build Coastguard Worker    * See http://b/26394120 for details.
61*8d67ca89SAndroid Build Coastguard Worker    */
62*8d67ca89SAndroid Build Coastguard Worker   ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000,
63*8d67ca89SAndroid Build Coastguard Worker 
64*8d67ca89SAndroid Build Coastguard Worker   ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
65*8d67ca89SAndroid Build Coastguard Worker                                            ANDROID_NAMESPACE_TYPE_ISOLATED,
66*8d67ca89SAndroid Build Coastguard Worker };
67*8d67ca89SAndroid Build Coastguard Worker 
68*8d67ca89SAndroid Build Coastguard Worker /*
69*8d67ca89SAndroid Build Coastguard Worker  * Creates new linker namespace.
70*8d67ca89SAndroid Build Coastguard Worker  * ld_library_path and default_library_path represent the search path
71*8d67ca89SAndroid Build Coastguard Worker  * for the libraries in the namespace.
72*8d67ca89SAndroid Build Coastguard Worker  *
73*8d67ca89SAndroid Build Coastguard Worker  * The libraries in the namespace are searched by folowing order:
74*8d67ca89SAndroid Build Coastguard Worker  * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
75*8d67ca89SAndroid Build Coastguard Worker  * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
76*8d67ca89SAndroid Build Coastguard Worker  * 3. deault_library_path (This of this as namespace-local default library path)
77*8d67ca89SAndroid Build Coastguard Worker  *
78*8d67ca89SAndroid Build Coastguard Worker  * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
79*8d67ca89SAndroid Build Coastguard Worker  * the libraries to be on the search path or under the permitted_when_isolated_path;
80*8d67ca89SAndroid Build Coastguard Worker  * the search_path is ld_library_path:default_library_path. Note that the
81*8d67ca89SAndroid Build Coastguard Worker  * permitted_when_isolated_path path is not part of the search_path and
82*8d67ca89SAndroid Build Coastguard Worker  * does not affect the search order. It is a way to allow loading libraries from specific
83*8d67ca89SAndroid Build Coastguard Worker  * locations when using absolute path.
84*8d67ca89SAndroid Build Coastguard Worker  * If a library or any of its dependencies are outside of the permitted_when_isolated_path
85*8d67ca89SAndroid Build Coastguard Worker  * and search_path, and it is not part of the public namespace dlopen will fail.
86*8d67ca89SAndroid Build Coastguard Worker  */
87*8d67ca89SAndroid Build Coastguard Worker extern struct android_namespace_t* android_create_namespace(const char* name,
88*8d67ca89SAndroid Build Coastguard Worker                                                             const char* ld_library_path,
89*8d67ca89SAndroid Build Coastguard Worker                                                             const char* default_library_path,
90*8d67ca89SAndroid Build Coastguard Worker                                                             uint64_t type,
91*8d67ca89SAndroid Build Coastguard Worker                                                             const char* permitted_when_isolated_path,
92*8d67ca89SAndroid Build Coastguard Worker                                                             android_namespace_t* parent);
93*8d67ca89SAndroid Build Coastguard Worker 
94*8d67ca89SAndroid Build Coastguard Worker extern bool android_link_namespaces(android_namespace_t* from,
95*8d67ca89SAndroid Build Coastguard Worker                                     android_namespace_t* to,
96*8d67ca89SAndroid Build Coastguard Worker                                     const char* shared_libs_sonames);
97*8d67ca89SAndroid Build Coastguard Worker 
98*8d67ca89SAndroid Build Coastguard Worker extern bool android_link_namespaces_all_libs(android_namespace_t* from,
99*8d67ca89SAndroid Build Coastguard Worker                                              android_namespace_t* to);
100*8d67ca89SAndroid Build Coastguard Worker 
101*8d67ca89SAndroid Build Coastguard Worker extern void android_set_application_target_sdk_version(int target);
102*8d67ca89SAndroid Build Coastguard Worker 
103*8d67ca89SAndroid Build Coastguard Worker __END_DECLS
104*8d67ca89SAndroid Build Coastguard Worker 
105*8d67ca89SAndroid Build Coastguard Worker #endif /* __ANDROID_DLEXT_NAMESPACES_H__ */
106