DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: dev@dpdk.org
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v5 2/2] eal: initialize shared plugins on Windows
Date: Tue, 12 Mar 2024 09:52:39 -0700	[thread overview]
Message-ID: <1710262359-14217-3-git-send-email-roretzla@linux.microsoft.com> (raw)
In-Reply-To: <1710262359-14217-1-git-send-email-roretzla@linux.microsoft.com>

When EAL is built with MSVC it is possible to dynamically load plugins
on Windows. Hook eal_plugins_init into rte_eal_init if built with MSVC
and provide code to load plugins on Windows.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++-------
 lib/eal/windows/eal.c               |  8 ++++
 2 files changed, 83 insertions(+), 15 deletions(-)

diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index e541f07..bd3f332 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -18,9 +18,7 @@
 #include <libgen.h>
 #endif
 #include <sys/stat.h>
-#ifndef RTE_EXEC_ENV_WINDOWS
 #include <dirent.h>
-#endif
 
 #include <rte_string_fns.h>
 #include <rte_eal.h>
@@ -123,10 +121,8 @@ struct shared_driver {
 static struct shared_driver_list solib_list =
 TAILQ_HEAD_INITIALIZER(solib_list);
 
-#ifndef RTE_EXEC_ENV_WINDOWS
 /* Default path of external loadable drivers */
 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
-#endif
 
 /*
  * Stringified version of solib path used by dpdk-pmdinfo.py
@@ -391,12 +387,12 @@ struct device_option {
 }
 
 #ifdef RTE_EXEC_ENV_WINDOWS
-int
-eal_plugins_init(void)
-{
-	return 0;
-}
+#define SOEXT    ".dll"
 #else
+#define SOEXT    ".so"
+#endif
+
+#define SOABIEXT  SOEXT"."ABI_VERSION
 
 static int
 eal_plugindir_init(const char *path)
@@ -417,12 +413,14 @@ struct device_option {
 
 	while ((dent = readdir(d)) != NULL) {
 		struct stat sb;
-		int nlen = strnlen(dent->d_name, sizeof(dent->d_name));
+		size_t nlen = strnlen(dent->d_name, sizeof(dent->d_name));
 
-		/* check if name ends in .so or .so.ABI_VERSION */
-		if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 &&
-		    strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)],
-			   ".so."ABI_VERSION) != 0)
+		if (nlen < strlen(SOABIEXT))
+			continue;
+
+		/* check if name ends in SOEXT or SOABIEXT */
+		if (strcmp(&dent->d_name[nlen - strlen(SOEXT)], SOEXT) != 0 &&
+		    strcmp(&dent->d_name[nlen - strlen(SOABIEXT)], SOABIEXT) != 0)
 			continue;
 
 		snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
@@ -440,6 +438,68 @@ struct device_option {
 	return (dent == NULL) ? 0 : -1;
 }
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+static void*
+eal_dlopen(const char *pathname)
+{
+	void *retval = NULL;
+	struct stat pathstat;
+	char *fullpath = _fullpath(NULL, pathname, 0);
+
+	const char *loadpath = fullpath;
+	DWORD loadflags = 0;
+
+	if (fullpath == NULL) {
+		RTE_LOG_LINE(ERR, EAL, "Error expanding full path for %s, %s",
+		pathname, strerror(errno));
+	} else {
+		/* Verify that the path exists */
+		if ((stat(fullpath, &pathstat) != 0) && (errno == ENOENT)) {
+			/* not a full or relative path, try a load from default dirs */
+			loadpath = pathname;
+			loadflags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS;
+		}
+
+		retval = LoadLibraryExA(loadpath, NULL, loadflags);
+		if (retval == NULL)
+			RTE_LOG_LINE(ERR, EAL, "Error loading %s, error code: %lu",
+			    loadpath, GetLastError());
+	}
+
+	free(fullpath);
+	return retval;
+}
+
+static int
+is_shared_build(void)
+{
+	int shared = 0;
+	HMODULE apphandle = NULL;
+	HMODULE libhandle = NULL;
+
+	/* if fail to get handle, assume statically linked */
+	apphandle = GetModuleHandleA(NULL);
+	if (apphandle == NULL) {
+		RTE_LOG_LINE(ERR, EAL, "Cannot get handle to the app");
+		goto out;
+	}
+
+	/* if fail to get handle, assume statically linked */
+	if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+	    GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+	    (LPCSTR)&eal_plugins_init,
+	    &libhandle)) {
+		if (apphandle != libhandle) {
+			/* lib and app handles are different. */
+			/* Therefore lib is dynamically linked */
+			shared = 1;
+		}
+	}
+
+out:
+	return shared;
+}
+#else
 static int
 verify_perms(const char *dirpath)
 {
@@ -547,6 +607,7 @@ struct device_option {
 	EAL_LOG(INFO, "Detected static linkage of DPDK");
 	return 0;
 }
+#endif
 
 int
 eal_plugins_init(void)
@@ -585,7 +646,6 @@ struct device_option {
 	}
 	return 0;
 }
-#endif
 
 /*
  * Parse the coremask given as argument (hexadecimal string) and fill
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 52f0e74..dc2bcb7 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -305,6 +305,14 @@ enum rte_proc_type_t
 	if (fctret < 0)
 		exit(1);
 
+#ifdef RTE_TOOLCHAIN_MSVC
+	if (eal_plugins_init() < 0) {
+		rte_eal_init_alert("Cannot init plugins");
+		rte_errno = EINVAL;
+		return -1;
+	}
+#endif
+
 	if (eal_option_device_parse()) {
 		rte_errno = ENODEV;
 		return -1;
-- 
1.8.3.1


  parent reply	other threads:[~2024-03-12 16:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 19:20 [PATCH] " Tyler Retzlaff
2023-12-07 19:20 ` Tyler Retzlaff
2023-12-07 19:43   ` Tyler Retzlaff
2023-12-07 20:26 ` [PATCH v2] " Tyler Retzlaff
2023-12-07 20:26   ` Tyler Retzlaff
2024-01-03  0:05 ` [PATCH v3] " Tyler Retzlaff
2024-01-03  0:05   ` Tyler Retzlaff
2024-01-08 23:38 ` [PATCH v4 0/2] " Tyler Retzlaff
2024-01-08 23:38   ` [PATCH v4 1/2] windows: include winapifamily header for macros Tyler Retzlaff
2024-01-25 21:58     ` Dmitry Kozlyuk
2024-01-08 23:38   ` [PATCH v4 2/2] eal: initialize shared plugins on Windows Tyler Retzlaff
2024-01-25 23:04     ` Dmitry Kozlyuk
2024-01-25 18:44   ` [PATCH v4 0/2] " Tyler Retzlaff
2024-03-12 16:52 ` [PATCH v5 " Tyler Retzlaff
2024-03-12 16:52   ` [PATCH v5 1/2] eal/windows: make dirent.h shim compatible with MinGW Tyler Retzlaff
2024-03-12 16:52   ` Tyler Retzlaff [this message]
2024-03-28 18:18   ` [PATCH v5 0/2] eal: initialize shared plugins on Windows Tyler Retzlaff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1710262359-14217-3-git-send-email-roretzla@linux.microsoft.com \
    --to=roretzla@linux.microsoft.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=pallavi.kadam@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).