update boost on linux
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Copyright 2014-2015 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2016-2019 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
@@ -7,10 +8,9 @@
|
||||
#ifndef BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP
|
||||
#define BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll/config.hpp>
|
||||
#include <boost/dll/detail/system_error.hpp>
|
||||
#include <boost/dll/detail/posix/program_location_impl.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/predef/os.h>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
@@ -30,7 +30,7 @@ namespace boost { namespace dll { namespace detail {
|
||||
);
|
||||
}
|
||||
|
||||
inline boost::filesystem::path path_from_handle(void* handle, boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) {
|
||||
handle = strip_handle(handle);
|
||||
|
||||
// Iterate through all images currently in memory
|
||||
@@ -53,12 +53,11 @@ namespace boost { namespace dll { namespace detail {
|
||||
}
|
||||
|
||||
boost::dll::detail::reset_dlerror();
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
|
||||
return boost::filesystem::path();
|
||||
return boost::dll::fs::path();
|
||||
}
|
||||
|
||||
}}} // namespace boost::dll::detail
|
||||
@@ -79,12 +78,12 @@ namespace boost { namespace dll { namespace detail {
|
||||
// ... // Ignoring remaning parts of the structure
|
||||
};
|
||||
|
||||
inline boost::filesystem::path path_from_handle(const void* handle, boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path path_from_handle(const void* handle, boost::dll::fs::error_code &ec) {
|
||||
static const std::size_t work_around_b_24465209__offset = 128;
|
||||
const struct soinfo* si = reinterpret_cast<const struct soinfo*>(
|
||||
static_cast<const char*>(handle) + work_around_b_24465209__offset
|
||||
);
|
||||
boost::filesystem::path ret = boost::dll::symbol_location_ptr(si->base, ec);
|
||||
boost::dll::fs::path ret = boost::dll::symbol_location_ptr(si->base, ec);
|
||||
|
||||
if (ec) {
|
||||
ec.clear();
|
||||
@@ -120,7 +119,7 @@ namespace boost { namespace dll { namespace detail {
|
||||
};
|
||||
#endif // #if BOOST_OS_QNX
|
||||
|
||||
inline boost::filesystem::path path_from_handle(void* handle, boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path path_from_handle(void* handle, boost::dll::fs::error_code &ec) {
|
||||
// RTLD_DI_LINKMAP (RTLD_DI_ORIGIN returns only folder and is not suitable for this case)
|
||||
// Obtain the Link_map for the handle that is specified.
|
||||
// The p argument points to a Link_map pointer (Link_map
|
||||
@@ -145,19 +144,18 @@ namespace boost { namespace dll { namespace detail {
|
||||
#endif
|
||||
if (!link_map) {
|
||||
boost::dll::detail::reset_dlerror();
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
|
||||
return boost::filesystem::path();
|
||||
return boost::dll::fs::path();
|
||||
}
|
||||
|
||||
if (!link_map->l_name || *link_map->l_name == '\0') {
|
||||
return program_location_impl(ec);
|
||||
}
|
||||
|
||||
return boost::filesystem::path(link_map->l_name);
|
||||
return boost::dll::fs::path(link_map->l_name);
|
||||
}
|
||||
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2015 Antony Polukhin.
|
||||
// Copyright 2015-2019 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
@@ -8,9 +8,8 @@
|
||||
#ifndef BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
|
||||
#define BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll/config.hpp>
|
||||
#include <boost/dll/detail/system_error.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/predef/os.h>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
@@ -22,23 +21,22 @@
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
|
||||
ec.clear();
|
||||
|
||||
char path[1024];
|
||||
uint32_t size = sizeof(path);
|
||||
if (_NSGetExecutablePath(path, &size) == 0)
|
||||
return boost::filesystem::path(path);
|
||||
|
||||
return boost::dll::fs::path(path);
|
||||
|
||||
char *p = new char[size];
|
||||
if (_NSGetExecutablePath(p, &size) != 0) {
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
}
|
||||
|
||||
boost::filesystem::path ret(p);
|
||||
boost::dll::fs::path ret(p);
|
||||
delete[] p;
|
||||
return ret;
|
||||
}
|
||||
@@ -48,10 +46,10 @@ namespace boost { namespace dll { namespace detail {
|
||||
|
||||
#include <stdlib.h>
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) {
|
||||
ec.clear();
|
||||
|
||||
return boost::filesystem::path(getexecname());
|
||||
return boost::dll::fs::path(getexecname());
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
@@ -62,7 +60,7 @@ namespace boost { namespace dll { namespace detail {
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code& ec) {
|
||||
ec.clear();
|
||||
|
||||
int mib[4];
|
||||
@@ -74,7 +72,7 @@ namespace boost { namespace dll { namespace detail {
|
||||
size_t cb = sizeof(buf);
|
||||
sysctl(mib, 4, buf, &cb, NULL, 0);
|
||||
|
||||
return boost::filesystem::path(buf);
|
||||
return boost::dll::fs::path(buf);
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
@@ -82,19 +80,18 @@ namespace boost { namespace dll { namespace detail {
|
||||
|
||||
#elif BOOST_OS_BSD_NET
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
|
||||
return boost::filesystem::read_symlink("/proc/curproc/exe", ec);
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
|
||||
return boost::dll::fs::read_symlink("/proc/curproc/exe", ec);
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
#elif BOOST_OS_BSD_DRAGONFLY
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
|
||||
return boost::filesystem::read_symlink("/proc/curproc/file", ec);
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
|
||||
return boost::dll::fs::read_symlink("/proc/curproc/file", ec);
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
@@ -103,7 +100,7 @@ namespace boost { namespace dll { namespace detail {
|
||||
#include <fstream>
|
||||
#include <string> // for std::getline
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
|
||||
ec.clear();
|
||||
|
||||
std::string s;
|
||||
@@ -111,26 +108,24 @@ namespace boost { namespace dll { namespace detail {
|
||||
std::getline(ifs, s);
|
||||
|
||||
if (ifs.fail() || s.empty()) {
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
}
|
||||
|
||||
return boost::filesystem::path(s);
|
||||
return boost::dll::fs::path(s);
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
#else // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
namespace boost { namespace dll { namespace detail {
|
||||
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
|
||||
inline boost::dll::fs::path program_location_impl(boost::dll::fs::error_code &ec) {
|
||||
// We can not use
|
||||
// boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore);
|
||||
// because such code returns empty path.
|
||||
|
||||
return boost::filesystem::read_symlink("/proc/self/exe", ec); // Linux specific
|
||||
return boost::dll::fs::read_symlink("/proc/self/exe", ec); // Linux specific
|
||||
}
|
||||
}}} // namespace boost::dll::detail
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
|
||||
// Copyright 2015-2016 Antony Polukhin.
|
||||
// Copyright 2015-2019 Antony Polukhin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
@@ -8,15 +8,13 @@
|
||||
#ifndef BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
#define BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/dll/config.hpp>
|
||||
#include <boost/dll/shared_library_load_mode.hpp>
|
||||
#include <boost/dll/detail/posix/path_from_handle.hpp>
|
||||
#include <boost/dll/detail/posix/program_location_impl.hpp>
|
||||
|
||||
#include <boost/move/utility.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/predef/os.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
@@ -48,7 +46,7 @@ public:
|
||||
~shared_library_impl() BOOST_NOEXCEPT {
|
||||
unload();
|
||||
}
|
||||
|
||||
|
||||
shared_library_impl(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT
|
||||
: handle_(sl.handle_)
|
||||
{
|
||||
@@ -60,16 +58,26 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
void load(boost::filesystem::path sl, load_mode::type mode, boost::system::error_code &ec) {
|
||||
|
||||
static boost::dll::fs::path decorate(const boost::dll::fs::path & sl) {
|
||||
boost::dll::fs::path actual_path = (
|
||||
std::strncmp(sl.filename().string().c_str(), "lib", 3)
|
||||
? boost::dll::fs::path((sl.has_parent_path() ? sl.parent_path() / L"lib" : L"lib").native() + sl.filename().native())
|
||||
: sl
|
||||
);
|
||||
actual_path += suffix();
|
||||
return actual_path;
|
||||
}
|
||||
|
||||
void load(boost::dll::fs::path sl, load_mode::type mode, boost::dll::fs::error_code &ec) {
|
||||
typedef int native_mode_t;
|
||||
unload();
|
||||
|
||||
// Do not allow opening NULL paths. User must use program_location() instead
|
||||
if (sl.empty()) {
|
||||
boost::dll::detail::reset_dlerror();
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -90,8 +98,8 @@ public:
|
||||
}
|
||||
#else
|
||||
if (!sl.is_absolute() && !(mode & load_mode::search_system_folders)) {
|
||||
boost::system::error_code current_path_ec;
|
||||
boost::filesystem::path prog_loc = boost::filesystem::current_path(current_path_ec);
|
||||
boost::dll::fs::error_code current_path_ec;
|
||||
boost::dll::fs::path prog_loc = boost::dll::fs::current_path(current_path_ec);
|
||||
if (!current_path_ec) {
|
||||
prog_loc /= sl;
|
||||
sl.swap(prog_loc);
|
||||
@@ -105,18 +113,21 @@ public:
|
||||
if (!!(mode & load_mode::append_decorations)) {
|
||||
mode &= ~load_mode::append_decorations;
|
||||
|
||||
boost::filesystem::path actual_path = (
|
||||
std::strncmp(sl.filename().string().c_str(), "lib", 3)
|
||||
? (sl.has_parent_path() ? sl.parent_path() / L"lib" : L"lib").native() + sl.filename().native()
|
||||
: sl
|
||||
);
|
||||
actual_path += suffix();
|
||||
|
||||
boost::dll::fs::path actual_path = decorate(sl);
|
||||
handle_ = dlopen(actual_path.c_str(), static_cast<native_mode_t>(mode));
|
||||
if (handle_) {
|
||||
boost::dll::detail::reset_dlerror();
|
||||
return;
|
||||
}
|
||||
boost::dll::fs::error_code prog_loc_err;
|
||||
boost::dll::fs::path loc = boost::dll::detail::program_location_impl(prog_loc_err);
|
||||
if (boost::dll::fs::exists(actual_path) && !boost::dll::fs::equivalent(sl, loc, prog_loc_err)) {
|
||||
// decorated path exists : current error is not a bad file descriptor and we are not trying to load the executable itself
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::executable_format_error
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Opening by exactly specified path
|
||||
@@ -126,28 +137,26 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
|
||||
// Maybe user wanted to load the executable itself? Checking...
|
||||
// We assume that usually user wants to load a dynamic library not the executable itself, that's why
|
||||
// we try this only after traditional load fails.
|
||||
boost::system::error_code prog_loc_err;
|
||||
boost::filesystem::path loc = boost::dll::detail::program_location_impl(prog_loc_err);
|
||||
if (!prog_loc_err && boost::filesystem::equivalent(sl, loc, prog_loc_err) && !prog_loc_err) {
|
||||
// As is known the function dlopen() loads the dynamic library file
|
||||
// named by the null-terminated string filename and returns an opaque
|
||||
// "handle" for the dynamic library. If filename is NULL, then the
|
||||
boost::dll::fs::error_code prog_loc_err;
|
||||
boost::dll::fs::path loc = boost::dll::detail::program_location_impl(prog_loc_err);
|
||||
if (!prog_loc_err && boost::dll::fs::equivalent(sl, loc, prog_loc_err) && !prog_loc_err) {
|
||||
// As is known the function dlopen() loads the dynamic library file
|
||||
// named by the null-terminated string filename and returns an opaque
|
||||
// "handle" for the dynamic library. If filename is NULL, then the
|
||||
// returned handle is for the main program.
|
||||
ec.clear();
|
||||
boost::dll::detail::reset_dlerror();
|
||||
handle_ = dlopen(NULL, static_cast<native_mode_t>(mode));
|
||||
if (!handle_) {
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::bad_file_descriptor,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::bad_file_descriptor
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -170,11 +179,11 @@ public:
|
||||
boost::swap(handle_, rhs.handle_);
|
||||
}
|
||||
|
||||
boost::filesystem::path full_module_path(boost::system::error_code &ec) const {
|
||||
boost::dll::fs::path full_module_path(boost::dll::fs::error_code &ec) const {
|
||||
return boost::dll::detail::path_from_handle(handle_, ec);
|
||||
}
|
||||
|
||||
static boost::filesystem::path suffix() {
|
||||
static boost::dll::fs::path suffix() {
|
||||
// https://sourceforge.net/p/predef/wiki/OperatingSystems/
|
||||
#if BOOST_OS_MACOS || BOOST_OS_IOS
|
||||
return ".dylib";
|
||||
@@ -183,13 +192,12 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
void* symbol_addr(const char* sb, boost::system::error_code &ec) const BOOST_NOEXCEPT {
|
||||
void* symbol_addr(const char* sb, boost::dll::fs::error_code &ec) const BOOST_NOEXCEPT {
|
||||
// dlsym - obtain the address of a symbol from a dlopen object
|
||||
void* const symbol = dlsym(handle_, sb);
|
||||
if (symbol == NULL) {
|
||||
ec = boost::system::error_code(
|
||||
boost::system::errc::invalid_seek,
|
||||
boost::system::generic_category()
|
||||
ec = boost::dll::fs::make_error_code(
|
||||
boost::dll::fs::errc::invalid_seek
|
||||
);
|
||||
}
|
||||
|
||||
@@ -212,4 +220,3 @@ private:
|
||||
}}} // boost::dll::detail
|
||||
|
||||
#endif // BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user