Botan 1.10.17
dyn_load.h
Go to the documentation of this file.
1/*
2* Dynamically Loaded Object
3* (C) 2010 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_DYNAMIC_LOADER_H__
9#define BOTAN_DYNAMIC_LOADER_H__
10
11#include <string>
12
13namespace Botan {
14
15/**
16* Represents a DLL or shared object
17*/
19 {
20 public:
21 /**
22 * Load a DLL (or fail with an exception)
23 * @param lib_name name or path to a library
24 *
25 * If you don't use a full path, the search order will be defined
26 * by whatever the system linker does by default. Always using fully
27 * qualified pathnames can help prevent code injection attacks (eg
28 * via manipulation of LD_LIBRARY_PATH on Linux)
29 */
30 Dynamically_Loaded_Library(const std::string& lib_name);
31
32 /**
33 * Unload the DLL
34 * @warning Any pointers returned by resolve()/resolve_symbol()
35 * should not be used after this destructor runs.
36 */
38
39 /**
40 * Load a symbol (or fail with an exception)
41 * @param symbol names the symbol to load
42 * @return address of the loaded symbol
43 */
44 void* resolve_symbol(const std::string& symbol);
45
46 /**
47 * Convenience function for casting symbol to the right type
48 * @param symbol names the symbol to load
49 * @return address of the loaded symbol
50 */
51 template<typename T>
52 T resolve(const std::string& symbol)
53 {
54#if defined(__GNUC__) && __GNUC__ < 4
55 return (T)(resolve_symbol(symbol));
56#else
57 return reinterpret_cast<T>(resolve_symbol(symbol));
58#endif
59 }
60
61 private:
64
65 std::string lib_name;
66 void* lib;
67 };
68
69}
70
71#endif
Dynamically_Loaded_Library(const std::string &lib_name)
Definition dyn_load.cpp:31
void * resolve_symbol(const std::string &symbol)
Definition dyn_load.cpp:61
T resolve(const std::string &symbol)
Definition dyn_load.h:52