DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols
@ 2021-02-20 23:29 Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
                   ` (7 more replies)
  0 siblings, 8 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Windows, rte_os.h contains a small POSIX compatibility set of
functions and macros. Exposing it from EAL can break consumer own POSIX
compatibility layer and is against standards in general.

First define required wrappers, then fix POSIX dependencies in
Windows-enabled libraries and drivers, then eliminate POSIX symbols from
Windows EAL API. Commits are arranged so that they all compile and are
limited in scope; patches 5, 6, 7 can be squashed if needed.

No "Fixes" tags, because it's really an enhancement,
preventing issues rather then solving direct ones.

Dmitry Kozlyuk (7):
  eal: add wrappers for POSIX string functions
  eal: add macro for maximum path length
  eal: add sleep API
  eal: add asprintf() internal wrapper
  lib: remove POSIX dependencies
  drivers: remove POSIX dependencies
  eal/windows: do not expose POSIX symbols

 doc/guides/rel_notes/release_21_05.rst        |  9 ++
 drivers/bus/pci/private.h                     |  2 +-
 drivers/bus/vdev/vdev.c                       |  4 +-
 drivers/bus/vdev/vdev_params.c                |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c         |  4 +-
 drivers/net/i40e/i40e_ethdev.c                | 56 +++++------
 lib/librte_cmdline/cmdline.c                  |  1 +
 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_dev.c        |  6 +-
 lib/librte_eal/common/eal_common_devargs.c    |  7 +-
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +-
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_log.c        |  5 +-
 lib/librte_eal/common/eal_common_options.c    | 42 ++++----
 lib/librte_eal/common/eal_common_timer.c      |  5 +-
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  4 +-
 .../common/eal_common_trace_utils.c           | 13 +--
 lib/librte_eal/common/eal_filesystem.h        |  8 +-
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_private.h           | 23 +++++
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  6 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 ++++++++
 lib/librte_eal/include/rte_thread.h           | 11 +++
 lib/librte_eal/linux/include/rte_os.h         |  6 +-
 lib/librte_eal/rte_eal_exports.def            |  2 +
 lib/librte_eal/unix/rte_thread.c              |  6 ++
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 30 ++++++
 lib/librte_eal/windows/eal_thread.c           |  9 +-
 lib/librte_eal/windows/include/dirent.h       | 21 ++--
 lib/librte_eal/windows/include/rte_os.h       | 99 ++-----------------
 lib/librte_ethdev/rte_class_eth.c             |  2 +-
 lib/librte_ethdev/rte_ethdev.c                |  2 +-
 lib/librte_kvargs/rte_kvargs.c                | 17 ++--
 38 files changed, 266 insertions(+), 206 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Jerin Jacob,
	Sunil Kumar Kori

POSIX strncasecmp(), strdup(), and strtok_r() have different names
on Windows, respectively, strnicmp(), _strdup(), and strtok_s().

Add wrappers as inline functions, because they're used from librte_kvargs,
and thus cannot be in librte_eal; besides, implementation is trivial.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_dev.c        |  6 +--
 lib/librte_eal/common/eal_common_devargs.c    |  7 ++--
 lib/librte_eal/common/eal_common_log.c        |  5 ++-
 lib/librte_eal/common/eal_common_options.c    | 12 +++---
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 +++++++++++++++++++
 7 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 8a3bd3100..0a15fdcf7 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,
 			if (!device_name) {
 				event_cb->dev_name = NULL;
 			} else {
-				event_cb->dev_name = strdup(device_name);
+				event_cb->dev_name = rte_strdup(device_name);
 				if (event_cb->dev_name == NULL) {
 					ret = -ENOMEM;
 					goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str)
 
 	end = strcspn(str, ",/");
 	if (str[end] == ',') {
-		copy = strdup(&str[end + 1]);
+		copy = rte_strdup(&str[end + 1]);
 	} else {
 		/* '/' or '\0' */
-		copy = strdup("");
+		copy = rte_strdup("");
 	}
 	if (copy == NULL) {
 		rte_errno = ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index fcf3d9a3c..14e082a27 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -18,6 +18,7 @@
 #include <rte_errno.h>
 #include <rte_kvargs.h>
 #include <rte_log.h>
+#include <rte_string_fns.h>
 #include <rte_tailq.h>
 #include "eal_private.h"
 
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
 	 * anything and keep referring only to it.
 	 */
 	if (devargs->data != devstr) {
-		devargs->data = strdup(devstr);
+		devargs->data = rte_strdup(devstr);
 		if (devargs->data == NULL) {
 			RTE_LOG(ERR, EAL, "OOM\n");
 			ret = -ENOMEM;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 	da->bus = bus;
 	/* Parse eventual device arguments */
 	if (devname[i] == ',')
-		da->args = strdup(&devname[i + 1]);
+		da->args = rte_strdup(&devname[i + 1]);
 	else
-		da->args = strdup("");
+		da->args = rte_strdup("");
 	if (da->args == NULL) {
 		RTE_LOG(ERR, EAL, "not enough memory to parse arguments\n");
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb..557a8243f 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -14,6 +14,7 @@
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_per_lcore.h>
+#include <rte_string_fns.h>
 
 #include "eal_private.h"
 
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,
 		if (regcomp(&opt_ll->re_match, regex, 0) != 0)
 			goto fail;
 	} else if (pattern) {
-		opt_ll->pattern = strdup(pattern);
+		opt_ll->pattern = rte_strdup(pattern);
 		if (opt_ll->pattern == NULL)
 			goto fail;
 	} else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)
 static int
 __rte_log_register(const char *name, int id)
 {
-	char *dup_name = strdup(name);
+	char *dup_name = rte_strdup(name);
 
 	if (dup_name == NULL)
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc42..3612ad441 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (i = 0; i < argc; i++) {
-		eal_args[i] = strdup(argv[i]);
+		eal_args[i] = rte_strdup(argv[i]);
 		if (strcmp(argv[i], "--") == 0)
 			break;
 	}
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (j = 0; i < argc; j++, i++)
-		eal_app_args[j] = strdup(argv[i]);
+		eal_app_args[j] = rte_strdup(argv[i]);
 	eal_app_args[j] = NULL;
 
 	return 0;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
-	str = strdup(arg);
+	str = rte_strdup(arg);
 	if (str == NULL)
 		return -1;
 
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)
 static enum rte_proc_type_t
 eal_parse_proc_type(const char *arg)
 {
-	if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
+	if (rte_strncasecmp(arg, "primary", sizeof("primary")) == 0)
 		return RTE_PROC_PRIMARY;
-	if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
+	if (rte_strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
 		return RTE_PROC_SECONDARY;
-	if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
+	if (rte_strncasecmp(arg, "auto", sizeof("auto")) == 0)
 		return RTE_PROC_AUTO;
 
 	return RTE_PROC_INVALID;
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 33e419aac..4041d9af6 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)
 	if (strstr(field, ".") == NULL && strstr(field, "->") == NULL)
 		return NULL;
 
-	out = strdup(field);
+	out = rte_strdup(field);
 	if (out == NULL)
 		return NULL;
 	p = out;
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 64f58fb66..d541a5ea9 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)
 		return -ENOMEM;
 	}
 
-	arg->val = strdup(val);
+	arg->val = rte_strdup(val);
 	if (arg->val == NULL) {
 		trace_err("failed to allocate memory for %s", val);
 		free(arg);
diff --git a/lib/librte_eal/include/rte_string_fns.h b/lib/librte_eal/include/rte_string_fns.h
index 8bac8243c..2d9d5afc8 100644
--- a/lib/librte_eal/include/rte_string_fns.h
+++ b/lib/librte_eal/include/rte_string_fns.h
@@ -116,6 +116,48 @@ rte_strlcat(char *dst, const char *src, size_t size)
 ssize_t
 rte_strscpy(char *dst, const char *src, size_t dsize);
 
+/**
+ * @internal
+ * strncasecmp(3) replacement for systems that don't have it.
+ */
+static inline int
+rte_strncasecmp(const char *s1, const char *s2, size_t size)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strnicmp(s1, s2, size);
+#else
+	return strncasecmp(s1, s2, size);
+#endif
+}
+
+/**
+ * @internal
+ * strtor_r(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strtok(char *str, const char *delim, char **saveptr)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return strtok_s(str, delim, saveptr);
+#else
+	return strtok_r(str, delim, saveptr);
+#endif
+}
+
+/**
+ * @internal
+ * strdup(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strdup(const char *str)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strdup(str);
+#else
+	return strdup(str);
+#endif
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 3/7] eal: add sleep API Dmitry Kozlyuk
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Anatoly Burakov,
	Jerin Jacob, Sunil Kumar Kori, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Path length limit is PATH_MAX on Unix and _MAX_PATH on Windows.
Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX
in "common" multiprocess code, because it's really Unix-specific.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
PATH_MAX is not removed until the last patch to keep PCI building.

 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +++----
 lib/librte_eal/common/eal_common_options.c    | 20 +++++++++---------
 .../common/eal_common_trace_utils.c           |  9 ++++----
 lib/librte_eal/common/eal_filesystem.h        |  8 +++----
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  2 ++
 lib/librte_eal/linux/include/rte_os.h         |  2 ++
 lib/librte_eal/windows/include/dirent.h       | 21 +++++++------------
 lib/librte_eal/windows/include/rte_os.h       |  2 ++
 12 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7..33e5a076a 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -18,7 +18,7 @@ static struct rte_config rte_config = {
 };
 
 /* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
+static char runtime_dir[RTE_PATH_MAX];
 
 /* internal configuration */
 static struct internal_config internal_config;
diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index d974f3dab..c21b8ec66 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)
 static int
 resize_and_map(int fd, void *addr, size_t len)
 {
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *map_addr;
 
 	if (eal_file_truncate(fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
 		unsigned int elt_sz)
 {
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	struct used_mask *msk;
 	struct mem_area *ma = NULL;
 	void *data = NULL;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr)
 {
 	struct mem_area *ma = NULL, *tmp = NULL;
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *data = NULL;
 	int fd = -1;
 
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)
 	struct mem_area *tmp = NULL;
 	size_t mmap_len;
 	int fd, ret;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3612ad441..bad389903 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);
 struct shared_driver {
 	TAILQ_ENTRY(shared_driver) next;
 
-	char    name[PATH_MAX];
+	char    name[RTE_PATH_MAX];
 	void*   lib_handle;
 };
 
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)
 		return -1;
 	}
 	memset(solib, 0, sizeof(*solib));
-	strlcpy(solib->name, path, PATH_MAX);
+	strlcpy(solib->name, path, RTE_PATH_MAX);
 	TAILQ_INSERT_TAIL(&solib_list, solib, next);
 
 	return 0;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path)
 {
 	DIR *d = NULL;
 	struct dirent *dent = NULL;
-	char sopath[PATH_MAX];
+	char sopath[RTE_PATH_MAX];
 
 	if (path == NULL || *path == '\0')
 		return 0;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)
 
 	/* if not root, check down one level first */
 	if (strcmp(dirpath, "/") != 0) {
-		static __thread char last_dir_checked[PATH_MAX];
-		char copy[PATH_MAX];
+		static __thread char last_dir_checked[RTE_PATH_MAX];
+		char copy[RTE_PATH_MAX];
 		const char *dir;
 
-		strlcpy(copy, dirpath, PATH_MAX);
+		strlcpy(copy, dirpath, RTE_PATH_MAX);
 		dir = dirname(copy);
-		if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
+		if (strncmp(dir, last_dir_checked, RTE_PATH_MAX) != 0) {
 			if (verify_perms(dir) != 0)
 				return -1;
-			strlcpy(last_dir_checked, dir, PATH_MAX);
+			strlcpy(last_dir_checked, dir, RTE_PATH_MAX);
 		}
 	}
 
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname)
 				pathname, strerror(errno));
 		goto out;
 	}
-	if (strnlen(realp, PATH_MAX) == PATH_MAX) {
-		RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
+	if (strnlen(realp, RTE_PATH_MAX) == RTE_PATH_MAX) {
+		RTE_LOG(ERR, EAL, "Error, driver path greater than RTE_PATH_MAX\n");
 		goto out;
 	}
 
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index d541a5ea9..6b81fdeec 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -369,11 +369,11 @@ trace_mkdir(void)
 static int
 trace_meta_save(struct trace *trace)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/metadata", trace->dir);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/metadata", trace->dir);
 	if (rc < 0)
 		return rc;
 
@@ -400,11 +400,12 @@ static int
 trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr,
 		uint32_t cnt)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/channel0_%d", trace->dir, cnt);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/channel0_%d",
+		trace->dir, cnt);
 	if (rc < 0)
 		return rc;
 
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 5d21f07c2..d28a9b23d 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);
 static inline const char *
 eal_runtime_config_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)
 static inline const char *
 eal_mp_socket_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
 static inline const char *
 eal_hugepage_info_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)
 static inline const char *
 eal_hugepage_data_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
diff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h
index 1b560d337..02b324ed1 100644
--- a/lib/librte_eal/common/eal_hugepages.h
+++ b/lib/librte_eal/common/eal_hugepages.h
@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <limits.h>
 
-#define MAX_HUGEPAGE_PATH PATH_MAX
+#define MAX_HUGEPAGE_PATH RTE_PATH_MAX
 
 /**
  * Structure used to store information about hugepages that we mapped
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2..c8ea3b8fc 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -27,7 +27,7 @@
  */
 struct hugepage_info {
 	uint64_t hugepage_sz;   /**< size of a huge page */
-	char hugedir[PATH_MAX];    /**< dir where hugetlbfs is mounted */
+	char hugedir[RTE_PATH_MAX];    /**< dir where hugetlbfs is mounted */
 	uint32_t num_pages[RTE_MAX_NUMA_NODES];
 	/**< number of hugepages of that size on each socket */
 	int lock_descriptor;    /**< file descriptor for hugepage dir */
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 06751eb23..ab915eb10 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -51,7 +51,7 @@ struct trace_arg {
 };
 
 struct trace {
-	char dir[PATH_MAX];
+	char dir[RTE_PATH_MAX];
 	int dir_offset;
 	int register_errno;
 	bool status;
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index eeb750cd8..b37d59b5e 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <pthread_np.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpuset_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) do \
 { \
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index 218d4fa86..af7d052d9 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <sched.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpu_set_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
diff --git a/lib/librte_eal/windows/include/dirent.h b/lib/librte_eal/windows/include/dirent.h
index 869a59837..3a9a694f4 100644
--- a/lib/librte_eal/windows/include/dirent.h
+++ b/lib/librte_eal/windows/include/dirent.h
@@ -28,11 +28,6 @@
 #include <sys/stat.h>
 #include <errno.h>
 
-/* Maximum length of file name */
-#if !defined(PATH_MAX)
-#   define PATH_MAX MAX_PATH
-#endif
-
 /* File type flags for d_type */
 #define DT_UNKNOWN 0
 #define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {
 	int d_type;
 
 	/* File name */
-	wchar_t d_name[PATH_MAX];
+	wchar_t d_name[RTE_PATH_MAX];
 };
 typedef struct _wdirent _wdirent;
 
@@ -113,7 +108,7 @@ struct dirent {
 	int d_type;
 
 	/* File name */
-	char d_name[PATH_MAX];
+	char d_name[RTE_PATH_MAX];
 };
 typedef struct dirent dirent;
 
@@ -388,12 +383,12 @@ opendir(const char *dirname)
 	/* Allocate memory for DIR structure */
 	dirp = (DIR *)malloc(sizeof(struct DIR));
 	if (dirp) {
-		wchar_t wname[PATH_MAX];
+		wchar_t wname[RTE_PATH_MAX];
 		size_t n;
 
 		/* Convert directory name to wide-character string */
-		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
-			dirname, PATH_MAX);
+		error = dirent_mbstowcs_s(&n, wname, RTE_PATH_MAX,
+			dirname, RTE_PATH_MAX);
 		if (!error) {
 
 			/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)
 
 		/* Attempt to convert file name to multi-byte string */
 		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
-			PATH_MAX, datap->cFileName, PATH_MAX);
+			RTE_PATH_MAX, datap->cFileName, RTE_PATH_MAX);
 
 		/*
 		 * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)
 		 */
 		if (error  &&  datap->cAlternateFileName[0] != '\0') {
 			error = dirent_wcstombs_s(
-				&n, dirp->ent.d_name, PATH_MAX,
-				datap->cAlternateFileName, PATH_MAX);
+				&n, dirp->ent.d_name, RTE_PATH_MAX,
+				datap->cAlternateFileName, RTE_PATH_MAX);
 		}
 
 		if (!error) {
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06..edca11bd2 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -20,6 +20,8 @@
 extern "C" {
 #endif
 
+#define RTE_PATH_MAX _MAX_PATH
+
 /* limits.h replacement, value as in <windows.h> */
 #ifndef PATH_MAX
 #define PATH_MAX _MAX_PATH
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 3/7] eal: add sleep API
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Ray Kinsella, Neil Horman

POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_timer.c |  5 +++--
 lib/librte_eal/include/rte_thread.h      | 11 +++++++++++
 lib/librte_eal/rte_eal_exports.def       |  2 ++
 lib/librte_eal/unix/rte_thread.c         |  6 ++++++
 lib/librte_eal/version.map               |  3 +++
 lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
 6 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035..0e89a4f7d 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -16,6 +16,7 @@
 #include <rte_cycles.h>
 #include <rte_pause.h>
 #include <rte_eal.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
 #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)
 #define CYC_PER_10MHZ 1E7
 	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
 		" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
+	/* assume that the rte_thread_sleep(1) will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_thread_sleep(1);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h
index e640ea185..f0c12dd79 100644
--- a/lib/librte_eal/include/rte_thread.h
+++ b/lib/librte_eal/include/rte_thread.h
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);
 __rte_experimental
 void *rte_thread_tls_value_get(rte_tls_key key);
 
+/**
+ * Suspend current OS thread for the specified time, yielding CPU to scheduler.
+ *
+ * @param sec
+ *  Number of seconds to sleep. The system may return control later,
+ *  but not earlier. Zero value always yields the CPU, but control may be
+ *  returned immediately.
+ */
+__rte_experimental
+void rte_thread_sleep(unsigned int sec);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index 474cf123f..494240b94 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -334,3 +334,5 @@ EXPORTS
 	rte_mem_map
 	rte_mem_page_size
 	rte_mem_unmap
+
+	rte_thread_sleep
diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c
index 86ffeebc9..029d39dd4 100644
--- a/lib/librte_eal/unix/rte_thread.c
+++ b/lib/librte_eal/unix/rte_thread.c
@@ -84,3 +84,9 @@ rte_thread_tls_value_get(rte_tls_key key)
 	}
 	return pthread_getspecific(key->thread_index);
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	sleep(sec);
+}
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112..106864469 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+    # added in 21.05
+	rte_thread_sleep;
 };
 
 INTERNAL {
diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c
index 908e726d1..957792301 100644
--- a/lib/librte_eal/windows/eal_thread.c
+++ b/lib/librte_eal/windows/eal_thread.c
@@ -11,9 +11,10 @@
 #include <rte_per_lcore.h>
 #include <rte_common.h>
 #include <rte_memory.h>
-#include <eal_thread.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
+#include "eal_thread.h"
 #include "eal_windows.h"
 
 /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
 	/* This is a stub, not the expected result */
 	return 0;
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	return Sleep(MS_PER_S * sec);
+}
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                   ` (2 preceding siblings ...)
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 3/7] eal: add sleep API Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Jerin Jacob,
	Sunil Kumar Kori, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

POSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_options.c    |  8 ++---
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/common/eal_private.h           | 18 +++++++++++
 lib/librte_eal/windows/eal.c                  | 30 +++++++++++++++++++
 7 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
index 66d6bad1a..db16a34cc 100644
--- a/lib/librte_eal/common/eal_common_lcore.c
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	callback = calloc(1, sizeof(*callback));
 	if (callback == NULL)
 		return NULL;
