summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLucian Petrut <lpetrut@cloudbasesolutions.com>2019-10-04 16:56:43 +0200
committerLucian Petrut <lpetrut@cloudbasesolutions.com>2020-04-14 13:11:32 +0200
commit6bf7a3eb40f012146e8b4d67585791aca519bd2c (patch)
tree6c1d2ee964d6c964e10d695b49cd31cbdfc9f41c /src
parentMerge pull request #34314 from ishanrai05/html-cleanup (diff)
downloadceph-6bf7a3eb40f012146e8b4d67585791aca519bd2c.tar.xz
ceph-6bf7a3eb40f012146e8b4d67585791aca519bd2c.zip
common: Add dlfcn_compat.h for win32
We'll emulate the dlfcn.h interface using Windows functions, which will allow loading Windows DLLs. Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/common/CMakeLists.txt4
-rw-r--r--src/common/PluginRegistry.cc9
-rw-r--r--src/common/TracepointProvider.h2
-rw-r--r--src/common/dlfcn_win32.cc57
-rw-r--r--src/erasure-code/ErasureCodePlugin.cc8
-rw-r--r--src/include/config-h.in.cmake3
-rw-r--r--src/include/dlfcn_compat.h48
-rw-r--r--src/osd/ClassHandler.cc5
9 files changed, 120 insertions, 17 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 460dde54a50..23fc2b80d91 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -408,6 +408,7 @@ endif()
if(WIN32)
list(APPEND ceph_common_deps ws2_32 mswsock)
+ list(APPEND ceph_common_deps dlfcn_win32)
endif()
if(WITH_BLUESTORE_PMEM OR WITH_RBD_RWL)
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 5e7fb6a78eb..cb6f4faa65e 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -7,6 +7,10 @@ add_library(common_texttable_obj OBJECT
add_library(common_prioritycache_obj OBJECT
PriorityCache.cc)
+if(WIN32)
+ add_library(dlfcn_win32 STATIC dlfcn_win32.cc)
+endif()
+
set(common_srcs
AsyncOpTracker.cc
BackTrace.cc
diff --git a/src/common/PluginRegistry.cc b/src/common/PluginRegistry.cc
index c697aaa17f0..1e01528de20 100644
--- a/src/common/PluginRegistry.cc
+++ b/src/common/PluginRegistry.cc
@@ -20,15 +20,10 @@
#include "common/ceph_context.h"
#include "common/errno.h"
#include "common/debug.h"
-
-#include <dlfcn.h>
+#include "include/dlfcn_compat.h"
#define PLUGIN_PREFIX "libceph_"
-#ifdef __APPLE__
-#define PLUGIN_SUFFIX ".dylib"
-#else
-#define PLUGIN_SUFFIX ".so"
-#endif
+#define PLUGIN_SUFFIX SHARED_LIB_SUFFIX
#define PLUGIN_INIT_FUNCTION "__ceph_plugin_init"
#define PLUGIN_VERSION_FUNCTION "__ceph_plugin_version"
diff --git a/src/common/TracepointProvider.h b/src/common/TracepointProvider.h
index 30e290600a5..fe447677ccb 100644
--- a/src/common/TracepointProvider.h
+++ b/src/common/TracepointProvider.h
@@ -7,7 +7,7 @@
#include "common/ceph_context.h"
#include "common/config_obs.h"
#include "common/ceph_mutex.h"
-#include <dlfcn.h>
+#include "include/dlfcn_compat.h"
class TracepointProvider : public md_config_obs_t {
public:
diff --git a/src/common/dlfcn_win32.cc b/src/common/dlfcn_win32.cc
new file mode 100644
index 00000000000..cfe4427a6e8
--- /dev/null
+++ b/src/common/dlfcn_win32.cc
@@ -0,0 +1,57 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2020 SUSE LINUX GmbH
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include <sstream>
+#include <windows.h>
+
+#include "include/dlfcn_compat.h"
+
+
+void* dlopen(const char *filename, int flags) {
+ return LoadLibrary(filename);
+}
+
+int dlclose(void* handle) {
+ //FreeLibrary returns 0 on error, as opposed to dlclose.
+ return !FreeLibrary(handle);
+}
+
+void* dlsym(void* handle, const char* symbol) {
+ return (void*)GetProcAddress(handle, symbol);
+}
+
+dl_errmsg_t dlerror() {
+ DWORD err_code = ::GetLastError();
+ // As opposed to dlerror messages, this has to be freed.
+ LPSTR msg = NULL;
+ DWORD msg_len = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err_code,
+ 0,
+ (LPSTR) &msg,
+ 0,
+ NULL);
+ if (!msg_len) {
+ std::ostringstream msg_stream;
+ msg_stream << "Unknown error (" << err_code << ").";
+ return msg_stream.str();
+ }
+ std::string msg_s(msg);
+ LocalFree(msg);
+ return msg_s;
+}
+
diff --git a/src/erasure-code/ErasureCodePlugin.cc b/src/erasure-code/ErasureCodePlugin.cc
index a42bd957a11..f189b91fdfe 100644
--- a/src/erasure-code/ErasureCodePlugin.cc
+++ b/src/erasure-code/ErasureCodePlugin.cc
@@ -16,22 +16,18 @@
*/
#include <errno.h>
-#include <dlfcn.h>
#include "ceph_ver.h"
#include "ErasureCodePlugin.h"
#include "common/errno.h"
+#include "include/dlfcn_compat.h"
#include "include/str_list.h"
#include "include/ceph_assert.h"
using namespace std;
#define PLUGIN_PREFIX "libec_"
-#if defined(__APPLE__)
-#define PLUGIN_SUFFIX ".dylib"
-#else
-#define PLUGIN_SUFFIX ".so"
-#endif
+#define PLUGIN_SUFFIX SHARED_LIB_SUFFIX
#define PLUGIN_INIT_FUNCTION "__erasure_code_init"
#define PLUGIN_VERSION_FUNCTION "__erasure_code_version"
diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake
index 31dfb8983a7..dc213938f5c 100644
--- a/src/include/config-h.in.cmake
+++ b/src/include/config-h.in.cmake
@@ -345,4 +345,7 @@
/* Define if RWL is enabled */
#cmakedefine WITH_RBD_RWL
+/* Shared library extension, such as .so, .dll or .dylib */
+#cmakedefine CMAKE_SHARED_LIBRARY_SUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@"
+
#endif /* CONFIG_H */
diff --git a/src/include/dlfcn_compat.h b/src/include/dlfcn_compat.h
new file mode 100644
index 00000000000..95fd64e51ab
--- /dev/null
+++ b/src/include/dlfcn_compat.h
@@ -0,0 +1,48 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2020 SUSE LINUX GmbH
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#ifndef DLFCN_COMPAT_H
+#define DLFCN_COMPAT_H
+
+#include "acconfig.h"
+
+#define SHARED_LIB_SUFFIX CMAKE_SHARED_LIBRARY_SUFFIX
+
+#ifdef _WIN32
+ #include <string>
+
+ using dl_errmsg_t = std::string;
+
+ // The load mode flags will be ignored on Windows. We keep the same
+ // values for debugging purposes though.
+ #define RTLD_LAZY 0x00001
+ #define RTLD_NOW 0x00002
+ #define RTLD_BINDING_MASK 0x3
+ #define RTLD_NOLOAD 0x00004
+ #define RTLD_DEEPBIND 0x00008
+ #define RTLD_GLOBAL 0x00100
+ #define RTLD_LOCAL 0
+ #define RTLD_NODELETE 0x01000
+
+ void* dlopen(const char *filename, int flags);
+ int dlclose(void* handle);
+ dl_errmsg_t dlerror();
+ void* dlsym(void* handle, const char* symbol);
+#else
+ #include <dlfcn.h>
+
+ using dl_errmsg_t = char*;
+#endif /* _WIN32 */
+
+#endif /* DLFCN_H */
diff --git a/src/osd/ClassHandler.cc b/src/osd/ClassHandler.cc
index 2bf6a69ad10..02c2cb694b1 100644
--- a/src/osd/ClassHandler.cc
+++ b/src/osd/ClassHandler.cc
@@ -5,8 +5,7 @@
#include "ClassHandler.h"
#include "common/errno.h"
#include "common/ceph_context.h"
-
-#include <dlfcn.h>
+#include "include/dlfcn_compat.h"
#include <map>
@@ -23,7 +22,7 @@
#define CLS_PREFIX "libcls_"
-#define CLS_SUFFIX ".so"
+#define CLS_SUFFIX SHARED_LIB_SUFFIX
using std::map;
using std::set;