eal: initialize shared plugins on Windows
PATCH 1/1 eal: initialize shared plugins on Windows
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.
Tyler Retzlaff (1):
eal: initialize shared plugins on Windows
lib/eal/common/eal_common_options.c | 92 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 84 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/1 eal: initialize shared plugins on Windows
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.
--- lib/eal/common/eal_common_options.c | 92 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 84 insertions(+), 16 deletions(-)
lib/eal/common/eal_common_options.c +76 -16
@@ -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>
@@ -74,7 +72,7 @@ {OPT_HELP, 0, NULL, OPT_HELP_NUM }, {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM }, {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, - {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, + {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, {OPT_TRACE, 1, NULL, OPT_TRACE_NUM },
@@ -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
@@ -371,12 +367,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_VERSIONstatic int eal_plugindir_init (const char *path)
@@ -397,12 +393,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);
@@ -420,6 +418,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 (ERR ,EAL ,"Error expanding full path for %s, %s\n" , + 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 (ERR ,EAL ,"Error loading %s, error code: %" PRIu32"\n" , + 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 (ERR ,EAL ,"Cannot get handle to the app\n" ); + 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) {
@@ -527,6 +587,7 @@ struct device_option {RTE_LOG (INFO ,EAL ,"Detected static linkage of DPDK\n" ); return 0; } +#endif int eal_plugins_init (void )
@@ -565,7 +626,6 @@ struct device_option { }return 0 ; } -#endif /* * Parse the coremask given as argument (hexadecimal string) and fill
lib/eal/windows/eal.c +8 -0
@@ -305,6 +305,14 @@ enum rte_proc_type_tif (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 ;
Signature · 1 line
1.8.3.1
Quoted 25 lines · Tyler Retzlaff
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.Signed-off-by Tyler Retzlaff <[email protected]>--- lib/eal/common/eal_common_options.c | 92 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 84 insertions(+), 16 deletions(-)lib/eal/common/eal_common_options.c +0
-2@@ -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>
lib/eal/common/eal_common_options.c line 75
Quoted 5 lines
lib/eal/common/eal_common_options.c +1
-1@@ -74,7 +72,7 @@ {OPT_HELP, 0, NULL, OPT_HELP_NUM }, {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM }, {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, - {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, + {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
accidentally converted 8 spaces to a tab here, will submit a new version to remove the change from this series (or maintainer can adjust).
thanks
PATCH v2 1/1 eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
v2:
* revert unintended / unrelated whitespace change
* include inttypes.h for use of PRIu32 in log format string
Tyler Retzlaff (1):
eal: initialize shared plugins on Windows
lib/eal/common/eal_common_options.c | 91 +++++++++++++++++++++++++++++++------ lib/eal/windows/eal.c | 8 ++++ 2 files changed, 84 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/1 eal: initialize shared plugins on Windows
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.
--- lib/eal/common/eal_common_options.c | 91 +++++++++++++++++++++++++++++++------ lib/eal/windows/eal.c | 8 ++++ 2 files changed, 84 insertions(+), 15 deletions(-)
lib/eal/common/eal_common_options.c +76 -15
@@ -5,6 +5,7 @@#include <stdlib.h> #include <string.h> +#include <inttypes.h> #include <pthread.h> #ifndef RTE_EXEC_ENV_WINDOWS #include <syslog.h>
@@ -18,9 +19,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 +122,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
@@ -371,12 +368,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_VERSIONstatic int eal_plugindir_init (const char *path)
@@ -397,12 +394,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);
@@ -420,6 +419,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 (ERR ,EAL ,"Error expanding full path for %s, %s\n" , + 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 (ERR ,EAL ,"Error loading %s, error code: %" PRIu32"\n" , + 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 (ERR ,EAL ,"Cannot get handle to the app\n" ); + 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) {
@@ -527,6 +588,7 @@ struct device_option {RTE_LOG (INFO ,EAL ,"Detected static linkage of DPDK\n" ); return 0; } +#endif int eal_plugins_init (void )
@@ -565,7 +627,6 @@ struct device_option { }return 0 ; } -#endif /* * Parse the coremask given as argument (hexadecimal string) and fill
lib/eal/windows/eal.c +8 -0
@@ -305,6 +305,14 @@ enum rte_proc_type_tif (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 ;
Signature · 1 line
1.8.3.1
PATCH v3 1/1 eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
Tyler Retzlaff (1):
eal: initialize shared plugins on Windows
lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 83 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/1 eal: initialize shared plugins on Windows
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.
--- lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 83 insertions(+), 15 deletions(-)
lib/eal/common/eal_common_options.c +75 -15
@@ -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
@@ -371,12 +367,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_VERSIONstatic int eal_plugindir_init (const char *path)
@@ -397,12 +393,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);
@@ -420,6 +418,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 (ERR ,EAL ,"Error expanding full path for %s, %s\n" , + 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 (ERR ,EAL ,"Error loading %s, error code: %lu\n" , + 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 (ERR ,EAL ,"Cannot get handle to the app\n" ); + 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) {
@@ -527,6 +587,7 @@ struct device_option {EAL_LOG (INFO ,"Detected static linkage of DPDK" ); return 0; } +#endif int eal_plugins_init (void )
@@ -565,7 +626,6 @@ struct device_option { }return 0 ; } -#endif /* * Parse the coremask given as argument (hexadecimal string) and fill
lib/eal/windows/eal.c +8 -0
@@ -305,6 +305,14 @@ enum rte_proc_type_tif (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 ;
Signature · 1 line
1.8.3.1
v4 cover eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
v4:
* include winipfamily.h header for WINAPI_FAMILY macros and provide definition for PHONE_APP if mingw winipfamily.h doesn't supply it
v3:
* revert use of PRIu32 from previous patch just use %lu to make unsigned long format happy
v2:
* revert unintended / unrelated whitespace change
* include inttypes.h for use of PRIu32 in log format string
Tyler Retzlaff (2):
windows: include winapifamily header for macros
eal: initialize shared plugins on Windows
lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ lib/eal/windows/include/dirent.h | 6 +++ 3 files changed, 89 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v4 1/2 windows: include winapifamily header for macros
Include winapifamily.h for WINAPI_FAMILY macro and provide a definition of WINAPI_FAMILY_PHONE_APP if not present (happens compiling under mingw)
--- lib/eal/windows/include/dirent.h | 6 ++++++ 1 file changed, 6 insertions(+)
lib/eal/windows/include/dirent.h +6 -0
@@ -8,6 +8,12 @@#ifndef DIRENT_H #define DIRENT_H +#include <winapifamily.h> + +#ifndef WINAPI_FAMILY_PHONE_APP +#define WINAPI_FAMILY_PHONE_APP 3 +#endif +/* * Include windows.h without Windows Sockets 1.1 to prevent conflicts with * Windows Sockets 2.0.
Signature · 1 line
1.8.3.1
Re: [PATCH v4 1/2] windows: include winapifamily header for macros
2024-01-08 15:38 (UTC-0800), Tyler Retzlaff:
Quoted 3 lines
Include
winapifamily.hforWINAPI_FAMILYmacro and provide a definition ofWINAPI_FAMILY_PHONE_APPif not present (happens compiling under mingw)
Given this explanation, I think the subject should be:
eal/windows: make dirent.h shim compatible with MinGW
PATCH v4 2/2 eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
--- lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 83 insertions(+), 15 deletions(-)
lib/eal/common/eal_common_options.c +75 -15
@@ -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
@@ -371,12 +367,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_VERSIONstatic int eal_plugindir_init (const char *path)
@@ -397,12 +393,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);
@@ -420,6 +418,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 (ERR ,EAL ,"Error expanding full path for %s, %s\n" , + 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 (ERR ,EAL ,"Error loading %s, error code: %lu\n" , + 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 (ERR ,EAL ,"Cannot get handle to the app\n" ); + 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) {
@@ -527,6 +587,7 @@ struct device_option {EAL_LOG (INFO ,"Detected static linkage of DPDK" ); return 0; } +#endif int eal_plugins_init (void )
@@ -565,7 +626,6 @@ struct device_option { }return 0 ; } -#endif /* * Parse the coremask given as argument (hexadecimal string) and fill
lib/eal/windows/eal.c +8 -0
@@ -305,6 +305,14 @@ enum rte_proc_type_tif (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 ;
Signature · 1 line
1.8.3.1
2024-01-08 15:38 (UTC-0800), Tyler Retzlaff:
Quoted 3 lines
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.
Windows implementation does not check directory permissions like its Unix counterpart does. I don't insist on porting it, because this feature is not documented and is more like a safety net.
Just making sure this is a conscious decision and not an oversight.
ping for Windows maintainers
thanks!
Quoted 27 lines · Tyler Retzlaff
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.v4:
* includewinipfamily.hheader forWINAPI_FAMILYmacros and provide definition forPHONE_APPif mingwwinipfamily.hdoesn't supply itv3:
* revert use of PRIu32 from previous patch just use %lu to make unsigned long format happyv2:
* revert unintended / unrelated whitespace change
* includeinttypes.hfor use of PRIu32 in log format stringTyler Retzlaff (2):
windows: include winapifamily header for macros
eal: initialize shared plugins on Windowslib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ lib/eal/windows/include/dirent.h | 6 +++ 3 files changed, 89 insertions(+), 15 deletions(-)Signature · 1 line
1.8.3.1
v5 cover eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
Note: For patch 2/2 no verify permissions is provided as it would be
redundant with the check performed by LoadLibrary.
CI warning also expected DWORD is not uint64_t on Windows.
v5:
* rebase series
* use RTE_LOG_LINE instead of RTE_LOG
* update commit subject on patch 1/2 as per maintainer suggestion
v4:
* include winipfamily.h header for WINAPI_FAMILY macros and provide definition for PHONE_APP if mingw winipfamily.h doesn't supply it
v3:
* revert use of PRIu32 from previous patch just use %lu to make unsigned long format happy
v2:
* revert unintended / unrelated whitespace change
* include inttypes.h for use of PRIu32 in log format string
Tyler Retzlaff (2):
eal/windows: make dirent.h shim compatible with MinGW
eal: initialize shared plugins on Windows
lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ lib/eal/windows/include/dirent.h | 6 +++ 3 files changed, 89 insertions(+), 15 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 1/2 eal/windows: make dirent.h shim compatible with MinGW
Include winapifamily.h for WINAPI_FAMILY macro and provide a definition of WINAPI_FAMILY_PHONE_APP if not present (happens compiling under mingw)
--- lib/eal/windows/include/dirent.h | 6 ++++++ 1 file changed, 6 insertions(+)
lib/eal/windows/include/dirent.h +6 -0
@@ -8,6 +8,12 @@#ifndef DIRENT_H #define DIRENT_H +#include <winapifamily.h> + +#ifndef WINAPI_FAMILY_PHONE_APP +#define WINAPI_FAMILY_PHONE_APP 3 +#endif +/* * Include windows.h without Windows Sockets 1.1 to prevent conflicts with * Windows Sockets 2.0.
Signature · 1 line
1.8.3.1
PATCH v5 2/2 eal: initialize shared plugins on Windows
In reply to Tyler RetzlaffWhen 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.
--- lib/eal/common/eal_common_options.c | 90 ++++++++++++++++++++++++++++++------- lib/eal/windows/eal.c | 8 ++++ 2 files changed, 83 insertions(+), 15 deletions(-)
lib/eal/common/eal_common_options.c +75 -15
@@ -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_VERSIONstatic 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
lib/eal/windows/eal.c +8 -0
@@ -305,6 +305,14 @@ enum rte_proc_type_tif (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 ;
Signature · 1 line
1.8.3.1
12/03/2024 17:52, Tyler Retzlaff:
lib/eal/common/eal_common_options.c struct device_option { · line 444
Quoted 11 lines
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.Signed-off-by Tyler Retzlaff <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>---
lib/eal/common/eal_common_options.c +4
-0+#ifdef RTE_EXEC_ENV_WINDOWS +static void * +eal_dlopen (const char *pathname) +{
I'm not sure about having a Windows-specific implementation in lib/eal/common/
Also, the CI is failing with this patchset.
Quoted 5 lines · Thomas Monjalon
12/03/2024 17:52, Tyler Retzlaff:
Quoted 4 lines
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.
Quoted 9 lines
lib/eal/common/eal_common_options.c struct device_option { · line 444
Quoted 7 lines
Signed-off-by Tyler Retzlaff <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>---
lib/eal/common/eal_common_options.c +4
-0+#ifdef RTE_EXEC_ENV_WINDOWS +static void * +eal_dlopen (const char *pathname) +{I'm not sure about having a Windows-specific implementation in
lib/eal/common/
are you asking for the unix and windows implementations to be moved out to eal/{windows,unix} respectively rather than the current conditional compiled in eal/common?
Quoted 3 lines
Also, the CI is failing with this patchset.
i'll take a look when i get a chance, you can leave it unmerged for now.
29/05/2024 19:56, Tyler Retzlaff:
Quoted 16 lines · Thomas Monjalon
Quoted 5 lines
12/03/2024 17:52, Tyler Retzlaff:
Quoted 4 lines
When EAL is built with MSVC it is possible to dynamically load plugins on Windows. Hook
eal_plugins_initintorte_eal_initif built with MSVC and provide code to load plugins on Windows.Quoted 9 lines
lib/eal/common/eal_common_options.c struct device_option { · line 444
Quoted 7 lines
Signed-off-by Tyler Retzlaff <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>---
lib/eal/common/eal_common_options.c +4
-0+#ifdef RTE_EXEC_ENV_WINDOWS +static void * +eal_dlopen (const char *pathname) +{I'm not sure about having a Windows-specific implementation in
lib/eal/common/
Quoted 3 lines
are you asking for the unix and windows implementations to be moved out to eal/{windows,unix} respectively rather than the current conditional compiled in eal/common?
Yes I feel it would be better.
Please tell me if I missed something.
Quoted 4 lines
Quoted 2 lines
Also, the CI is failing with this patchset.
i'll take a look when i get a chance, you can leave it unmerged for now.
Quoted 11 lines · On Thu, 30 May 2024 10:02:46 +0200 Thomas Monjalon <[email protected]> wrote:
Quoted 3 lines
are you asking for the unix and windows implementations to be moved out to eal/{windows,unix} respectively rather than the current conditional compiled in eal/common?
Yes I feel it would be better.
Please tell me if I missed something.Quoted 4 lines
Quoted 2 lines
Also, the CI is failing with this patchset.
i'll take a look when i get a chance, you can leave it unmerged for now.
Marking it as changes requested.
Would be good to split as requested.
Recheck-request: github-robot