-	if (asprintf(&callback->name, "%s-%p", name, arg) == -1) {
+	if (eal_asprintf(&callback->name, "%s-%p", name, arg) == -1) {
 		free(callback);
 		return NULL;
 	}
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index bad389903..275f879d7 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1435,7 +1435,7 @@ available_cores(void)
 		return NULL;
 
 	/* first sequence */
-	if (asprintf(&str, "%d", idx) < 0)
+	if (eal_asprintf(&str, "%d", idx) < 0)
 		return NULL;
 	previous = idx;
 	sequence = 0;
@@ -1452,7 +1452,7 @@ available_cores(void)
 
 		/* finish current sequence */
 		if (sequence) {
-			if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+			if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 				free(str);
 				return NULL;
 			}
@@ -1461,7 +1461,7 @@ available_cores(void)
 		}
 
 		/* new sequence */
-		if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
+		if (eal_asprintf(&tmp, "%s,%d", str, idx) < 0) {
 			free(str);
 			return NULL;
 		}
@@ -1473,7 +1473,7 @@ available_cores(void)
 
 	/* finish last sequence */
 	if (sequence) {
-		if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+		if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 			free(str);
 			return NULL;
 		}
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 24e27387b..d57bb8ecc 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype)
 	fixup = trace_metadata_fixup_field(in);
 	if (fixup != NULL)
 		in = fixup;
-	rc = asprintf(&field, "%s        %s %s;\n",
+	rc = eal_asprintf(&field, "%s        %s %s;\n",
 		RTE_PER_LCORE(ctf_field) != NULL ?
 			RTE_PER_LCORE(ctf_field) : "",
 		datatype, in);
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 4041d9af6..31df7262e 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)
 	for (i = 0; i < RTE_DIM(ctf_reserved_words); i++) {
 		if (strcmp(field, ctf_reserved_words[i]) != 0)
 			continue;
-		if (asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
+		if (eal_asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
 			out = NULL;
 		return out;
 	}
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 6b81fdeec..1773140ac 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)
 		return -ENAMETOOLONG;
 	}
 
