• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2    Copyright 2014 Renato Tegon Forti, Antony Polukhin
3    Copyright 2015-2019 Antony Polukhin
4    Distributed under the Boost Software License, Version 1.0.
5    (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6/]
7
8[section F.A.Q.]
9
10* [*Question:]  Is Boost.DLL thread-safe?
11  * [*Answer:]  Some platforms allow concurrent calls to `dlopen` like functions.
12For those platforms Boost.DLL is safe in the manner as all the C++ Standard Library containers are: it is
13safe to use different instances of shared_library from different threads even if all the instances loaded the same library. On other platforms it
14is not safe to concurrently call any of the functions from Boost.DLL (even a `shared_library::location()` call triggers a race condition).
15See [link boost_dll.limitations.multithread Limitations, Thread safe library loading].
16
17[pre
18]
19
20* [*Question:]  Why on Linux symbols from one plugin are seen in another? Can't get symbol with same name from right plugin!
21  * [*Answer:]  You've run into the symbol shadowing problem. Compile your plugins with "-fvisibility=hidden"
22flag and take a look to the Tutorial section.
23
24[pre
25]
26
27* [*Question:]  How Unicode (Windows) is handled?
28  * [*Answer:]  Boost.DLL supports Unicode, so that you could provide Unicode paths to it.
29
30[pre
31]
32
33* [*Question:]  Can I open an executable file?
34  * [*Answer:]  Yes, you can. Symbols need be exported using in the executable using `BOOST_SYMBOL_EXPORT`
35or `BOOST_DLL_ALIAS`. You can call `shared_library(program_location())` to load yourself. Refer to
36the Tutorial section for more info. You can also query executables, just provide a path to the executable
37to `library_info` class.
38
39[pre
40]
41
42* [*Question:]  What if I specify wrong type in `shared_library::get<T>` or `import<T>`?
43  * [*Answer:]  Usually you'll end up with `Segmentation Fault`. However it is safe to make types
44more strict, for example making `const int` from an `int` will not harm.
45
46[pre
47]
48
49* [*Question:]  Does your library guarantee ABI stability of methods?
50  * [*Answer:]  Library only guarantees that alias names created using the `BOOST_DLL_ALIAS` macros
51will not change with the change of compiler or platform. You must take care of functions ABI and API
52stability by your own.
53
54[pre
55]
56
57* [*Question:]  Are there any function signature restrictions for the exported/imported functions?
58  * [*Answer:]  No. You may import/export functions with any signature and any return parameter.
59
60[pre
61]
62
63* [*Question:]  I have 2 plugins that use same shared library. Would be the shared library loaded twice?
64  * [*Answer:]  No. Pugins will share the shared library instance.
65
66[pre
67]
68
69* [*Question:]  I have 2 plugins each of them must work with it's own version of `libsome_library` shared library. How to achieve that?
70  * [*Answer:]  Avoid such situations by statically linking in the libsome_library into each plugin and loading plugins with `load_mode::rtld_deepbind`.
71
72[pre
73]
74
75* [*Question:]  How to load a shared object from memory??
76  * [*Answer:]  All existing OS avoid loading shared libraries directly from userspace memory, so you'll find no syscall for such case. Currently Boost.DLL provides no means for honest loading shared objects from memory. This requires reimplementing dynamic linker logic in userspace for all the platforms, which is a huge amount of work and very error-prone. However working patches are welcomed!
77
78Workaround would be to write plugin into a temporary file in RAM and load plugin from it:
79```
80#include <boost/filesystem.hpp>
81#include <boost/dll.hpp>
82using namespace boost;
83
84dll:shared_library load_from_memory(unsigned char* data, std::size_t size, const filesystem::path& tmp_plugin_path = filesystem::unique_path() / "libplugin.so") {
85    const filesystem::path plugin_location = filesystem::temp_directory_path() / tmp_plugin_path;
86    filesystem::create_directories(plugin_location.parent_path());
87    filesystem::ofstream ofs(plugin_location, std::ios::out|std::ios::bin|std::ios::trunc);
88    ofs.write(data, size);
89
90    return dll::shared_library(plugin_location);
91}
92```
93
94But there's no guarantee that `filesystem::temp_directory_path()` will actually write to RAM, that's very platform dependent.
95
96[pre
97]
98
99* [*Question:]  I have found a bug, how do I notify?
100  * [*Answer:]  Create an [@https://github.com/apolukhin/Boost.DLL/issues issue at GitHub] with a detailed description.
101
102[endsect]
103
104
105
106