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/*
25 * Initializes public and anonymous namespaces. The public_ns_sonames is the list of sonames
26 * to be included into public namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
27 * The libraries in this list should be loaded prior to this call.
28 *
29 * The anon_ns_library_path is the search path for anonymous namespace. The anonymous namespace
30 * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
31 * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
32 */
33extern bool android_init_namespaces(const char* public_ns_sonames,
34                                    const char* anon_ns_library_path);
35
36
37enum {
38  /* A regular namespace is the namespace with a custom search path that does
39   * not impose any restrictions on the location of native libraries.
40   */
41  ANDROID_NAMESPACE_TYPE_REGULAR = 0,
42
43  /* An isolated namespace requires all the libraries to be on the search path
44   * or under permitted_when_isolated_path. The search path is the union of
45   * ld_library_path and default_library_path.
46   */
47  ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
48
49  /* The shared namespace clones the list of libraries of the caller namespace upon creation
50   * which means that they are shared between namespaces - the caller namespace and the new one
51   * will use the same copy of a library if it was loaded prior to android_create_namespace call.
52   *
53   * Note that libraries loaded after the namespace is created will not be shared.
54   *
55   * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
56   * permitted_path from the caller's namespace.
57   */
58  ANDROID_NAMESPACE_TYPE_SHARED = 2,
59  ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
60                                           ANDROID_NAMESPACE_TYPE_ISOLATED,
61};
62
63/*
64 * Creates new linker namespace.
65 * ld_library_path and default_library_path represent the search path
66 * for the libraries in the namespace.
67 *
68 * The libraries in the namespace are searched by folowing order:
69 * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
70 * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
71 * 3. deault_library_path (This of this as namespace-local default library path)
72 *
73 * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
74 * the libraries to be on the search path or under the permitted_when_isolated_path;
75 * the search_path is ld_library_path:default_library_path. Note that the
76 * permitted_when_isolated_path path is not part of the search_path and
77 * does not affect the search order. It is a way to allow loading libraries from specific
78 * locations when using absolute path.
79 * If a library or any of its dependencies are outside of the permitted_when_isolated_path
80 * and search_path, and it is not part of the public namespace dlopen will fail.
81 */
82extern struct android_namespace_t* android_create_namespace(const char* name,
83                                                            const char* ld_library_path,
84                                                            const char* default_library_path,
85                                                            uint64_t type,
86                                                            const char* permitted_when_isolated_path,
87                                                            android_namespace_t* parent);
88
89extern void android_set_application_target_sdk_version(uint32_t target);
90
91__END_DECLS
92
93#endif /* __ANDROID_DLEXT_NAMESPACES_H__ */
94