1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015-2016 Antony Polukhin.
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/config.hpp>
12 #include <boost/predef/os.h>
13 #include <boost/predef/library/c.h>
16 //#include <boost/detail/winapi/dll.hpp>
17 #include <boost/detail/winapi/dll.hpp>
22 #ifdef BOOST_HAS_PRAGMA_ONCE
26 /// \file boost/dll/shared_library_load_mode.hpp
27 /// \brief Contains only the boost::dll::load_mode::type enum and operators related to it.
29 namespace boost { namespace dll { namespace load_mode {
31 /*! Library load modes.
33 * Each of system family provides own modes. Flags not supported by a particular platform will be silently ignored.
35 * For a detailed description of platform specific options see:
36 * <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179(v=vs.85).aspx">Windows specific options</a>,
37 * <a href="http://pubs.opengroup.org/onlinepubs/000095399/functions/dlopen.html">POSIX specific options</a>.
42 #ifdef BOOST_DLL_DOXYGEN
44 * Default open mode. See the \b Default: comments below to find out the flags that are enabled by default.
49 * \b Platforms: Windows
51 * \b Default: disabled
53 * If this value is used, and the executable module is a DLL, the system does
54 * not call DllMain for process and thread initialization and termination.
55 * Also, the system does not load additional executable modules that are
56 * referenced by the specified module.
58 * Note Do not use this value; it is provided only for backward compatibility.
59 * If you are planning to access only data or resources in the DLL, use
60 * LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE or LOAD_LIBRARY_AS_IMAGE_RESOURCE
63 dont_resolve_dll_references,
66 * \b Platforms: Windows
68 * \b Default: disabled
70 * If this value is used, the system does not check AppLocker rules or
71 * apply Software Restriction Policies for the DLL.
73 load_ignore_code_authz_level,
76 * \b Platforms: Windows
78 * \b Default: disabled
80 * If this value is used and lpFileName specifies an absolute path,
81 * the system uses the alternate file search strategy.
83 * This value cannot be combined with any LOAD_LIBRARY_SEARCH flag.
85 load_with_altered_search_path,
92 * Relocations shall be performed at an implementation-defined time, ranging
93 * from the time of the dlopen() call until the first reference to a given
96 * Specifying RTLD_LAZY should improve performance on implementations
97 * supporting dynamic symbol binding as a process may not reference all of
98 * the functions in any given object. And, for systems supporting dynamic
99 * symbol resolution for normal process execution, this behavior mimics
100 * the normal handling of process execution.
105 * \b Platforms: POSIX
107 * \b Default: disabled
109 * All necessary relocations shall be performed when the object is first
110 * loaded. This may waste some processing if relocations are performed for
111 * functions that are never referenced. This behavior may be useful for
112 * plugins that need to know as soon as an object is loaded that all
113 * symbols referenced during execution are available.
118 * \b Platforms: POSIX
120 * \b Default: disabled
122 * The object's symbols shall be made available for the relocation
123 * processing of any other object. In addition, symbol lookup using
124 * dlopen(0, mode) and an associated dlsym() allows objects loaded
125 * with this mode to be searched.
130 * \b Platforms: POSIX
132 * \b Default: enabled
134 * The object's symbols shall not be made available for the relocation
135 * processing of any other object.
137 * This is a default Windows behavior that can not be changed.
142 * \b Platforms: POSIX (requires glibc >= 2.3.4)
144 * \b Default: disabled
146 * The object will use its own symbols in preference to global symbols
147 * with the same name contained in libraries that have already been loaded.
148 * This flag is not specified in POSIX.1-2001.
153 * \b Platforms: Windows, POSIX
155 * \b Default: disabled
157 * Append a platform specific extension and prefix to shared library filename before trying to load it.
158 * If load attempt fails, try to load with exactly specified name.
162 * // Opens `./my_plugins/plugin1.dll` on Windows, `./my_plugins/libplugin1.so` on Linux, `./my_plugins/libplugin1.dylib` on MacOS.
163 * // If that fails, loads `./my_plugins/plugin1`
164 * boost::dll::shared_library lib("./my_plugins/plugin1", load_mode::append_decorations);
169 * \b Platforms: Windows, POSIX
171 * \b Default: disabled
173 * Allow loading from system folders if path to library contains no parent path.
175 search_system_folders
176 #elif BOOST_OS_WINDOWS
178 dont_resolve_dll_references = boost::detail::winapi::DONT_RESOLVE_DLL_REFERENCES_,
179 load_ignore_code_authz_level = boost::detail::winapi::LOAD_IGNORE_CODE_AUTHZ_LEVEL_,
180 load_with_altered_search_path = boost::detail::winapi::LOAD_WITH_ALTERED_SEARCH_PATH_,
186 append_decorations = 0x00800000,
187 search_system_folders = (append_decorations << 1)
190 dont_resolve_dll_references = 0,
191 load_ignore_code_authz_level = 0,
192 load_with_altered_search_path = 0,
193 rtld_lazy = RTLD_LAZY,
195 rtld_global = RTLD_GLOBAL,
196 rtld_local = RTLD_LOCAL,
198 #if BOOST_LIB_C_GNU < BOOST_VERSION_NUMBER(2,3,4)
201 rtld_deepbind = RTLD_DEEPBIND,
204 append_decorations = 0x00800000,
205 search_system_folders = (append_decorations << 1)
210 /// Free operators for load_mode::type flag manipulation.
211 BOOST_CONSTEXPR inline type operator|(type left, type right) BOOST_NOEXCEPT {
212 return static_cast<type>(
213 static_cast<unsigned int>(left) | static_cast<unsigned int>(right)
216 BOOST_CXX14_CONSTEXPR inline type& operator|=(type& left, type right) BOOST_NOEXCEPT {
221 BOOST_CONSTEXPR inline type operator&(type left, type right) BOOST_NOEXCEPT {
222 return static_cast<type>(
223 static_cast<unsigned int>(left) & static_cast<unsigned int>(right)
226 BOOST_CXX14_CONSTEXPR inline type& operator&=(type& left, type right) BOOST_NOEXCEPT {
231 BOOST_CONSTEXPR inline type operator^(type left, type right) BOOST_NOEXCEPT {
232 return static_cast<type>(
233 static_cast<unsigned int>(left) ^ static_cast<unsigned int>(right)
236 BOOST_CXX14_CONSTEXPR inline type& operator^=(type& left, type right) BOOST_NOEXCEPT {
241 BOOST_CONSTEXPR inline type operator~(type left) BOOST_NOEXCEPT {
242 return static_cast<type>(
243 ~static_cast<unsigned int>(left)
247 }}} // boost::dll::load_mode
249 #endif // BOOST_DLL_SHARED_LIBRARY_MODE_HPP