-	if (asprintf(&dir_path, "%s/", val) == -1) {
+	if (eal_asprintf(&dir_path, "%s/", val) == -1) {
 		trace_err("failed to copy directory: %s", strerror(errno));
 		return -ENOMEM;
 	}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4684c4c7d..a5d9c5123 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * Allocate a buffer large enough to hold the formatted string
+ * and perform formatting, equivalent to Unix asprintf(3).
+ *
+ * @param buffer
+ *  Receives a pointer to allocated memory, call free(buffer) to deallocate.
+ * @param format
+ *  Format string.
+ * @return
+ *  Number of bytes allocated on success, (-1) on failure.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+#else
+#define eal_asprintf asprintf
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 1e5f6576f..47495b36a 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <stdarg.h>
+
 #include <fcntl.h>
 #include <io.h>
 #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
+/* Don't use MinGW asprintf() to have identical code with all toolchains. */
+int
+eal_asprintf(char **buffer, const char *format, ...)
+{
+	int size, ret;
+	va_list arg;
+
+	va_start(arg, format);
+	size = vsnprintf(NULL, 0, format, arg);
+	va_end(arg);
+	if (size < 0)
+		return -1;
+	size++;
+
+	*buffer = malloc(size);
+	if (*buffer == NULL)
+		return -1;
+
+	va_start(arg, format);
+	ret = vsnprintf(*buffer, size, format, arg);
+	va_end(arg);
+	if (ret != size - 1) {
+		free(*buffer);
+		return -1;
+	}
+	return ret;
+}
+
 int
 rte_vfio_container_dma_map(__rte_unused int container_fd,
 			__rte_unused uint64_t vaddr,
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                   ` (3 preceding siblings ...)
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 6/7] drivers: " Dmitry Kozlyuk
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Olivier Matz,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup()   with EAL rte_strdup().
Locally rename Windows _close() to standard close().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.c      |  1 +
 lib/librte_ethdev/rte_class_eth.c |  2 +-
 lib/librte_ethdev/rte_ethdev.c    |  2 +-
 lib/librte_kvargs/rte_kvargs.c    | 17 ++++++++++-------
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c..4dfa1178f 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -19,6 +19,7 @@
 #include "cmdline_private.h"
 
 #ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
 #define write _write
 #endif
 
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
index ca2ce87f7..9b72bdf15 100644
--- a/lib/librte_ethdev/rte_class_eth.c
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,
 		return -1; /* not a representor port */
 
 	/* Parse devargs representor values. */
-	values = strdup(value);
+	values = rte_strdup(value);
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388..a09fec2ce 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
 	struct rte_kvargs_pair *pair;
 	char *letter;
 
-	arglist->str = strdup(str_in);
+	arglist->str = rte_strdup(str_in);
 	if (arglist->str == NULL)
 		return -ENOMEM;
 
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86..fd1103b33 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
 	 */
-	kvlist->str = strdup(params);
+	kvlist->str = rte_strdup(params);
 	if (kvlist->str == NULL)
 		return -1;
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	while ((str = rte_strtok(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].key = rte_strtok(
+			str, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].value = rte_strtok(
+			NULL, RTE_KVARGS_KV_DELIM, &ctx2);
 		if (kvlist->pairs[i].key == NULL ||
 		    kvlist->pairs[i].value == NULL)
 			return -1;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 		if (str[0] == '[') {
 			/* Find the end of the list. */
 			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
+				/* Restore the comma erased by rte_strtok(). */
 				if (ctx1 == NULL || ctx1[0] == '\0')
 					return -1; /* no closing bracket */
 				str[strlen(str)] = ',';
 				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
+				str = rte_strtok(
+					NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
 				if (str == NULL)
 					return -1; /* no closing bracket */
 			}
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
 	if (valid_ends == NULL)
 		return rte_kvargs_parse(args, valid_keys);
 
-	copy = strdup(args);
+	copy = rte_strdup(args);
 	if (copy == NULL)
 		return NULL;
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 6/7] drivers: remove POSIX dependencies
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                   ` (4 preceding siblings ...)
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing, Jeff Guo

Replace POSIX strncasecmp() with EAL rte_strncasecmp().
Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
i40e: checkpatches.sh complains about long lines (it's ~85).
      I doubt that mechanical fix would keep the code readable.
      It's on 5th level of indentation, so I'd extract a function,
      but would like to hear from maintainers first.

 drivers/bus/pci/private.h             |  2 +-
 drivers/bus/vdev/vdev.c               |  4 +-
 drivers/bus/vdev/vdev_params.c        |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c |  4 +-
 drivers/net/i40e/i40e_ethdev.c        | 56 +++++++++++++--------------
 5 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5..5648916d1 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -92,7 +92,7 @@ struct mapped_pci_resource {
 	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 	struct pci_msix_table msix_table;
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 9a673347a..a490d26a2 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args)
 
 	devargs->bus = &rte_vdev_bus;
 	if (args)
-		devargs->args = strdup(args);
+		devargs->args = rte_strdup(args);
 	else
-		devargs->args = strdup("");
+		devargs->args = rte_strdup("");
 
 	ret = strlcpy(devargs->name, name, sizeof(devargs->name));
 	if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
index 6f74704d1..64848f4c2 100644
--- a/drivers/bus/vdev/vdev_params.c
+++ b/drivers/bus/vdev/vdev_params.c
@@ -8,6 +8,7 @@
 #include <rte_bus.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
+#include <rte_string_fns.h>
 
 #include "vdev_logs.h"
 #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,
 	char *name;
 
 	/* cannot pass const dev->name to rte_kvargs_process() */
-	name = strdup(dev->name);
+	name = rte_strdup(dev->name);
 	if (name == NULL)
 		return -1;
 	ret = rte_kvargs_process(kvlist,
diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index 2b657686d..37f4182e2 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -88,7 +88,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 		return *ret;
 	}
 	nstr_org = nstr;
-	found = strtok_r(nstr, ":", &refstr);
+	found = rte_strtok(nstr, ":", &refstr);
 	if (!found)
 		goto err;
 	do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 			goto err;
 		}
 		*ret |= class_val;
-		found = strtok_r(NULL, ":", &refstr);
+		found = rte_strtok(NULL, ":", &refstr);
 	} while (found);
 err:
 	free(nstr_org);
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7cd04989..5b806d201 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -12036,110 +12036,110 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
 				memset(name, 0, sizeof(name));
 				strcpy(name, proto[n].name);
 				PMD_DRV_LOG(INFO, "name = %s\n", name);
-				if (!strncasecmp(name, "PPPOE", 5))
+				if (!rte_strncasecmp(name, "PPPOE", 5))
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L2_ETHER_PPPOE;
-				else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV4", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV4", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV4", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV4", 4) &&
+				else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV6", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV6", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV6", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6", 4) &&
+				else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_UDP;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_UDP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_TCP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_TCP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_SCTP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_SCTP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_ICMP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_ICMP;
-				else if (!strncasecmp(name, "GTPC", 4)) {
+				else if (!rte_strncasecmp(name, "GTPC", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPC;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GTPU", 4)) {
+				} else if (!rte_strncasecmp(name, "GTPU", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPU;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "ESP", 3)) {
+				} else if (!rte_strncasecmp(name, "ESP", 3)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_ESP;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GRENAT", 6)) {
+				} else if (!rte_strncasecmp(name, "GRENAT", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GRENAT;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
-					   !strncasecmp(name, "L2TPV2", 6) ||
-					   !strncasecmp(name, "L2TPV3", 6)) {
+				} else if (!rte_strncasecmp(name, "L2TPV2CTL", 9) ||
+					   !rte_strncasecmp(name, "L2TPV2", 6) ||
+					   !rte_strncasecmp(name, "L2TPV3", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_L2TP;
 					in_tunnel = true;
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                   ` (5 preceding siblings ...)
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 6/7] drivers: " Dmitry Kozlyuk
@ 2021-02-20 23:29 ` Dmitry Kozlyuk
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-20 23:29 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Exposing POSIX symbols could break consumer POSIX compatibility code.

* Make renaming of close() and unlink() private to EAL.

* Remove renaming of strncasecmp(), strtok_r(), and sleep()
  in favor of using EAL wrappers. Similarly remove PATH_MAX macro.

* Replace index(3p), which is not available on Windows, with strchr(3),
  as recommended by POSIX.1-2008. strerror_r() is only used inside EAL,
  rename it only where it's needed. Same for asprintf(), it has an
  internal EAL wrapper and is removed from public API.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 doc/guides/rel_notes/release_21_05.rst     |  9 ++
 lib/librte_eal/common/eal_common_errno.c   |  4 +
 lib/librte_eal/common/eal_common_options.c |  2 +-
 lib/librte_eal/common/eal_private.h        |  5 ++
 lib/librte_eal/freebsd/include/rte_os.h    |  4 +-
 lib/librte_eal/linux/include/rte_os.h      |  4 +-
 lib/librte_eal/windows/include/rte_os.h    | 99 ++--------------------
 7 files changed, 29 insertions(+), 98 deletions(-)

diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index 5aa9ed7db..6380dfa53 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -84,6 +84,15 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols
+  has been incorrect and could conflict with consumer POSIX implementations.
+  Wrappers are provided for
+  ``strtok_r(3p)`` (``rte_strtok``),
+  ``strncasecmp(3p)`` (``rte_strncasecmp``),
+  ``sleep(3p)`` (``rte_thread_sleep``),
+  ``PATH_MAX`` (``RTE_PATH_MAX``).
+  Removed are ``strerror_r(3p)`` and ``asprintf(3p)``.
+
 
 ABI Changes
 -----------
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823..536eea0c3 100644
--- a/lib/librte_eal/common/eal_common_errno.c
+++ b/lib/librte_eal/common/eal_common_errno.c
@@ -15,6 +15,10 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define strerror_r(a, b, c) strerror_s(b, c, a)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 275f879d7..fd3b22e8a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1936,7 +1936,7 @@ eal_check_common_options(struct internal_config *internal_cfg)
 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
 		return -1;
 	}
-	if (index(eal_get_hugefile_prefix(), '%') != NULL) {
+	if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
 		RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
 			"option\n");
 		return -1;
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index a5d9c5123..860551661 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);
 #define eal_asprintf asprintf
 #endif
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
+#define unlink _unlink
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index b37d59b5e..a5bf10021 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * freebsd OS. Functions will be added in future releases.
+ * freebsd OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <pthread_np.h>
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index af7d052d9..04f510eec 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * linux OS. Functions will be added in future releases.
+ * linux OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <sched.h>
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index edca11bd2..9c9c31214 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -6,15 +6,11 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
- * which are not supported natively or named differently in the
- * Windows OS. It must not include Windows-specific headers.
+ * This header should contain any function/macro definition
+ * which are not supported natively or named differently in Windows OS.
  */
 
-#include <stdarg.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -22,101 +18,18 @@ extern "C" {
 
 #define RTE_PATH_MAX _MAX_PATH
 
-/* limits.h replacement, value as in <windows.h> */
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
-
-#ifndef sleep
-#define sleep(x) Sleep(1000 * (x))
-#endif
-
-#ifndef strerror_r
-#define strerror_r(a, b, c) strerror_s(b, c, a)
-#endif
-
-#ifndef strdup
-/* strdup is deprecated in Microsoft libc and _strdup is preferred */
-#define strdup(str) _strdup(str)
-#endif
-
-#ifndef strtok_r
-#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
-#endif
-
-#ifndef index
-#define index(a, b)     strchr(a, b)
-#endif
-
-#ifndef rindex
-#define rindex(a, b)    strrchr(a, b)
-#endif
-
-#ifndef strncasecmp
-#define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
-#endif
-
-#ifndef close
-#define close _close
-#endif
-
-#ifndef unlink
-#define unlink _unlink
-#endif
-
 /* cpu_set macros implementation */
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
 #define RTE_CPU_FILL(set) CPU_FILL(set)
 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
 
-/* as in <windows.h> */
+/* This is an exception without "rte_" prefix, because Windows does have
+ * ssize_t, but it's defined in <windows.h> which we avoid to expose.
+ * If ssize_t is defined in user code, it necessarily has the same type.
+ */
 typedef long long ssize_t;
 
-#ifndef RTE_TOOLCHAIN_GCC
-
-static inline int
-asprintf(char **buffer, const char *format, ...)
-{
-	int size, ret;
-	va_list arg;
-
-	va_start(arg, format);
-	size = vsnprintf(NULL, 0, format, arg);
-	va_end(arg);
-	if (size < 0)
-		return -1;
-	size++;
-
-	*buffer = (char *)malloc(size);
-	if (*buffer == NULL)
-		return -1;
-
-	va_start(arg, format);
-	ret = vsnprintf(*buffer, size, format, arg);
-	va_end(arg);
-	if (ret != size - 1) {
-		free(*buffer);
-		return -1;
-	}
-	return ret;
-}
-
-static inline const char *
-eal_strerror(int code)
-{
-	static char buffer[128];
-
-	strerror_s(buffer, sizeof(buffer), code);
-	return buffer;
-}
-
-#ifndef strerror
-#define strerror eal_strerror
-#endif
-
-#endif /* RTE_TOOLCHAIN_GCC */
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 0/7] eal/windows: do not expose POSIX symbols
  2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                   ` (6 preceding siblings ...)
  2021-02-20 23:29 ` [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-02-21  1:28 ` Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
                     ` (7 more replies)
  7 siblings, 8 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Windows, rte_os.h contains a small POSIX compatibility set of
functions and macros. Exposing it from EAL can break consumer own POSIX
compatibility layer and is against standards in general.

First define required wrappers, then fix POSIX dependencies in
Windows-enabled libraries and drivers, then eliminate POSIX symbols from
Windows EAL API. Commits are arranged so that they all compile and are
limited in scope; patches 5, 6, 7 can be squashed if needed.

No "Fixes" tags, because it's really an enhancement,
preventing issues rather then solving direct ones.

v2: fix compilation issues in 3/7 and 6/7.

Dmitry Kozlyuk (7):
  eal: add wrappers for POSIX string functions
  eal: add macro for maximum path length
  eal: add sleep API
  eal: add asprintf() internal wrapper
  lib: remove POSIX dependencies
  drivers: remove POSIX dependencies
  eal/windows: do not expose POSIX symbols

 doc/guides/rel_notes/release_21_05.rst        |  9 ++
 drivers/bus/pci/private.h                     |  2 +-
 drivers/bus/vdev/vdev.c                       |  4 +-
 drivers/bus/vdev/vdev_params.c                |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c         |  4 +-
 drivers/common/mlx5/mlx5_common_pci.h         |  1 +
 drivers/net/i40e/i40e_ethdev.c                | 56 +++++------
 lib/librte_cmdline/cmdline.c                  |  1 +
 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_dev.c        |  6 +-
 lib/librte_eal/common/eal_common_devargs.c    |  7 +-
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +-
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_log.c        |  5 +-
 lib/librte_eal/common/eal_common_options.c    | 42 ++++----
 lib/librte_eal/common/eal_common_timer.c      |  5 +-
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  4 +-
 .../common/eal_common_trace_utils.c           | 13 +--
 lib/librte_eal/common/eal_filesystem.h        |  8 +-
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_private.h           | 23 +++++
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  6 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 ++++++++
 lib/librte_eal/include/rte_thread.h           | 11 +++
 lib/librte_eal/linux/include/rte_os.h         |  6 +-
 lib/librte_eal/rte_eal_exports.def            |  2 +
 lib/librte_eal/unix/rte_thread.c              | 10 +-
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 30 ++++++
 lib/librte_eal/windows/eal_thread.c           |  9 +-
 lib/librte_eal/windows/include/dirent.h       | 21 ++--
 lib/librte_eal/windows/include/rte_os.h       | 99 ++-----------------
 lib/librte_ethdev/rte_class_eth.c             |  2 +-
 lib/librte_ethdev/rte_ethdev.c                |  2 +-
 lib/librte_kvargs/rte_kvargs.c                | 17 ++--
 39 files changed, 270 insertions(+), 207 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-22 11:47     ` Bruce Richardson
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Jerin Jacob,
	Sunil Kumar Kori

POSIX strncasecmp(), strdup(), and strtok_r() have different names
on Windows, respectively, strnicmp(), _strdup(), and strtok_s().

Add wrappers as inline functions, because they're used from librte_kvargs,
and thus cannot be in librte_eal; besides, implementation is trivial.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_dev.c        |  6 +--
 lib/librte_eal/common/eal_common_devargs.c    |  7 ++--
 lib/librte_eal/common/eal_common_log.c        |  5 ++-
 lib/librte_eal/common/eal_common_options.c    | 12 +++---
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 +++++++++++++++++++
 7 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 8a3bd3100..0a15fdcf7 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,
 			if (!device_name) {
 				event_cb->dev_name = NULL;
 			} else {
-				event_cb->dev_name = strdup(device_name);
+				event_cb->dev_name = rte_strdup(device_name);
 				if (event_cb->dev_name == NULL) {
 					ret = -ENOMEM;
 					goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str)
 
 	end = strcspn(str, ",/");
 	if (str[end] == ',') {
-		copy = strdup(&str[end + 1]);
+		copy = rte_strdup(&str[end + 1]);
 	} else {
 		/* '/' or '\0' */
-		copy = strdup("");
+		copy = rte_strdup("");
 	}
 	if (copy == NULL) {
 		rte_errno = ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index fcf3d9a3c..14e082a27 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -18,6 +18,7 @@
 #include <rte_errno.h>
 #include <rte_kvargs.h>
 #include <rte_log.h>
+#include <rte_string_fns.h>
 #include <rte_tailq.h>
 #include "eal_private.h"
 
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
 	 * anything and keep referring only to it.
 	 */
 	if (devargs->data != devstr) {
-		devargs->data = strdup(devstr);
+		devargs->data = rte_strdup(devstr);
 		if (devargs->data == NULL) {
 			RTE_LOG(ERR, EAL, "OOM\n");
 			ret = -ENOMEM;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 	da->bus = bus;
 	/* Parse eventual device arguments */
 	if (devname[i] == ',')
-		da->args = strdup(&devname[i + 1]);
+		da->args = rte_strdup(&devname[i + 1]);
 	else
-		da->args = strdup("");
+		da->args = rte_strdup("");
 	if (da->args == NULL) {
 		RTE_LOG(ERR, EAL, "not enough memory to parse arguments\n");
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb..557a8243f 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -14,6 +14,7 @@
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_per_lcore.h>
+#include <rte_string_fns.h>
 
 #include "eal_private.h"
 
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,
 		if (regcomp(&opt_ll->re_match, regex, 0) != 0)
 			goto fail;
 	} else if (pattern) {
-		opt_ll->pattern = strdup(pattern);
+		opt_ll->pattern = rte_strdup(pattern);
 		if (opt_ll->pattern == NULL)
 			goto fail;
 	} else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)
 static int
 __rte_log_register(const char *name, int id)
 {
-	char *dup_name = strdup(name);
+	char *dup_name = rte_strdup(name);
 
 	if (dup_name == NULL)
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc42..3612ad441 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (i = 0; i < argc; i++) {
-		eal_args[i] = strdup(argv[i]);
+		eal_args[i] = rte_strdup(argv[i]);
 		if (strcmp(argv[i], "--") == 0)
 			break;
 	}
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (j = 0; i < argc; j++, i++)
-		eal_app_args[j] = strdup(argv[i]);
+		eal_app_args[j] = rte_strdup(argv[i]);
 	eal_app_args[j] = NULL;
 
 	return 0;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
-	str = strdup(arg);
+	str = rte_strdup(arg);
 	if (str == NULL)
 		return -1;
 
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)
 static enum rte_proc_type_t
 eal_parse_proc_type(const char *arg)
 {
-	if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
+	if (rte_strncasecmp(arg, "primary", sizeof("primary")) == 0)
 		return RTE_PROC_PRIMARY;
-	if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
+	if (rte_strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
 		return RTE_PROC_SECONDARY;
-	if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
+	if (rte_strncasecmp(arg, "auto", sizeof("auto")) == 0)
 		return RTE_PROC_AUTO;
 
 	return RTE_PROC_INVALID;
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 33e419aac..4041d9af6 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)
 	if (strstr(field, ".") == NULL && strstr(field, "->") == NULL)
 		return NULL;
 
-	out = strdup(field);
+	out = rte_strdup(field);
 	if (out == NULL)
 		return NULL;
 	p = out;
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 64f58fb66..d541a5ea9 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)
 		return -ENOMEM;
 	}
 
-	arg->val = strdup(val);
+	arg->val = rte_strdup(val);
 	if (arg->val == NULL) {
 		trace_err("failed to allocate memory for %s", val);
 		free(arg);
diff --git a/lib/librte_eal/include/rte_string_fns.h b/lib/librte_eal/include/rte_string_fns.h
index 8bac8243c..2d9d5afc8 100644
--- a/lib/librte_eal/include/rte_string_fns.h
+++ b/lib/librte_eal/include/rte_string_fns.h
@@ -116,6 +116,48 @@ rte_strlcat(char *dst, const char *src, size_t size)
 ssize_t
 rte_strscpy(char *dst, const char *src, size_t dsize);
 
+/**
+ * @internal
+ * strncasecmp(3) replacement for systems that don't have it.
+ */
+static inline int
+rte_strncasecmp(const char *s1, const char *s2, size_t size)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strnicmp(s1, s2, size);
+#else
+	return strncasecmp(s1, s2, size);
+#endif
+}
+
+/**
+ * @internal
+ * strtor_r(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strtok(char *str, const char *delim, char **saveptr)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return strtok_s(str, delim, saveptr);
+#else
+	return strtok_r(str, delim, saveptr);
+#endif
+}
+
+/**
+ * @internal
+ * strdup(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strdup(const char *str)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strdup(str);
+#else
+	return strdup(str);
+#endif
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Dmitry Kozlyuk
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Anatoly Burakov,
	Jerin Jacob, Sunil Kumar Kori, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Path length limit is PATH_MAX on Unix and _MAX_PATH on Windows.
Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX
in "common" multiprocess code, because it's really Unix-specific.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +++----
 lib/librte_eal/common/eal_common_options.c    | 20 +++++++++---------
 .../common/eal_common_trace_utils.c           |  9 ++++----
 lib/librte_eal/common/eal_filesystem.h        |  8 +++----
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  2 ++
 lib/librte_eal/linux/include/rte_os.h         |  2 ++
 lib/librte_eal/windows/include/dirent.h       | 21 +++++++------------
 lib/librte_eal/windows/include/rte_os.h       |  2 ++
 12 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7..33e5a076a 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -18,7 +18,7 @@ static struct rte_config rte_config = {
 };
 
 /* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
+static char runtime_dir[RTE_PATH_MAX];
 
 /* internal configuration */
 static struct internal_config internal_config;
diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index d974f3dab..c21b8ec66 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)
 static int
 resize_and_map(int fd, void *addr, size_t len)
 {
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *map_addr;
 
 	if (eal_file_truncate(fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
 		unsigned int elt_sz)
 {
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	struct used_mask *msk;
 	struct mem_area *ma = NULL;
 	void *data = NULL;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr)
 {
 	struct mem_area *ma = NULL, *tmp = NULL;
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *data = NULL;
 	int fd = -1;
 
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)
 	struct mem_area *tmp = NULL;
 	size_t mmap_len;
 	int fd, ret;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3612ad441..bad389903 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);
 struct shared_driver {
 	TAILQ_ENTRY(shared_driver) next;
 
-	char    name[PATH_MAX];
+	char    name[RTE_PATH_MAX];
 	void*   lib_handle;
 };
 
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)
 		return -1;
 	}
 	memset(solib, 0, sizeof(*solib));
-	strlcpy(solib->name, path, PATH_MAX);
+	strlcpy(solib->name, path, RTE_PATH_MAX);
 	TAILQ_INSERT_TAIL(&solib_list, solib, next);
 
 	return 0;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path)
 {
 	DIR *d = NULL;
 	struct dirent *dent = NULL;
-	char sopath[PATH_MAX];
+	char sopath[RTE_PATH_MAX];
 
 	if (path == NULL || *path == '\0')
 		return 0;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)
 
 	/* if not root, check down one level first */
 	if (strcmp(dirpath, "/") != 0) {
-		static __thread char last_dir_checked[PATH_MAX];
-		char copy[PATH_MAX];
+		static __thread char last_dir_checked[RTE_PATH_MAX];
+		char copy[RTE_PATH_MAX];
 		const char *dir;
 
-		strlcpy(copy, dirpath, PATH_MAX);
+		strlcpy(copy, dirpath, RTE_PATH_MAX);
 		dir = dirname(copy);
-		if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
+		if (strncmp(dir, last_dir_checked, RTE_PATH_MAX) != 0) {
 			if (verify_perms(dir) != 0)
 				return -1;
-			strlcpy(last_dir_checked, dir, PATH_MAX);
+			strlcpy(last_dir_checked, dir, RTE_PATH_MAX);
 		}
 	}
 
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname)
 				pathname, strerror(errno));
 		goto out;
 	}
-	if (strnlen(realp, PATH_MAX) == PATH_MAX) {
-		RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
+	if (strnlen(realp, RTE_PATH_MAX) == RTE_PATH_MAX) {
+		RTE_LOG(ERR, EAL, "Error, driver path greater than RTE_PATH_MAX\n");
 		goto out;
 	}
 
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index d541a5ea9..6b81fdeec 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -369,11 +369,11 @@ trace_mkdir(void)
 static int
 trace_meta_save(struct trace *trace)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/metadata", trace->dir);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/metadata", trace->dir);
 	if (rc < 0)
 		return rc;
 
@@ -400,11 +400,12 @@ static int
 trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr,
 		uint32_t cnt)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/channel0_%d", trace->dir, cnt);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/channel0_%d",
+		trace->dir, cnt);
 	if (rc < 0)
 		return rc;
 
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 5d21f07c2..d28a9b23d 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);
 static inline const char *
 eal_runtime_config_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)
 static inline const char *
 eal_mp_socket_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
 static inline const char *
 eal_hugepage_info_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)
 static inline const char *
 eal_hugepage_data_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
diff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h
index 1b560d337..02b324ed1 100644
--- a/lib/librte_eal/common/eal_hugepages.h
+++ b/lib/librte_eal/common/eal_hugepages.h
@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <limits.h>
 
-#define MAX_HUGEPAGE_PATH PATH_MAX
+#define MAX_HUGEPAGE_PATH RTE_PATH_MAX
 
 /**
  * Structure used to store information about hugepages that we mapped
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2..c8ea3b8fc 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -27,7 +27,7 @@
  */
 struct hugepage_info {
 	uint64_t hugepage_sz;   /**< size of a huge page */
-	char hugedir[PATH_MAX];    /**< dir where hugetlbfs is mounted */
+	char hugedir[RTE_PATH_MAX];    /**< dir where hugetlbfs is mounted */
 	uint32_t num_pages[RTE_MAX_NUMA_NODES];
 	/**< number of hugepages of that size on each socket */
 	int lock_descriptor;    /**< file descriptor for hugepage dir */
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 06751eb23..ab915eb10 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -51,7 +51,7 @@ struct trace_arg {
 };
 
 struct trace {
-	char dir[PATH_MAX];
+	char dir[RTE_PATH_MAX];
 	int dir_offset;
 	int register_errno;
 	bool status;
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index eeb750cd8..b37d59b5e 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <pthread_np.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpuset_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) do \
 { \
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index 218d4fa86..af7d052d9 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <sched.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpu_set_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
diff --git a/lib/librte_eal/windows/include/dirent.h b/lib/librte_eal/windows/include/dirent.h
index 869a59837..3a9a694f4 100644
--- a/lib/librte_eal/windows/include/dirent.h
+++ b/lib/librte_eal/windows/include/dirent.h
@@ -28,11 +28,6 @@
 #include <sys/stat.h>
 #include <errno.h>
 
-/* Maximum length of file name */
-#if !defined(PATH_MAX)
-#   define PATH_MAX MAX_PATH
-#endif
-
 /* File type flags for d_type */
 #define DT_UNKNOWN 0
 #define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {
 	int d_type;
 
 	/* File name */
-	wchar_t d_name[PATH_MAX];
+	wchar_t d_name[RTE_PATH_MAX];
 };
 typedef struct _wdirent _wdirent;
 
@@ -113,7 +108,7 @@ struct dirent {
 	int d_type;
 
 	/* File name */
-	char d_name[PATH_MAX];
+	char d_name[RTE_PATH_MAX];
 };
 typedef struct dirent dirent;
 
@@ -388,12 +383,12 @@ opendir(const char *dirname)
 	/* Allocate memory for DIR structure */
 	dirp = (DIR *)malloc(sizeof(struct DIR));
 	if (dirp) {
-		wchar_t wname[PATH_MAX];
+		wchar_t wname[RTE_PATH_MAX];
 		size_t n;
 
 		/* Convert directory name to wide-character string */
-		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
-			dirname, PATH_MAX);
+		error = dirent_mbstowcs_s(&n, wname, RTE_PATH_MAX,
+			dirname, RTE_PATH_MAX);
 		if (!error) {
 
 			/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)
 
 		/* Attempt to convert file name to multi-byte string */
 		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
-			PATH_MAX, datap->cFileName, PATH_MAX);
+			RTE_PATH_MAX, datap->cFileName, RTE_PATH_MAX);
 
 		/*
 		 * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)
 		 */
 		if (error  &&  datap->cAlternateFileName[0] != '\0') {
 			error = dirent_wcstombs_s(
-				&n, dirp->ent.d_name, PATH_MAX,
-				datap->cAlternateFileName, PATH_MAX);
+				&n, dirp->ent.d_name, RTE_PATH_MAX,
+				datap->cAlternateFileName, RTE_PATH_MAX);
 		}
 
 		if (!error) {
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06..edca11bd2 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -20,6 +20,8 @@
 extern "C" {
 #endif
 
+#define RTE_PATH_MAX _MAX_PATH
+
 /* limits.h replacement, value as in <windows.h> */
 #ifndef PATH_MAX
 #define PATH_MAX _MAX_PATH
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 3/7] eal: add sleep API
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  8:58     ` Tal Shnaiderman
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Ray Kinsella, Neil Horman

POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_timer.c |  5 +++--
 lib/librte_eal/include/rte_thread.h      | 11 +++++++++++
 lib/librte_eal/rte_eal_exports.def       |  2 ++
 lib/librte_eal/unix/rte_thread.c         | 10 +++++++++-
 lib/librte_eal/version.map               |  3 +++
 lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
 6 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035..0e89a4f7d 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -16,6 +16,7 @@
 #include <rte_cycles.h>
 #include <rte_pause.h>
 #include <rte_eal.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
 #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)
 #define CYC_PER_10MHZ 1E7
 	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
 		" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
+	/* assume that the rte_thread_sleep(1) will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_thread_sleep(1);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h
index e640ea185..f0c12dd79 100644
--- a/lib/librte_eal/include/rte_thread.h
+++ b/lib/librte_eal/include/rte_thread.h
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);
 __rte_experimental
 void *rte_thread_tls_value_get(rte_tls_key key);
 
+/**
+ * Suspend current OS thread for the specified time, yielding CPU to scheduler.
+ *
+ * @param sec
+ *  Number of seconds to sleep. The system may return control later,
+ *  but not earlier. Zero value always yields the CPU, but control may be
+ *  returned immediately.
+ */
+__rte_experimental
+void rte_thread_sleep(unsigned int sec);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index 474cf123f..494240b94 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -334,3 +334,5 @@ EXPORTS
 	rte_mem_map
 	rte_mem_page_size
 	rte_mem_unmap
+
+	rte_thread_sleep
diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c
index 86ffeebc9..91babfe88 100644
--- a/lib/librte_eal/unix/rte_thread.c
+++ b/lib/librte_eal/unix/rte_thread.c
@@ -3,10 +3,12 @@
  */
 
 #include <errno.h>
-#include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <pthread.h>
+#include <unistd.h>
+
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key)
 	}
 	return pthread_getspecific(key->thread_index);
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	sleep(sec);
+}
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112..106864469 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+    # added in 21.05
+	rte_thread_sleep;
 };
 
 INTERNAL {
diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c
index 908e726d1..957792301 100644
--- a/lib/librte_eal/windows/eal_thread.c
+++ b/lib/librte_eal/windows/eal_thread.c
@@ -11,9 +11,10 @@
 #include <rte_per_lcore.h>
 #include <rte_common.h>
 #include <rte_memory.h>
-#include <eal_thread.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
+#include "eal_thread.h"
 #include "eal_windows.h"
 
 /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
 	/* This is a stub, not the expected result */
 	return 0;
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	return Sleep(MS_PER_S * sec);
+}
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
                     ` (2 preceding siblings ...)
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Jerin Jacob,
	Sunil Kumar Kori, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

POSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_options.c    |  8 ++---
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/common/eal_private.h           | 18 +++++++++++
 lib/librte_eal/windows/eal.c                  | 30 +++++++++++++++++++
 7 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
index 66d6bad1a..db16a34cc 100644
--- a/lib/librte_eal/common/eal_common_lcore.c
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	callback = calloc(1, sizeof(*callback));
 	if (callback == NULL)
 		return NULL;
-	if (asprintf(&callback->name, "%s-%p", name, arg) == -1) {
+	if (eal_asprintf(&callback->name, "%s-%p", name, arg) == -1) {
 		free(callback);
 		return NULL;
 	}
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index bad389903..275f879d7 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1435,7 +1435,7 @@ available_cores(void)
 		return NULL;
 
 	/* first sequence */
-	if (asprintf(&str, "%d", idx) < 0)
+	if (eal_asprintf(&str, "%d", idx) < 0)
 		return NULL;
 	previous = idx;
 	sequence = 0;
@@ -1452,7 +1452,7 @@ available_cores(void)
 
 		/* finish current sequence */
 		if (sequence) {
-			if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+			if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 				free(str);
 				return NULL;
 			}
@@ -1461,7 +1461,7 @@ available_cores(void)
 		}
 
 		/* new sequence */
-		if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
+		if (eal_asprintf(&tmp, "%s,%d", str, idx) < 0) {
 			free(str);
 			return NULL;
 		}
@@ -1473,7 +1473,7 @@ available_cores(void)
 
 	/* finish last sequence */
 	if (sequence) {
-		if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+		if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 			free(str);
 			return NULL;
 		}
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 24e27387b..d57bb8ecc 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype)
 	fixup = trace_metadata_fixup_field(in);
 	if (fixup != NULL)
 		in = fixup;
-	rc = asprintf(&field, "%s        %s %s;\n",
+	rc = eal_asprintf(&field, "%s        %s %s;\n",
 		RTE_PER_LCORE(ctf_field) != NULL ?
 			RTE_PER_LCORE(ctf_field) : "",
 		datatype, in);
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 4041d9af6..31df7262e 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)
 	for (i = 0; i < RTE_DIM(ctf_reserved_words); i++) {
 		if (strcmp(field, ctf_reserved_words[i]) != 0)
 			continue;
-		if (asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
+		if (eal_asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
 			out = NULL;
 		return out;
 	}
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 6b81fdeec..1773140ac 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)
 		return -ENAMETOOLONG;
 	}
 
-	if (asprintf(&dir_path, "%s/", val) == -1) {
+	if (eal_asprintf(&dir_path, "%s/", val) == -1) {
 		trace_err("failed to copy directory: %s", strerror(errno));
 		return -ENOMEM;
 	}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4684c4c7d..a5d9c5123 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * Allocate a buffer large enough to hold the formatted string
+ * and perform formatting, equivalent to Unix asprintf(3).
+ *
+ * @param buffer
+ *  Receives a pointer to allocated memory, call free(buffer) to deallocate.
+ * @param format
+ *  Format string.
+ * @return
+ *  Number of bytes allocated on success, (-1) on failure.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+#else
+#define eal_asprintf asprintf
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 1e5f6576f..47495b36a 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <stdarg.h>
+
 #include <fcntl.h>
 #include <io.h>
 #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
+/* Don't use MinGW asprintf() to have identical code with all toolchains. */
+int
+eal_asprintf(char **buffer, const char *format, ...)
+{
+	int size, ret;
+	va_list arg;
+
+	va_start(arg, format);
+	size = vsnprintf(NULL, 0, format, arg);
+	va_end(arg);
+	if (size < 0)
+		return -1;
+	size++;
+
+	*buffer = malloc(size);
+	if (*buffer == NULL)
+		return -1;
+
+	va_start(arg, format);
+	ret = vsnprintf(*buffer, size, format, arg);
+	va_end(arg);
+	if (ret != size - 1) {
+		free(*buffer);
+		return -1;
+	}
+	return ret;
+}
+
 int
 rte_vfio_container_dma_map(__rte_unused int container_fd,
 			__rte_unused uint64_t vaddr,
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
                     ` (3 preceding siblings ...)
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Olivier Matz,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup()   with EAL rte_strdup().
Locally rename Windows _close() to standard close().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.c      |  1 +
 lib/librte_ethdev/rte_class_eth.c |  2 +-
 lib/librte_ethdev/rte_ethdev.c    |  2 +-
 lib/librte_kvargs/rte_kvargs.c    | 17 ++++++++++-------
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c..4dfa1178f 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -19,6 +19,7 @@
 #include "cmdline_private.h"
 
 #ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
 #define write _write
 #endif
 
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
index ca2ce87f7..9b72bdf15 100644
--- a/lib/librte_ethdev/rte_class_eth.c
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,
 		return -1; /* not a representor port */
 
 	/* Parse devargs representor values. */
-	values = strdup(value);
+	values = rte_strdup(value);
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388..a09fec2ce 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
 	struct rte_kvargs_pair *pair;
 	char *letter;
 
-	arglist->str = strdup(str_in);
+	arglist->str = rte_strdup(str_in);
 	if (arglist->str == NULL)
 		return -ENOMEM;
 
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86..fd1103b33 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
 	 */
