|
|
@ -24,38 +24,38 @@
|
|
|
|
#include "glog/logging.h"
|
|
|
|
#include "glog/logging.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
#include <dlfcn.h> // dladdr
|
|
|
|
#include <dlfcn.h> // dladdr
|
|
|
|
#include <execinfo.h> // backtrace
|
|
|
|
#include <execinfo.h> // backtrace
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <algorithm> // std::accumulate
|
|
|
|
#include <algorithm> // std::accumulate
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <io.h> // _popen, _pclose
|
|
|
|
#include <io.h> // _popen, _pclose
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <numeric> // std::accumulate in msvc
|
|
|
|
#include <numeric> // std::accumulate in msvc
|
|
|
|
#ifndef S_ISDIR // windows port for sys/stat.h
|
|
|
|
#ifndef S_ISDIR // windows port for sys/stat.h
|
|
|
|
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
|
|
|
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
|
|
|
#endif // S_ISDIR
|
|
|
|
#endif // S_ISDIR
|
|
|
|
|
|
|
|
|
|
|
|
static void *dlsym(void *handle, const char *symbol_name) {
|
|
|
|
static void *dlsym(void *handle, const char *symbol_name) {
|
|
|
|
FARPROC found_symbol;
|
|
|
|
FARPROC found_symbol;
|
|
|
|
found_symbol = GetProcAddress((HMODULE)handle, symbol_name);
|
|
|
|
found_symbol = GetProcAddress((HMODULE)handle, symbol_name);
|
|
|
|
|
|
|
|
|
|
|
|
if (found_symbol == NULL) {
|
|
|
|
if (found_symbol == NULL) {
|
|
|
|
throw std::runtime_error(std::string(symbol_name) + " not found.");
|
|
|
|
throw std::runtime_error(std::string(symbol_name) + " not found.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<void *>(found_symbol);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<void *>(found_symbol);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *dlopen(const char *filename, int flag) {
|
|
|
|
static void *dlopen(const char *filename, int flag) {
|
|
|
|
std::string file_name(filename);
|
|
|
|
std::string file_name(filename);
|
|
|
|
file_name.replace(0, file_name.size() - 1, '/', '\\');
|
|
|
|
file_name.replace(0, file_name.size() - 1, '/', '\\');
|
|
|
|
HMODULE hModule = LoadLibrary(file_name.c_str());
|
|
|
|
HMODULE hModule = LoadLibrary(file_name.c_str());
|
|
|
|
if (!hModule) {
|
|
|
|
if (!hModule) {
|
|
|
|
throw std::runtime_error(file_name + " not found.");
|
|
|
|
throw std::runtime_error(file_name + " not found.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<void *>(hModule);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<void *>(hModule);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !_WIN32
|
|
|
|
#endif // !_WIN32
|
|
|
|
|
|
|
|
|
|
|
|