dlext_namespaces.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef __ANDROID_DLEXT_NAMESPACES_H__
  17. #define __ANDROID_DLEXT_NAMESPACES_H__
  18. #include <android/dlext.h>
  19. #include <stdbool.h>
  20. __BEGIN_DECLS
  21. /*
  22. * Initializes anonymous namespaces. The shared_libs_sonames is the list of sonames
  23. * to be shared by default namespace separated by colon. Example: "libc.so:libm.so:libdl.so".
  24. *
  25. * The library_search_path is the search path for anonymous namespace. The anonymous namespace
  26. * is used in the case when linker cannot identify the caller of dlopen/dlsym. This happens
  27. * for the code not loaded by dynamic linker; for example calls from the mono-compiled code.
  28. */
  29. extern bool android_init_anonymous_namespace(const char* shared_libs_sonames,
  30. const char* library_search_path);
  31. enum {
  32. /* A regular namespace is the namespace with a custom search path that does
  33. * not impose any restrictions on the location of native libraries.
  34. */
  35. ANDROID_NAMESPACE_TYPE_REGULAR = 0,
  36. /* An isolated namespace requires all the libraries to be on the search path
  37. * or under permitted_when_isolated_path. The search path is the union of
  38. * ld_library_path and default_library_path.
  39. */
  40. ANDROID_NAMESPACE_TYPE_ISOLATED = 1,
  41. /* The shared namespace clones the list of libraries of the caller namespace upon creation
  42. * which means that they are shared between namespaces - the caller namespace and the new one
  43. * will use the same copy of a library if it was loaded prior to android_create_namespace call.
  44. *
  45. * Note that libraries loaded after the namespace is created will not be shared.
  46. *
  47. * Shared namespaces can be isolated or regular. Note that they do not inherit the search path nor
  48. * permitted_path from the caller's namespace.
  49. */
  50. ANDROID_NAMESPACE_TYPE_SHARED = 2,
  51. /* This flag instructs linker to enable grey-list workaround for the namespace.
  52. * See http://b/26394120 for details.
  53. */
  54. ANDROID_NAMESPACE_TYPE_GREYLIST_ENABLED = 0x08000000,
  55. ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED |
  56. ANDROID_NAMESPACE_TYPE_ISOLATED,
  57. };
  58. /*
  59. * Creates new linker namespace.
  60. * ld_library_path and default_library_path represent the search path
  61. * for the libraries in the namespace.
  62. *
  63. * The libraries in the namespace are searched by folowing order:
  64. * 1. ld_library_path (Think of this as namespace-local LD_LIBRARY_PATH)
  65. * 2. In directories specified by DT_RUNPATH of the "needed by" binary.
  66. * 3. deault_library_path (This of this as namespace-local default library path)
  67. *
  68. * When type is ANDROID_NAMESPACE_TYPE_ISOLATED the resulting namespace requires all of
  69. * the libraries to be on the search path or under the permitted_when_isolated_path;
  70. * the search_path is ld_library_path:default_library_path. Note that the
  71. * permitted_when_isolated_path path is not part of the search_path and
  72. * does not affect the search order. It is a way to allow loading libraries from specific
  73. * locations when using absolute path.
  74. * If a library or any of its dependencies are outside of the permitted_when_isolated_path
  75. * and search_path, and it is not part of the public namespace dlopen will fail.
  76. */
  77. extern struct android_namespace_t* android_create_namespace(
  78. const char* name, const char* ld_library_path, const char* default_library_path, uint64_t type,
  79. const char* permitted_when_isolated_path, struct android_namespace_t* parent);
  80. /*
  81. * Creates a link between namespaces. Every link has list of sonames of
  82. * shared libraries. These are the libraries which are accessible from
  83. * namespace 'from' but loaded within namespace 'to' context.
  84. * When to namespace is nullptr this function establishes a link between
  85. * 'from' namespace and the default namespace.
  86. *
  87. * The lookup order of the libraries in namespaces with links is following:
  88. * 1. Look inside current namespace using 'this' namespace search path.
  89. * 2. Look in linked namespaces
  90. * 2.1. Perform soname check - if library soname is not in the list of shared
  91. * libraries sonames skip this link, otherwise
  92. * 2.2. Search library using linked namespace search path. Note that this
  93. * step will not go deeper into linked namespaces for this library but
  94. * will do so for DT_NEEDED libraries.
  95. */
  96. extern bool android_link_namespaces(struct android_namespace_t* from,
  97. struct android_namespace_t* to,
  98. const char* shared_libs_sonames);
  99. extern struct android_namespace_t* android_get_exported_namespace(const char* name);
  100. __END_DECLS
  101. #endif /* __ANDROID_DLEXT_NAMESPACES_H__ */