1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright Antony Polukhin, 2015-2022.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_DLL_SHARED_LIBRARY_MODE_HPP
9 #define BOOST_DLL_SHARED_LIBRARY_MODE_HPP
11 #include <boost/dll/config.hpp>
12 #include <boost/predef/os.h>
13 #include <boost/predef/library/c.h>
16 # include <boost/winapi/dll.hpp>
21 #ifdef BOOST_HAS_PRAGMA_ONCE
25 /// \file boost/dll/shared_library_load_mode.hpp
26 /// \brief Contains only the boost::dll::load_mode::type enum and operators related to it.
28 namespace boost { namespace dll { namespace load_mode {
30 /*! Library load modes.
32 * Each of system family provides own modes. Flags not supported by a particular platform will be silently ignored.
34 * For a detailed description of platform specific options see:
35 * <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx">Windows specific options</a>,
36 * <a href="http://pubs.opengroup.org/onlinepubs/000095399/functions/dlopen.html">POSIX specific options</a>.
41 #ifdef BOOST_DLL_DOXYGEN
43 * Default open mode. See the \b Default: comments below to find out the flags that are enabled by default.
48 * \b Platforms: Windows
50 * \b Default: disabled
52 * If this value is used, and the executable module is a DLL, the system does
53 * not call DllMain for process and thread initialization and termination.
54 * Also, the system does not load additional executable modules that are
55 * referenced by the specified module.
57 * Note Do not use this value; it is provided only for backward compatibility.
58 * If you are planning to access only data or resources in the DLL, use
59 * LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE or LOAD_LIBRARY_AS_IMAGE_RESOURCE
62 dont_resolve_dll_references,
65 * \b Platforms: Windows
67 * \b Default: disabled
69 * If this value is used, the system does not check AppLocker rules or
70 * apply Software Restriction Policies for the DLL.
72 load_ignore_code_authz_level,
75 * \b Platforms: Windows
77 * \b Default: disabled
79 * If this value is used and lpFileName specifies an absolute path,
80 * the system uses the alternate file search strategy.
82 * This value cannot be combined with any LOAD_LIBRARY_SEARCH flag.
84 load_with_altered_search_path,
91 * Relocations shall be performed at an implementation-defined time, ranging
92 * from the time of the dlopen() call until the first reference to a given
95 * Specifying RTLD_LAZY should improve performance on implementations
96 * supporting dynamic symbol binding as a process may not reference all of
97 * the functions in any given object. And, for systems supporting dynamic
98 * symbol resolution for normal process execution, this behavior mimics
99 * the normal handling of process execution.
104 * \b Platforms: POSIX
106 * \b Default: disabled
108 * All necessary relocations shall be performed when the object is first
109 * loaded. This may waste some processing if relocations are performed for
110 * functions that are never referenced. This behavior may be useful for
111 * plugins that need to know as soon as an object is loaded that all
112 * symbols referenced during execution are available.
117 * \b Platforms: POSIX
119 * \b Default: disabled
121 * The object's symbols shall be made available for the relocation
122 * processing of any other object. In addition, symbol lookup using
123 * dlopen(0, mode) and an associated dlsym() allows objects loaded
124 * with this mode to be searched.
129 * \b Platforms: POSIX
131 * \b Default: enabled
133 * The object's symbols shall not be made available for the relocation
134 * processing of any other object.
136 * This is a default Windows behavior that can not be changed.
141 * \b Platforms: POSIX (requires glibc >= 2.3.4)
143 * \b Default: disabled
145 * The object will use its own symbols in preference to global symbols
146 * with the same name contained in libraries that have already been loaded.
147 * This flag is not specified in POSIX.1-2001.
152 * \b Platforms: Windows, POSIX
154 * \b Default: disabled
156 * Append a platform specific extension and prefix to shared library filename before trying to load it.
157 * If load attempt fails, try to load with exactly specified name.
161 * // Opens `./my_plugins/plugin1.dll` on Windows, `./my_plugins/libplugin1.so` on Linux, `./my_plugins/libplugin1.dylib` on MacOS.
162 * // If that fails, loads `./my_plugins/plugin1`
163 * boost::dll::shared_library lib("./my_plugins/plugin1", load_mode::append_decorations);
168 * \b Platforms: Windows, POSIX
170 * \b Default: disabled
172 * Allow loading from system folders if path to library contains no parent path.
174 search_system_folders
175 #elif BOOST_OS_WINDOWS
177 dont_resolve_dll_references = boost::winapi::DONT_RESOLVE_DLL_REFERENCES_,
178 load_ignore_code_authz_level = boost::winapi::LOAD_IGNORE_CODE_AUTHZ_LEVEL_,
179 load_with_altered_search_path = boost::winapi::LOAD_WITH_ALTERED_SEARCH_PATH_,
185 append_decorations = 0x00800000,
186 search_system_folders = (append_decorations << 1)
189 dont_resolve_dll_references = 0,
190 load_ignore_code_authz_level = 0,
191 load_with_altered_search_path = 0,
192 rtld_lazy = RTLD_LAZY,
194 rtld_global = RTLD_GLOBAL,
195 rtld_local = RTLD_LOCAL,
197 #if BOOST_LIB_C_GNU < BOOST_VERSION_NUMBER(2,3,4)
200 rtld_deepbind = RTLD_DEEPBIND,
203 append_decorations = 0x00800000,
204 search_system_folders = (append_decorations << 1)
209 /// Free operators for load_mode::type flag manipulation.
210 BOOST_CONSTEXPR inline type operator|(type left, type right) BOOST_NOEXCEPT {
211 return static_cast<type>(
212 static_cast<unsigned int>(left) | static_cast<unsigned int>(right)
215 BOOST_CXX14_CONSTEXPR inline type& operator|=(type& left, type right) BOOST_NOEXCEPT {
220 BOOST_CONSTEXPR inline type operator&(type left, type right) BOOST_NOEXCEPT {
221 return static_cast<type>(
222 static_cast<unsigned int>(left) & static_cast<unsigned int>(right)
225 BOOST_CXX14_CONSTEXPR inline type& operator&=(type& left, type right) BOOST_NOEXCEPT {
230 BOOST_CONSTEXPR inline type operator^(type left, type right) BOOST_NOEXCEPT {
231 return static_cast<type>(
232 static_cast<unsigned int>(left) ^ static_cast<unsigned int>(right)
235 BOOST_CXX14_CONSTEXPR inline type& operator^=(type& left, type right) BOOST_NOEXCEPT {
240 BOOST_CONSTEXPR inline type operator~(type left) BOOST_NOEXCEPT {
241 return static_cast<type>(
242 ~static_cast<unsigned int>(left)
246 }}} // boost::dll::load_mode
248 #endif // BOOST_DLL_SHARED_LIBRARY_MODE_HPP