2010-11-29 19:44:50 +00:00
|
|
|
//===-- llvm/Support/DynamicLibrary.h - Portable Dynamic Library -*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-11-18 04:33:39 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-11-18 04:33:39 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the sys::DynamicLibrary class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYSTEM_DYNAMIC_LIBRARY_H
|
|
|
|
#define LLVM_SYSTEM_DYNAMIC_LIBRARY_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
|
|
|
/// This class provides a portable interface to dynamic libraries which also
|
2005-04-21 20:48:15 +00:00
|
|
|
/// might be known as shared libraries, shared objects, dynamic shared
|
2004-11-18 04:33:39 +00:00
|
|
|
/// objects, or dynamic link libraries. Regardless of the terminology or the
|
|
|
|
/// operating system interface, this class provides a portable interface that
|
2010-02-10 16:03:48 +00:00
|
|
|
/// allows dynamic libraries to be loaded and searched for externally
|
2004-11-18 04:33:39 +00:00
|
|
|
/// defined symbols. This is typically used to provide "plug-in" support.
|
2006-01-30 04:33:51 +00:00
|
|
|
/// It also allows for symbols to be defined which don't live in any library,
|
|
|
|
/// but rather the main program itself, useful on Windows where the main
|
|
|
|
/// executable cannot be searched.
|
2004-11-18 04:33:39 +00:00
|
|
|
class DynamicLibrary {
|
2009-07-07 18:01:58 +00:00
|
|
|
DynamicLibrary(); // DO NOT IMPLEMENT
|
|
|
|
public:
|
|
|
|
/// This function allows a library to be loaded without instantiating a
|
|
|
|
/// DynamicLibrary object. Consequently, it is marked as being permanent
|
|
|
|
/// and will only be unloaded when the program terminates. This returns
|
|
|
|
/// false on success or returns true and fills in *ErrMsg on failure.
|
|
|
|
/// @brief Open a dynamic library permanently.
|
2009-07-07 18:17:07 +00:00
|
|
|
///
|
|
|
|
/// NOTE: This function is not thread safe.
|
|
|
|
///
|
2009-07-07 18:01:58 +00:00
|
|
|
static bool LoadLibraryPermanently(const char *filename,
|
|
|
|
std::string *ErrMsg = 0);
|
2004-11-29 10:38:54 +00:00
|
|
|
|
2009-07-07 18:01:58 +00:00
|
|
|
/// This function will search through all previously loaded dynamic
|
|
|
|
/// libraries for the symbol \p symbolName. If it is found, the addressof
|
|
|
|
/// that symbol is returned. If not, null is returned. Note that this will
|
|
|
|
/// search permanently loaded libraries (LoadLibraryPermanently) as well
|
|
|
|
/// as ephemerally loaded libraries (constructors).
|
|
|
|
/// @throws std::string on error.
|
|
|
|
/// @brief Search through libraries for address of a symbol
|
2009-07-07 18:17:07 +00:00
|
|
|
///
|
|
|
|
/// NOTE: This function is not thread safe.
|
|
|
|
///
|
2009-07-07 18:01:58 +00:00
|
|
|
static void *SearchForAddressOfSymbol(const char *symbolName);
|
2004-11-18 04:33:39 +00:00
|
|
|
|
2009-07-07 18:01:58 +00:00
|
|
|
/// @brief Convenience function for C++ophiles.
|
2009-07-07 18:17:07 +00:00
|
|
|
///
|
|
|
|
/// NOTE: This function is not thread safe.
|
|
|
|
///
|
2009-07-07 18:01:58 +00:00
|
|
|
static void *SearchForAddressOfSymbol(const std::string &symbolName) {
|
|
|
|
return SearchForAddressOfSymbol(symbolName.c_str());
|
|
|
|
}
|
2004-11-29 13:27:56 +00:00
|
|
|
|
2009-07-07 18:01:58 +00:00
|
|
|
/// This functions permanently adds the symbol \p symbolName with the
|
|
|
|
/// value \p symbolValue. These symbols are searched before any
|
|
|
|
/// libraries.
|
|
|
|
/// @brief Add searchable symbol/value pair.
|
2009-07-07 18:17:07 +00:00
|
|
|
///
|
|
|
|
/// NOTE: This function is not thread safe.
|
|
|
|
///
|
2009-07-07 18:01:58 +00:00
|
|
|
static void AddSymbol(const char *symbolName, void *symbolValue);
|
2004-11-29 13:27:56 +00:00
|
|
|
|
2009-07-07 18:01:58 +00:00
|
|
|
/// @brief Convenience function for C++ophiles.
|
2009-07-07 18:17:07 +00:00
|
|
|
///
|
|
|
|
/// NOTE: This function is not thread safe.
|
|
|
|
///
|
2009-07-07 18:01:58 +00:00
|
|
|
static void AddSymbol(const std::string &symbolName, void *symbolValue) {
|
|
|
|
AddSymbol(symbolName.c_str(), symbolValue);
|
|
|
|
}
|
2004-11-18 04:33:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End sys namespace
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif // LLVM_SYSTEM_DYNAMIC_LIBRARY_H
|