-	kvlist->str = strdup(params);
+	kvlist->str = rte_strdup(params);
 	if (kvlist->str == NULL)
 		return -1;
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	while ((str = rte_strtok(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].key = rte_strtok(
+			str, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].value = rte_strtok(
+			NULL, RTE_KVARGS_KV_DELIM, &ctx2);
 		if (kvlist->pairs[i].key == NULL ||
 		    kvlist->pairs[i].value == NULL)
 			return -1;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 		if (str[0] == '[') {
 			/* Find the end of the list. */
 			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
+				/* Restore the comma erased by rte_strtok(). */
 				if (ctx1 == NULL || ctx1[0] == '\0')
 					return -1; /* no closing bracket */
 				str[strlen(str)] = ',';
 				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
+				str = rte_strtok(
+					NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
 				if (str == NULL)
 					return -1; /* no closing bracket */
 			}
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
 	if (valid_ends == NULL)
 		return rte_kvargs_parse(args, valid_keys);
 
-	copy = strdup(args);
+	copy = rte_strdup(args);
 	if (copy == NULL)
 		return NULL;
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
                     ` (4 preceding siblings ...)
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  8:59     ` Tal Shnaiderman
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing, Jeff Guo

Replace POSIX strncasecmp() with EAL rte_strncasecmp().
Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
i40e: checkpatches.sh complains about long lines (it's ~85).
      I doubt that mechanical fix would keep the code readable.
      It's on 5th level of indentation, so I'd extract a function,
      but would like to hear from maintainers first.

 drivers/bus/pci/private.h             |  2 +-
 drivers/bus/vdev/vdev.c               |  4 +-
 drivers/bus/vdev/vdev_params.c        |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c |  4 +-
 drivers/common/mlx5/mlx5_common_pci.h |  1 +
 drivers/net/i40e/i40e_ethdev.c        | 56 +++++++++++++--------------
 6 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5..5648916d1 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -92,7 +92,7 @@ struct mapped_pci_resource {
 	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 	struct pci_msix_table msix_table;
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 9a673347a..a490d26a2 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args)
 
 	devargs->bus = &rte_vdev_bus;
 	if (args)
-		devargs->args = strdup(args);
+		devargs->args = rte_strdup(args);
 	else
-		devargs->args = strdup("");
+		devargs->args = rte_strdup("");
 
 	ret = strlcpy(devargs->name, name, sizeof(devargs->name));
 	if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
index 6f74704d1..64848f4c2 100644
--- a/drivers/bus/vdev/vdev_params.c
+++ b/drivers/bus/vdev/vdev_params.c
@@ -8,6 +8,7 @@
 #include <rte_bus.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
+#include <rte_string_fns.h>
 
 #include "vdev_logs.h"
 #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,
 	char *name;
 
 	/* cannot pass const dev->name to rte_kvargs_process() */
-	name = strdup(dev->name);
+	name = rte_strdup(dev->name);
 	if (name == NULL)
 		return -1;
 	ret = rte_kvargs_process(kvlist,
diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index 2b657686d..37f4182e2 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -88,7 +88,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 		return *ret;
 	}
 	nstr_org = nstr;
-	found = strtok_r(nstr, ":", &refstr);
+	found = rte_strtok(nstr, ":", &refstr);
 	if (!found)
 		goto err;
 	do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 			goto err;
 		}
 		*ret |= class_val;
-		found = strtok_r(NULL, ":", &refstr);
+		found = rte_strtok(NULL, ":", &refstr);
 	} while (found);
 err:
 	free(nstr_org);
diff --git a/drivers/common/mlx5/mlx5_common_pci.h b/drivers/common/mlx5/mlx5_common_pci.h
index de89bb98b..729d0f4cc 100644
--- a/drivers/common/mlx5/mlx5_common_pci.h
+++ b/drivers/common/mlx5/mlx5_common_pci.h
@@ -45,6 +45,7 @@ extern "C" {
 
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
+#include <rte_string_fns.h>
 
 #include <mlx5_common.h>
 
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7cd04989..5b806d201 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -12036,110 +12036,110 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
 				memset(name, 0, sizeof(name));
 				strcpy(name, proto[n].name);
 				PMD_DRV_LOG(INFO, "name = %s\n", name);
-				if (!strncasecmp(name, "PPPOE", 5))
+				if (!rte_strncasecmp(name, "PPPOE", 5))
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L2_ETHER_PPPOE;
-				else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV4", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV4", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV4", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV4", 4) &&
+				else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV6", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV6", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV6", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6", 4) &&
+				else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_UDP;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_UDP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_TCP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_TCP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_SCTP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_SCTP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_ICMP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_ICMP;
-				else if (!strncasecmp(name, "GTPC", 4)) {
+				else if (!rte_strncasecmp(name, "GTPC", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPC;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GTPU", 4)) {
+				} else if (!rte_strncasecmp(name, "GTPU", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPU;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "ESP", 3)) {
+				} else if (!rte_strncasecmp(name, "ESP", 3)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_ESP;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GRENAT", 6)) {
+				} else if (!rte_strncasecmp(name, "GRENAT", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GRENAT;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
-					   !strncasecmp(name, "L2TPV2", 6) ||
-					   !strncasecmp(name, "L2TPV3", 6)) {
+				} else if (!rte_strncasecmp(name, "L2TPV2CTL", 9) ||
+					   !rte_strncasecmp(name, "L2TPV2", 6) ||
+					   !rte_strncasecmp(name, "L2TPV3", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_L2TP;
 					in_tunnel = true;
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
                     ` (5 preceding siblings ...)
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk
@ 2021-02-21  1:28   ` Dmitry Kozlyuk
  2021-02-21  8:59     ` Tal Shnaiderman
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21  1:28 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Nick Connolly, Dmitry Kozlyuk, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Exposing POSIX symbols could break consumer POSIX compatibility code.

* Make renaming of close() and unlink() private to EAL.

* Remove renaming of strncasecmp(), strtok_r(), and sleep()
  in favor of using EAL wrappers. Similarly remove PATH_MAX macro.

* Replace index(3p), which is not available on Windows, with strchr(3),
  as recommended by POSIX.1-2008. strerror_r() is only used inside EAL,
  rename it only where it's needed. Same for asprintf(), it has an
  internal EAL wrapper and is removed from public API.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 doc/guides/rel_notes/release_21_05.rst     |  9 ++
 lib/librte_eal/common/eal_common_errno.c   |  4 +
 lib/librte_eal/common/eal_common_options.c |  2 +-
 lib/librte_eal/common/eal_private.h        |  5 ++
 lib/librte_eal/freebsd/include/rte_os.h    |  4 +-
 lib/librte_eal/linux/include/rte_os.h      |  4 +-
 lib/librte_eal/windows/include/rte_os.h    | 99 ++--------------------
 7 files changed, 29 insertions(+), 98 deletions(-)

diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index 5aa9ed7db..6380dfa53 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -84,6 +84,15 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols
+  has been incorrect and could conflict with consumer POSIX implementations.
+  Wrappers are provided for
+  ``strtok_r(3p)`` (``rte_strtok``),
+  ``strncasecmp(3p)`` (``rte_strncasecmp``),
+  ``sleep(3p)`` (``rte_thread_sleep``),
+  ``PATH_MAX`` (``RTE_PATH_MAX``).
+  Removed are ``strerror_r(3p)`` and ``asprintf(3p)``.
+
 
 ABI Changes
 -----------
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823..536eea0c3 100644
--- a/lib/librte_eal/common/eal_common_errno.c
+++ b/lib/librte_eal/common/eal_common_errno.c
@@ -15,6 +15,10 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define strerror_r(a, b, c) strerror_s(b, c, a)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 275f879d7..fd3b22e8a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1936,7 +1936,7 @@ eal_check_common_options(struct internal_config *internal_cfg)
 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
 		return -1;
 	}
-	if (index(eal_get_hugefile_prefix(), '%') != NULL) {
+	if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
 		RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
 			"option\n");
 		return -1;
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index a5d9c5123..860551661 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);
 #define eal_asprintf asprintf
 #endif
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
+#define unlink _unlink
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index b37d59b5e..a5bf10021 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * freebsd OS. Functions will be added in future releases.
+ * freebsd OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <pthread_np.h>
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index af7d052d9..04f510eec 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * linux OS. Functions will be added in future releases.
+ * linux OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <sched.h>
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index edca11bd2..9c9c31214 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -6,15 +6,11 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
- * which are not supported natively or named differently in the
- * Windows OS. It must not include Windows-specific headers.
+ * This header should contain any function/macro definition
+ * which are not supported natively or named differently in Windows OS.
  */
 
-#include <stdarg.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -22,101 +18,18 @@ extern "C" {
 
 #define RTE_PATH_MAX _MAX_PATH
 
-/* limits.h replacement, value as in <windows.h> */
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
-
-#ifndef sleep
-#define sleep(x) Sleep(1000 * (x))
-#endif
-
-#ifndef strerror_r
-#define strerror_r(a, b, c) strerror_s(b, c, a)
-#endif
-
-#ifndef strdup
-/* strdup is deprecated in Microsoft libc and _strdup is preferred */
-#define strdup(str) _strdup(str)
-#endif
-
-#ifndef strtok_r
-#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
-#endif
-
-#ifndef index
-#define index(a, b)     strchr(a, b)
-#endif
-
-#ifndef rindex
-#define rindex(a, b)    strrchr(a, b)
-#endif
-
-#ifndef strncasecmp
-#define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
-#endif
-
-#ifndef close
-#define close _close
-#endif
-
-#ifndef unlink
-#define unlink _unlink
-#endif
-
 /* cpu_set macros implementation */
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
 #define RTE_CPU_FILL(set) CPU_FILL(set)
 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
 
-/* as in <windows.h> */
+/* This is an exception without "rte_" prefix, because Windows does have
+ * ssize_t, but it's defined in <windows.h> which we avoid to expose.
+ * If ssize_t is defined in user code, it necessarily has the same type.
+ */
 typedef long long ssize_t;
 
-#ifndef RTE_TOOLCHAIN_GCC
-
-static inline int
-asprintf(char **buffer, const char *format, ...)
-{
-	int size, ret;
-	va_list arg;
-
-	va_start(arg, format);
-	size = vsnprintf(NULL, 0, format, arg);
-	va_end(arg);
-	if (size < 0)
-		return -1;
-	size++;
-
-	*buffer = (char *)malloc(size);
-	if (*buffer == NULL)
-		return -1;
-
-	va_start(arg, format);
-	ret = vsnprintf(*buffer, size, format, arg);
-	va_end(arg);
-	if (ret != size - 1) {
-		free(*buffer);
-		return -1;
-	}
-	return ret;
-}
-
-static inline const char *
-eal_strerror(int code)
-{
-	static char buffer[128];
-
-	strerror_s(buffer, sizeof(buffer), code);
-	return buffer;
-}
-
-#ifndef strerror
-#define strerror eal_strerror
-#endif
-
-#endif /* RTE_TOOLCHAIN_GCC */
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/7] eal: add sleep API
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Dmitry Kozlyuk
@ 2021-02-21  8:58     ` Tal Shnaiderman
  0 siblings, 0 replies; 56+ messages in thread
From: Tal Shnaiderman @ 2021-02-21  8:58 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Nick Connolly, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Ray Kinsella, Neil Horman

> Subject: [dpdk-dev] [PATCH v2 3/7] eal: add sleep API
> 
> External email: Use caution opening links or attachments
> 
> 
> POSIX sleep(3) is missing from Windows.
> Add generic rte_thread_sleep() to suspend current OS thread.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  lib/librte_eal/common/eal_common_timer.c |  5 +++--
>  lib/librte_eal/include/rte_thread.h      | 11 +++++++++++
>  lib/librte_eal/rte_eal_exports.def       |  2 ++
>  lib/librte_eal/unix/rte_thread.c         | 10 +++++++++-
>  lib/librte_eal/version.map               |  3 +++
>  lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
>  6 files changed, 36 insertions(+), 4 deletions(-)
> 

[snip]

> diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map index
> fce90a112..106864469 100644
> --- a/lib/librte_eal/version.map
> +++ b/lib/librte_eal/version.map
> @@ -412,6 +412,9 @@ EXPERIMENTAL {
>         rte_thread_tls_key_delete;
>         rte_thread_tls_value_get;
>         rte_thread_tls_value_set;
> +
> +    # added in 21.05

Spaces, should be tab.

> +       rte_thread_sleep;
>  };
> 
>  INTERNAL {
> diff --git a/lib/librte_eal/windows/eal_thread.c
> b/lib/librte_eal/windows/eal_thread.c
> index 908e726d1..957792301 100644
> --- a/lib/librte_eal/windows/eal_thread.c
> +++ b/lib/librte_eal/windows/eal_thread.c
> @@ -11,9 +11,10 @@
>  #include <rte_per_lcore.h>
>  #include <rte_common.h>
>  #include <rte_memory.h>
> -#include <eal_thread.h>
> +#include <rte_thread.h>
> 
>  #include "eal_private.h"
> +#include "eal_thread.h"
>  #include "eal_windows.h"
> 
>  /*
> @@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id,
> __rte_unused const char *name)
>         /* This is a stub, not the expected result */
>         return 0;
>  }
> +
> +void
> +rte_thread_sleep(unsigned int sec)
> +{
> +       return Sleep(MS_PER_S * sec);
> +}
> --
> 2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk
@ 2021-02-21  8:59     ` Tal Shnaiderman
  2021-02-21 15:54       ` Andrew Rybchenko
  0 siblings, 1 reply; 56+ messages in thread
From: Tal Shnaiderman @ 2021-02-21  8:59 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Nick Connolly, Matan Azrad, Shahaf Shuler,
	Slava Ovsiienko, Beilei Xing, Jeff Guo

> Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
> 
> External email: Use caution opening links or attachments
> 
> 
> Replace POSIX strncasecmp() with EAL rte_strncasecmp().
> Replace POSIX strtok_r() with EAL rte_strtok().
> Replace POSIX strdup() with EAL rte_strdup().
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
> i40e: checkpatches.sh complains about long lines (it's ~85).
>       I doubt that mechanical fix would keep the code readable.
>       It's on 5th level of indentation, so I'd extract a function,
>       but would like to hear from maintainers first.
> 
>  drivers/bus/pci/private.h             |  2 +-
>  drivers/bus/vdev/vdev.c               |  4 +-
>  drivers/bus/vdev/vdev_params.c        |  3 +-
>  drivers/common/mlx5/mlx5_common_pci.c |  4 +-

bus_cmdline_options_handler in mlx5_common_pci.c has a call to strdup which needs to be renamed to rte_strdup
(Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-02-21  8:59     ` Tal Shnaiderman
  2021-02-21 10:24       ` Dmitry Kozlyuk
  0 siblings, 1 reply; 56+ messages in thread
From: Tal Shnaiderman @ 2021-02-21  8:59 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Nick Connolly, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

> Subject: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX
> symbols
> 
> External email: Use caution opening links or attachments
> 
> 
> Exposing POSIX symbols could break consumer POSIX compatibility code.
> 
> * Make renaming of close() and unlink() private to EAL.
> 
> * Remove renaming of strncasecmp(), strtok_r(), and sleep()
>   in favor of using EAL wrappers. Similarly remove PATH_MAX macro.
> 
> * Replace index(3p), which is not available on Windows, with strchr(3),
>   as recommended by POSIX.1-2008. strerror_r() is only used inside EAL,
>   rename it only where it's needed. Same for asprintf(), it has an
>   internal EAL wrapper and is removed from public API.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

[snip]

> diff --git a/lib/librte_eal/windows/include/rte_os.h
> b/lib/librte_eal/windows/include/rte_os.h
> index edca11bd2..9c9c31214 100644
> --- a/lib/librte_eal/windows/include/rte_os.h
> +++ b/lib/librte_eal/windows/include/rte_os.h
> @@ -6,15 +6,11 @@
>  #define _RTE_OS_H_
> 
>  /**
> - * This is header should contain any function/macro definition
> - * which are not supported natively or named differently in the
> - * Windows OS. It must not include Windows-specific headers.
> + * This header should contain any function/macro definition
> + * which are not supported natively or named differently in Windows OS.
>   */
> 
> -#include <stdarg.h>
> -#include <stdio.h>
>  #include <stdlib.h>
> -#include <string.h>
> 
>  #ifdef __cplusplus
>  extern "C" {
> @@ -22,101 +18,18 @@ extern "C" {
> 
>  #define RTE_PATH_MAX _MAX_PATH
> 
> -/* limits.h replacement, value as in <windows.h> */ -#ifndef PATH_MAX -
> #define PATH_MAX _MAX_PATH -#endif
> -
> -#ifndef sleep
> -#define sleep(x) Sleep(1000 * (x))
> -#endif
> -
> -#ifndef strerror_r
> -#define strerror_r(a, b, c) strerror_s(b, c, a) -#endif
> -
> -#ifndef strdup
> -/* strdup is deprecated in Microsoft libc and _strdup is preferred */ -
> #define strdup(str) _strdup(str) -#endif
> -
> -#ifndef strtok_r
> -#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr) -#endif
> -
> -#ifndef index
> -#define index(a, b)     strchr(a, b)
> -#endif
> -
> -#ifndef rindex
> -#define rindex(a, b)    strrchr(a, b)
> -#endif
> -
> -#ifndef strncasecmp
> -#define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
> -#endif
> -
> -#ifndef close
> -#define close _close
> -#endif

mlx5 uses close() in mlx5.c and is broken after this change above, BTW why not add an rte_close instead of local definition?

> -
> -#ifndef unlink
> -#define unlink _unlink
> -#endif
> -

[snip]

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21  8:59     ` Tal Shnaiderman
@ 2021-02-21 10:24       ` Dmitry Kozlyuk
  2021-02-21 11:58         ` Tal Shnaiderman
  0 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 10:24 UTC (permalink / raw)
  To: Tal Shnaiderman
  Cc: dev, Tyler Retzlaff, Nick Connolly, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Sun, 21 Feb 2021 08:59:50 +0000, Tal Shnaiderman wrote:
[...]
> > -#ifndef close
> > -#define close _close
> > -#endif  
> 
> mlx5 uses close() in mlx5.c and is broken after this change above, BTW why not add an rte_close instead of local definition?

I'm reluctant to add file manipulation API to EAL. It would be replication of
POSIX with "rte_" prefix, while standard C has everything needed to deal with
files (and IOCTLs are platform-specific code anyway). I think libraries and
PMDs striving to be cross-platform should move to using FILE* some day. For
now, local definitions keep them running without any risk of breakage.

Thanks for all your comments, it's weird I didn't hit the failures locally.
Will fix in v3.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21 10:24       ` Dmitry Kozlyuk
@ 2021-02-21 11:58         ` Tal Shnaiderman
  2021-02-21 14:33           ` Dmitry Kozlyuk
  0 siblings, 1 reply; 56+ messages in thread
From: Tal Shnaiderman @ 2021-02-21 11:58 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Nick Connolly, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

> Subject: Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX
> symbols
> 
> External email: Use caution opening links or attachments
> 
> 
> On Sun, 21 Feb 2021 08:59:50 +0000, Tal Shnaiderman wrote:
> [...]
> > > -#ifndef close
> > > -#define close _close
> > > -#endif
> >
> > mlx5 uses close() in mlx5.c and is broken after this change above, BTW why
> not add an rte_close instead of local definition?
> 
> I'm reluctant to add file manipulation API to EAL. It would be replication of
> POSIX with "rte_" prefix, while standard C has everything needed to deal
> with files (and IOCTLs are platform-specific code anyway). I think libraries and
> PMDs striving to be cross-platform should move to using FILE* some day. For
> now, local definitions keep them running without any risk of breakage.
> 
> Thanks for all your comments, it's weird I didn't hit the failures locally.
> Will fix in v3.

You might be missing the DevX SDK installation, without it meson will skip the mlx5 build.

You can get it either by installation WIOF2 2.60 [1] or get only the SDK from [2] (I attached it to the Bugzilla ticket when asked the UNH team to add mlx5 compilation to CI.

[1] - https://www.mellanox.com/products/adapter-software/ethernet/windows/winof-2
[2] - https://bugs.dpdk.org/show_bug.cgi?id=620
 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 0/7] eal/windows: do not expose POSIX symbols
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
                     ` (6 preceding siblings ...)
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-02-21 14:28   ` Dmitry Kozlyuk
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
                       ` (7 more replies)
  7 siblings, 8 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Tyler Retzlaff, Nick Connolly

On Windows, rte_os.h contains a small POSIX compatibility set of
functions and macros. Exposing it from EAL can break consumer own POSIX
compatibility layer and is against standards in general.

First define required wrappers, then fix POSIX dependencies in
Windows-enabled libraries and drivers, then eliminate POSIX symbols from
Windows EAL API. Commits are arranged so that they all compile and are
limited in scope; patches 5, 6, 7 can be squashed if needed.

No "Fixes" tags, because it's really an enhancement,
preventing issues rather then solving direct ones.

v3:
    * Fix indentation in 3/7 (Tal Shnaiderman).
    * Fix build failures in 6/7 and 7/7 (Tal Shnaiderman).
v2:
    * Fix compilation issues in 3/7 and 6/7 (self).

Dmitry Kozlyuk (7):
  eal: add wrappers for POSIX string functions
  eal: add macro for maximum path length
  eal: add sleep API
  eal: add asprintf() internal wrapper
  lib: remove POSIX dependencies
  drivers: remove POSIX dependencies
  eal/windows: do not expose POSIX symbols

 doc/guides/rel_notes/release_21_05.rst        |  9 ++
 drivers/bus/pci/private.h                     |  2 +-
 drivers/bus/vdev/vdev.c                       |  4 +-
 drivers/bus/vdev/vdev_params.c                |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c         |  6 +-
 drivers/common/mlx5/mlx5_common_pci.h         |  1 +
 drivers/net/i40e/i40e_ethdev.c                | 56 +++++------
 drivers/net/mlx5/mlx5.c                       |  4 +
 lib/librte_cmdline/cmdline.c                  |  1 +
 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_dev.c        |  6 +-
 lib/librte_eal/common/eal_common_devargs.c    |  7 +-
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +-
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_log.c        |  5 +-
 lib/librte_eal/common/eal_common_options.c    | 42 ++++----
 lib/librte_eal/common/eal_common_timer.c      |  5 +-
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  4 +-
 .../common/eal_common_trace_utils.c           | 13 +--
 lib/librte_eal/common/eal_filesystem.h        |  8 +-
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_private.h           | 23 +++++
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  6 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 ++++++++
 lib/librte_eal/include/rte_thread.h           | 11 +++
 lib/librte_eal/linux/include/rte_os.h         |  6 +-
 lib/librte_eal/rte_eal_exports.def            |  2 +
 lib/librte_eal/unix/rte_thread.c              | 10 +-
 lib/librte_eal/version.map                    |  3 +
 lib/librte_eal/windows/eal.c                  | 30 ++++++
 lib/librte_eal/windows/eal_thread.c           |  9 +-
 lib/librte_eal/windows/include/dirent.h       | 21 ++--
 lib/librte_eal/windows/include/rte_os.h       | 99 ++-----------------
 lib/librte_ethdev/rte_class_eth.c             |  2 +-
 lib/librte_ethdev/rte_ethdev.c                |  2 +-
 lib/librte_kvargs/rte_kvargs.c                | 17 ++--
 40 files changed, 275 insertions(+), 208 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-02-23  7:11       ` Andrew Rybchenko
  2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
                       ` (6 subsequent siblings)
  7 siblings, 2 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev; +Cc: Tal Shnaiderman, Dmitry Kozlyuk, Jerin Jacob, Sunil Kumar Kori

POSIX strncasecmp(), strdup(), and strtok_r() have different names
on Windows, respectively, strnicmp(), _strdup(), and strtok_s().

Add wrappers as inline functions, because they're used from librte_kvargs,
and thus cannot be in librte_eal; besides, implementation is trivial.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_dev.c        |  6 +--
 lib/librte_eal/common/eal_common_devargs.c    |  7 ++--
 lib/librte_eal/common/eal_common_log.c        |  5 ++-
 lib/librte_eal/common/eal_common_options.c    | 12 +++---
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/include/rte_string_fns.h       | 42 +++++++++++++++++++
 7 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 8a3bd3100..0a15fdcf7 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,
 			if (!device_name) {
 				event_cb->dev_name = NULL;
 			} else {
-				event_cb->dev_name = strdup(device_name);
+				event_cb->dev_name = rte_strdup(device_name);
 				if (event_cb->dev_name == NULL) {
 					ret = -ENOMEM;
 					goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str)
 
 	end = strcspn(str, ",/");
 	if (str[end] == ',') {
-		copy = strdup(&str[end + 1]);
+		copy = rte_strdup(&str[end + 1]);
 	} else {
 		/* '/' or '\0' */
-		copy = strdup("");
+		copy = rte_strdup("");
 	}
 	if (copy == NULL) {
 		rte_errno = ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index fcf3d9a3c..14e082a27 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -18,6 +18,7 @@
 #include <rte_errno.h>
 #include <rte_kvargs.h>
 #include <rte_log.h>
+#include <rte_string_fns.h>
 #include <rte_tailq.h>
 #include "eal_private.h"
 
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
 	 * anything and keep referring only to it.
 	 */
 	if (devargs->data != devstr) {
-		devargs->data = strdup(devstr);
+		devargs->data = rte_strdup(devstr);
 		if (devargs->data == NULL) {
 			RTE_LOG(ERR, EAL, "OOM\n");
 			ret = -ENOMEM;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
 	da->bus = bus;
 	/* Parse eventual device arguments */
 	if (devname[i] == ',')
-		da->args = strdup(&devname[i + 1]);
+		da->args = rte_strdup(&devname[i + 1]);
 	else
-		da->args = strdup("");
+		da->args = rte_strdup("");
 	if (da->args == NULL) {
 		RTE_LOG(ERR, EAL, "not enough memory to parse arguments\n");
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb..557a8243f 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -14,6 +14,7 @@
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_per_lcore.h>
+#include <rte_string_fns.h>
 
 #include "eal_private.h"
 
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,
 		if (regcomp(&opt_ll->re_match, regex, 0) != 0)
 			goto fail;
 	} else if (pattern) {
-		opt_ll->pattern = strdup(pattern);
+		opt_ll->pattern = rte_strdup(pattern);
 		if (opt_ll->pattern == NULL)
 			goto fail;
 	} else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)
 static int
 __rte_log_register(const char *name, int id)
 {
-	char *dup_name = strdup(name);
+	char *dup_name = rte_strdup(name);
 
 	if (dup_name == NULL)
 		return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc42..3612ad441 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (i = 0; i < argc; i++) {
-		eal_args[i] = strdup(argv[i]);
+		eal_args[i] = rte_strdup(argv[i]);
 		if (strcmp(argv[i], "--") == 0)
 			break;
 	}
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)
 		return -1;
 
 	for (j = 0; i < argc; j++, i++)
-		eal_app_args[j] = strdup(argv[i]);
+		eal_app_args[j] = rte_strdup(argv[i]);
 	eal_app_args[j] = NULL;
 
 	return 0;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)
 	char *str, *level;
 	int priority;
 
-	str = strdup(arg);
+	str = rte_strdup(arg);
 	if (str == NULL)
 		return -1;
 
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)
 static enum rte_proc_type_t
 eal_parse_proc_type(const char *arg)
 {
-	if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
+	if (rte_strncasecmp(arg, "primary", sizeof("primary")) == 0)
 		return RTE_PROC_PRIMARY;
-	if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
+	if (rte_strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
 		return RTE_PROC_SECONDARY;
-	if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
+	if (rte_strncasecmp(arg, "auto", sizeof("auto")) == 0)
 		return RTE_PROC_AUTO;
 
 	return RTE_PROC_INVALID;
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 33e419aac..4041d9af6 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)
 	if (strstr(field, ".") == NULL && strstr(field, "->") == NULL)
 		return NULL;
 
-	out = strdup(field);
+	out = rte_strdup(field);
 	if (out == NULL)
 		return NULL;
 	p = out;
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 64f58fb66..d541a5ea9 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)
 		return -ENOMEM;
 	}
 
-	arg->val = strdup(val);
+	arg->val = rte_strdup(val);
 	if (arg->val == NULL) {
 		trace_err("failed to allocate memory for %s", val);
 		free(arg);
diff --git a/lib/librte_eal/include/rte_string_fns.h b/lib/librte_eal/include/rte_string_fns.h
index 8bac8243c..2d9d5afc8 100644
--- a/lib/librte_eal/include/rte_string_fns.h
+++ b/lib/librte_eal/include/rte_string_fns.h
@@ -116,6 +116,48 @@ rte_strlcat(char *dst, const char *src, size_t size)
 ssize_t
 rte_strscpy(char *dst, const char *src, size_t dsize);
 
+/**
+ * @internal
+ * strncasecmp(3) replacement for systems that don't have it.
+ */
+static inline int
+rte_strncasecmp(const char *s1, const char *s2, size_t size)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strnicmp(s1, s2, size);
+#else
+	return strncasecmp(s1, s2, size);
+#endif
+}
+
+/**
+ * @internal
+ * strtor_r(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strtok(char *str, const char *delim, char **saveptr)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return strtok_s(str, delim, saveptr);
+#else
+	return strtok_r(str, delim, saveptr);
+#endif
+}
+
+/**
+ * @internal
+ * strdup(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strdup(const char *str)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	return _strdup(str);
+#else
+	return strdup(str);
+#endif
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
                       ` (5 subsequent siblings)
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Anatoly Burakov, Jerin Jacob,
	Sunil Kumar Kori, Bruce Richardson, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

Path length limit is PATH_MAX on Unix and _MAX_PATH on Windows.
Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX
in "common" multiprocess code, because it's really Unix-specific.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_config.c     |  2 +-
 lib/librte_eal/common/eal_common_fbarray.c    |  8 +++----
 lib/librte_eal/common/eal_common_options.c    | 20 +++++++++---------
 .../common/eal_common_trace_utils.c           |  9 ++++----
 lib/librte_eal/common/eal_filesystem.h        |  8 +++----
 lib/librte_eal/common/eal_hugepages.h         |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
 lib/librte_eal/common/eal_trace.h             |  2 +-
 lib/librte_eal/freebsd/include/rte_os.h       |  2 ++
 lib/librte_eal/linux/include/rte_os.h         |  2 ++
 lib/librte_eal/windows/include/dirent.h       | 21 +++++++------------
 lib/librte_eal/windows/include/rte_os.h       |  2 ++
 12 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7..33e5a076a 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -18,7 +18,7 @@ static struct rte_config rte_config = {
 };
 
 /* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
+static char runtime_dir[RTE_PATH_MAX];
 
 /* internal configuration */
 static struct internal_config internal_config;
diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index d974f3dab..c21b8ec66 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c
@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len)
 static int
 resize_and_map(int fd, void *addr, size_t len)
 {
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *map_addr;
 
 	if (eal_file_truncate(fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
 		unsigned int elt_sz)
 {
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	struct used_mask *msk;
 	struct mem_area *ma = NULL;
 	void *data = NULL;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr)
 {
 	struct mem_area *ma = NULL, *tmp = NULL;
 	size_t page_sz, mmap_len;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	void *data = NULL;
 	int fd = -1;
 
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)
 	struct mem_area *tmp = NULL;
 	size_t mmap_len;
 	int fd, ret;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3612ad441..bad389903 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver);
 struct shared_driver {
 	TAILQ_ENTRY(shared_driver) next;
 
-	char    name[PATH_MAX];
+	char    name[RTE_PATH_MAX];
 	void*   lib_handle;
 };
 
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path)
 		return -1;
 	}
 	memset(solib, 0, sizeof(*solib));
-	strlcpy(solib->name, path, PATH_MAX);
+	strlcpy(solib->name, path, RTE_PATH_MAX);
 	TAILQ_INSERT_TAIL(&solib_list, solib, next);
 
 	return 0;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path)
 {
 	DIR *d = NULL;
 	struct dirent *dent = NULL;
-	char sopath[PATH_MAX];
+	char sopath[RTE_PATH_MAX];
 
 	if (path == NULL || *path == '\0')
 		return 0;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath)
 
 	/* if not root, check down one level first */
 	if (strcmp(dirpath, "/") != 0) {
-		static __thread char last_dir_checked[PATH_MAX];
-		char copy[PATH_MAX];
+		static __thread char last_dir_checked[RTE_PATH_MAX];
+		char copy[RTE_PATH_MAX];
 		const char *dir;
 
-		strlcpy(copy, dirpath, PATH_MAX);
+		strlcpy(copy, dirpath, RTE_PATH_MAX);
 		dir = dirname(copy);
-		if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
+		if (strncmp(dir, last_dir_checked, RTE_PATH_MAX) != 0) {
 			if (verify_perms(dir) != 0)
 				return -1;
-			strlcpy(last_dir_checked, dir, PATH_MAX);
+			strlcpy(last_dir_checked, dir, RTE_PATH_MAX);
 		}
 	}
 
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname)
 				pathname, strerror(errno));
 		goto out;
 	}
-	if (strnlen(realp, PATH_MAX) == PATH_MAX) {
-		RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
+	if (strnlen(realp, RTE_PATH_MAX) == RTE_PATH_MAX) {
+		RTE_LOG(ERR, EAL, "Error, driver path greater than RTE_PATH_MAX\n");
 		goto out;
 	}
 
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index d541a5ea9..6b81fdeec 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -369,11 +369,11 @@ trace_mkdir(void)
 static int
 trace_meta_save(struct trace *trace)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/metadata", trace->dir);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/metadata", trace->dir);
 	if (rc < 0)
 		return rc;
 
@@ -400,11 +400,12 @@ static int
 trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr,
 		uint32_t cnt)
 {
-	char file_name[PATH_MAX];
+	char file_name[RTE_PATH_MAX];
 	FILE *f;
 	int rc;
 
-	rc = snprintf(file_name, PATH_MAX, "%s/channel0_%d", trace->dir, cnt);
+	rc = snprintf(file_name, RTE_PATH_MAX, "%s/channel0_%d",
+		trace->dir, cnt);
 	if (rc < 0)
 		return rc;
 
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 5d21f07c2..d28a9b23d 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h
@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void);
 static inline const char *
 eal_runtime_config_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
@@ -48,7 +48,7 @@ eal_runtime_config_path(void)
 static inline const char *
 eal_mp_socket_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
 static inline const char *
 eal_hugepage_info_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void)
 static inline const char *
 eal_hugepage_data_path(void)
 {
-	static char buffer[PATH_MAX]; /* static so auto-zeroed */
+	static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */
 
 	snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
diff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h
index 1b560d337..02b324ed1 100644
--- a/lib/librte_eal/common/eal_hugepages.h
+++ b/lib/librte_eal/common/eal_hugepages.h
@@ -9,7 +9,7 @@
 #include <stdint.h>
 #include <limits.h>
 
-#define MAX_HUGEPAGE_PATH PATH_MAX
+#define MAX_HUGEPAGE_PATH RTE_PATH_MAX
 
 /**
  * Structure used to store information about hugepages that we mapped
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2..c8ea3b8fc 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -27,7 +27,7 @@
  */
 struct hugepage_info {
 	uint64_t hugepage_sz;   /**< size of a huge page */
-	char hugedir[PATH_MAX];    /**< dir where hugetlbfs is mounted */
+	char hugedir[RTE_PATH_MAX];    /**< dir where hugetlbfs is mounted */
 	uint32_t num_pages[RTE_MAX_NUMA_NODES];
 	/**< number of hugepages of that size on each socket */
 	int lock_descriptor;    /**< file descriptor for hugepage dir */
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 06751eb23..ab915eb10 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -51,7 +51,7 @@ struct trace_arg {
 };
 
 struct trace {
-	char dir[PATH_MAX];
+	char dir[RTE_PATH_MAX];
 	int dir_offset;
 	int register_errno;
 	bool status;
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index eeb750cd8..b37d59b5e 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <pthread_np.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpuset_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) do \
 { \
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index 218d4fa86..af7d052d9 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -13,6 +13,8 @@
 
 #include <sched.h>
 
+#define RTE_PATH_MAX PATH_MAX
+
 typedef cpu_set_t rte_cpuset_t;
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
diff --git a/lib/librte_eal/windows/include/dirent.h b/lib/librte_eal/windows/include/dirent.h
index 869a59837..3a9a694f4 100644
--- a/lib/librte_eal/windows/include/dirent.h
+++ b/lib/librte_eal/windows/include/dirent.h
@@ -28,11 +28,6 @@
 #include <sys/stat.h>
 #include <errno.h>
 
-/* Maximum length of file name */
-#if !defined(PATH_MAX)
-#   define PATH_MAX MAX_PATH
-#endif
-
 /* File type flags for d_type */
 #define DT_UNKNOWN 0
 #define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent {
 	int d_type;
 
 	/* File name */
-	wchar_t d_name[PATH_MAX];
+	wchar_t d_name[RTE_PATH_MAX];
 };
 typedef struct _wdirent _wdirent;
 
@@ -113,7 +108,7 @@ struct dirent {
 	int d_type;
 
 	/* File name */
-	char d_name[PATH_MAX];
+	char d_name[RTE_PATH_MAX];
 };
 typedef struct dirent dirent;
 
@@ -388,12 +383,12 @@ opendir(const char *dirname)
 	/* Allocate memory for DIR structure */
 	dirp = (DIR *)malloc(sizeof(struct DIR));
 	if (dirp) {
-		wchar_t wname[PATH_MAX];
+		wchar_t wname[RTE_PATH_MAX];
 		size_t n;
 
 		/* Convert directory name to wide-character string */
-		error = dirent_mbstowcs_s(&n, wname, PATH_MAX,
-			dirname, PATH_MAX);
+		error = dirent_mbstowcs_s(&n, wname, RTE_PATH_MAX,
+			dirname, RTE_PATH_MAX);
 		if (!error) {
 
 			/* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp)
 
 		/* Attempt to convert file name to multi-byte string */
 		error = dirent_wcstombs_s(&n, dirp->ent.d_name,
-			PATH_MAX, datap->cFileName, PATH_MAX);
+			RTE_PATH_MAX, datap->cFileName, RTE_PATH_MAX);
 
 		/*
 		 * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp)
 		 */
 		if (error  &&  datap->cAlternateFileName[0] != '\0') {
 			error = dirent_wcstombs_s(
-				&n, dirp->ent.d_name, PATH_MAX,
-				datap->cAlternateFileName, PATH_MAX);
+				&n, dirp->ent.d_name, RTE_PATH_MAX,
+				datap->cAlternateFileName, RTE_PATH_MAX);
 		}
 
 		if (!error) {
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06..edca11bd2 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -20,6 +20,8 @@
 extern "C" {
 #endif
 
+#define RTE_PATH_MAX _MAX_PATH
+
 /* limits.h replacement, value as in <windows.h> */
 #ifndef PATH_MAX
 #define PATH_MAX _MAX_PATH
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 3/7] eal: add sleep API
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-02-23 22:06       ` Nick Connolly
  2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
                       ` (4 subsequent siblings)
  7 siblings, 2 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Ray Kinsella, Neil Horman

POSIX sleep(3) is missing from Windows.
Add generic rte_thread_sleep() to suspend current OS thread.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_timer.c |  5 +++--
 lib/librte_eal/include/rte_thread.h      | 11 +++++++++++
 lib/librte_eal/rte_eal_exports.def       |  2 ++
 lib/librte_eal/unix/rte_thread.c         | 10 +++++++++-
 lib/librte_eal/version.map               |  3 +++
 lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
 6 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035..0e89a4f7d 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -16,6 +16,7 @@
 #include <rte_cycles.h>
 #include <rte_pause.h>
 #include <rte_eal.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
 #include "eal_memcfg.h"
@@ -47,9 +48,9 @@ estimate_tsc_freq(void)
 #define CYC_PER_10MHZ 1E7
 	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
 		" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
+	/* assume that the rte_thread_sleep(1) will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_thread_sleep(1);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h
index e640ea185..f0c12dd79 100644
--- a/lib/librte_eal/include/rte_thread.h
+++ b/lib/librte_eal/include/rte_thread.h
@@ -106,6 +106,17 @@ int rte_thread_tls_value_set(rte_tls_key key, const void *value);
 __rte_experimental
 void *rte_thread_tls_value_get(rte_tls_key key);
 
+/**
+ * Suspend current OS thread for the specified time, yielding CPU to scheduler.
+ *
+ * @param sec
+ *  Number of seconds to sleep. The system may return control later,
+ *  but not earlier. Zero value always yields the CPU, but control may be
+ *  returned immediately.
+ */
+__rte_experimental
+void rte_thread_sleep(unsigned int sec);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index 474cf123f..494240b94 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -334,3 +334,5 @@ EXPORTS
 	rte_mem_map
 	rte_mem_page_size
 	rte_mem_unmap
+
+	rte_thread_sleep
diff --git a/lib/librte_eal/unix/rte_thread.c b/lib/librte_eal/unix/rte_thread.c
index 86ffeebc9..91babfe88 100644
--- a/lib/librte_eal/unix/rte_thread.c
+++ b/lib/librte_eal/unix/rte_thread.c
@@ -3,10 +3,12 @@
  */
 
 #include <errno.h>
-#include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <pthread.h>
+#include <unistd.h>
+
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_log.h>
@@ -84,3 +86,9 @@ rte_thread_tls_value_get(rte_tls_key key)
 	}
 	return pthread_getspecific(key->thread_index);
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	sleep(sec);
+}
diff --git a/lib/librte_eal/version.map b/lib/librte_eal/version.map
index fce90a112..b9240e7f8 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -412,6 +412,9 @@ EXPERIMENTAL {
 	rte_thread_tls_key_delete;
 	rte_thread_tls_value_get;
 	rte_thread_tls_value_set;
+
+	# added in 21.05
+	rte_thread_sleep;
 };
 
 INTERNAL {
diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c
index 908e726d1..957792301 100644
--- a/lib/librte_eal/windows/eal_thread.c
+++ b/lib/librte_eal/windows/eal_thread.c
@@ -11,9 +11,10 @@
 #include <rte_per_lcore.h>
 #include <rte_common.h>
 #include <rte_memory.h>
-#include <eal_thread.h>
+#include <rte_thread.h>
 
 #include "eal_private.h"
+#include "eal_thread.h"
 #include "eal_windows.h"
 
 /*
@@ -154,3 +155,9 @@ rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
 	/* This is a stub, not the expected result */
 	return 0;
 }
+
+void
+rte_thread_sleep(unsigned int sec)
+{
+	return Sleep(MS_PER_S * sec);
+}
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (2 preceding siblings ...)
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-03-04  6:48       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
                       ` (3 subsequent siblings)
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Jerin Jacob, Sunil Kumar Kori,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

POSIX asprintf() is unavailable on Windows.
Add eal_asprintf() wrapper for EAL internal use.
On Windows it's a function, on Unix it's a macro for asprintf().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_lcore.c      |  2 +-
 lib/librte_eal/common/eal_common_options.c    |  8 ++---
 lib/librte_eal/common/eal_common_trace.c      |  2 +-
 lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
 .../common/eal_common_trace_utils.c           |  2 +-
 lib/librte_eal/common/eal_private.h           | 18 +++++++++++
 lib/librte_eal/windows/eal.c                  | 30 +++++++++++++++++++
 7 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
index 66d6bad1a..db16a34cc 100644
--- a/lib/librte_eal/common/eal_common_lcore.c
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -282,7 +282,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	callback = calloc(1, sizeof(*callback));
 	if (callback == NULL)
 		return NULL;
-	if (asprintf(&callback->name, "%s-%p", name, arg) == -1) {
+	if (eal_asprintf(&callback->name, "%s-%p", name, arg) == -1) {
 		free(callback);
 		return NULL;
 	}
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index bad389903..275f879d7 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1435,7 +1435,7 @@ available_cores(void)
 		return NULL;
 
 	/* first sequence */
-	if (asprintf(&str, "%d", idx) < 0)
+	if (eal_asprintf(&str, "%d", idx) < 0)
 		return NULL;
 	previous = idx;
 	sequence = 0;
@@ -1452,7 +1452,7 @@ available_cores(void)
 
 		/* finish current sequence */
 		if (sequence) {
-			if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+			if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 				free(str);
 				return NULL;
 			}
@@ -1461,7 +1461,7 @@ available_cores(void)
 		}
 
 		/* new sequence */
-		if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
+		if (eal_asprintf(&tmp, "%s,%d", str, idx) < 0) {
 			free(str);
 			return NULL;
 		}
@@ -1473,7 +1473,7 @@ available_cores(void)
 
 	/* finish last sequence */
 	if (sequence) {
-		if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
+		if (eal_asprintf(&tmp, "%s-%d", str, previous) < 0) {
 			free(str);
 			return NULL;
 		}
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index 24e27387b..d57bb8ecc 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -435,7 +435,7 @@ __rte_trace_point_emit_field(size_t sz, const char *in, const char *datatype)
 	fixup = trace_metadata_fixup_field(in);
 	if (fixup != NULL)
 		in = fixup;
-	rc = asprintf(&field, "%s        %s %s;\n",
+	rc = eal_asprintf(&field, "%s        %s %s;\n",
 		RTE_PER_LCORE(ctf_field) != NULL ?
 			RTE_PER_LCORE(ctf_field) : "",
 		datatype, in);
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 4041d9af6..31df7262e 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -389,7 +389,7 @@ char *trace_metadata_fixup_field(const char *field)
 	for (i = 0; i < RTE_DIM(ctf_reserved_words); i++) {
 		if (strcmp(field, ctf_reserved_words[i]) != 0)
 			continue;
-		if (asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
+		if (eal_asprintf(&out, "_%s", ctf_reserved_words[i]) == -1)
 			out = NULL;
 		return out;
 	}
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 6b81fdeec..1773140ac 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -253,7 +253,7 @@ eal_trace_dir_args_save(char const *val)
 		return -ENAMETOOLONG;
 	}
 
-	if (asprintf(&dir_path, "%s/", val) == -1) {
+	if (eal_asprintf(&dir_path, "%s/", val) == -1) {
 		trace_err("failed to copy directory: %s", strerror(errno));
 		return -ENOMEM;
 	}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 4684c4c7d..a5d9c5123 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -738,4 +738,22 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * Allocate a buffer large enough to hold the formatted string
+ * and perform formatting, equivalent to Unix asprintf(3).
+ *
+ * @param buffer
+ *  Receives a pointer to allocated memory, call free(buffer) to deallocate.
+ * @param format
+ *  Format string.
+ * @return
+ *  Number of bytes allocated on success, (-1) on failure.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+#else
+#define eal_asprintf asprintf
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 1e5f6576f..47495b36a 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -2,6 +2,8 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <stdarg.h>
+
 #include <fcntl.h>
 #include <io.h>
 #include <share.h>
@@ -410,6 +412,34 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
+/* Don't use MinGW asprintf() to have identical code with all toolchains. */
+int
+eal_asprintf(char **buffer, const char *format, ...)
+{
+	int size, ret;
+	va_list arg;
+
+	va_start(arg, format);
+	size = vsnprintf(NULL, 0, format, arg);
+	va_end(arg);
+	if (size < 0)
+		return -1;
+	size++;
+
+	*buffer = malloc(size);
+	if (*buffer == NULL)
+		return -1;
+
+	va_start(arg, format);
+	ret = vsnprintf(*buffer, size, format, arg);
+	va_end(arg);
+	if (ret != size - 1) {
+		free(*buffer);
+		return -1;
+	}
+	return ret;
+}
+
 int
 rte_vfio_container_dma_map(__rte_unused int container_fd,
 			__rte_unused uint64_t vaddr,
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (3 preceding siblings ...)
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-03-04  6:48       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk
                       ` (2 subsequent siblings)
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Olivier Matz, Thomas Monjalon,
	Ferruh Yigit, Andrew Rybchenko

Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup()   with EAL rte_strdup().
Locally rename Windows _close() to standard close().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.c      |  1 +
 lib/librte_ethdev/rte_class_eth.c |  2 +-
 lib/librte_ethdev/rte_ethdev.c    |  2 +-
 lib/librte_kvargs/rte_kvargs.c    | 17 ++++++++++-------
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c..4dfa1178f 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -19,6 +19,7 @@
 #include "cmdline_private.h"
 
 #ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
 #define write _write
 #endif
 
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
index ca2ce87f7..9b72bdf15 100644
--- a/lib/librte_ethdev/rte_class_eth.c
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -73,7 +73,7 @@ eth_representor_cmp(const char *key __rte_unused,
 		return -1; /* not a representor port */
 
 	/* Parse devargs representor values. */
-	values = strdup(value);
+	values = rte_strdup(value);
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388..a09fec2ce 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5515,7 +5515,7 @@ eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
 	struct rte_kvargs_pair *pair;
 	char *letter;
 
-	arglist->str = strdup(str_in);
+	arglist->str = rte_strdup(str_in);
 	if (arglist->str == NULL)
 		return -ENOMEM;
 
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86..fd1103b33 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -26,20 +26,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
 	 */
-	kvlist->str = strdup(params);
+	kvlist->str = rte_strdup(params);
 	if (kvlist->str == NULL)
 		return -1;
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	while ((str = rte_strtok(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].key = rte_strtok(
+			str, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].value = rte_strtok(
+			NULL, RTE_KVARGS_KV_DELIM, &ctx2);
 		if (kvlist->pairs[i].key == NULL ||
 		    kvlist->pairs[i].value == NULL)
 			return -1;
@@ -49,12 +51,13 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 		if (str[0] == '[') {
 			/* Find the end of the list. */
 			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
+				/* Restore the comma erased by rte_strtok(). */
 				if (ctx1 == NULL || ctx1[0] == '\0')
 					return -1; /* no closing bracket */
 				str[strlen(str)] = ',';
 				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
+				str = rte_strtok(
+					NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
 				if (str == NULL)
 					return -1; /* no closing bracket */
 			}
@@ -199,7 +202,7 @@ rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
 	if (valid_ends == NULL)
 		return rte_kvargs_parse(args, valid_keys);
 
-	copy = strdup(args);
+	copy = rte_strdup(args);
 	if (copy == NULL)
 		return NULL;
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 6/7] drivers: remove POSIX dependencies
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (4 preceding siblings ...)
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-03-04  6:49       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-03-04  6:46     ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Beilei Xing, Jeff Guo

Replace POSIX strncasecmp() with EAL rte_strncasecmp().
Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup() with EAL rte_strdup().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
i40e: checkpatches.sh complains about long lines (it's ~85).
      I doubt that mechanical fix would keep the code readable.
      It's on 5th level of indentation, so I'd extract a function,
      but would like to hear from maintainers first.

 drivers/bus/pci/private.h             |  2 +-
 drivers/bus/vdev/vdev.c               |  4 +-
 drivers/bus/vdev/vdev_params.c        |  3 +-
 drivers/common/mlx5/mlx5_common_pci.c |  6 +--
 drivers/common/mlx5/mlx5_common_pci.h |  1 +
 drivers/net/i40e/i40e_ethdev.c        | 56 +++++++++++++--------------
 drivers/net/mlx5/mlx5.c               |  4 ++
 7 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5..5648916d1 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -92,7 +92,7 @@ struct mapped_pci_resource {
 	TAILQ_ENTRY(mapped_pci_resource) next;
 
 	struct rte_pci_addr pci_addr;
-	char path[PATH_MAX];
+	char path[RTE_PATH_MAX];
 	int nb_maps;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 	struct pci_msix_table msix_table;
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 9a673347a..a490d26a2 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -245,9 +245,9 @@ alloc_devargs(const char *name, const char *args)
 
 	devargs->bus = &rte_vdev_bus;
 	if (args)
-		devargs->args = strdup(args);
+		devargs->args = rte_strdup(args);
 	else
-		devargs->args = strdup("");
+		devargs->args = rte_strdup("");
 
 	ret = strlcpy(devargs->name, name, sizeof(devargs->name));
 	if (ret < 0 || ret >= (int)sizeof(devargs->name)) {
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
index 6f74704d1..64848f4c2 100644
--- a/drivers/bus/vdev/vdev_params.c
+++ b/drivers/bus/vdev/vdev_params.c
@@ -8,6 +8,7 @@
 #include <rte_bus.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
+#include <rte_string_fns.h>
 
 #include "vdev_logs.h"
 #include "vdev_private.h"
@@ -31,7 +32,7 @@ vdev_dev_match(const struct rte_device *dev,
 	char *name;
 
 	/* cannot pass const dev->name to rte_kvargs_process() */
-	name = strdup(dev->name);
+	name = rte_strdup(dev->name);
 	if (name == NULL)
 		return -1;
 	ret = rte_kvargs_process(kvlist,
diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index 2b657686d..0b2c50f46 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -82,13 +82,13 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 	char *refstr = NULL;
 
 	*ret = 0;
-	nstr = strdup(class_names);
+	nstr = rte_strdup(class_names);
 	if (!nstr) {
 		*ret = -ENOMEM;
 		return *ret;
 	}
 	nstr_org = nstr;
-	found = strtok_r(nstr, ":", &refstr);
+	found = rte_strtok(nstr, ":", &refstr);
 	if (!found)
 		goto err;
 	do {
@@ -102,7 +102,7 @@ bus_cmdline_options_handler(__rte_unused const char *key,
 			goto err;
 		}
 		*ret |= class_val;
-		found = strtok_r(NULL, ":", &refstr);
+		found = rte_strtok(NULL, ":", &refstr);
 	} while (found);
 err:
 	free(nstr_org);
diff --git a/drivers/common/mlx5/mlx5_common_pci.h b/drivers/common/mlx5/mlx5_common_pci.h
index de89bb98b..729d0f4cc 100644
--- a/drivers/common/mlx5/mlx5_common_pci.h
+++ b/drivers/common/mlx5/mlx5_common_pci.h
@@ -45,6 +45,7 @@ extern "C" {
 
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
+#include <rte_string_fns.h>
 
 #include <mlx5_common.h>
 
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7cd04989..5b806d201 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -12036,110 +12036,110 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
 				memset(name, 0, sizeof(name));
 				strcpy(name, proto[n].name);
 				PMD_DRV_LOG(INFO, "name = %s\n", name);
-				if (!strncasecmp(name, "PPPOE", 5))
+				if (!rte_strncasecmp(name, "PPPOE", 5))
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L2_ETHER_PPPOE;
-				else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV4FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV4FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV4", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV4", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV4", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV4", 4) &&
+				else if (!rte_strncasecmp(name, "IPV4", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					 !in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_FRAG;
-				} else if (!strncasecmp(name, "IPV6FRAG", 8) &&
+				} else if (!rte_strncasecmp(name, "IPV6FRAG", 8) &&
 					   in_tunnel) {
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_FRAG;
-				} else if (!strncasecmp(name, "OIPV6", 5)) {
+				} else if (!rte_strncasecmp(name, "OIPV6", 5)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "IPV6", 4) &&
+				} else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					   !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "IPV6", 4) &&
+				else if (!rte_strncasecmp(name, "IPV6", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 					    RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_UDP;
-				else if (!strncasecmp(name, "UDP", 3) &&
+				else if (!rte_strncasecmp(name, "UDP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_UDP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_TCP;
-				else if (!strncasecmp(name, "TCP", 3) &&
+				else if (!rte_strncasecmp(name, "TCP", 3) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_TCP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_SCTP;
-				else if (!strncasecmp(name, "SCTP", 4) &&
+				else if (!rte_strncasecmp(name, "SCTP", 4) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_SCTP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 !in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_L4_ICMP;
-				else if ((!strncasecmp(name, "ICMP", 4) ||
-					  !strncasecmp(name, "ICMPV6", 6)) &&
+				else if ((!rte_strncasecmp(name, "ICMP", 4) ||
+					  !rte_strncasecmp(name, "ICMPV6", 6)) &&
 					 in_tunnel)
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_INNER_L4_ICMP;
-				else if (!strncasecmp(name, "GTPC", 4)) {
+				else if (!rte_strncasecmp(name, "GTPC", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPC;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GTPU", 4)) {
+				} else if (!rte_strncasecmp(name, "GTPU", 4)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GTPU;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "ESP", 3)) {
+				} else if (!rte_strncasecmp(name, "ESP", 3)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_ESP;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "GRENAT", 6)) {
+				} else if (!rte_strncasecmp(name, "GRENAT", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_GRENAT;
 					in_tunnel = true;
-				} else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
-					   !strncasecmp(name, "L2TPV2", 6) ||
-					   !strncasecmp(name, "L2TPV3", 6)) {
+				} else if (!rte_strncasecmp(name, "L2TPV2CTL", 9) ||
+					   !rte_strncasecmp(name, "L2TPV2", 6) ||
+					   !rte_strncasecmp(name, "L2TPV3", 6)) {
 					ptype_mapping[i].sw_ptype |=
 						RTE_PTYPE_TUNNEL_L2TP;
 					in_tunnel = true;
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index aae2ef9af..22fbcef7e 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -41,6 +41,10 @@
 #include "mlx5_flow_os.h"
 #include "rte_pmd_mlx5.h"
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
+#endif
+
 /* Device parameter to enable RX completion queue compression. */
 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (5 preceding siblings ...)
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk
@ 2021-02-21 14:28     ` Dmitry Kozlyuk
  2021-03-04  6:49       ` [dpdk-dev] [EXTERNAL] " Khoa To
  2021-03-04  6:46     ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To
  7 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:28 UTC (permalink / raw)
  To: dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Exposing POSIX symbols could break consumer POSIX compatibility code.

* Make renaming of close() and unlink() private to EAL.

* Remove renaming of strncasecmp(), strtok_r(), and sleep()
  in favor of using EAL wrappers. Similarly remove PATH_MAX macro.

* Replace index(3p), which is not available on Windows, with strchr(3),
  as recommended by POSIX.1-2008. strerror_r() is only used inside EAL,
  rename it only where it's needed. Same for asprintf(), it has an
  internal EAL wrapper and is removed from public API.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 doc/guides/rel_notes/release_21_05.rst     |  9 ++
 lib/librte_eal/common/eal_common_errno.c   |  4 +
 lib/librte_eal/common/eal_common_options.c |  2 +-
 lib/librte_eal/common/eal_private.h        |  5 ++
 lib/librte_eal/freebsd/include/rte_os.h    |  4 +-
 lib/librte_eal/linux/include/rte_os.h      |  4 +-
 lib/librte_eal/windows/include/rte_os.h    | 99 ++--------------------
 7 files changed, 29 insertions(+), 98 deletions(-)

diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index 5aa9ed7db..6380dfa53 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -84,6 +84,15 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* eal/windows: Removed POSIX symbols from EAL headers. Exposing POSIX symbols
+  has been incorrect and could conflict with consumer POSIX implementations.
+  Wrappers are provided for
+  ``strtok_r(3p)`` (``rte_strtok``),
+  ``strncasecmp(3p)`` (``rte_strncasecmp``),
+  ``sleep(3p)`` (``rte_thread_sleep``),
+  ``PATH_MAX`` (``RTE_PATH_MAX``).
+  Removed are ``strerror_r(3p)`` and ``asprintf(3p)``.
+
 
 ABI Changes
 -----------
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823..536eea0c3 100644
--- a/lib/librte_eal/common/eal_common_errno.c
+++ b/lib/librte_eal/common/eal_common_errno.c
@@ -15,6 +15,10 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define strerror_r(a, b, c) strerror_s(b, c, a)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 275f879d7..fd3b22e8a 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1936,7 +1936,7 @@ eal_check_common_options(struct internal_config *internal_cfg)
 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
 		return -1;
 	}
-	if (index(eal_get_hugefile_prefix(), '%') != NULL) {
+	if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
 		RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
 			"option\n");
 		return -1;
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index a5d9c5123..860551661 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -756,4 +756,9 @@ int eal_asprintf(char **buffer, const char *format, ...);
 #define eal_asprintf asprintf
 #endif
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
+#define unlink _unlink
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index b37d59b5e..a5bf10021 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * freebsd OS. Functions will be added in future releases.
+ * freebsd OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <pthread_np.h>
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index af7d052d9..04f510eec 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h
@@ -6,9 +6,9 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
+ * This header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * linux OS. Functions will be added in future releases.
+ * linux OS. It must not define symbols without "rte_" prefix.
  */
 
 #include <sched.h>
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index edca11bd2..9c9c31214 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -6,15 +6,11 @@
 #define _RTE_OS_H_
 
 /**
- * This is header should contain any function/macro definition
- * which are not supported natively or named differently in the
- * Windows OS. It must not include Windows-specific headers.
+ * This header should contain any function/macro definition
+ * which are not supported natively or named differently in Windows OS.
  */
 
-#include <stdarg.h>
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -22,101 +18,18 @@ extern "C" {
 
 #define RTE_PATH_MAX _MAX_PATH
 
-/* limits.h replacement, value as in <windows.h> */
-#ifndef PATH_MAX
-#define PATH_MAX _MAX_PATH
-#endif
-
-#ifndef sleep
-#define sleep(x) Sleep(1000 * (x))
-#endif
-
-#ifndef strerror_r
-#define strerror_r(a, b, c) strerror_s(b, c, a)
-#endif
-
-#ifndef strdup
-/* strdup is deprecated in Microsoft libc and _strdup is preferred */
-#define strdup(str) _strdup(str)
-#endif
-
-#ifndef strtok_r
-#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
-#endif
-
-#ifndef index
-#define index(a, b)     strchr(a, b)
-#endif
-
-#ifndef rindex
-#define rindex(a, b)    strrchr(a, b)
-#endif
-
-#ifndef strncasecmp
-#define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
-#endif
-
-#ifndef close
-#define close _close
-#endif
-
-#ifndef unlink
-#define unlink _unlink
-#endif
-
 /* cpu_set macros implementation */
 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
 #define RTE_CPU_FILL(set) CPU_FILL(set)
 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
 
-/* as in <windows.h> */
+/* This is an exception without "rte_" prefix, because Windows does have
+ * ssize_t, but it's defined in <windows.h> which we avoid to expose.
+ * If ssize_t is defined in user code, it necessarily has the same type.
+ */
 typedef long long ssize_t;
 
-#ifndef RTE_TOOLCHAIN_GCC
-
-static inline int
-asprintf(char **buffer, const char *format, ...)
-{
-	int size, ret;
-	va_list arg;
-
-	va_start(arg, format);
-	size = vsnprintf(NULL, 0, format, arg);
-	va_end(arg);
-	if (size < 0)
-		return -1;
-	size++;
-
-	*buffer = (char *)malloc(size);
-	if (*buffer == NULL)
-		return -1;
-
-	va_start(arg, format);
-	ret = vsnprintf(*buffer, size, format, arg);
-	va_end(arg);
-	if (ret != size - 1) {
-		free(*buffer);
-		return -1;
-	}
-	return ret;
-}
-
-static inline const char *
-eal_strerror(int code)
-{
-	static char buffer[128];
-
-	strerror_s(buffer, sizeof(buffer), code);
-	return buffer;
-}
-
-#ifndef strerror
-#define strerror eal_strerror
-#endif
-
-#endif /* RTE_TOOLCHAIN_GCC */
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.29.2


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21 11:58         ` Tal Shnaiderman
@ 2021-02-21 14:33           ` Dmitry Kozlyuk
  0 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 14:33 UTC (permalink / raw)
  To: Tal Shnaiderman
  Cc: dev, Tyler Retzlaff, Nick Connolly, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

On Sun, 21 Feb 2021 11:58:39 +0000, Tal Shnaiderman wrote:
[...] 
> > Thanks for all your comments, it's weird I didn't hit the failures locally.
> > Will fix in v3.  
> 
> You might be missing the DevX SDK installation, without it meson will skip the mlx5 build.
> 
> You can get it either by installation WIOF2 2.60 [1] or get only the SDK from [2] (I attached it to the Bugzilla ticket when asked the UNH team to add mlx5 compilation to CI.
> 
> [1] - https://www.mellanox.com/products/adapter-software/ethernet/windows/winof-2
> [2] - https://bugs.dpdk.org/show_bug.cgi?id=620

Indeed it was the case, thank you again.


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
  2021-02-21  8:59     ` Tal Shnaiderman
@ 2021-02-21 15:54       ` Andrew Rybchenko
  2021-02-21 17:05         ` Dmitry Kozlyuk
  0 siblings, 1 reply; 56+ messages in thread
From: Andrew Rybchenko @ 2021-02-21 15:54 UTC (permalink / raw)
  To: Tal Shnaiderman, Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Nick Connolly, Matan Azrad, Shahaf Shuler,
	Slava Ovsiienko, Beilei Xing, Jeff Guo

On 2/21/21 11:59 AM, Tal Shnaiderman wrote:
>> Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
>>
>> External email: Use caution opening links or attachments
>>
>>
>> Replace POSIX strncasecmp() with EAL rte_strncasecmp().
>> Replace POSIX strtok_r() with EAL rte_strtok().
>> Replace POSIX strdup() with EAL rte_strdup().
>>
>> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
>> ---
>> i40e: checkpatches.sh complains about long lines (it's ~85).
>>        I doubt that mechanical fix would keep the code readable.
>>        It's on 5th level of indentation, so I'd extract a function,
>>        but would like to hear from maintainers first.
>>
>>   drivers/bus/pci/private.h             |  2 +-
>>   drivers/bus/vdev/vdev.c               |  4 +-
>>   drivers/bus/vdev/vdev_params.c        |  3 +-
>>   drivers/common/mlx5/mlx5_common_pci.c |  4 +-
> 
> bus_cmdline_options_handler in mlx5_common_pci.c has a call to strdup which needs to be renamed to rte_strdup
> (Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )
> 


Frankly speaking I don't understand why such changes are useful/needed.
Patch description does not explain/prove it.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
  2021-02-21 15:54       ` Andrew Rybchenko
@ 2021-02-21 17:05         ` Dmitry Kozlyuk
  0 siblings, 0 replies; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-21 17:05 UTC (permalink / raw)
  To: Andrew Rybchenko
  Cc: Tal Shnaiderman, dev, Tyler Retzlaff, Nick Connolly, Matan Azrad,
	Shahaf Shuler, Slava Ovsiienko, Beilei Xing, Jeff Guo

On Sun, 21 Feb 2021 18:54:01 +0300, Andrew Rybchenko wrote:
> On 2/21/21 11:59 AM, Tal Shnaiderman wrote:
> >> Subject: [dpdk-dev] [PATCH v2 6/7] drivers: remove POSIX dependencies
> >>
> >> External email: Use caution opening links or attachments
> >>
> >>
> >> Replace POSIX strncasecmp() with EAL rte_strncasecmp().
> >> Replace POSIX strtok_r() with EAL rte_strtok().
> >> Replace POSIX strdup() with EAL rte_strdup().
> >>
> >> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> >> ---
> >> i40e: checkpatches.sh complains about long lines (it's ~85).
> >>        I doubt that mechanical fix would keep the code readable.
> >>        It's on 5th level of indentation, so I'd extract a function,
> >>        but would like to hear from maintainers first.
> >>
> >>   drivers/bus/pci/private.h             |  2 +-
> >>   drivers/bus/vdev/vdev.c               |  4 +-
> >>   drivers/bus/vdev/vdev_params.c        |  3 +-
> >>   drivers/common/mlx5/mlx5_common_pci.c |  4 +-  
> > 
> > bus_cmdline_options_handler in mlx5_common_pci.c has a call to strdup which needs to be renamed to rte_strdup
> > (Also failed CI: https://lab.dpdk.org/results/dashboard/patchsets/15674/ )
> >   
> 
> 
> Frankly speaking I don't understand why such changes are useful/needed.
> Patch description does not explain/prove it.

Please see the cover letter (better to partially repeat in each patch?):

	https://mails.dpdk.org/archives/dev/2021-February/199981.html

Driver code using POSIX functions is not really portable without a shim.
Having a shim in public API is wrong, it makes DPDK expose non-DPDK symbols.

An alternative approach would be to make the shim DPDK-internal. It would
require just a change in #includes for drivers and libs. My doubt is whether
EAL should emulate POSIX.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
@ 2021-02-22 11:47     ` Bruce Richardson
  2021-02-22 12:48       ` Nick Connolly
  0 siblings, 1 reply; 56+ messages in thread
From: Bruce Richardson @ 2021-02-22 11:47 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Nick Connolly, Jerin Jacob, Sunil Kumar Kori

On Sun, Feb 21, 2021 at 04:28:25AM +0300, Dmitry Kozlyuk wrote:
> POSIX strncasecmp(), strdup(), and strtok_r() have different names
> on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
> 
> Add wrappers as inline functions, because they're used from librte_kvargs,
> and thus cannot be in librte_eal; besides, implementation is trivial.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  lib/librte_eal/common/eal_common_dev.c        |  6 +--
>  lib/librte_eal/common/eal_common_devargs.c    |  7 ++--
>  lib/librte_eal/common/eal_common_log.c        |  5 ++-
>  lib/librte_eal/common/eal_common_options.c    | 12 +++---
>  lib/librte_eal/common/eal_common_trace_ctf.c  |  2 +-
>  .../common/eal_common_trace_utils.c           |  2 +-
>  lib/librte_eal/include/rte_string_fns.h       | 42 +++++++++++++++++++
>  7 files changed, 60 insertions(+), 16 deletions(-)
> 
Rather than defining "rte_" versions of these functions, is it possible
just to provide the unprefixed definitions of them for internal use?
While this probably won't work for any functions used in public headers,
for any functions only used in C files, we can use meson to detect the
presence of the standard function and set a macro flag for the compatiblity
version if not present. This is something we already support for the
strlcpy/strlcat functions from libbsd, and it basically allows the
well-known (and loved?) functions to be used directly, and saves DPDK
developers having to worry about what "standard" functions can be used
directly, and which can't.

/Bruce

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 11:47     ` Bruce Richardson
@ 2021-02-22 12:48       ` Nick Connolly
  2021-02-22 14:26         ` Bruce Richardson
  2021-02-22 18:07         ` Tyler Retzlaff
  0 siblings, 2 replies; 56+ messages in thread
From: Nick Connolly @ 2021-02-22 12:48 UTC (permalink / raw)
  To: Bruce Richardson, Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori


> Rather than defining "rte_" versions of these functions, is it possible
> just to provide the unprefixed definitions of them for internal use?
> While this probably won't work for any functions used in public headers,
> for any functions only used in C files, we can use meson to detect the
> presence of the standard function and set a macro flag for the compatiblity
> version if not present. This is something we already support for the
> strlcpy/strlcat functions from libbsd, and it basically allows the
> well-known (and loved?) functions to be used directly, and saves DPDK
> developers having to worry about what "standard" functions can be used
> directly, and which can't.

Hi Bruce,

You're asking a really good question here that highlights a fundamental 
issue:
Does the DPDK code base have an implied POSIX dependency, or should it only
depend upon the standard C library and 'rte_ ' functions.  This hasn't 
been an
issue before, but Windows isn't 'POSIX' based.

Using "well-known" names for missing functions is ok where the definitions
are in private header files, but if the headers are public, or the 
implementation
is better done in a C file, then there can be a clash with the 
application which
is likely dealing with the same issues.

There seem to be two viable approaches to handling this:

 1. Expect the platform to provide POSIX semantic (through an external
    library
    such as Cygwin). That way it becomes "an 'external' problem" and the
    DPDK
    can use the "well-known" names and expected behaviour.

 2. Provide the missing functionality, but wrap it in 'internal' header
    files
    and 'rte_' versions to avoid link errors. This is the approach that
    Dmitry has
    taken based on the guidance we've received.

For background, the approach I've taken with adding Windows support to SPDK
is to create an 'external' library (https://wpdk.github.io) with header 
files that
provide the missing POSIX functionality and functions with a prefix to 
avoid link
errors. As a result, the whole of SPDK can now build and run unchanged.

Regards,
Nick

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 12:48       ` Nick Connolly
@ 2021-02-22 14:26         ` Bruce Richardson
  2021-02-22 18:21           ` Nick Connolly
  2021-02-22 22:57           ` Dmitry Kozlyuk
  2021-02-22 18:07         ` Tyler Retzlaff
  1 sibling, 2 replies; 56+ messages in thread
From: Bruce Richardson @ 2021-02-22 14:26 UTC (permalink / raw)
  To: Nick Connolly
  Cc: Dmitry Kozlyuk, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori

On Mon, Feb 22, 2021 at 12:48:39PM +0000, Nick Connolly wrote:
> Rather than defining "rte_" versions of these functions, is it possible
> just to provide the unprefixed definitions of them for internal use?
> While this probably won't work for any functions used in public headers,
> for any functions only used in C files, we can use meson to detect the
> presence of the standard function and set a macro flag for the compatiblity
> version if not present. This is something we already support for the
> strlcpy/strlcat functions from libbsd, and it basically allows the
> well-known (and loved?) functions to be used directly, and saves DPDK
> developers having to worry about what "standard" functions can be used
> directly, and which can't.
> 
>    Hi Bruce,
>    You're asking a really good question here that highlights a fundamental
>    issue:
>    Does the DPDK code base have an implied POSIX dependency, or should it
>    only
>    depend upon the standard C library and 'rte_ ' functions.  This hasn't
>    been an
>    issue before, but Windows isn't 'POSIX' based.
>    Using "well-known" names for missing functions is ok where the
>    definitions
>    are in private header files, but if the headers are public, or the
>    implementation
>    is better done in a C file, then there can be a clash with the
>    application which
>    is likely dealing with the same issues.
>    There seem to be two viable approaches to handling this:
>     1. Expect the platform to provide POSIX semantic (through an external
>        library
>        such as Cygwin). That way it becomes "an 'external' problem" and
>        the DPDK
>        can use the "well-known" names and expected behaviour.
>     2. Provide the missing functionality, but wrap it in 'internal' header
>        files
>        and 'rte_' versions to avoid link errors. This is the approach that
>        Dmitry has
>        taken based on the guidance we've received.
> 
>    For background, the approach I've taken with adding Windows support to
>    SPDK
>    is to create an 'external' library ([1]https://wpdk.github.io) with
>    header files that
>    provide the missing POSIX functionality and functions with a prefix to
>    avoid link
>    errors. As a result, the whole of SPDK can now build and run unchanged.
>    Regards,
>    Nick
> 

Whatever about the specific implementation, I'd very much like to get to
the point where we don't have to do search-replace for a bunch of functions
like this, not to mention that we'd need to have checkpatch rules in place
to ensure that further instances are not re-introduced.
As you say, though, the main issue will be whether we have instances in
public header files or not. I would hope that no static inline functions in
DPDK use any of the functions in question, but I'm not sure. Perhaps if
there are instances in public headers those could be reworked to not use
the problematic functions.

For any functions, such as strdup, which are not in a public header I would
suggest the following as a possible start point, based off what was done
for strlcpy.

* In DPDK (probably EAL), define an rte_strdup function for use as a
  fallback.
* Inside the meson build scripts, use "cc.has_function()" to check if the
  regular strdup function is available. If not, then add "-DRTE_NO_STRDUP"
  to the c_args for DPDK building
* Inside our DPDK header (rte_string_fns.h in the strdup case), we can add
  a conditional define such as:
   #ifdef RTE_NO_STRDUP
   #define strdup(s) rte_strdup(s)
   #endif

Thoughts on this?
/Bruce

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 12:48       ` Nick Connolly
  2021-02-22 14:26         ` Bruce Richardson
@ 2021-02-22 18:07         ` Tyler Retzlaff
  2021-02-22 18:36           ` Nick Connolly
  1 sibling, 1 reply; 56+ messages in thread
From: Tyler Retzlaff @ 2021-02-22 18:07 UTC (permalink / raw)
  To: Nick Connolly
  Cc: Bruce Richardson, Dmitry Kozlyuk, dev, Tyler Retzlaff,
	Jerin Jacob, Sunil Kumar Kori

On Mon, Feb 22, 2021 at 12:48:39PM +0000, Nick Connolly wrote:
> 
> There seem to be two viable approaches to handling this:
> 
> 1. Expect the platform to provide POSIX semantic (through an external
>    library
>    such as Cygwin). That way it becomes "an 'external' problem" and the
>    DPDK
>    can use the "well-known" names and expected behaviour.

I'd prefer not to see this be a requirement of the platform. There have
been multiple attempts over the years to provide a POSIX surfaces
on Windows which arguably haven't been that successful.

It would be helpful if DPDK dependence on POSIX APIs were limited to
be only as necessary to improve portability to non-POSIX platforms.

Ty

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 14:26         ` Bruce Richardson
@ 2021-02-22 18:21           ` Nick Connolly
  2021-02-22 22:57           ` Dmitry Kozlyuk
  1 sibling, 0 replies; 56+ messages in thread
From: Nick Connolly @ 2021-02-22 18:21 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: Dmitry Kozlyuk, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori


> For any functions, such as strdup, which are not in a public header I would
> suggest the following as a possible start point, based off what was done
> for strlcpy.
>
> * In DPDK (probably EAL), define an rte_strdup function for use as a
>    fallback.
> * Inside the meson build scripts, use "cc.has_function()" to check if the
>    regular strdup function is available. If not, then add "-DRTE_NO_STRDUP"
>    to the c_args for DPDK building
> * Inside our DPDK header (rte_string_fns.h in the strdup case), we can add
>    a conditional define such as:
>     #ifdef RTE_NO_STRDUP
>     #define strdup(s) rte_strdup(s)
>     #endif
>
> Thoughts on this?
Looks like an elegant approach to me.
Nick

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 18:07         ` Tyler Retzlaff
@ 2021-02-22 18:36           ` Nick Connolly
  0 siblings, 0 replies; 56+ messages in thread
From: Nick Connolly @ 2021-02-22 18:36 UTC (permalink / raw)
  To: Tyler Retzlaff
  Cc: Bruce Richardson, Dmitry Kozlyuk, dev, Tyler Retzlaff,
	Jerin Jacob, Sunil Kumar Kori


>> There seem to be two viable approaches to handling this:
>>
>> 1. Expect the platform to provide POSIX semantic (through an external
>>     ...
> I'd prefer not to see this be a requirement of the platform. There have
> been multiple attempts over the years to provide a POSIX surfaces
> on Windows which arguably haven't been that successful.
+1
'viable' was the wrong word - I can't see a general-purpose POSIX 
surface giving a good outcome.

> It would be helpful if DPDK dependence on POSIX APIs were limited to
> be only as necessary to improve portability to non-POSIX platforms.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 14:26         ` Bruce Richardson
  2021-02-22 18:21           ` Nick Connolly
@ 2021-02-22 22:57           ` Dmitry Kozlyuk
  2021-02-23  9:45             ` Bruce Richardson
  1 sibling, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-22 22:57 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: Nick Connolly, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori

2021-02-22 14:26, Bruce Richardson:
> As you say, though, the main issue will be whether we have instances in
> public header files or not. I would hope that no static inline functions in
> DPDK use any of the functions in question, but I'm not sure. Perhaps if
> there are instances in public headers those could be reworked to not use
> the problematic functions.

No instances of strdup(), strncasecmp(), or strtok_r() in any DPDK headers.

> For any functions, such as strdup, which are not in a public header I would
> suggest the following as a possible start point, based off what was done
> for strlcpy.
> 
> * In DPDK (probably EAL), define an rte_strdup function for use as a
>   fallback.
> * Inside the meson build scripts, use "cc.has_function()" to check if the
>   regular strdup function is available. If not, then add "-DRTE_NO_STRDUP"
>   to the c_args for DPDK building
> * Inside our DPDK header (rte_string_fns.h in the strdup case), we can add
>   a conditional define such as:
>    #ifdef RTE_NO_STRDUP
>    #define strdup(s) rte_strdup(s)
>    #endif
> 
> Thoughts on this?

Looks good to me, I can rework the patchset like so.

Policy considerations:
1. The approach only applies to platform-agnostic functions, like str*().
   Functions like sleep() still belong to librte_eal.
2. Deprecated functions, like index(3p), should be replaced
   with alternatives suggested by the standard.
3. If a standard C11 alternative is available, it should be used.
   This mostly applies to types, like u_int32 -> uint32_t
   (it's even in DPDK coding style already, isn't it?).

A nit: RTE_NO_XXX -> RTE_HAS_XXX (for consistency with existing macros)?

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
@ 2021-02-23  7:11       ` Andrew Rybchenko
  2021-02-23 21:53         ` Nick Connolly
  2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
  1 sibling, 1 reply; 56+ messages in thread
From: Andrew Rybchenko @ 2021-02-23  7:11 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev; +Cc: Tal Shnaiderman, Jerin Jacob, Sunil Kumar Kori

On 2/21/21 5:28 PM, Dmitry Kozlyuk wrote:
> POSIX strncasecmp(), strdup(), and strtok_r() have different names
> on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
> 
> Add wrappers as inline functions, because they're used from librte_kvargs,
> and thus cannot be in librte_eal; besides, implementation is trivial.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

[snip]

> +/**
> + * @internal
> + * strdup(3) replacement for systems that don't have it.
> + */
> +static inline char *
> +rte_strdup(const char *str)
> +{
> +#ifdef RTE_EXEC_ENV_WINDOWS
> +	return _strdup(str);
> +#else
> +	return strdup(str);
> +#endif
> +}

Allocating memory using rte_strdup() I'd use rte_free()
to release it. I guess it will fail badly.
So, I think that a different, more specific prefix is
required for POSIX wrappers.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-22 22:57           ` Dmitry Kozlyuk
@ 2021-02-23  9:45             ` Bruce Richardson
  2021-02-27 20:23               ` Dmitry Kozlyuk
  0 siblings, 1 reply; 56+ messages in thread
From: Bruce Richardson @ 2021-02-23  9:45 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: Nick Connolly, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori

On Tue, Feb 23, 2021 at 01:57:50AM +0300, Dmitry Kozlyuk wrote:
> 2021-02-22 14:26, Bruce Richardson:
> > As you say, though, the main issue will be whether we have instances in
> > public header files or not. I would hope that no static inline functions in
> > DPDK use any of the functions in question, but I'm not sure. Perhaps if
> > there are instances in public headers those could be reworked to not use
> > the problematic functions.
> 
> No instances of strdup(), strncasecmp(), or strtok_r() in any DPDK headers.
> 
> > For any functions, such as strdup, which are not in a public header I would
> > suggest the following as a possible start point, based off what was done
> > for strlcpy.
> > 
> > * In DPDK (probably EAL), define an rte_strdup function for use as a
> >   fallback.
> > * Inside the meson build scripts, use "cc.has_function()" to check if the
> >   regular strdup function is available. If not, then add "-DRTE_NO_STRDUP"
> >   to the c_args for DPDK building
> > * Inside our DPDK header (rte_string_fns.h in the strdup case), we can add
> >   a conditional define such as:
> >    #ifdef RTE_NO_STRDUP
> >    #define strdup(s) rte_strdup(s)
> >    #endif
> > 
> > Thoughts on this?
> 
> Looks good to me, I can rework the patchset like so.
> 
> Policy considerations:
> 1. The approach only applies to platform-agnostic functions, like str*().
>    Functions like sleep() still belong to librte_eal.
> 2. Deprecated functions, like index(3p), should be replaced
>    with alternatives suggested by the standard.
> 3. If a standard C11 alternative is available, it should be used.
>    This mostly applies to types, like u_int32 -> uint32_t
>    (it's even in DPDK coding style already, isn't it?).
> 
> A nit: RTE_NO_XXX -> RTE_HAS_XXX (for consistency with existing macros)?

Sure, thanks.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
  2021-02-23  7:11       ` Andrew Rybchenko
@ 2021-02-23 21:53         ` Nick Connolly
  2021-02-24  7:21           ` Andrew Rybchenko
  0 siblings, 1 reply; 56+ messages in thread
From: Nick Connolly @ 2021-02-23 21:53 UTC (permalink / raw)
  To: Andrew Rybchenko, Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Jerin Jacob, Sunil Kumar Kori


> Allocating memory using rte_strdup() I'd use rte_free()
> to release it. I guess it will fail badly.
> So, I think that a different, more specific prefix is
> required for POSIX wrappers.

Andrew: my understanding of Bruce's proposal is that the strdup() name 
will now be kept (in this case through an inline definition), so I think 
this will be ok.  However, your comment reminded me of something else 
that it's probably worth mentioning as an aside:

As a general guideline on Windows, memory allocated within a shared 
library is best freed within the same DLL to ensure it goes back to the 
correct heap.  So we'd want to avoid calling strdup and then returning 
the value to the application for it to free (hopefully this doesn't 
happen). With an inline definition there's no change in behaviour, but 
adding rte_strdup (or anything else that calls malloc) into librte_eal 
might be an issue.

Regards,
Nick


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v3 3/7] eal: add sleep API
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
@ 2021-02-23 22:06       ` Nick Connolly
  2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
  1 sibling, 0 replies; 56+ messages in thread
From: Nick Connolly @ 2021-02-23 22:06 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Ray Kinsella, Neil Horman

Hi Dmitry,
> +void
> +rte_thread_sleep(unsigned int sec)
> +{
> +	return Sleep(MS_PER_S * sec);
> +}
There's probably no benefit in returning the 'void' value - I'd suggest 
just call Sleep().

Regards,
Nick

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
  2021-02-23 21:53         ` Nick Connolly
@ 2021-02-24  7:21           ` Andrew Rybchenko
  0 siblings, 0 replies; 56+ messages in thread
From: Andrew Rybchenko @ 2021-02-24  7:21 UTC (permalink / raw)
  To: Nick Connolly, Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Jerin Jacob, Sunil Kumar Kori

On 2/24/21 12:53 AM, Nick Connolly wrote:
> 
>> Allocating memory using rte_strdup() I'd use rte_free()
>> to release it. I guess it will fail badly.
>> So, I think that a different, more specific prefix is
>> required for POSIX wrappers.
> 
> Andrew: my understanding of Bruce's proposal is that the strdup() name
> will now be kept (in this case through an inline definition), so I think
> this will be ok. 

Very good, glad to hear it. Thanks.

> However, your comment reminded me of something else
> that it's probably worth mentioning as an aside:
> 
> As a general guideline on Windows, memory allocated within a shared
> library is best freed within the same DLL to ensure it goes back to the
> correct heap.  So we'd want to avoid calling strdup and then returning
> the value to the application for it to free (hopefully this doesn't
> happen). With an inline definition there's no change in behaviour, but
> adding rte_strdup (or anything else that calls malloc) into librte_eal
> might be an issue.
> 
> Regards,
> Nick


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-23  9:45             ` Bruce Richardson
@ 2021-02-27 20:23               ` Dmitry Kozlyuk
  2021-03-01 21:31                 ` Nick Connolly
  0 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-02-27 20:23 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: Nick Connolly, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori

2021-02-23 09:45, Bruce Richardson:
> On Tue, Feb 23, 2021 at 01:57:50AM +0300, Dmitry Kozlyuk wrote:
> > 2021-02-22 14:26, Bruce Richardson:  
> > > As you say, though, the main issue will be whether we have instances in
> > > public header files or not. I would hope that no static inline functions in
> > > DPDK use any of the functions in question, but I'm not sure. Perhaps if
> > > there are instances in public headers those could be reworked to not use
> > > the problematic functions.  
> > 
> > No instances of strdup(), strncasecmp(), or strtok_r() in any DPDK headers.
> >   
> > > For any functions, such as strdup, which are not in a public header I would
> > > suggest the following as a possible start point, based off what was done
> > > for strlcpy.
> > > 
> > > * In DPDK (probably EAL), define an rte_strdup function for use as a
> > >   fallback.
> > > * Inside the meson build scripts, use "cc.has_function()" to check if the
> > >   regular strdup function is available. If not, then add "-DRTE_NO_STRDUP"
> > >   to the c_args for DPDK building
> > > * Inside our DPDK header (rte_string_fns.h in the strdup case), we can add
> > >   a conditional define such as:
> > >    #ifdef RTE_NO_STRDUP
> > >    #define strdup(s) rte_strdup(s)
> > >    #endif
> > > 
> > > Thoughts on this?  
> > 
> > Looks good to me, I can rework the patchset like so.
> > 
> > Policy considerations:
> > 1. The approach only applies to platform-agnostic functions, like str*().
> >    Functions like sleep() still belong to librte_eal.
> > 2. Deprecated functions, like index(3p), should be replaced
> >    with alternatives suggested by the standard.
> > 3. If a standard C11 alternative is available, it should be used.
> >    This mostly applies to types, like u_int32 -> uint32_t
> >    (it's even in DPDK coding style already, isn't it?).
> > 
> > A nit: RTE_NO_XXX -> RTE_HAS_XXX (for consistency with existing macros)?  
> 
> Sure, thanks.

There's a meson issue with `cc.has_function()`:
https://github.com/mesonbuild/meson/issues/5628

What if we just define RTE_INTERNAL for librte_eal/windows/include/rte_os.h
(and other public headers if need be) to distinguish the case when it's used
from within DPDK?

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-02-27 20:23               ` Dmitry Kozlyuk
@ 2021-03-01 21:31                 ` Nick Connolly
  2021-03-02  0:22                   ` Dmitry Kozlyuk
  0 siblings, 1 reply; 56+ messages in thread
From: Nick Connolly @ 2021-03-01 21:31 UTC (permalink / raw)
  To: Dmitry Kozlyuk, Bruce Richardson
  Cc: dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori


> There's a meson issue with `cc.has_function()`:
> https://github.com/mesonbuild/meson/issues/5628
>
> What if we just define RTE_INTERNAL for librte_eal/windows/include/rte_os.h
> (and other public headers if need be) to distinguish the case when it's used
> from within DPDK?
It's a pragmatic solution to the problem, but sadly it's not quite as 
clean as letting the build system determine if each 'wrapper' is needed. 
DPDK supports a variety of platforms and toolsets and my experience with 
SPDK suggests that we'll end up with compiler specific ifdef's. It's all 
protected by RTE_INTERNAL so it's not really a problem, but I wonder if 
it makes it easier for someone to accidentally introduce definitions 
outside of the #ifdef RTE_INTERNAL?

How about a new header rte_os_internal.h that contains the 'wrappers'? 
It gets included from rte_os.h only if RTE_INTERNAL is set and doesn't 
get installed so can't impact the user environment. I'm not sure I like 
it, but I guess we could do the same thing for every header that needs 
wrappers. I'm really 'thinking aloud' here and I'm not convinced it's 
the best route forward, so feel free to ignore. What I'm searching for 
is a way of wrapping that's clean and has a reasonably low risk of 
future human error.

Regards,
Nick


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-03-01 21:31                 ` Nick Connolly
@ 2021-03-02  0:22                   ` Dmitry Kozlyuk
  2021-03-02 11:27                     ` Nick Connolly
  0 siblings, 1 reply; 56+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-02  0:22 UTC (permalink / raw)
  To: Nick Connolly
  Cc: Bruce Richardson, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori

2021-03-01 21:31, Nick Connolly:
> > There's a meson issue with `cc.has_function()`:
> > https://github.com/mesonbuild/meson/issues/5628
> >
> > What if we just define RTE_INTERNAL for librte_eal/windows/include/rte_os.h
> > (and other public headers if need be) to distinguish the case when it's used
> > from within DPDK?  
> It's a pragmatic solution to the problem, but sadly it's not quite as 
> clean as letting the build system determine if each 'wrapper' is needed. 
> DPDK supports a variety of platforms and toolsets and my experience with 
> SPDK suggests that we'll end up with compiler specific ifdef's.

I'd argue they are inevitable. Consider POSIX close(): if it's missing, what
would be a correct fallback? It depends on the execution environment (OS).
String function fallbacks, of course, are easily implemented from scratch.

> It's all 
> protected by RTE_INTERNAL so it's not really a problem, but I wonder if 
> it makes it easier for someone to accidentally introduce definitions 
> outside of the #ifdef RTE_INTERNAL?

Public functions without rte_ prefix shall not be introduced at all.

Remember the issue this patchset targets: export of POSIX symbols from EAL.
They are already defined in a way DPDK consumes successfully. RTE_INTERNAL
is a straightforward way to ensure symbols affect to other consumers.
(I'm talking about macros; asprintf should be moved inside EAL in any case.)


^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions
  2021-03-02  0:22                   ` Dmitry Kozlyuk
@ 2021-03-02 11:27                     ` Nick Connolly
  0 siblings, 0 replies; 56+ messages in thread
From: Nick Connolly @ 2021-03-02 11:27 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: Bruce Richardson, dev, Tyler Retzlaff, Jerin Jacob, Sunil Kumar Kori


>
>> DPDK supports a variety of platforms and toolsets and my experience with
>> SPDK suggests that we'll end up with compiler specific ifdef's.
> I'd argue they are inevitable. Consider POSIX close(): if it's missing, what
> would be a correct fallback? It depends on the execution environment (OS).
> String function fallbacks, of course, are easily implemented from scratch.
Agreed.

>> Public functions without rte_ prefix shall not be introduced at all.
Agreed. Perhaps as a separate patch we should consider validation rules 
to enforce the requirements.

Regards,
Nick

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] eal/windows: do not expose POSIX symbols
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (6 preceding siblings ...)
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-03-04  6:46     ` Khoa To
  7 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:46 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Kadam, Pallavi, Tyler Retzlaff, Nick Connolly


> On Windows, rte_os.h contains a small POSIX compatibility set of
> functions and macros. Exposing it from EAL can break consumer own POSIX
> compatibility layer and is against standards in general.
> 
> First define required wrappers, then fix POSIX dependencies in
> Windows-enabled libraries and drivers, then eliminate POSIX symbols from
> Windows EAL API. Commits are arranged so that they all compile and are
> limited in scope; patches 5, 6, 7 can be squashed if needed.
> 
> No "Fixes" tags, because it's really an enhancement,
> preventing issues rather then solving direct ones.
> 
> v3:
>     * Fix indentation in 3/7 (Tal Shnaiderman).
>     * Fix build failures in 6/7 and 7/7 (Tal Shnaiderman).
> v2:
>     * Fix compilation issues in 3/7 and 6/7 (self).
> 

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 1/7] eal: add wrappers for POSIX string functions
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
  2021-02-23  7:11       ` Andrew Rybchenko
@ 2021-03-04  6:47       ` Khoa To
  1 sibling, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:47 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Jerin Jacob, Sunil Kumar Kori


> POSIX strncasecmp(), strdup(), and strtok_r() have different names
> on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
> 
> Add wrappers as inline functions, because they're used from librte_kvargs,
> and thus cannot be in librte_eal; besides, implementation is trivial.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 2/7] eal: add macro for maximum path length
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
@ 2021-03-04  6:47       ` Khoa To
  0 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:47 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Anatoly Burakov, Jerin Jacob,
	Sunil Kumar Kori, Bruce Richardson, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Kadam, Pallavi


> Path length limit is PATH_MAX on Unix and _MAX_PATH on Windows.
> Add RTE_PATH_MAX macro for use in OS-independent code. Keep
> PATH_MAX
> in "common" multiprocess code, because it's really Unix-specific.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL]  [PATCH v3 3/7] eal: add sleep API
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
  2021-02-23 22:06       ` Nick Connolly
@ 2021-03-04  6:47       ` Khoa To
  1 sibling, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:47 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Kadam, Pallavi, Ray Kinsella, Neil Horman


> POSIX sleep(3) is missing from Windows.
> Add generic rte_thread_sleep() to suspend current OS thread.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 4/7] eal: add asprintf() internal wrapper
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-03-04  6:48       ` Khoa To
  0 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:48 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Jerin Jacob, Sunil Kumar Kori,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Kadam, Pallavi

> POSIX asprintf() is unavailable on Windows.
> Add eal_asprintf() wrapper for EAL internal use.
> On Windows it's a function, on Unix it's a macro for asprintf().
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 5/7] lib: remove POSIX dependencies
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
@ 2021-03-04  6:48       ` Khoa To
  0 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:48 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Olivier Matz, thomas,
	Ferruh Yigit, Andrew Rybchenko

> Replace POSIX strtok_r() with EAL rte_strtok().
> Replace POSIX strdup()   with EAL rte_strdup().
> Locally rename Windows _close() to standard close().
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 6/7] drivers: remove POSIX dependencies
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk
@ 2021-03-04  6:49       ` Khoa To
  0 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:49 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Beilei Xing, Jeff Guo

> Replace POSIX strncasecmp() with EAL rte_strncasecmp().
> Replace POSIX strtok_r() with EAL rte_strtok().
> Replace POSIX strdup() with EAL rte_strdup().
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [dpdk-dev] [EXTERNAL] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols
  2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-03-04  6:49       ` Khoa To
  0 siblings, 0 replies; 56+ messages in thread
From: Khoa To @ 2021-03-04  6:49 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tal Shnaiderman, Dmitry Kozlyuk, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Kadam, Pallavi

> Exposing POSIX symbols could break consumer POSIX compatibility code.
> 
> * Make renaming of close() and unlink() private to EAL.
> 
> * Remove renaming of strncasecmp(), strtok_r(), and sleep()
>   in favor of using EAL wrappers. Similarly remove PATH_MAX macro.
> 
> * Replace index(3p), which is not available on Windows, with strchr(3),
>   as recommended by POSIX.1-2008. strerror_r() is only used inside EAL,
>   rename it only where it's needed. Same for asprintf(), it has an
>   internal EAL wrapper and is removed from public API.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Khoa To <khot@microsoft.com>

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2021-03-04  6:49 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 6/7] drivers: " Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
2021-02-22 11:47     ` Bruce Richardson
2021-02-22 12:48       ` Nick Connolly
2021-02-22 14:26         ` Bruce Richardson
2021-02-22 18:21           ` Nick Connolly
2021-02-22 22:57           ` Dmitry Kozlyuk
2021-02-23  9:45             ` Bruce Richardson
2021-02-27 20:23               ` Dmitry Kozlyuk
2021-03-01 21:31                 ` Nick Connolly
2021-03-02  0:22                   ` Dmitry Kozlyuk
2021-03-02 11:27                     ` Nick Connolly
2021-02-22 18:07         ` Tyler Retzlaff
2021-02-22 18:36           ` Nick Connolly
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-21  8:58     ` Tal Shnaiderman
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk
2021-02-21  8:59     ` Tal Shnaiderman
2021-02-21 15:54       ` Andrew Rybchenko
2021-02-21 17:05         ` Dmitry Kozlyuk
2021-02-21  1:28   ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-21  8:59     ` Tal Shnaiderman
2021-02-21 10:24       ` Dmitry Kozlyuk
2021-02-21 11:58         ` Tal Shnaiderman
2021-02-21 14:33           ` Dmitry Kozlyuk
2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
2021-02-23  7:11       ` Andrew Rybchenko
2021-02-23 21:53         ` Nick Connolly
2021-02-24  7:21           ` Andrew Rybchenko
2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-23 22:06       ` Nick Connolly
2021-03-04  6:47       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-03-04  6:48       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-03-04  6:48       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk
2021-03-04  6:49       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28     ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-04  6:49       ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-03-04  6:46     ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git