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
                   ` (8 more replies)
  0 siblings, 9 replies; 132+ 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] 132+ 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
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 132+ 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] 132+ 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
  2021-03-17 19:19 ` [dpdk-dev] [PATCH 0/7] " Ranjit Menon
  8 siblings, 0 replies; 132+ 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] 132+ 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)
  2021-03-17 19:19 ` [dpdk-dev] [PATCH 0/7] " Ranjit Menon
  8 siblings, 8 replies; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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
                       ` (8 more replies)
  7 siblings, 9 replies; 132+ 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] 132+ 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
                       ` (7 subsequent siblings)
  8 siblings, 2 replies; 132+ 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] 132+ 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
                       ` (6 subsequent siblings)
  8 siblings, 1 reply; 132+ 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] 132+ 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
                       ` (5 subsequent siblings)
  8 siblings, 2 replies; 132+ 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] 132+ 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
                       ` (4 subsequent siblings)
  8 siblings, 1 reply; 132+ 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] 132+ 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
                       ` (3 subsequent siblings)
  8 siblings, 1 reply; 132+ 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] 132+ 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
                       ` (2 subsequent siblings)
  8 siblings, 1 reply; 132+ 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] 132+ 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
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
  8 siblings, 1 reply; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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
  2021-03-16  9:51                 ` Thomas Monjalon
  0 siblings, 2 replies; 132+ 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] 132+ 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
  2021-03-16  9:51                 ` Thomas Monjalon
  1 sibling, 1 reply; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
  8 siblings, 0 replies; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ 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; 132+ 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] 132+ messages in thread

* [dpdk-dev] [PATCH v4 0/4] eal/windows: do not expose POSIX symbols
  2021-02-21 14:28   ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
                       ` (7 preceding siblings ...)
  2021-03-04  6:46     ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To
@ 2021-03-06  0:04     ` Dmitry Kozlyuk
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk
                         ` (5 more replies)
  8 siblings, 6 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-06  0:04 UTC (permalink / raw)
  To: dev; +Cc: Nick Connolly, Khoa To, Dmitry Kozlyuk

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.
Hide these symbols from external consumers, while keeping them available
for DPDK code.

v4:
    * Instead of creating wrappers and replacing POSIX names in lib/ and
      drivers/, provide POSIX names only to internal consumers.
    * Move renaming from librte_cmdline to librte_eal.

Dmitry Kozlyuk (4):
  eal: add sleep API
  eal: add asprintf() internal wrapper
  build: indicate usage at build time for public headers
  eal/windows: do not expose POSIX symbols

 config/meson.build                            |   3 +
 doc/guides/rel_notes/release_21_05.rst        |   3 +
 lib/librte_cmdline/cmdline.c                  |   4 -
 lib/librte_cmdline/cmdline_socket.c           |   4 -
 lib/librte_eal/common/eal_common_errno.c      |   4 +
 lib/librte_eal/common/eal_common_lcore.c      |   2 +-
 lib/librte_eal/common/eal_common_options.c    |  10 +-
 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  |   2 +-
 .../common/eal_common_trace_utils.c           |   2 +-
 lib/librte_eal/common/eal_private.h           |  18 +++
 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.c                  |  30 +++++
 lib/librte_eal/windows/eal_thread.c           |   9 +-
 lib/librte_eal/windows/include/rte_os.h       | 103 ++++--------------
 19 files changed, 122 insertions(+), 105 deletions(-)

-- 
2.29.2


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

* [dpdk-dev] [PATCH v4 1/4] eal: add sleep API
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
@ 2021-03-06  0:04       ` Dmitry Kozlyuk
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk
                         ` (4 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-06  0:04 UTC (permalink / raw)
  To: dev
  Cc: Nick Connolly, Khoa To, 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>
Acked-by: Khoa To <khot@microsoft.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] 132+ messages in thread

* [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk
@ 2021-03-06  0:04       ` Dmitry Kozlyuk
  2021-03-06 15:27         ` Lance Richardson
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk
                         ` (3 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-06  0:04 UTC (permalink / raw)
  To: dev
  Cc: Nick Connolly, Khoa To, 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>
Acked-by: Khoa To <khot@microsoft.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 622c7bc42..230bac9f3 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 33e419aac..f64ca9496 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 64f58fb66..e32237b8e 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 b8a0d2002..323240dd7 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -745,4 +745,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 2fc3d6141..162671f9c 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>
@@ -411,6 +413,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] 132+ messages in thread

* [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-03-06  0:04       ` Dmitry Kozlyuk
  2021-03-16  9:59         ` Thomas Monjalon
  2021-03-06  0:05       ` [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                         ` (2 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-06  0:04 UTC (permalink / raw)
  To: dev; +Cc: Nick Connolly, Khoa To, Dmitry Kozlyuk, Bruce Richardson

DPDK code often relies on functions that are not standard C,
but are found on all platforms, even if by slightly different names.
Some headers provide macros or inline difinitions for such symbols.
However, when placed in public headers, these symbols are unnecessarily
exposed to DPDK consumers.

Define RTE_BUILD_INTERNAL at build time.
In its presense public headers can provide additional definitions
for internal code, but hide them from external consumers.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 config/meson.build | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/config/meson.build b/config/meson.build
index 3cf560b8a..51a49855c 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -287,6 +287,9 @@ dpdk_conf.set('RTE_EAL_VFIO', is_linux)
 # specify -D_GNU_SOURCE unconditionally
 add_project_arguments('-D_GNU_SOURCE', language: 'c')
 
+# specify that sources are building as part of DPDK
+add_project_arguments('-DRTE_BUILD_INTERNAL', language: 'c')
+
 # specify -D__BSD_VISIBLE for FreeBSD
 if is_freebsd
 	add_project_arguments('-D__BSD_VISIBLE', language: 'c')
-- 
2.29.2


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

* [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
                         ` (2 preceding siblings ...)
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk
@ 2021-03-06  0:05       ` Dmitry Kozlyuk
  2021-03-17 19:23       ` [dpdk-dev] [PATCH v4 0/4] " Ranjit Menon
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-06  0:05 UTC (permalink / raw)
  To: dev
  Cc: Nick Connolly, Khoa To, Dmitry Kozlyuk, Olivier Matz,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Exposing POSIX symbols could break consumer POSIX compatibility code.
Export POSIX names for commonly used symbols only to internal consumers.
Move definitions used only by EAL inside EAL.
Replace deprecated [r]index() with standard str[r]chr().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 doc/guides/rel_notes/release_21_05.rst     |   3 +
 lib/librte_cmdline/cmdline.c               |   4 -
 lib/librte_cmdline/cmdline_socket.c        |   4 -
 lib/librte_eal/common/eal_common_errno.c   |   4 +
 lib/librte_eal/common/eal_common_options.c |   2 +-
 lib/librte_eal/windows/include/rte_os.h    | 103 ++++-----------------
 6 files changed, 27 insertions(+), 93 deletions(-)

diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst
index 5aa9ed7db..f606186ec 100644
--- a/doc/guides/rel_notes/release_21_05.rst
+++ b/doc/guides/rel_notes/release_21_05.rst
@@ -84,6 +84,9 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* eal/windows: Removed POSIX symbol export from ``<rte_os.h>``.
+  It has been incorrect and could conflict with consumer POSIX implementations.
+
 
 ABI Changes
 -----------
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c..49770869b 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe149700..998e8ade2 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823..f86802705 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#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 230bac9f3..6d4d6ff19 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/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06..d97e07890 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -11,7 +11,6 @@
  * Windows OS. It must not include Windows-specific headers.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -20,100 +19,36 @@
 extern "C" {
 #endif
 
-/* 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> */
-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++;
+/* Allow DPDK to call common functions by POSIX names. */
+#ifdef RTE_BUILD_INTERNAL
 
-	*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;
-}
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
 
-static inline const char *
-eal_strerror(int code)
-{
-	static char buffer[128];
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
 
-	strerror_s(buffer, sizeof(buffer), code);
-	return buffer;
-}
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
 
-#ifndef strerror
-#define strerror eal_strerror
-#endif
+#endif /* RTE_BUILD_INTERNAL */
 
-#endif /* RTE_TOOLCHAIN_GCC */
+/* 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;
 
 #ifdef __cplusplus
 }
-- 
2.29.2


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

* Re: [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk
@ 2021-03-06 15:27         ` Lance Richardson
  0 siblings, 0 replies; 132+ messages in thread
From: Lance Richardson @ 2021-03-06 15:27 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Nick Connolly, Khoa To, Jerin Jacob, Sunil Kumar Kori,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

[-- Attachment #1: Type: text/plain, Size: 460 bytes --]

On Fri, Mar 5, 2021 at 7:05 PM Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> wrote:
>
> POSIX asprintf() is unavailable on Windows.

AFAIK asprintf() is not a POSIX API, it is a GNU extension that has
also been implemented in some BSDs.

> 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] 132+ 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-16  9:51                 ` Thomas Monjalon
  1 sibling, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-16  9:51 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: Bruce Richardson, dev, Nick Connolly, dev, Tyler Retzlaff,
	Jerin Jacob, Sunil Kumar Kori

27/02/2021 21:23, Dmitry Kozlyuk:
> 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

The meson issue can be fixed or workarounded probably.
Is it the reason for the RTE_INTERNAL proposal below?

> 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?

I'm not sure to follow the need for RTE_INTERNAL.

In general, 3 guidelines:
	- avoid inline functions in public headers
	- mark exported internal functions with __rte_internal and in version.map
	- export internal functions in a separate file



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

* Re: [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers
  2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk
@ 2021-03-16  9:59         ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-16  9:59 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: dev, Nick Connolly, Khoa To, Bruce Richardson

06/03/2021 01:04, Dmitry Kozlyuk:
> DPDK code often relies on functions that are not standard C,
> but are found on all platforms, even if by slightly different names.
> Some headers provide macros or inline difinitions for such symbols.
> However, when placed in public headers, these symbols are unnecessarily
> exposed to DPDK consumers.
> 
> Define RTE_BUILD_INTERNAL at build time.
> In its presense public headers can provide additional definitions
> for internal code, but hide them from external consumers.

Is there a way to split public and internal headers,
and avoid playing with RTE_BUILD_INTERNAL?




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

* Re: [dpdk-dev] [PATCH 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
                   ` (7 preceding siblings ...)
  2021-02-21  1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
@ 2021-03-17 19:19 ` Ranjit Menon
  8 siblings, 0 replies; 132+ messages in thread
From: Ranjit Menon @ 2021-03-17 19:19 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Nick Connolly, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

On 2/20/2021 3:29 PM, Dmitry Kozlyuk wrote:
> 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(-)
>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>



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

* Re: [dpdk-dev] [PATCH v4 0/4] eal/windows: do not expose POSIX symbols
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
                         ` (3 preceding siblings ...)
  2021-03-06  0:05       ` [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-03-17 19:23       ` Ranjit Menon
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Ranjit Menon @ 2021-03-17 19:23 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev; +Cc: Nick Connolly, Khoa To

On 3/5/2021 4:04 PM, Dmitry Kozlyuk wrote:
> 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.
> Hide these symbols from external consumers, while keeping them available
> for DPDK code.
>
> v4:
>      * Instead of creating wrappers and replacing POSIX names in lib/ and
>        drivers/, provide POSIX names only to internal consumers.
>      * Move renaming from librte_cmdline to librte_eal.
>
> Dmitry Kozlyuk (4):
>    eal: add sleep API
>    eal: add asprintf() internal wrapper
>    build: indicate usage at build time for public headers
>    eal/windows: do not expose POSIX symbols
>
>   config/meson.build                            |   3 +
>   doc/guides/rel_notes/release_21_05.rst        |   3 +
>   lib/librte_cmdline/cmdline.c                  |   4 -
>   lib/librte_cmdline/cmdline_socket.c           |   4 -
>   lib/librte_eal/common/eal_common_errno.c      |   4 +
>   lib/librte_eal/common/eal_common_lcore.c      |   2 +-
>   lib/librte_eal/common/eal_common_options.c    |  10 +-
>   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  |   2 +-
>   .../common/eal_common_trace_utils.c           |   2 +-
>   lib/librte_eal/common/eal_private.h           |  18 +++
>   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.c                  |  30 +++++
>   lib/librte_eal/windows/eal_thread.c           |   9 +-
>   lib/librte_eal/windows/include/rte_os.h       | 103 ++++--------------
>   19 files changed, 122 insertions(+), 105 deletions(-)
>
Sorry, ack-ed the v1 of this patch series by mistake. This is the real ACK!


Acked-by: Ranjit Menon <ranjit.menon@intel.com>



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

* [dpdk-dev] [PATCH v5 0/5] eal/windows: do not expose POSIX symbols
  2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
                         ` (4 preceding siblings ...)
  2021-03-17 19:23       ` [dpdk-dev] [PATCH v4 0/4] " Ranjit Menon
@ 2021-03-20 11:27       ` Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
                           ` (5 more replies)
  5 siblings, 6 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev; +Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v5:
    * Unify series with removing Windows networking shim
      to eliminate dependency between series and CI failures.
    * RTE_BUILD_INTERNAL -> rte_os_internal.h (Thomas Monjalon).
    * Remove release notes: hidden symbols were never part of API.

v4:
    * Instead of creating wrappers and replacing POSIX names in lib/ and
      drivers/, provide POSIX names only to internal consumers.
    * Move renaming from librte_cmdline to librte_eal.

Dmitry Kozlyuk (5):
  eal: add sleep API
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: provide IP-related API on any OS
  net: replace Windows networking shim

 drivers/bus/pci/private.h                     |  4 +-
 drivers/bus/vdev/vdev_private.h               |  2 +
 drivers/common/mlx5/mlx5_common.h             |  1 +
 drivers/net/i40e/i40e_ethdev.c                |  1 +
 drivers/net/i40e/i40e_fdir.c                  |  1 +
 drivers/net/mlx5/mlx5.h                       |  2 +-
 drivers/net/mlx5/mlx5_flow.c                  |  4 +-
 drivers/net/mlx5/mlx5_flow.h                  |  4 +-
 drivers/net/mlx5/mlx5_mac.c                   |  1 -
 examples/cmdline/commands.c                   |  5 -
 examples/cmdline/parse_obj_list.c             |  2 -
 lib/librte_cmdline/cmdline.c                  |  5 -
 lib/librte_cmdline/cmdline_os_windows.c       |  2 -
 lib/librte_cmdline/cmdline_parse.c            |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c  |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c     |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h     |  2 +-
 lib/librte_cmdline/cmdline_private.h          |  1 +
 lib/librte_cmdline/cmdline_socket.c           |  4 -
 lib/librte_eal/common/eal_common_config.c     |  1 -
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_options.c    |  2 +-
 lib/librte_eal/common/eal_common_timer.c      |  5 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  1 +
 lib/librte_eal/common/eal_private.h           | 11 +++
 .../freebsd/include/rte_os_internal.h         | 14 +++
 lib/librte_eal/include/rte_thread.h           | 11 +++
 .../linux/include/rte_os_internal.h           | 14 +++
 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_hugepages.c        |  1 -
 lib/librte_eal/windows/eal_lcore.c            |  1 -
 lib/librte_eal/windows/eal_memalloc.c         |  1 -
 lib/librte_eal/windows/eal_thread.c           |  9 +-
 lib/librte_eal/windows/include/arpa/inet.h    | 30 ------
 lib/librte_eal/windows/include/netinet/in.h   | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h   | 10 --
 lib/librte_eal/windows/include/rte_os.h       | 92 +------------------
 .../windows/include/rte_os_internal.h         | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h   | 24 -----
 lib/librte_ethdev/ethdev_private.h            |  2 +
 lib/librte_ethdev/rte_ethdev.c                | 13 +--
 lib/librte_ethdev/rte_ethdev_core.h           |  1 -
 lib/librte_kvargs/rte_kvargs.c                |  1 +
 lib/librte_net/rte_ether.h                    | 26 ++++--
 lib/librte_net/rte_ip.h                       |  7 ++
 lib/librte_net/rte_net.c                      |  1 +
 49 files changed, 202 insertions(+), 254 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.2


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

* [dpdk-dev] [PATCH v5 1/5] eal: add sleep API
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
@ 2021-03-20 11:27         ` Dmitry Kozlyuk
  2021-03-22  8:57           ` Kinsella, Ray
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                           ` (4 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Khoa To,
	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>
Acked-by: Khoa To <khot@microsoft.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 71e0bd035a..0e89a4f7df 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 e640ea1857..f0c12dd79d 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 474cf123fa..494240b940 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 86ffeebc95..91babfe887 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 756c60ed1d..823c6639ec 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -419,6 +419,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 9c3f6d69fd..c84e67009c 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] 132+ messages in thread

* [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
@ 2021-03-20 11:27         ` Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal Dmitry Kozlyuk
                           ` (3 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Khoa To,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
---
 lib/librte_eal/common/eal_private.h | 11 +++++++++++
 lib/librte_eal/windows/eal.c        | 30 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..31eda4d2da 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..162671f9ce 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>
@@ -411,6 +413,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] 132+ messages in thread

* [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-03-20 11:27         ` Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
                           ` (2 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing, Jeff Guo,
	Olivier Matz, Bruce Richardson, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Thomas Monjalon, Ferruh Yigit,
	Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move all shims to <rte_os_internal.h>, a header to be used instead of
<rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/bus/pci/private.h                     |  4 +-
 drivers/bus/vdev/vdev_private.h               |  2 +
 drivers/common/mlx5/mlx5_common.h             |  1 +
 drivers/net/i40e/i40e_ethdev.c                |  1 +
 lib/librte_cmdline/cmdline.c                  |  4 -
 lib/librte_cmdline/cmdline_os_windows.c       |  2 -
 lib/librte_cmdline/cmdline_private.h          |  1 +
 lib/librte_cmdline/cmdline_socket.c           |  4 -
 lib/librte_eal/common/eal_common_config.c     |  1 -
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_options.c    |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  1 +
 .../freebsd/include/rte_os_internal.h         | 14 +++
 .../linux/include/rte_os_internal.h           | 14 +++
 lib/librte_eal/windows/eal_hugepages.c        |  1 -
 lib/librte_eal/windows/eal_lcore.c            |  1 -
 lib/librte_eal/windows/eal_memalloc.c         |  1 -
 lib/librte_eal/windows/include/rte_os.h       | 92 +------------------
 .../windows/include/rte_os_internal.h         | 28 ++++++
 lib/librte_ethdev/ethdev_private.h            |  2 +
 lib/librte_kvargs/rte_kvargs.c                |  1 +
 21 files changed, 77 insertions(+), 104 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..d95e6f71a2 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_internal.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..1a60c1b5d2 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_internal.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 3855582d0d..14b061690f 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_internal.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7cd049891..0719504e24 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_internal.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..ca45db9493 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_internal.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#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 622c7bc429..28da464fc9 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_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..fc7cb3efaf 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_internal.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_internal.h b/lib/librte_eal/freebsd/include/rte_os_internal.h
new file mode 100644
index 0000000000..cabe9648fa
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_internal.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/linux/include/rte_os_internal.h b/lib/librte_eal/linux/include/rte_os_internal.h
new file mode 100644
index 0000000000..cabe9648fa
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_internal.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06c..8d845c57b7 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -11,7 +11,6 @@
  * Windows OS. It must not include Windows-specific headers.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -20,101 +19,18 @@
 extern "C" {
 #endif
 
-/* 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
diff --git a/lib/librte_eal/windows/include/rte_os_internal.h b/lib/librte_eal/windows/include/rte_os_internal.h
new file mode 100644
index 0000000000..84e39eb2ae
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_internal.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 905a45c337..bd601072fa 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_internal.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86c..f5221a2f71 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <rte_os_internal.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.2


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

* [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
                           ` (2 preceding siblings ...)
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-03-20 11:27         ` Dmitry Kozlyuk
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim Dmitry Kozlyuk
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Olivier Matz,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constatns, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX include
in components enabled on Windows.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/net/mlx5/mlx5.h                      |  2 +-
 drivers/net/mlx5/mlx5_flow.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.h                 |  4 ++--
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 -----
 examples/cmdline/parse_obj_list.c            |  2 --
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ------
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ------
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_ethdev/rte_ethdev.c               | 13 +++++--------
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  3 +++
 14 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index a281fd20ea..f04da06abd 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
+
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index ab5be3dacc..73253bd39e 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,13 +3,13 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
 
+#include <sys/queue.h>
+
 #include <rte_common.h>
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8324e188e1..c4e5f19faa 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,12 +5,12 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 
+#include <sys/queue.h>
+
 #include <rte_alarm.h>
 #include <rte_mtr.h>
 
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index 6ffcfcd97a..f0450735e2 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388b..f363794369 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,15 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 212ff2c4fd..2cf7b0bd28 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,7 +16,10 @@
  */
 
 #include <stdint.h>
+
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 
-- 
2.29.2


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

* [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
                           ` (3 preceding siblings ...)
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-03-20 11:27         ` Dmitry Kozlyuk
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 11:27 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Ranjit Menon,
	Beilei Xing, Jeff Guo, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Olivier Matz

Remove networking shim from Windows EAL.

Replace it with system headers with two workarounds:

1. Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
   conflicts with `s_addr` field of `struct rte_ether_hdr`. Undefining
   this macro in <rte_ether.h> had been breaking some usages of DPDK
   and Windows headers in one file.

   Renaming is planned:
   https://mails.dpdk.org/archives/dev/2021-March/201444.html

   Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
   definition to avoid conflict. Place source MAC address in both
   `s_addr` and `S_un.S_addr` fields, so that access works either
   directly or through the macro.

2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
---
 drivers/net/i40e/i40e_fdir.c                  |  1 +
 lib/librte_eal/windows/include/arpa/inet.h    | 30 ---------------
 lib/librte_eal/windows/include/netinet/in.h   | 38 -------------------
 lib/librte_eal/windows/include/netinet/ip.h   | 10 -----
 .../windows/include/rte_os_internal.h         |  8 ++++
 lib/librte_eal/windows/include/sys/socket.h   | 24 ------------
 lib/librte_net/rte_ether.h                    | 26 ++++++++++---
 lib/librte_net/rte_ip.h                       |  4 ++
 lib/librte_net/rte_net.c                      |  1 +
 9 files changed, 34 insertions(+), 108 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index c572d003cb..b8960ff5a3 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_internal.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_internal.h b/lib/librte_eal/windows/include/rte_os_internal.h
index 84e39eb2ae..89ac5c9cbd 100644
--- a/lib/librte_eal/windows/include/rte_os_internal.h
+++ b/lib/librte_eal/windows/include/rte_os_internal.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 2cf7b0bd28..3c24bc4ca4 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -17,11 +17,15 @@
 
 #include <stdint.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..b615f8f839 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_internal.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.2


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

* [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols
  2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
                           ` (4 preceding siblings ...)
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim Dmitry Kozlyuk
@ 2021-03-20 13:05         ` Dmitry Kozlyuk
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk
                             ` (5 more replies)
  5 siblings, 6 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev; +Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v6:
    * Rebase on ToT to resolve conflicts.

v5:
    * Unify series with removing Windows networking shim
      to eliminate dependency between series and CI failures.
    * RTE_BUILD_INTERNAL -> rte_os_internal.h (Thomas Monjalon).
    * Remove release notes: hidden symbols were never part of API.

Dmitry Kozlyuk (5):
  eal: add sleep API
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: provide IP-related API on any OS
  net: replace Windows networking shim

 drivers/bus/pci/private.h                     |  4 +-
 drivers/bus/vdev/vdev_private.h               |  2 +
 drivers/common/mlx5/mlx5_common.h             |  1 +
 drivers/net/i40e/i40e_ethdev.c                |  1 +
 drivers/net/i40e/i40e_fdir.c                  |  1 +
 drivers/net/mlx5/mlx5.h                       |  2 +-
 drivers/net/mlx5/mlx5_flow.c                  |  4 +-
 drivers/net/mlx5/mlx5_flow.h                  |  4 +-
 drivers/net/mlx5/mlx5_mac.c                   |  1 -
 examples/cmdline/commands.c                   |  5 -
 examples/cmdline/parse_obj_list.c             |  2 -
 lib/librte_cmdline/cmdline.c                  |  5 -
 lib/librte_cmdline/cmdline_os_windows.c       |  2 -
 lib/librte_cmdline/cmdline_parse.c            |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c  |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c     |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h     |  2 +-
 lib/librte_cmdline/cmdline_private.h          |  1 +
 lib/librte_cmdline/cmdline_socket.c           |  4 -
 lib/librte_eal/common/eal_common_config.c     |  1 -
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_options.c    |  2 +-
 lib/librte_eal/common/eal_common_timer.c      |  5 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  1 +
 lib/librte_eal/common/eal_private.h           | 11 +++
 .../freebsd/include/rte_os_internal.h         | 14 +++
 lib/librte_eal/include/rte_thread.h           | 11 +++
 .../linux/include/rte_os_internal.h           | 14 +++
 lib/librte_eal/rte_eal_exports.def            |  2 +
 lib/librte_eal/unix/rte_thread.c              | 10 +-
 lib/librte_eal/version.map                    |  1 +
 lib/librte_eal/windows/eal.c                  | 30 ++++++
 lib/librte_eal/windows/eal_hugepages.c        |  1 -
 lib/librte_eal/windows/eal_lcore.c            |  1 -
 lib/librte_eal/windows/eal_memalloc.c         |  1 -
 lib/librte_eal/windows/eal_thread.c           |  9 +-
 lib/librte_eal/windows/include/arpa/inet.h    | 30 ------
 lib/librte_eal/windows/include/netinet/in.h   | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h   | 10 --
 lib/librte_eal/windows/include/rte_os.h       | 92 +------------------
 .../windows/include/rte_os_internal.h         | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h   | 24 -----
 lib/librte_ethdev/ethdev_private.h            |  2 +
 lib/librte_ethdev/rte_ethdev.c                | 13 +--
 lib/librte_ethdev/rte_ethdev_core.h           |  1 -
 lib/librte_kvargs/rte_kvargs.c                |  1 +
 lib/librte_net/rte_ether.h                    | 26 ++++--
 lib/librte_net/rte_ip.h                       |  7 ++
 lib/librte_net/rte_net.c                      |  1 +
 49 files changed, 200 insertions(+), 254 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.3


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

* [dpdk-dev] [PATCH v6 1/5] eal: add sleep API
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-03-20 13:05           ` Dmitry Kozlyuk
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                             ` (4 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Khoa To,
	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>
Acked-by: Khoa To <khot@microsoft.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               |  1 +
 lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
 6 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035a..0e89a4f7df 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 e640ea1857..f0c12dd79d 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 474cf123fa..494240b940 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 86ffeebc95..91babfe887 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 48a2b55d57..da527f41bf 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -415,6 +415,7 @@ EXPERIMENTAL {
 	rte_thread_tls_value_set;
 
 	# added in 21.05
+	rte_thread_sleep;
 	rte_version_minor;
 	rte_version_month;
 	rte_version_prefix;
diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c
index 9c3f6d69fd..c84e67009c 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.3


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

* [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk
@ 2021-03-20 13:05           ` Dmitry Kozlyuk
  2021-03-26  9:04             ` Thomas Monjalon
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk
                             ` (3 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Khoa To,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
---
 lib/librte_eal/common/eal_private.h | 11 +++++++++++
 lib/librte_eal/windows/eal.c        | 30 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..31eda4d2da 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..162671f9ce 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>
@@ -411,6 +413,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.3


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

* [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-03-20 13:05           ` Dmitry Kozlyuk
  2021-03-26  9:12             ` Thomas Monjalon
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
                             ` (2 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing, Jeff Guo,
	Olivier Matz, Bruce Richardson, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Thomas Monjalon, Ferruh Yigit,
	Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move all shims to <rte_os_internal.h>, a header to be used instead of
<rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/bus/pci/private.h                     |  4 +-
 drivers/bus/vdev/vdev_private.h               |  2 +
 drivers/common/mlx5/mlx5_common.h             |  1 +
 drivers/net/i40e/i40e_ethdev.c                |  1 +
 lib/librte_cmdline/cmdline.c                  |  4 -
 lib/librte_cmdline/cmdline_os_windows.c       |  2 -
 lib/librte_cmdline/cmdline_private.h          |  1 +
 lib/librte_cmdline/cmdline_socket.c           |  4 -
 lib/librte_eal/common/eal_common_config.c     |  1 -
 lib/librte_eal/common/eal_common_errno.c      |  4 +
 lib/librte_eal/common/eal_common_options.c    |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h      |  1 +
 .../freebsd/include/rte_os_internal.h         | 14 +++
 .../linux/include/rte_os_internal.h           | 14 +++
 lib/librte_eal/windows/eal_hugepages.c        |  1 -
 lib/librte_eal/windows/eal_lcore.c            |  1 -
 lib/librte_eal/windows/eal_memalloc.c         |  1 -
 lib/librte_eal/windows/include/rte_os.h       | 92 +------------------
 .../windows/include/rte_os_internal.h         | 28 ++++++
 lib/librte_ethdev/ethdev_private.h            |  2 +
 lib/librte_kvargs/rte_kvargs.c                |  1 +
 21 files changed, 77 insertions(+), 104 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_internal.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_internal.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..d95e6f71a2 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_internal.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..1a60c1b5d2 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_internal.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 3855582d0d..14b061690f 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_internal.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index d7cd049891..0719504e24 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_internal.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..ca45db9493 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_internal.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#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 622c7bc429..28da464fc9 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_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..fc7cb3efaf 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_internal.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_internal.h b/lib/librte_eal/freebsd/include/rte_os_internal.h
new file mode 100644
index 0000000000..cabe9648fa
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_internal.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/linux/include/rte_os_internal.h b/lib/librte_eal/linux/include/rte_os_internal.h
new file mode 100644
index 0000000000..cabe9648fa
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_internal.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06c..8d845c57b7 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -11,7 +11,6 @@
  * Windows OS. It must not include Windows-specific headers.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -20,101 +19,18 @@
 extern "C" {
 #endif
 
-/* 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
diff --git a/lib/librte_eal/windows/include/rte_os_internal.h b/lib/librte_eal/windows/include/rte_os_internal.h
new file mode 100644
index 0000000000..84e39eb2ae
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_internal.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_INTERNAL_H_
+#define _RTE_OS_INTERNAL_H_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 905a45c337..bd601072fa 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_internal.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86c..f5221a2f71 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <rte_os_internal.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.3


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

* [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                             ` (2 preceding siblings ...)
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-03-20 13:05           ` Dmitry Kozlyuk
  2021-03-26  9:22             ` Thomas Monjalon
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Olivier Matz,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constatns, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX include
in components enabled on Windows.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/net/mlx5/mlx5.h                      |  2 +-
 drivers/net/mlx5/mlx5_flow.c                 |  4 ++--
 drivers/net/mlx5/mlx5_flow.h                 |  4 ++--
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 -----
 examples/cmdline/parse_obj_list.c            |  2 --
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ------
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ------
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_ethdev/rte_ethdev.c               | 13 +++++--------
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  3 +++
 14 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index a281fd20ea..f04da06abd 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
+
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index ab5be3dacc..73253bd39e 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,13 +3,13 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
 
+#include <sys/queue.h>
+
 #include <rte_common.h>
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8324e188e1..c4e5f19faa 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,12 +5,12 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 
+#include <sys/queue.h>
+
 #include <rte_alarm.h>
 #include <rte_mtr.h>
 
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index 6ffcfcd97a..f0450735e2 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388b..f363794369 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,15 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 212ff2c4fd..2cf7b0bd28 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,7 +16,10 @@
  */
 
 #include <stdint.h>
+
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
 
-- 
2.29.3


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

* [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                             ` (3 preceding siblings ...)
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-03-20 13:05           ` Dmitry Kozlyuk
  2021-03-26  9:28             ` Thomas Monjalon
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-03-20 13:05 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Ranjit Menon,
	Beilei Xing, Jeff Guo, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Olivier Matz

Remove networking shim from Windows EAL.

Replace it with system headers with two workarounds:

1. Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
   conflicts with `s_addr` field of `struct rte_ether_hdr`. Undefining
   this macro in <rte_ether.h> had been breaking some usages of DPDK
   and Windows headers in one file.

   Renaming is planned:
   https://mails.dpdk.org/archives/dev/2021-March/201444.html

   Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
   definition to avoid conflict. Place source MAC address in both
   `s_addr` and `S_un.S_addr` fields, so that access works either
   directly or through the macro.

2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
---
 drivers/net/i40e/i40e_fdir.c                  |  1 +
 lib/librte_eal/windows/include/arpa/inet.h    | 30 ---------------
 lib/librte_eal/windows/include/netinet/in.h   | 38 -------------------
 lib/librte_eal/windows/include/netinet/ip.h   | 10 -----
 .../windows/include/rte_os_internal.h         |  8 ++++
 lib/librte_eal/windows/include/sys/socket.h   | 24 ------------
 lib/librte_net/rte_ether.h                    | 26 ++++++++++---
 lib/librte_net/rte_ip.h                       |  4 ++
 lib/librte_net/rte_net.c                      |  1 +
 9 files changed, 34 insertions(+), 108 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index c572d003cb..b8960ff5a3 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_internal.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_internal.h b/lib/librte_eal/windows/include/rte_os_internal.h
index 84e39eb2ae..89ac5c9cbd 100644
--- a/lib/librte_eal/windows/include/rte_os_internal.h
+++ b/lib/librte_eal/windows/include/rte_os_internal.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_INTERNAL_H_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 2cf7b0bd28..3c24bc4ca4 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -17,11 +17,15 @@
 
 #include <stdint.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..b615f8f839 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_internal.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.3


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

* Re: [dpdk-dev] [PATCH v5 1/5] eal: add sleep API
  2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
@ 2021-03-22  8:57           ` Kinsella, Ray
  0 siblings, 0 replies; 132+ messages in thread
From: Kinsella, Ray @ 2021-03-22  8:57 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Jie Zhou, Khoa To, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Neil Horman


On 20/03/2021 11:27, Dmitry Kozlyuk wrote:
> 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>
> ---
>  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]

Acked-by: Ray Kinsella <mdr@ashroe.eu>

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

* Re: [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-03-26  9:04             ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-26  9:04 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Dmitry Kozlyuk, Khoa To,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

20/03/2021 14:05, Dmitry Kozlyuk:
> Make asprintf(3) implementation for Windows private to EAL, so that it's
> hidden from external consumers. It is not exposed to internal consumers
> either, because they don't need asprintf() and also because callers from
> other modules would have no reliable way to free allocated memory.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Acked-by: Khoa To <khot@microsoft.com>
> ---
>  lib/librte_eal/common/eal_private.h | 11 +++++++++++
>  lib/librte_eal/windows/eal.c        | 30 +++++++++++++++++++++++++++++
>  2 files changed, 41 insertions(+)

It would be logic to remove the asprintf implementation from rte_os.h
in this patch.




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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-03-26  9:12             ` Thomas Monjalon
  2021-03-31 21:05               ` Nick Connolly
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-26  9:12 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

20/03/2021 14:05, Dmitry Kozlyuk:
> DPDK code often relies on functions and macros that are not standard C,
> but are found on all platforms, even if by slightly different names.
> Windows <rte_os.h> provided macros or inline definitions for such symbols.
> However, when placed in public header, these symbols were unnecessarily
> exposed, breaking consumer POSIX compatibility code.
> 
> Move all shims to <rte_os_internal.h>, a header to be used instead of
> <rte_os.h> by internal code. Include it in libraries and PMDs that
> previously imported shims from <rte_os.h>.

This shim could have been convenient for applications.
If not named "internal", we could export the header file
and allow apps including it.

Otherwise the app can recreate this file on its side,
it is not a big deal.
Opinions?



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

* Re: [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-03-26  9:22             ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-26  9:22 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Matan Azrad, Viacheslav Ovsiienko,
	Olivier Matz, Ferruh Yigit, Andrew Rybchenko, david.marchand

20/03/2021 14:05, Dmitry Kozlyuk:
> Users of <rte_ip.h> relied on it to provide IP-related defines,
> like IPPROTO_* constatns, but still had to include POSIX headers

typo: constants

> for inet_pton() and other standard IP-related facilities.
> 
> Extend <rte_ip.h> so that it is a single header to gain access
> to IP-related facilities on any OS. Use it to replace POSIX include
> in components enabled on Windows.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
[...]
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -10,7 +10,7 @@
>  #include <stdbool.h>
>  #include <stdint.h>
>  #include <limits.h>
> -#include <netinet/in.h>
> +
>  #include <sys/queue.h>

No need of blank space between system includes.
(same comments for other files)

> --- a/lib/librte_net/rte_ip.h
> +++ b/lib/librte_net/rte_ip.h
>  #include <stdint.h>
> +

That's an unneeded blank line.

> +#include <sys/socket.h>
>  #include <sys/types.h>
> +#include <arpa/inet.h>
>  #include <netinet/in.h>
>  #include <netinet/ip.h>

The benefit is not obvious because the removal of Windows code
is done in another patch.
Please could you re-arrange the patch to be more atomic?



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

* Re: [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk
@ 2021-03-26  9:28             ` Thomas Monjalon
  2021-04-01 23:03               ` Dmitry Kozlyuk
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-26  9:28 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Ranjit Menon, Beilei Xing,
	Jeff Guo, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Olivier Matz

20/03/2021 14:05, Dmitry Kozlyuk:
> Remove networking shim from Windows EAL.
> 
> Replace it with system headers with two workarounds:
> 
> 1. Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
>    conflicts with `s_addr` field of `struct rte_ether_hdr`. Undefining
>    this macro in <rte_ether.h> had been breaking some usages of DPDK
>    and Windows headers in one file.

I don't understand this last sentence.

> 
>    Renaming is planned:
>    https://mails.dpdk.org/archives/dev/2021-March/201444.html
> 
>    Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
>    definition to avoid conflict. Place source MAC address in both
>    `s_addr` and `S_un.S_addr` fields, so that access works either
>    directly or through the macro.

It could be a patch in itself.

> 
> 2. Provide some IPPROTO_* constants and IPVERSION, missing on Windows.

I think it belongs to previous patch about extending the IP-related API.

> --- a/drivers/net/i40e/i40e_fdir.c
> +++ b/drivers/net/i40e/i40e_fdir.c
> @@ -22,6 +22,7 @@
>  #include <rte_sctp.h>
>  #include <rte_hash_crc.h>
>  #include <rte_bitmap.h>
> +#include <rte_os_internal.h>

Why is it needed?

[...]
> --- a/lib/librte_net/rte_ip.h
> +++ b/lib/librte_net/rte_ip.h
> @@ -17,11 +17,15 @@
>  
>  #include <stdint.h>
>  
> +#ifdef RTE_EXEC_ENV_WINDOWS
> +#include <ws2tcpip.h>
> +#else
>  #include <sys/socket.h>
>  #include <sys/types.h>
>  #include <arpa/inet.h>
>  #include <netinet/in.h>
>  #include <netinet/ip.h>
> +#endif

Should be in previous patch about extending IP API to any OS.

> --- a/lib/librte_net/rte_net.c
> +++ b/lib/librte_net/rte_net.c
> @@ -15,6 +15,7 @@
>  #include <rte_gre.h>
>  #include <rte_mpls.h>
>  #include <rte_net.h>
> +#include <rte_os_internal.h>

Why is it needed?



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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-26  9:12             ` Thomas Monjalon
@ 2021-03-31 21:05               ` Nick Connolly
  2021-03-31 21:19                 ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Nick Connolly @ 2021-03-31 21:05 UTC (permalink / raw)
  To: Thomas Monjalon, Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam


> This shim could have been convenient for applications.
> If not named "internal", we could export the header file
> and allow apps including it.
>
> Otherwise the app can recreate this file on its side,
> it is not a big deal.
> Opinions?
Based on my experience with SPDK, I believe this would get messy
very quickly.

For example, a common usage is to redefine close to _close.
If the application is going to use sockets without requiring changes,
then a fake fd is needed to represent a socket and close has to
handle it as well ... which will clash with the 'simplistic' redefinition
to _close, so we'd need some way of turning these on/off
individually.

I think there are really only two models that are viable - either an
external POSIX layer that is used by everything (in the general case,
Cygwin would be an example), or a private implementation that is
not exposed publicly.

Keeping the implementation private is not just about keeping
POSIX out of the headers. It's about avoiding conflicts with the
application; e.g. making sure that any signal implementation can
co-exist with the application.

Regards,
Nick


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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-31 21:05               ` Nick Connolly
@ 2021-03-31 21:19                 ` Thomas Monjalon
  2021-03-31 21:45                   ` Nick Connolly
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-31 21:19 UTC (permalink / raw)
  To: Dmitry Kozlyuk, Nick Connolly
  Cc: dev, Tyler Retzlaff, Jie Zhou, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

31/03/2021 23:05, Nick Connolly:
> 
> > This shim could have been convenient for applications.
> > If not named "internal", we could export the header file
> > and allow apps including it.
> >
> > Otherwise the app can recreate this file on its side,
> > it is not a big deal.
> > Opinions?
> Based on my experience with SPDK, I believe this would get messy
> very quickly.
> 
> For example, a common usage is to redefine close to _close.
> If the application is going to use sockets without requiring changes,
> then a fake fd is needed to represent a socket and close has to
> handle it as well ... which will clash with the 'simplistic' redefinition
> to _close, so we'd need some way of turning these on/off
> individually.
> 
> I think there are really only two models that are viable - either an
> external POSIX layer that is used by everything (in the general case,
> Cygwin would be an example), or a private implementation that is
> not exposed publicly.
> 
> Keeping the implementation private is not just about keeping
> POSIX out of the headers. It's about avoiding conflicts with the
> application; e.g. making sure that any signal implementation can
> co-exist with the application.

I don't understand your point.
I am just proposing to allow some apps to explicitly include the shim
for their convenience in case they are fully based on DPDK and
understand the risk of conflict with some other code.



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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-31 21:19                 ` Thomas Monjalon
@ 2021-03-31 21:45                   ` Nick Connolly
  2021-03-31 21:55                     ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Nick Connolly @ 2021-03-31 21:45 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Bruce Richardson, Dmitry Kozlyuk, Dmitry Malloy, Jie Zhou,
	Narcisa Ana Maria Vasile, Olivier Matz, Pallavi Kadam,
	Tyler Retzlaff, dev

>
> I don't understand your point.
> I am just proposing to allow some apps to explicitly include the shim
> for their convenience in case they are fully based on DPDK and
> understand the risk of conflict with some other code.


Agreed - there’s no harm in doing so.

My point was simply that for a non-trivial application I suspect it will
have limited value due to the sorts of conflicts that are likely to arise.

Regards,
Nick

>

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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-31 21:45                   ` Nick Connolly
@ 2021-03-31 21:55                     ` Thomas Monjalon
  2021-04-01 23:10                       ` Dmitry Kozlyuk
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-03-31 21:55 UTC (permalink / raw)
  To: Nick Connolly
  Cc: Bruce Richardson, Dmitry Kozlyuk, Dmitry Malloy, Jie Zhou,
	Narcisa Ana Maria Vasile, Olivier Matz, Pallavi Kadam,
	Tyler Retzlaff, dev

31/03/2021 23:45, Nick Connolly:
> >
> > I don't understand your point.
> > I am just proposing to allow some apps to explicitly include the shim
> > for their convenience in case they are fully based on DPDK and
> > understand the risk of conflict with some other code.
> 
> 
> Agreed - there’s no harm in doing so.
> 
> My point was simply that for a non-trivial application I suspect it will
> have limited value due to the sorts of conflicts that are likely to arise.

OK yes.
If we expose this header, we should bring it with a disclaimer.



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

* Re: [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim
  2021-03-26  9:28             ` Thomas Monjalon
@ 2021-04-01 23:03               ` Dmitry Kozlyuk
  0 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-01 23:03 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: dev, Tyler Retzlaff, Jie Zhou, Ranjit Menon, Beilei Xing,
	Jeff Guo, Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Olivier Matz

2021-03-26 10:28 (UTC+0100), Thomas Monjalon:
> 20/03/2021 14:05, Dmitry Kozlyuk:
[...]
> > --- a/drivers/net/i40e/i40e_fdir.c
> > +++ b/drivers/net/i40e/i40e_fdir.c
> > @@ -22,6 +22,7 @@
> >  #include <rte_sctp.h>
> >  #include <rte_hash_crc.h>
> >  #include <rte_bitmap.h>
> > +#include <rte_os_internal.h>  
> 
> Why is it needed?

I deliberately put all shim definitions, like missing IPPROTO_* constants that
are used in this file, in <rte_os_internal.h> so that they are never exposed
to DPDK users. Other inclusions of this file have the same reason.

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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-03-31 21:55                     ` Thomas Monjalon
@ 2021-04-01 23:10                       ` Dmitry Kozlyuk
  2021-04-01 23:18                         ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-01 23:10 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Nick Connolly, Bruce Richardson, Dmitry Malloy, Jie Zhou,
	Narcisa Ana Maria Vasile, Olivier Matz, Pallavi Kadam,
	Tyler Retzlaff, dev

2021-03-31 23:55 (UTC+0200), Thomas Monjalon:
> 31/03/2021 23:45, Nick Connolly:
> > >
> > > I don't understand your point.
> > > I am just proposing to allow some apps to explicitly include the shim
> > > for their convenience in case they are fully based on DPDK and
> > > understand the risk of conflict with some other code.  
> > 
> > 
> > Agreed - there’s no harm in doing so.
> > 
> > My point was simply that for a non-trivial application I suspect it will
> > have limited value due to the sorts of conflicts that are likely to arise.  
> 
> OK yes.
> If we expose this header, we should bring it with a disclaimer.

Let's now avoid "internal" (rte_os_shim?), but expose it later, if ever:

1. The concept of "not so public" API is new, probably a techboard subject.
2. We may want devtools checks against including it from public headers.

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

* Re: [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal
  2021-04-01 23:10                       ` Dmitry Kozlyuk
@ 2021-04-01 23:18                         ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-01 23:18 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: Nick Connolly, Bruce Richardson, Dmitry Malloy, Jie Zhou,
	Narcisa Ana Maria Vasile, Olivier Matz, Pallavi Kadam,
	Tyler Retzlaff, dev

02/04/2021 01:10, Dmitry Kozlyuk:
> 2021-03-31 23:55 (UTC+0200), Thomas Monjalon:
> > 31/03/2021 23:45, Nick Connolly:
> > > >
> > > > I don't understand your point.
> > > > I am just proposing to allow some apps to explicitly include the shim
> > > > for their convenience in case they are fully based on DPDK and
> > > > understand the risk of conflict with some other code.  
> > > 
> > > 
> > > Agreed - there’s no harm in doing so.
> > > 
> > > My point was simply that for a non-trivial application I suspect it will
> > > have limited value due to the sorts of conflicts that are likely to arise.  
> > 
> > OK yes.
> > If we expose this header, we should bring it with a disclaimer.
> 
> Let's now avoid "internal" (rte_os_shim?), but expose it later, if ever:
> 
> 1. The concept of "not so public" API is new, probably a techboard subject.
> 2. We may want devtools checks against including it from public headers.

Yes it should be well discussed and checked with scripts.
For now, let's not expose such shim, but as you said,
adopt a more descriptive name avoiding "internal" qualifier.



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

* [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols
  2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                             ` (4 preceding siblings ...)
  2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk
@ 2021-04-03 23:41           ` Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
                               ` (5 more replies)
  5 siblings, 6 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev; +Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v7:
    * Rearrange patches, improve wording, fix typo.
    * rte_os_internal.h -> rte_os_shim.h for possible later exposure
    * Remove unnecessary blank lines.

Dmitry Kozlyuk (5):
  eal: add sleep API
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: work around s_addr macro on Windows
  net: provide IP-related API on any OS

 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +-
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 --
 examples/cmdline/parse_obj_list.c            |  2 -
 lib/librte_cmdline/cmdline.c                 |  5 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_parse.c           |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 -
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  5 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/common/eal_private.h          | 11 +++
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
 lib/librte_eal/include/rte_thread.h          | 11 +++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
 lib/librte_eal/rte_eal_exports.def           |  2 +
 lib/librte_eal/unix/rte_thread.c             | 10 ++-
 lib/librte_eal/version.map                   |  1 +
 lib/librte_eal/windows/eal.c                 | 30 +++++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/eal_thread.c          |  9 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
 lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -----
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_ethdev/rte_ethdev.c               | 12 +--
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 lib/librte_net/rte_ether.h                   | 26 ++++--
 lib/librte_net/rte_ip.h                      |  7 ++
 lib/librte_net/rte_net.c                     |  1 +
 49 files changed, 196 insertions(+), 255 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.3


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

* [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-04-03 23:41             ` Dmitry Kozlyuk
  2021-04-06 14:34               ` Morten Brørup
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                               ` (4 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk, Khoa To,
	Ray Kinsella, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, 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>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
---
 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               |  1 +
 lib/librte_eal/windows/eal_thread.c      |  9 ++++++++-
 6 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035a..0e89a4f7df 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 8be8ed8f36..450d72a2fc 100644
--- a/lib/librte_eal/include/rte_thread.h
+++ b/lib/librte_eal/include/rte_thread.h
@@ -119,6 +119,17 @@ int rte_thread_value_set(rte_thread_key key, const void *value);
 __rte_experimental
 void *rte_thread_value_get(rte_thread_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 c320077547..300c86eb3f 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 c72d619ec1..a7130b5870 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>
@@ -90,3 +92,9 @@ rte_thread_value_get(rte_thread_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 e23745ae6e..cd35b67a9a 100644
--- a/lib/librte_eal/version.map
+++ b/lib/librte_eal/version.map
@@ -413,6 +413,7 @@ EXPERIMENTAL {
 	# added in 21.05
 	rte_thread_key_create;
 	rte_thread_key_delete;
+	rte_thread_sleep;
 	rte_thread_value_get;
 	rte_thread_value_set;
 	rte_version_minor;
diff --git a/lib/librte_eal/windows/eal_thread.c b/lib/librte_eal/windows/eal_thread.c
index 9c3f6d69fd..c84e67009c 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.3


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

* [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
@ 2021-04-03 23:41             ` Dmitry Kozlyuk
  2021-04-10  7:05               ` Nick Connolly
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal Dmitry Kozlyuk
                               ` (3 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk, Khoa To,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
---
 lib/librte_eal/common/eal_private.h     | 11 +++++++++
 lib/librte_eal/windows/eal.c            | 30 +++++++++++++++++++++++++
 lib/librte_eal/windows/include/rte_os.h | 30 -------------------------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..31eda4d2da 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..162671f9ce 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>
@@ -411,6 +413,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,
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index f0512f20a6..1afe49f35e 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -10,7 +10,6 @@
  * which is not supported natively or named differently in Windows.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {
 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)
 {
@@ -111,7 +82,6 @@ eal_strerror(int code)
 #ifndef strerror
 #define strerror eal_strerror
 #endif
-
 #endif /* RTE_TOOLCHAIN_GCC */
 
 #ifdef __cplusplus
-- 
2.29.3


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

* [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-04-03 23:41             ` Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows Dmitry Kozlyuk
                               ` (2 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing,
	Jeff Guo, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move all shims to <rte_os_shim.h>, a header to be used instead of
<rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 lib/librte_cmdline/cmdline.c                 |  4 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 --
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 ++
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/rte_os.h      | 62 ++------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 21 files changed, 77 insertions(+), 74 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..4cd9d14ec7 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_shim.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..e683f5f133 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 8eda6749b4..211e330178 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_shim.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index fcf150e127..cf9e996ca5 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..a87c45275c 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#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 622c7bc429..28da464fc9 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_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..d6c0470eb8 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_shim.h b/lib/librte_eal/freebsd/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/linux/include/rte_os_shim.h b/lib/librte_eal/linux/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 1afe49f35e..66c711d458 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -18,72 +18,18 @@
 extern "C" {
 #endif
 
-/* 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 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
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
new file mode 100644
index 0000000000..edd9a1082c
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 220ddd4408..9bb0879538 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index ffae8914cf..4c1f7dc2c1 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <rte_os_shim.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.3


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

* [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                               ` (2 preceding siblings ...)
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-04-03 23:41             ` Dmitry Kozlyuk
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS Dmitry Kozlyuk
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Ranjit Menon, Olivier Matz

Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
conflicts with definition of `s_addr` field of `struct rte_ether_hdr`.
Prieviously `s_addr` was undefined in <rte_ether.h>, which had been
breaking access to `s_addr` field of `struct in_addr`, so some DPDK
and Windows headers could not be included in one file.

Renaming of `struct rte_ether_hdr` is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html

Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
definition to avoid conflict. Place source MAC address in both `s_addr`
and `S_un.S_addr` fields, so that access works either directly or
through the macro as defined in Windows headers.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
-- 
2.29.3


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

* [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                               ` (3 preceding siblings ...)
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows Dmitry Kozlyuk
@ 2021-04-03 23:41             ` Dmitry Kozlyuk
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-03 23:41 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Beilei Xing, Jeff Guo, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Olivier Matz, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Thomas Monjalon, Ferruh Yigit,
	Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constants, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX includes
in components enabled on Windows. Move missing constants from Windows
networking shim to OS shim header and include it where needed.

Remove Windows networking shim that is no longer needed.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +--
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 ---
 examples/cmdline/parse_obj_list.c            |  2 --
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
 lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
 lib/librte_ethdev/rte_ethdev.c               | 12 +++----
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  7 ++++
 lib/librte_net/rte_net.c                     |  1 +
 21 files changed, 24 insertions(+), 141 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index c572d003cb..e7361bf520 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 6faba4fbb1..392e89d3f5 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index c347f8130e..0f1a9c5ed9 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,12 +3,11 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
 {
 }
 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8324e188e1..d03eb0a7a7 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,11 +5,10 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/queue.h>
 
 #include <rte_alarm.h>
 #include <rte_mtr.h>
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index a7946f7756..19981d26d8 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
index edd9a1082c..f40fb62d1d 100644
--- a/lib/librte_eal/windows/include/rte_os_shim.h
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 3059aa55b3..441f01df53 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,14 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index b59c4d67a3..8c189009b0 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,9 +16,16 @@
  */
 
 #include <stdint.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..d680accc16 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_shim.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.3


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

* Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
@ 2021-04-06 14:34               ` Morten Brørup
  2021-04-06 23:29                 ` Dmitry Kozlyuk
  0 siblings, 1 reply; 132+ messages in thread
From: Morten Brørup @ 2021-04-06 14:34 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Khoa To, Ray Kinsella,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Neil Horman

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Dmitry Kozlyuk
> Sent: Sunday, April 4, 2021 1:41 AM
> 
> 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>
> Acked-by: Ray Kinsella <mdr@ashroe.eu>

How is this better than the rte_delay_us_sleep() function in rte_cycles.h?


Med venlig hilsen / kind regards
- Morten Brørup


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

* Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
  2021-04-06 14:34               ` Morten Brørup
@ 2021-04-06 23:29                 ` Dmitry Kozlyuk
  2021-04-07  7:31                   ` Morten Brørup
  0 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-06 23:29 UTC (permalink / raw)
  To: Morten Brørup
  Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Khoa To,
	Ray Kinsella, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Neil Horman

2021-04-06 16:34 (UTC+0200), Morten Brørup:
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Dmitry Kozlyuk
> > Sent: Sunday, April 4, 2021 1:41 AM
> > 
> > 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>
> > Acked-by: Ray Kinsella <mdr@ashroe.eu>  
> 
> How is this better than the rte_delay_us_sleep() function in rte_cycles.

Honestly, I just assumed the sleep() shim existed for a reason.
Now that you pointed to it, I think indeed no new API is needed.

I wonder why rte_delay_us_sleep() is not used throughout DPDK.
Should their usages be converted as soon as code is enabled for Windows?

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

* Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
  2021-04-06 23:29                 ` Dmitry Kozlyuk
@ 2021-04-07  7:31                   ` Morten Brørup
  2021-04-29 17:09                     ` Tyler Retzlaff
  0 siblings, 1 reply; 132+ messages in thread
From: Morten Brørup @ 2021-04-07  7:31 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Khoa To,
	Ray Kinsella, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Neil Horman

> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Dmitry Kozlyuk
> Sent: Wednesday, April 7, 2021 1:30 AM
> 
> 2021-04-06 16:34 (UTC+0200), Morten Brørup:
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Dmitry Kozlyuk
> > > Sent: Sunday, April 4, 2021 1:41 AM
> > >
> > > 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>
> > > Acked-by: Ray Kinsella <mdr@ashroe.eu>
> >
> > How is this better than the rte_delay_us_sleep() function in
> rte_cycles.
> 
> Honestly, I just assumed the sleep() shim existed for a reason.
> Now that you pointed to it, I think indeed no new API is needed.
> 
> I wonder why rte_delay_us_sleep() is not used throughout DPDK.

I think it's just tradition from Linux/BSD developers not being used to cross-platform development or having forgotten how to develop software for deeply embedded systems without a standard O/S below. We use POSIX functions like sleep() without thinking about it, and simply forget looking for an EAL variant of the function first.

> Should their usages be converted as soon as code is enabled for
> Windows?

Yes. The Environment Abstraction Layer is there to avoid using O/S specific function calls. So it should be safe to replace all these sleep() calls with the EAL variant at any time.


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

* [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols
  2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                               ` (4 preceding siblings ...)
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-04-07 22:22             ` Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                                 ` (4 more replies)
  5 siblings, 5 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-07 22:22 UTC (permalink / raw)
  To: dev; +Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v8:
   * Drop rte_thread_sleep API, use rte_delay_us_sleep (Morten Brørup).
v7:
    * Rearrange patches, improve wording, fix typo.
    * rte_os_internal.h -> rte_os_shim.h for possible later exposure
    * Remove unnecessary blank lines.


*** BLURB HERE ***

Dmitry Kozlyuk (4):
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: work around s_addr macro on Windows
  net: provide IP-related API on any OS

 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +-
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 --
 examples/cmdline/parse_obj_list.c            |  2 -
 lib/librte_cmdline/cmdline.c                 |  5 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_parse.c           |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 -
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/common/eal_private.h          | 11 +++
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
 lib/librte_eal/windows/eal.c                 | 30 +++++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
 lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -----
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_ethdev/rte_ethdev.c               | 12 +--
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 lib/librte_net/rte_ether.h                   | 26 ++++--
 lib/librte_net/rte_ip.h                      |  7 ++
 lib/librte_net/rte_net.c                     |  1 +
 44 files changed, 164 insertions(+), 253 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.3


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

* [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-04-07 22:22               ` Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal Dmitry Kozlyuk
                                 ` (3 subsequent siblings)
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-07 22:22 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk, Khoa To,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
---
 lib/librte_eal/common/eal_private.h     | 11 +++++++++
 lib/librte_eal/windows/eal.c            | 30 +++++++++++++++++++++++++
 lib/librte_eal/windows/include/rte_os.h | 30 -------------------------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b8a0d20021..31eda4d2da 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 2fc3d6141c..162671f9ce 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>
@@ -411,6 +413,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,
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index f0512f20a6..1afe49f35e 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -10,7 +10,6 @@
  * which is not supported natively or named differently in Windows.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {
 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)
 {
@@ -111,7 +82,6 @@ eal_strerror(int code)
 #ifndef strerror
 #define strerror eal_strerror
 #endif
-
 #endif /* RTE_TOOLCHAIN_GCC */
 
 #ifdef __cplusplus
-- 
2.29.3


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

* [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-04-07 22:22               ` Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
                                 ` (2 subsequent siblings)
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-07 22:22 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko, Beilei Xing,
	Jeff Guo, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move most of the shims to <rte_os_shim.h>, a header to be used instead
of <rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>. Directly replace shims that
were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 lib/librte_cmdline/cmdline.c                 |  4 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 --
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 ++
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/rte_os.h      | 62 ++------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 22 files changed, 79 insertions(+), 76 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..4cd9d14ec7 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_shim.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..e683f5f133 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 8eda6749b4..211e330178 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_shim.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index fcf150e127..cf9e996ca5 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..a87c45275c 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#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 622c7bc429..28da464fc9 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_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035a..86f8429847 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -47,9 +47,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_delay_us_sleep() will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_delay_us_sleep(US_PER_S);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..d6c0470eb8 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_shim.h b/lib/librte_eal/freebsd/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/linux/include/rte_os_shim.h b/lib/librte_eal/linux/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 1afe49f35e..66c711d458 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -18,72 +18,18 @@
 extern "C" {
 #endif
 
-/* 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 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
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
new file mode 100644
index 0000000000..edd9a1082c
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 220ddd4408..9bb0879538 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index ffae8914cf..4c1f7dc2c1 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <rte_os_shim.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.3


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

* [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-04-07 22:22               ` Dmitry Kozlyuk
  2021-04-08 11:26                 ` Olivier Matz
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  4 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-07 22:22 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Ranjit Menon, Olivier Matz

Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
conflicts with definition of `s_addr` field of `struct rte_ether_hdr`.
Prieviously `s_addr` was undefined in <rte_ether.h>, which had been
breaking access to `s_addr` field of `struct in_addr`, so some DPDK
and Windows headers could not be included in one file.

Renaming of `struct rte_ether_hdr` is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html

Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
definition to avoid conflict. Place source MAC address in both `s_addr`
and `S_un.S_addr` fields, so that access works either directly or
through the macro as defined in Windows headers.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
-- 
2.29.3


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

* [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                                 ` (2 preceding siblings ...)
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
@ 2021-04-07 22:22               ` Dmitry Kozlyuk
  2021-04-08 11:45                 ` Olivier Matz
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  4 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-07 22:22 UTC (permalink / raw)
  To: dev
  Cc: Tyler Retzlaff, Jie Zhou, Nick Connolly, Dmitry Kozlyuk,
	Beilei Xing, Jeff Guo, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Olivier Matz, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Thomas Monjalon, Ferruh Yigit,
	Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constants, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX includes
in components enabled on Windows. Move missing constants from Windows
networking shim to OS shim header and include it where needed.

Remove Windows networking shim that is no longer needed.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +--
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 ---
 examples/cmdline/parse_obj_list.c            |  2 --
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
 lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
 lib/librte_ethdev/rte_ethdev.c               | 12 +++----
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  7 ++++
 lib/librte_net/rte_net.c                     |  1 +
 21 files changed, 24 insertions(+), 141 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index c572d003cb..e7361bf520 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 6faba4fbb1..392e89d3f5 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index c347f8130e..0f1a9c5ed9 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,12 +3,11 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
 {
 }
 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8324e188e1..d03eb0a7a7 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,11 +5,10 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/queue.h>
 
 #include <rte_alarm.h>
 #include <rte_mtr.h>
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index a7946f7756..19981d26d8 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
index edd9a1082c..f40fb62d1d 100644
--- a/lib/librte_eal/windows/include/rte_os_shim.h
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 3059aa55b3..441f01df53 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,14 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index b59c4d67a3..8c189009b0 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,9 +16,16 @@
  */
 
 #include <stdint.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..d680accc16 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_shim.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.3


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

* Re: [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
@ 2021-04-08 11:26                 ` Olivier Matz
  0 siblings, 0 replies; 132+ messages in thread
From: Olivier Matz @ 2021-04-08 11:26 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Ranjit Menon

On Thu, Apr 08, 2021 at 01:22:48AM +0300, Dmitry Kozlyuk wrote:
> Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
> conflicts with definition of `s_addr` field of `struct rte_ether_hdr`.
> Prieviously `s_addr` was undefined in <rte_ether.h>, which had been
> breaking access to `s_addr` field of `struct in_addr`, so some DPDK
> and Windows headers could not be included in one file.
> 
> Renaming of `struct rte_ether_hdr` is planned:
> https://mails.dpdk.org/archives/dev/2021-March/201444.html
> 
> Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
> definition to avoid conflict. Place source MAC address in both `s_addr`
> and `S_un.S_addr` fields, so that access works either directly or
> through the macro as defined in Windows headers.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Acked-by: Ranjit Menon <ranjit.menon@intel.com>

Acked-by: Olivier Matz <olivier.matz@6wind.com>

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

* Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-04-08 11:45                 ` Olivier Matz
  2021-04-08 19:51                   ` Dmitry Kozlyuk
  2021-04-14 21:47                   ` Thomas Monjalon
  0 siblings, 2 replies; 132+ messages in thread
From: Olivier Matz @ 2021-04-08 11:45 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Beilei Xing,
	Jeff Guo, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Hi Dmitry,

On Thu, Apr 08, 2021 at 01:22:49AM +0300, Dmitry Kozlyuk wrote:
> Users of <rte_ip.h> relied on it to provide IP-related defines,
> like IPPROTO_* constants, but still had to include POSIX headers
> for inet_pton() and other standard IP-related facilities.
> 
> Extend <rte_ip.h> so that it is a single header to gain access
> to IP-related facilities on any OS. Use it to replace POSIX includes
> in components enabled on Windows. Move missing constants from Windows
> networking shim to OS shim header and include it where needed.
> 
> Remove Windows networking shim that is no longer needed.
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>  drivers/net/i40e/i40e_fdir.c                 |  1 +
>  drivers/net/mlx5/mlx5.h                      |  1 -
>  drivers/net/mlx5/mlx5_flow.c                 |  4 +--
>  drivers/net/mlx5/mlx5_flow.h                 |  3 +-
>  drivers/net/mlx5/mlx5_mac.c                  |  1 -
>  examples/cmdline/commands.c                  |  5 ---
>  examples/cmdline/parse_obj_list.c            |  2 --
>  lib/librte_cmdline/cmdline.c                 |  1 -
>  lib/librte_cmdline/cmdline_parse.c           |  2 --
>  lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
>  lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
>  lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
>  lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
>  lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
>  lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
>  lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
>  lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
>  lib/librte_ethdev/rte_ethdev.c               | 12 +++----
>  lib/librte_ethdev/rte_ethdev_core.h          |  1 -
>  lib/librte_net/rte_ip.h                      |  7 ++++
>  lib/librte_net/rte_net.c                     |  1 +
>  21 files changed, 24 insertions(+), 141 deletions(-)
>  delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
>  delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
>  delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
>  delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

I see it has already been discussed for posix functions like close() or
strdup(), so I won't reopen the door too long ;)

Since DPDK is a network-oriented project, it provides network defines or
structure, prefixed with rte_. This API is on some aspects more complete
than the one provided in libc (for instance, more protocol headers are
available) . So, to me, it would make sense to define RTE_IPPROTO_* and
replace usages of IPPROTO_*, and avoid inclusions of network libc
headers in DPDK code.

This can be done later, if there is a consensus.

> diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
> index c572d003cb..e7361bf520 100644
> --- a/drivers/net/i40e/i40e_fdir.c
> +++ b/drivers/net/i40e/i40e_fdir.c
> @@ -22,6 +22,7 @@
>  #include <rte_sctp.h>
>  #include <rte_hash_crc.h>
>  #include <rte_bitmap.h>
> +#include <rte_os_shim.h>
>  

If I understand the logic, rte_ip.h provides OS-specific IP-related
stuff (like IPPROTO_*), and rte_os_shim.h provides the POSIX definitions
that are missing after including rte_ip.h.

Would it make sense to include rte_os_shim.h from rte_ip.h, so that
including rte_ip.h is always sufficient? Or is it because we want to
avoid implicit inclusion of rte_os_shim.h?

Thanks,
Olivier

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

* Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
  2021-04-08 11:45                 ` Olivier Matz
@ 2021-04-08 19:51                   ` Dmitry Kozlyuk
  2021-04-09 13:33                     ` Olivier Matz
  2021-04-14 21:47                   ` Thomas Monjalon
  1 sibling, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-08 19:51 UTC (permalink / raw)
  To: Olivier Matz
  Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Beilei Xing,
	Jeff Guo, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

2021-04-08 13:45 (UTC+0200), Olivier Matz:
[...]
> > diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
> > index c572d003cb..e7361bf520 100644
> > --- a/drivers/net/i40e/i40e_fdir.c
> > +++ b/drivers/net/i40e/i40e_fdir.c
> > @@ -22,6 +22,7 @@
> >  #include <rte_sctp.h>
> >  #include <rte_hash_crc.h>
> >  #include <rte_bitmap.h>
> > +#include <rte_os_shim.h>
> >    
> 
> If I understand the logic, rte_ip.h provides OS-specific IP-related
> stuff (like IPPROTO_*), and rte_os_shim.h provides the POSIX definitions
> that are missing after including rte_ip.h.
> 
> Would it make sense to include rte_os_shim.h from rte_ip.h, so that
> including rte_ip.h is always sufficient? Or is it because we want to
> avoid implicit inclusion of rte_os_shim.h?

Yes, currently rte_os_shim.h is not exposed at all.
It it ever will, this reason still applies.

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

* Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
  2021-04-08 19:51                   ` Dmitry Kozlyuk
@ 2021-04-09 13:33                     ` Olivier Matz
  0 siblings, 0 replies; 132+ messages in thread
From: Olivier Matz @ 2021-04-09 13:33 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Tyler Retzlaff, Jie Zhou, Nick Connolly, Beilei Xing,
	Jeff Guo, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

On Thu, Apr 08, 2021 at 10:51:34PM +0300, Dmitry Kozlyuk wrote:
> 2021-04-08 13:45 (UTC+0200), Olivier Matz:
> [...]
> > > diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
> > > index c572d003cb..e7361bf520 100644
> > > --- a/drivers/net/i40e/i40e_fdir.c
> > > +++ b/drivers/net/i40e/i40e_fdir.c
> > > @@ -22,6 +22,7 @@
> > >  #include <rte_sctp.h>
> > >  #include <rte_hash_crc.h>
> > >  #include <rte_bitmap.h>
> > > +#include <rte_os_shim.h>
> > >    
> > 
> > If I understand the logic, rte_ip.h provides OS-specific IP-related
> > stuff (like IPPROTO_*), and rte_os_shim.h provides the POSIX definitions
> > that are missing after including rte_ip.h.
> > 
> > Would it make sense to include rte_os_shim.h from rte_ip.h, so that
> > including rte_ip.h is always sufficient? Or is it because we want to
> > avoid implicit inclusion of rte_os_shim.h?
> 
> Yes, currently rte_os_shim.h is not exposed at all.
> It it ever will, this reason still applies.

Ok, thank you for the clarification.

Acked-by: Olivier Matz <olivier.matz@6wind.com>

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

* Re: [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim
  2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-04-10  7:05               ` Nick Connolly
  0 siblings, 0 replies; 132+ messages in thread
From: Nick Connolly @ 2021-04-10  7:05 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev
  Cc: Tyler Retzlaff, Jie Zhou, Khoa To, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam


> Make asprintf(3) implementation for Windows private to EAL, so that it's
> hidden from external consumers. It is not exposed to internal consumers
> either, because they don't need asprintf() and also because callers from
> other modules would have no reliable way to free allocated memory.
>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Acked-by: Khoa To <khot@microsoft.com>
Acked-by: Nick Connolly <nick.connolly@mayadata.io>


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

* [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                                 ` (3 preceding siblings ...)
  2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-04-10 22:47               ` Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                                   ` (5 more replies)
  4 siblings, 6 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-10 22:47 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v9:
    * Fix missing <rte_os_shim.h> include in rte_common_log.c.
      (This will happen again. Going to add a checkpatch test
       after this series is merged.)
v8:
    * Drop rte_thread_sleep API, use rte_delay_us_sleep (Morten Brørup).

Dmitry Kozlyuk (4):
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: work around s_addr macro on Windows
  net: provide IP-related API on any OS

 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +-
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 --
 examples/cmdline/parse_obj_list.c            |  2 -
 lib/librte_cmdline/cmdline.c                 |  5 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_parse.c           |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 -
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 +
 lib/librte_eal/common/eal_common_log.c       |  1 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/common/eal_private.h          | 11 +++
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
 lib/librte_eal/windows/eal.c                 | 30 +++++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
 lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -----
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_ethdev/rte_ethdev.c               | 12 +--
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 lib/librte_net/rte_ether.h                   | 26 ++++--
 lib/librte_net/rte_ip.h                      |  7 ++
 lib/librte_net/rte_net.c                     |  1 +
 45 files changed, 165 insertions(+), 253 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.3


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

* [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
@ 2021-04-10 22:47                 ` Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk
                                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-10 22:47 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Khoa To, Nick Connolly, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
Acked-by: Nick Connolly <nick.connolly@mayadata.io>
---
 lib/librte_eal/common/eal_private.h     | 11 +++++++++
 lib/librte_eal/windows/eal.c            | 30 +++++++++++++++++++++++++
 lib/librte_eal/windows/include/rte_os.h | 30 -------------------------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index e3512111d9..64cf4e81c8 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -716,4 +716,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 41be20d89f..28c787c0b0 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>
@@ -416,6 +418,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,
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index f0512f20a6..1afe49f35e 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -10,7 +10,6 @@
  * which is not supported natively or named differently in Windows.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {
 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)
 {
@@ -111,7 +82,6 @@ eal_strerror(int code)
 #ifndef strerror
 #define strerror eal_strerror
 #endif
-
 #endif /* RTE_TOOLCHAIN_GCC */
 
 #ifdef __cplusplus
-- 
2.29.3


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

* [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-04-10 22:47                 ` Dmitry Kozlyuk
  2021-04-14 21:33                   ` Thomas Monjalon
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
                                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-10 22:47 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko,
	Beilei Xing, Jeff Guo, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move most of the shims to <rte_os_shim.h>, a header to be used instead
of <rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>. Directly replace shims that
were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 lib/librte_cmdline/cmdline.c                 |  4 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 --
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 ++
 lib/librte_eal/common/eal_common_log.c       |  1 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/rte_os.h      | 62 ++------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 23 files changed, 80 insertions(+), 76 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..4cd9d14ec7 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_shim.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..e683f5f133 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 8eda6749b4..211e330178 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_shim.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index fcf150e127..cf9e996ca5 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..a87c45275c 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index bed83a402a..cedf9f0894 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -13,6 +13,7 @@
 
 #include <rte_eal.h>
 #include <rte_log.h>
+#include <rte_os_shim.h>
 #include <rte_per_lcore.h>
 
 #include "eal_log.h"
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 2951b1aca2..66f9114715 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1959,7 +1959,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_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035a..86f8429847 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -47,9 +47,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_delay_us_sleep() will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_delay_us_sleep(US_PER_S);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..d6c0470eb8 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_shim.h b/lib/librte_eal/freebsd/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/linux/include/rte_os_shim.h b/lib/librte_eal/linux/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 1afe49f35e..66c711d458 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -18,72 +18,18 @@
 extern "C" {
 #endif
 
-/* 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 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
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
new file mode 100644
index 0000000000..edd9a1082c
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 220ddd4408..9bb0879538 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index ffae8914cf..4c1f7dc2c1 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <rte_os_shim.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.3


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

* [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-04-10 22:47                 ` Dmitry Kozlyuk
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
                                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-10 22:47 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk, Ranjit Menon, Olivier Matz

Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
conflicts with definition of `s_addr` field of `struct rte_ether_hdr`.
Prieviously `s_addr` was undefined in <rte_ether.h>, which had been
breaking access to `s_addr` field of `struct in_addr`, so some DPDK
and Windows headers could not be included in one file.

Renaming of `struct rte_ether_hdr` is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html

Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
definition to avoid conflict. Place source MAC address in both `s_addr`
and `S_un.S_addr` fields, so that access works either directly or
through the macro as defined in Windows headers.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
---
 lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
-- 
2.29.3


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

* [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                                   ` (2 preceding siblings ...)
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
@ 2021-04-10 22:47                 ` Dmitry Kozlyuk
  2021-04-13  4:46                 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
  5 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-10 22:47 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Olivier Matz, Beilei Xing, Jeff Guo, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Thomas Monjalon, Ferruh Yigit,
	Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constants, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX includes
in components enabled on Windows. Move missing constants from Windows
networking shim to OS shim header and include it where needed.

Remove Windows networking shim that is no longer needed.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
---
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +--
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 ---
 examples/cmdline/parse_obj_list.c            |  2 --
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
 lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
 lib/librte_ethdev/rte_ethdev.c               | 12 +++----
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  7 ++++
 lib/librte_net/rte_net.c                     |  1 +
 21 files changed, 24 insertions(+), 141 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index c572d003cb..e7361bf520 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 6faba4fbb1..392e89d3f5 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index c347f8130e..0f1a9c5ed9 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,12 +3,11 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
 {
 }
 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8324e188e1..d03eb0a7a7 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,11 +5,10 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/queue.h>
 
 #include <rte_alarm.h>
 #include <rte_mtr.h>
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index a7946f7756..19981d26d8 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
index edd9a1082c..f40fb62d1d 100644
--- a/lib/librte_eal/windows/include/rte_os_shim.h
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 3059aa55b3..441f01df53 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,14 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index b59c4d67a3..8c189009b0 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,9 +16,16 @@
  */
 
 #include <stdint.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..d680accc16 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_shim.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.3


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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                                   ` (3 preceding siblings ...)
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-04-13  4:46                 ` Ranjit Menon
  2021-04-13  7:00                   ` Dmitry Kozlyuk
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
  5 siblings, 1 reply; 132+ messages in thread
From: Ranjit Menon @ 2021-04-13  4:46 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev

Hi Dmitry,

On 4/10/2021 3:47 PM, Dmitry Kozlyuk wrote:
> On Windows, EAL contains two sets of functions and macros for POSIX
> compatibility: <rte_os.h> and a networking shim (socket headers).
> The latter conflicts with system headers and should not exist.
> Exposing the former from EAL can break consumer own POSIX compatibility
> layer and is against standards in general. Hide these symbols from
> external consumers, while keeping them available for DPDK code.
>
> v9:
>      * Fix missing <rte_os_shim.h> include in rte_common_log.c.
>        (This will happen again. Going to add a checkpatch test
>         after this series is merged.)
> v8:
>      * Drop rte_thread_sleep API, use rte_delay_us_sleep (Morten Brørup).
>
> Dmitry Kozlyuk (4):
>    eal/windows: hide asprintf() shim
>    eal: make OS shims internal
>    net: work around s_addr macro on Windows
>    net: provide IP-related API on any OS
>
> <Snip>

The change to remove the networking shim breaks l2fwd compilation on 
Windows, since l2fwd/main.c includes netinet/in.h explicitly.

How do you propose we fix this, only for Windows?

ranjit m.


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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-13  4:46                 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
@ 2021-04-13  7:00                   ` Dmitry Kozlyuk
  2021-04-14 21:12                     ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-13  7:00 UTC (permalink / raw)
  To: Ranjit Menon; +Cc: dev

Hi Ranjit,

2021-04-12 21:46 (UTC-0700), Ranjit Menon:
[...]
> The change to remove the networking shim breaks l2fwd compilation on 
> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
> 
> How do you propose we fix this, only for Windows?

This include is redundant for this file on all platforms, it can be removed.
Since -Dexamples=all doesn't work on Windows because of missing dependencies,
I wonder which of them need fixing.


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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-13  7:00                   ` Dmitry Kozlyuk
@ 2021-04-14 21:12                     ` Thomas Monjalon
  2021-04-14 21:34                       ` Ranjit Menon
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 21:12 UTC (permalink / raw)
  To: Ranjit Menon, Dmitry Kozlyuk; +Cc: dev

13/04/2021 09:00, Dmitry Kozlyuk:
> Hi Ranjit,
> 
> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
> [...]
> > The change to remove the networking shim breaks l2fwd compilation on 
> > Windows, since l2fwd/main.c includes netinet/in.h explicitly.
> > 
> > How do you propose we fix this, only for Windows?
> 
> This include is redundant for this file on all platforms, it can be removed.
> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
> I wonder which of them need fixing.

Let's fix the examples which are supported on Windows.
Other examples may require more updates anyway.




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

* Re: [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal
  2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-04-14 21:33                   ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 21:33 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko,
	Beilei Xing, Jeff Guo, Olivier Matz, Bruce Richardson,
	Narcisa Ana Maria Vasile, Dmitry Malloy, Pallavi Kadam,
	Ferruh Yigit, Andrew Rybchenko, Dmitry Kozlyuk

11/04/2021 00:47, Dmitry Kozlyuk:
> DPDK code often relies on functions and macros that are not standard C,
> but are found on all platforms, even if by slightly different names.
> Windows <rte_os.h> provided macros or inline definitions for such symbols.
> However, when placed in public header, these symbols were unnecessarily
> exposed, breaking consumer POSIX compatibility code.
> 
> Move most of the shims to <rte_os_shim.h>, a header to be used instead
> of <rte_os.h> by internal code. Include it in libraries and PMDs that
> previously imported shims from <rte_os.h>. Directly replace shims that
> were only used inside EAL:
> * index -> strchr, rindex -> strrchr
> * sleep -> rte_delay_us_sleep
> * strerror_r -> strerror_s
> 
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

Acked-by: Thomas Monjalon <thomas@monjalon.net>



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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 21:12                     ` Thomas Monjalon
@ 2021-04-14 21:34                       ` Ranjit Menon
  2021-04-14 21:42                         ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Ranjit Menon @ 2021-04-14 21:34 UTC (permalink / raw)
  To: Thomas Monjalon, Dmitry Kozlyuk; +Cc: dev


On 4/14/2021 2:12 PM, Thomas Monjalon wrote:
> 13/04/2021 09:00, Dmitry Kozlyuk:
>> Hi Ranjit,
>>
>> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
>> [...]
>>> The change to remove the networking shim breaks l2fwd compilation on
>>> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
>>>
>>> How do you propose we fix this, only for Windows?
>> This include is redundant for this file on all platforms, it can be removed.
>> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
>> I wonder which of them need fixing.
> Let's fix the examples which are supported on Windows.
> Other examples may require more updates anyway.
>
Thanks, Thomas. For now, this is only required in l2fwd.

Dmitry, can you please include this in your patch 4/4?

thanks,

ranjit m.

>

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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 21:34                       ` Ranjit Menon
@ 2021-04-14 21:42                         ` Thomas Monjalon
  2021-04-14 21:47                           ` Ranjit Menon
  0 siblings, 1 reply; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 21:42 UTC (permalink / raw)
  To: Ranjit Menon; +Cc: Dmitry Kozlyuk, dev

14/04/2021 23:34, Ranjit Menon:
> On 4/14/2021 2:12 PM, Thomas Monjalon wrote:
> > 13/04/2021 09:00, Dmitry Kozlyuk:
> >> Hi Ranjit,
> >>
> >> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
> >> [...]
> >>> The change to remove the networking shim breaks l2fwd compilation on
> >>> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
> >>>
> >>> How do you propose we fix this, only for Windows?
> >> This include is redundant for this file on all platforms, it can be removed.
> >> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
> >> I wonder which of them need fixing.
> > Let's fix the examples which are supported on Windows.
> > Other examples may require more updates anyway.
> >
> Thanks, Thomas. For now, this is only required in l2fwd.

Only l2fwd is supported on Windows?

> Dmitry, can you please include this in your patch 4/4?

Ranjit, if you tell me what exactly is needed, I can do it
and merge the series quickly.



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

* Re: [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS
  2021-04-08 11:45                 ` Olivier Matz
  2021-04-08 19:51                   ` Dmitry Kozlyuk
@ 2021-04-14 21:47                   ` Thomas Monjalon
  1 sibling, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 21:47 UTC (permalink / raw)
  To: Olivier Matz
  Cc: Dmitry Kozlyuk, dev, Tyler Retzlaff, Jie Zhou, Nick Connolly,
	Beilei Xing, Jeff Guo, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Ferruh Yigit, Andrew Rybchenko

08/04/2021 13:45, Olivier Matz:
> I see it has already been discussed for posix functions like close() or
> strdup(), so I won't reopen the door too long ;)
> 
> Since DPDK is a network-oriented project, it provides network defines or
> structure, prefixed with rte_. This API is on some aspects more complete
> than the one provided in libc (for instance, more protocol headers are
> available) . So, to me, it would make sense to define RTE_IPPROTO_* and
> replace usages of IPPROTO_*, and avoid inclusions of network libc
> headers in DPDK code.
> 
> This can be done later, if there is a consensus.

That's an interesting question.
What would be the benefit of avoiding network libc includes?




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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 21:42                         ` Thomas Monjalon
@ 2021-04-14 21:47                           ` Ranjit Menon
  2021-04-14 22:08                             ` Dmitry Kozlyuk
  0 siblings, 1 reply; 132+ messages in thread
From: Ranjit Menon @ 2021-04-14 21:47 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: Dmitry Kozlyuk, dev


On 4/14/2021 2:42 PM, Thomas Monjalon wrote:
> 14/04/2021 23:34, Ranjit Menon:
>> On 4/14/2021 2:12 PM, Thomas Monjalon wrote:
>>> 13/04/2021 09:00, Dmitry Kozlyuk:
>>>> Hi Ranjit,
>>>>
>>>> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
>>>> [...]
>>>>> The change to remove the networking shim breaks l2fwd compilation on
>>>>> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
>>>>>
>>>>> How do you propose we fix this, only for Windows?
>>>> This include is redundant for this file on all platforms, it can be removed.
>>>> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
>>>> I wonder which of them need fixing.
>>> Let's fix the examples which are supported on Windows.
>>> Other examples may require more updates anyway.
>>>
>> Thanks, Thomas. For now, this is only required in l2fwd.
> Only l2fwd is supported on Windows?
>
>> Dmitry, can you please include this in your patch 4/4?
> Ranjit, if you tell me what exactly is needed, I can do it
> and merge the series quickly.

Sure, Thomas. In l2wfd/main.c, all we need to do is remove the #include 
<netinet/in.h> line.

This include file will not exist on Windows anymore, and Dmitry 
determined that this include is not required in l2fwd on all platforms.


ranjit m.

>

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

* [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols
  2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
                                   ` (4 preceding siblings ...)
  2021-04-13  4:46                 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
@ 2021-04-14 22:06                 ` Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
                                     ` (4 more replies)
  5 siblings, 5 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:06 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers).
The latter conflicts with system headers and should not exist.
Exposing the former from EAL can break consumer own POSIX compatibility
layer and is against standards in general. Hide these symbols from
external consumers, while keeping them available for DPDK code.

v10:
    * Fix examples that build on Windows.
v9:
    * Fix missing <rte_os_shim.h> include in rte_common_log.c.
      (This will happen again. Going to add a checkpatch test
       after this series is merged.)

Dmitry Kozlyuk (4):
  eal/windows: hide asprintf() shim
  eal: make OS shims internal
  net: work around s_addr macro on Windows
  net: provide IP-related API on any OS

 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +-
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 --
 examples/cmdline/parse_obj_list.c            |  2 -
 examples/flow_filtering/main.c               |  1 -
 examples/l2fwd/main.c                        |  1 -
 examples/link_status_interrupt/main.c        |  1 -
 examples/service_cores/main.c                |  4 +-
 lib/librte_cmdline/cmdline.c                 |  5 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_parse.c           |  2 -
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 -
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 +
 lib/librte_eal/common/eal_common_log.c       |  1 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/common/eal_private.h          | 11 +++
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
 lib/librte_eal/windows/eal.c                 | 30 +++++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
 lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -----
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_ethdev/rte_ethdev.c               | 12 +--
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 lib/librte_net/rte_ether.h                   | 26 ++++--
 lib/librte_net/rte_ip.h                      |  7 ++
 lib/librte_net/rte_net.c                     |  1 +
 49 files changed, 167 insertions(+), 258 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

-- 
2.29.3


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

* [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
@ 2021-04-14 22:06                   ` Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal Dmitry Kozlyuk
                                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:06 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Khoa To, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam

Make asprintf(3) implementation for Windows private to EAL, so that it's
hidden from external consumers. It is not exposed to internal consumers
either, because they don't need asprintf() and also because callers from
other modules would have no reliable way to free allocated memory.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Khoa To <khot@microsoft.com>
---
 lib/librte_eal/common/eal_private.h     | 11 +++++++++
 lib/librte_eal/windows/eal.c            | 30 +++++++++++++++++++++++++
 lib/librte_eal/windows/include/rte_os.h | 30 -------------------------
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index e3512111d9..64cf4e81c8 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -716,4 +716,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
  */
 void __rte_thread_uninit(void);
 
+/**
+ * asprintf(3) replacement for Windows.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+__rte_format_printf(2, 3)
+int eal_asprintf(char **buffer, const char *format, ...);
+
+#define asprintf(buffer, format, ...) \
+		eal_asprintf(buffer, format, ##__VA_ARGS__)
+#endif
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 41be20d89f..28c787c0b0 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>
@@ -416,6 +418,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,
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index f0512f20a6..1afe49f35e 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -10,7 +10,6 @@
  * which is not supported natively or named differently in Windows.
  */
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,34 +70,6 @@ extern "C" {
 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)
 {
@@ -111,7 +82,6 @@ eal_strerror(int code)
 #ifndef strerror
 #define strerror eal_strerror
 #endif
-
 #endif /* RTE_TOOLCHAIN_GCC */
 
 #ifdef __cplusplus
-- 
2.29.3


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

* [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
@ 2021-04-14 22:06                   ` Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
                                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:06 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Thomas Monjalon, Matan Azrad, Shahaf Shuler,
	Viacheslav Ovsiienko, Beilei Xing, Jeff Guo, Harry van Haaren,
	Olivier Matz, Bruce Richardson, Narcisa Ana Maria Vasile,
	Dmitry Malloy, Pallavi Kadam, Ferruh Yigit, Andrew Rybchenko

DPDK code often relies on functions and macros that are not standard C,
but are found on all platforms, even if by slightly different names.
Windows <rte_os.h> provided macros or inline definitions for such symbols.
However, when placed in public header, these symbols were unnecessarily
exposed, breaking consumer POSIX compatibility code.

Move most of the shims to <rte_os_shim.h>, a header to be used instead
of <rte_os.h> by internal code. Include it in libraries and PMDs that
previously imported shims from <rte_os.h>. Directly replace shims that
were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s

Remove sleep(3) shim in favour of rte_delay_us_sleep().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 examples/service_cores/main.c                |  4 +-
 lib/librte_cmdline/cmdline.c                 |  4 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 --
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 ++
 lib/librte_eal/common/eal_common_log.c       |  1 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/rte_os.h      | 62 ++------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 24 files changed, 82 insertions(+), 78 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h

diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..4cd9d14ec7 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_shim.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index ba6dc48ff3..e683f5f133 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 327374fdcf..f3c6beb23b 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_shim.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index c03e4a0a4b..ea5d384283 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
diff --git a/examples/service_cores/main.c b/examples/service_cores/main.c
index c7c792810d..0b3d8c8073 100644
--- a/examples/service_cores/main.c
+++ b/examples/service_cores/main.c
@@ -209,10 +209,10 @@ main(int argc, char **argv)
 		apply_profile(i);
 		printf("\n==> Profile: %s\n\n", profiles[i].name);
 
-		sleep(1);
+		rte_delay_us_sleep(1 * US_PER_S);
 		rte_service_dump(stdout, UINT32_MAX);
 
-		sleep(5);
+		rte_delay_us_sleep(5 * US_PER_S);
 		rte_service_dump(stdout, UINT32_MAX);
 
 		i++;
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c8..49770869bb 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
diff --git a/lib/librte_cmdline/cmdline_os_windows.c b/lib/librte_cmdline/cmdline_os_windows.c
index e9585c9eea..73ed9ba290 100644
--- a/lib/librte_cmdline/cmdline_os_windows.c
+++ b/lib/librte_cmdline/cmdline_os_windows.c
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index a8a6ee9e69..a87c45275c 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 0fe1497008..998e8ade25 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7f..1c4c4dd585 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
diff --git a/lib/librte_eal/common/eal_common_errno.c b/lib/librte_eal/common/eal_common_errno.c
index 2a10fb823f..f86802705a 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(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index bed83a402a..cedf9f0894 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -13,6 +13,7 @@
 
 #include <rte_eal.h>
 #include <rte_log.h>
+#include <rte_os_shim.h>
 #include <rte_per_lcore.h>
 
 #include "eal_log.h"
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 2951b1aca2..66f9114715 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1959,7 +1959,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_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
index 71e0bd035a..86f8429847 100644
--- a/lib/librte_eal/common/eal_common_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -47,9 +47,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_delay_us_sleep() will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_delay_us_sleep(US_PER_S);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..d6c0470eb8 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
diff --git a/lib/librte_eal/freebsd/include/rte_os_shim.h b/lib/librte_eal/freebsd/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/freebsd/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/linux/include/rte_os_shim.h b/lib/librte_eal/linux/include/rte_os_shim.h
new file mode 100644
index 0000000000..1e85229ca9
--- /dev/null
+++ b/lib/librte_eal/linux/include/rte_os_shim.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c
index 83a3d0ffc6..b007dceb39 100644
--- a/lib/librte_eal/windows/eal_hugepages.c
+++ b/lib/librte_eal/windows/eal_hugepages.c
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
diff --git a/lib/librte_eal/windows/eal_lcore.c b/lib/librte_eal/windows/eal_lcore.c
index a85149be95..476c2d2bdf 100644
--- a/lib/librte_eal/windows/eal_lcore.c
+++ b/lib/librte_eal/windows/eal_lcore.c
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
diff --git a/lib/librte_eal/windows/eal_memalloc.c b/lib/librte_eal/windows/eal_memalloc.c
index 85a9712cea..4459d59b1a 100644
--- a/lib/librte_eal/windows/eal_memalloc.c
+++ b/lib/librte_eal/windows/eal_memalloc.c
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 1afe49f35e..66c711d458 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -18,72 +18,18 @@
 extern "C" {
 #endif
 
-/* 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 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
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
new file mode 100644
index 0000000000..edd9a1082c
--- /dev/null
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 220ddd4408..9bb0879538 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 4cce8e953b..38e9d5c1ca 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <rte_os_shim.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
-- 
2.29.3


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

* [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal Dmitry Kozlyuk
@ 2021-04-14 22:06                   ` Dmitry Kozlyuk
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
  2021-04-14 22:50                   ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:06 UTC (permalink / raw)
  To: dev; +Cc: Dmitry Kozlyuk, Ranjit Menon, Olivier Matz

Windows Sockets headers contain `#define s_addr S_un.S_addr`, which
conflicts with definition of `s_addr` field of `struct rte_ether_hdr`.
Prieviously `s_addr` was undefined in <rte_ether.h>, which had been
breaking access to `s_addr` field of `struct in_addr`, so some DPDK
and Windows headers could not be included in one file.

Renaming of `struct rte_ether_hdr` is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html

Temporarily disable `s_addr` macro around `struct rte_ether_hdr`
definition to avoid conflict. Place source MAC address in both `s_addr`
and `S_un.S_addr` fields, so that access works either directly or
through the macro as defined in Windows headers.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
---
 lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9b..a303c24a8c 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
-- 
2.29.3


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

* [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
                                     ` (2 preceding siblings ...)
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
@ 2021-04-14 22:06                   ` Dmitry Kozlyuk
  2021-04-14 22:50                   ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
  4 siblings, 0 replies; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:06 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Beilei Xing, Jeff Guo, Matan Azrad,
	Shahaf Shuler, Viacheslav Ovsiienko, Olivier Matz, Ori Kam,
	Bruce Richardson, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Users of <rte_ip.h> relied on it to provide IP-related defines,
like IPPROTO_* constants, but still had to include POSIX headers
for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access
to IP-related facilities on any OS. Use it to replace POSIX includes
in components enabled on Windows. Move missing constants from Windows
networking shim to OS shim header and include it where needed.

Remove Windows networking shim that is no longer needed.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +--
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 ---
 examples/cmdline/parse_obj_list.c            |  2 --
 examples/flow_filtering/main.c               |  1 -
 examples/l2fwd/main.c                        |  1 -
 examples/link_status_interrupt/main.c        |  1 -
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
 lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
 lib/librte_ethdev/rte_ethdev.c               | 12 +++----
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  7 ++++
 lib/librte_net/rte_net.c                     |  1 +
 24 files changed, 24 insertions(+), 144 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index da089baa4d..22e6e34640 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 0f69f9d125..bac8bc0377 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -10,7 +10,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index c347f8130e..0f1a9c5ed9 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -3,12 +3,11 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
 {
 }
 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index ec673c29ab..1ee5a9eb15 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -5,11 +5,10 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/queue.h>
 
 #include <rte_alarm.h>
 #include <rte_mtr.h>
diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c
index a7946f7756..19981d26d8 100644
--- a/drivers/net/mlx5/mlx5_mac.c
+++ b/drivers/net/mlx5/mlx5_mac.c
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
diff --git a/examples/cmdline/commands.c b/examples/cmdline/commands.c
index f43eacfbad..9ce8ef389f 100644
--- a/examples/cmdline/commands.c
+++ b/examples/cmdline/commands.c
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
diff --git a/examples/cmdline/parse_obj_list.c b/examples/cmdline/parse_obj_list.c
index b04adbea58..959bcd1452 100644
--- a/examples/cmdline/parse_obj_list.c
+++ b/examples/cmdline/parse_obj_list.c
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
diff --git a/examples/flow_filtering/main.c b/examples/flow_filtering/main.c
index 93523d625b..bc28468f17 100644
--- a/examples/flow_filtering/main.c
+++ b/examples/flow_filtering/main.c
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index 3377b08322..be5bf7bc90 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
diff --git a/examples/link_status_interrupt/main.c b/examples/link_status_interrupt/main.c
index f1653b4fb8..8ca3586e05 100644
--- a/examples/link_status_interrupt/main.c
+++ b/examples/link_status_interrupt/main.c
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 49770869bb..a176d15130 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse.c b/lib/librte_cmdline/cmdline_parse.c
index fe366841cd..f5cc934782 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
diff --git a/lib/librte_cmdline/cmdline_parse_etheraddr.c b/lib/librte_cmdline/cmdline_parse_etheraddr.c
index 5cb10de321..433b828a72 100644
--- a/lib/librte_cmdline/cmdline_parse_etheraddr.c
+++ b/lib/librte_cmdline/cmdline_parse_etheraddr.c
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.c b/lib/librte_cmdline/cmdline_parse_ipaddr.c
index f8dbdf204c..5e278c963f 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.c
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.c
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
diff --git a/lib/librte_cmdline/cmdline_parse_ipaddr.h b/lib/librte_cmdline/cmdline_parse_ipaddr.h
index 0ba81647bc..0118c31d44 100644
--- a/lib/librte_cmdline/cmdline_parse_ipaddr.h
+++ b/lib/librte_cmdline/cmdline_parse_ipaddr.h
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644
index 96b6984383..0000000000
--- a/lib/librte_eal/windows/include/arpa/inet.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644
index 6455b9ba51..0000000000
--- a/lib/librte_eal/windows/include/netinet/in.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644
index 2126498797..0000000000
--- a/lib/librte_eal/windows/include/netinet/ip.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
diff --git a/lib/librte_eal/windows/include/rte_os_shim.h b/lib/librte_eal/windows/include/rte_os_shim.h
index edd9a1082c..f40fb62d1d 100644
--- a/lib/librte_eal/windows/include/rte_os_shim.h
+++ b/lib/librte_eal/windows/include/rte_os_shim.h
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_SHIM_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644
index 9536cf8e62..0000000000
--- a/lib/librte_eal/windows/include/sys/socket.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 0419500fc3..c73d263c2f 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -2,18 +2,14 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h
index 918a34ed1f..4679d948fa 100644
--- a/lib/librte_ethdev/rte_ethdev_core.h
+++ b/lib/librte_ethdev/rte_ethdev_core.h
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index b59c4d67a3..8c189009b0 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -16,9 +16,16 @@
  */
 
 #include <stdint.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
diff --git a/lib/librte_net/rte_net.c b/lib/librte_net/rte_net.c
index bfe5003976..d680accc16 100644
--- a/lib/librte_net/rte_net.c
+++ b/lib/librte_net/rte_net.c
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_shim.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
-- 
2.29.3


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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 21:47                           ` Ranjit Menon
@ 2021-04-14 22:08                             ` Dmitry Kozlyuk
  2021-04-14 22:58                               ` Thomas Monjalon
  0 siblings, 1 reply; 132+ messages in thread
From: Dmitry Kozlyuk @ 2021-04-14 22:08 UTC (permalink / raw)
  To: Ranjit Menon, Thomas Monjalon; +Cc: dev

2021-04-14 14:47 (UTC-0700), Ranjit Menon:
> On 4/14/2021 2:42 PM, Thomas Monjalon wrote:
> > 14/04/2021 23:34, Ranjit Menon:  
> >> On 4/14/2021 2:12 PM, Thomas Monjalon wrote:  
> >>> 13/04/2021 09:00, Dmitry Kozlyuk:  
> >>>> Hi Ranjit,
> >>>>
> >>>> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
> >>>> [...]  
> >>>>> The change to remove the networking shim breaks l2fwd compilation on
> >>>>> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
> >>>>>
> >>>>> How do you propose we fix this, only for Windows?  
> >>>> This include is redundant for this file on all platforms, it can be removed.
> >>>> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
> >>>> I wonder which of them need fixing.  
> >>> Let's fix the examples which are supported on Windows.
> >>> Other examples may require more updates anyway.
> >>>  
> >> Thanks, Thomas. For now, this is only required in l2fwd.  
> > Only l2fwd is supported on Windows?
> >  
> >> Dmitry, can you please include this in your patch 4/4?  
> > Ranjit, if you tell me what exactly is needed, I can do it
> > and merge the series quickly.  

I've just sent v10 with all required fixes.

> Sure, Thomas. In l2wfd/main.c, all we need to do is remove the #include 
> <netinet/in.h> line.
> 
> This include file will not exist on Windows anymore, and Dmitry 
> determined that this include is not required in l2fwd on all platforms.

For the reference, complete list of examples that can build for Windows:

	helloworld
	cmdline
	flow_filtering
	ipv4_multicast
	l2fwd
	link_status_interrupt
	qos_meter
	rxtx_callbacks (-Wformat with clang)
	service_cores
	skeleton

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

* Re: [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
                                     ` (3 preceding siblings ...)
  2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
@ 2021-04-14 22:50                   ` Ranjit Menon
  2021-04-14 23:57                     ` Thomas Monjalon
  4 siblings, 1 reply; 132+ messages in thread
From: Ranjit Menon @ 2021-04-14 22:50 UTC (permalink / raw)
  To: Dmitry Kozlyuk, dev


On 4/14/2021 3:06 PM, Dmitry Kozlyuk wrote:
> On Windows, EAL contains two sets of functions and macros for POSIX
> compatibility: <rte_os.h> and a networking shim (socket headers).
> The latter conflicts with system headers and should not exist.
> Exposing the former from EAL can break consumer own POSIX compatibility
> layer and is against standards in general. Hide these symbols from
> external consumers, while keeping them available for DPDK code.
>
> v10:
>      * Fix examples that build on Windows.
> v9:
>      * Fix missing <rte_os_shim.h> include in rte_common_log.c.
>        (This will happen again. Going to add a checkpatch test
>         after this series is merged.)
>
> Dmitry Kozlyuk (4):
>    eal/windows: hide asprintf() shim
>    eal: make OS shims internal
>    net: work around s_addr macro on Windows
>    net: provide IP-related API on any OS
>
>   drivers/bus/pci/private.h                    |  4 +-
>   drivers/bus/vdev/vdev_private.h              |  2 +
>   drivers/common/mlx5/mlx5_common.h            |  1 +
>   drivers/net/i40e/i40e_ethdev.c               |  1 +
>   drivers/net/i40e/i40e_fdir.c                 |  1 +
>   drivers/net/mlx5/mlx5.h                      |  1 -
>   drivers/net/mlx5/mlx5_flow.c                 |  4 +-
>   drivers/net/mlx5/mlx5_flow.h                 |  3 +-
>   drivers/net/mlx5/mlx5_mac.c                  |  1 -
>   examples/cmdline/commands.c                  |  5 --
>   examples/cmdline/parse_obj_list.c            |  2 -
>   examples/flow_filtering/main.c               |  1 -
>   examples/l2fwd/main.c                        |  1 -
>   examples/link_status_interrupt/main.c        |  1 -
>   examples/service_cores/main.c                |  4 +-
>   lib/librte_cmdline/cmdline.c                 |  5 --
>   lib/librte_cmdline/cmdline_os_windows.c      |  2 -
>   lib/librte_cmdline/cmdline_parse.c           |  2 -
>   lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
>   lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
>   lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
>   lib/librte_cmdline/cmdline_private.h         |  1 +
>   lib/librte_cmdline/cmdline_socket.c          |  4 -
>   lib/librte_eal/common/eal_common_config.c    |  1 -
>   lib/librte_eal/common/eal_common_errno.c     |  4 +
>   lib/librte_eal/common/eal_common_log.c       |  1 +
>   lib/librte_eal/common/eal_common_options.c   |  2 +-
>   lib/librte_eal/common/eal_common_timer.c     |  4 +-
>   lib/librte_eal/common/eal_internal_cfg.h     |  1 +
>   lib/librte_eal/common/eal_private.h          | 11 +++
>   lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
>   lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
>   lib/librte_eal/windows/eal.c                 | 30 +++++++
>   lib/librte_eal/windows/eal_hugepages.c       |  1 -
>   lib/librte_eal/windows/eal_lcore.c           |  1 -
>   lib/librte_eal/windows/eal_memalloc.c        |  1 -
>   lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
>   lib/librte_eal/windows/include/netinet/in.h  | 38 --------
>   lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
>   lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
>   lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
>   lib/librte_eal/windows/include/sys/socket.h  | 24 -----
>   lib/librte_ethdev/ethdev_private.h           |  2 +
>   lib/librte_ethdev/rte_ethdev.c               | 12 +--
>   lib/librte_ethdev/rte_ethdev_core.h          |  1 -
>   lib/librte_kvargs/rte_kvargs.c               |  1 +
>   lib/librte_net/rte_ether.h                   | 26 ++++--
>   lib/librte_net/rte_ip.h                      |  7 ++
>   lib/librte_net/rte_net.c                     |  1 +
>   49 files changed, 167 insertions(+), 258 deletions(-)
>   create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
>   create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
>   delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
>   delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
>   delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
>   create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
>   delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

Thanks, Dmitry.

Acked-by: Ranjit Menon <ranjit.menon@intel.com>


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

* Re: [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 22:08                             ` Dmitry Kozlyuk
@ 2021-04-14 22:58                               ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 22:58 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: Ranjit Menon, dev

15/04/2021 00:08, Dmitry Kozlyuk:
> 2021-04-14 14:47 (UTC-0700), Ranjit Menon:
> > On 4/14/2021 2:42 PM, Thomas Monjalon wrote:
> > > 14/04/2021 23:34, Ranjit Menon:  
> > >> On 4/14/2021 2:12 PM, Thomas Monjalon wrote:  
> > >>> 13/04/2021 09:00, Dmitry Kozlyuk:  
> > >>>> Hi Ranjit,
> > >>>>
> > >>>> 2021-04-12 21:46 (UTC-0700), Ranjit Menon:
> > >>>> [...]  
> > >>>>> The change to remove the networking shim breaks l2fwd compilation on
> > >>>>> Windows, since l2fwd/main.c includes netinet/in.h explicitly.
> > >>>>>
> > >>>>> How do you propose we fix this, only for Windows?  
> > >>>> This include is redundant for this file on all platforms, it can be removed.
> > >>>> Since -Dexamples=all doesn't work on Windows because of missing dependencies,
> > >>>> I wonder which of them need fixing.  
> > >>> Let's fix the examples which are supported on Windows.
> > >>> Other examples may require more updates anyway.
> > >>>  
> > >> Thanks, Thomas. For now, this is only required in l2fwd.  
> > > Only l2fwd is supported on Windows?
> > >  
> > >> Dmitry, can you please include this in your patch 4/4?  
> > > Ranjit, if you tell me what exactly is needed, I can do it
> > > and merge the series quickly.  
> 
> I've just sent v10 with all required fixes.

Thank you
Some acks were removed from this v10, I am re-adding them.

> > Sure, Thomas. In l2wfd/main.c, all we need to do is remove the #include 
> > <netinet/in.h> line.
> > 
> > This include file will not exist on Windows anymore, and Dmitry 
> > determined that this include is not required in l2fwd on all platforms.
> 
> For the reference, complete list of examples that can build for Windows:
> 
> 	helloworld
> 	cmdline
> 	flow_filtering
> 	ipv4_multicast
> 	l2fwd
> 	link_status_interrupt
> 	qos_meter
> 	rxtx_callbacks (-Wformat with clang)
> 	service_cores
> 	skeleton

devtools/test-meson-builds.sh should be updated to compile these examples
with MinGW.



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

* Re: [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols
  2021-04-14 22:50                   ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
@ 2021-04-14 23:57                     ` Thomas Monjalon
  0 siblings, 0 replies; 132+ messages in thread
From: Thomas Monjalon @ 2021-04-14 23:57 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: dev, Ranjit Menon, olivier.matz

> > Dmitry Kozlyuk (4):
> >    eal/windows: hide asprintf() shim
> >    eal: make OS shims internal
> >    net: work around s_addr macro on Windows
> >    net: provide IP-related API on any OS
> 
> Thanks, Dmitry.
> 
> Acked-by: Ranjit Menon <ranjit.menon@intel.com>

Applied, thanks




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

* Re: [dpdk-dev] [PATCH v7 1/5] eal: add sleep API
  2021-04-07  7:31                   ` Morten Brørup
@ 2021-04-29 17:09                     ` Tyler Retzlaff
  0 siblings, 0 replies; 132+ messages in thread
From: Tyler Retzlaff @ 2021-04-29 17:09 UTC (permalink / raw)
  To: Morten Brørup
  Cc: Dmitry Kozlyuk, dev, Jie Zhou, Nick Connolly, Khoa To,
	Ray Kinsella, Narcisa Ana Maria Vasile, Dmitry Malloy,
	Pallavi Kadam, Neil Horman

On Wed, Apr 07, 2021 at 09:31:43AM +0200, Morten Brørup wrote:
> 
> I think it's just tradition from Linux/BSD developers not being used to cross-platform development or having forgotten how to develop software for deeply embedded systems without a standard O/S below. We use POSIX functions like sleep() without thinking about it, and simply forget looking for an EAL variant of the function first.
> 

it's easy to make this mistake if by including dpdk application headers
we indirectly introduce platform specific headers into the applications
namespace.

if this wasn't happening the application would be forced to confront the
issue by directly including unistd.h itself directly making it more
obvious that they were writing inherently non-portable code.

i think this is being fixed but it is a work in progress but it
highlights the reason why there needs to be scrutiny around what goes
into the eal and other library headers.

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

end of thread, other threads:[~2021-04-29 17:09 UTC | newest]

Thread overview: 132+ 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-03-16  9:51                 ` Thomas Monjalon
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
2021-03-06  0:04     ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk
2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-03-06 15:27         ` Lance Richardson
2021-03-06  0:04       ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk
2021-03-16  9:59         ` Thomas Monjalon
2021-03-06  0:05       ` [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-17 19:23       ` [dpdk-dev] [PATCH v4 0/4] " Ranjit Menon
2021-03-20 11:27       ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
2021-03-22  8:57           ` Kinsella, Ray
2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-03-20 11:27         ` [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim Dmitry Kozlyuk
2021-03-20 13:05         ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk
2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-03-26  9:04             ` Thomas Monjalon
2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-03-26  9:12             ` Thomas Monjalon
2021-03-31 21:05               ` Nick Connolly
2021-03-31 21:19                 ` Thomas Monjalon
2021-03-31 21:45                   ` Nick Connolly
2021-03-31 21:55                     ` Thomas Monjalon
2021-04-01 23:10                       ` Dmitry Kozlyuk
2021-04-01 23:18                         ` Thomas Monjalon
2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-03-26  9:22             ` Thomas Monjalon
2021-03-20 13:05           ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk
2021-03-26  9:28             ` Thomas Monjalon
2021-04-01 23:03               ` Dmitry Kozlyuk
2021-04-03 23:41           ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
2021-04-06 14:34               ` Morten Brørup
2021-04-06 23:29                 ` Dmitry Kozlyuk
2021-04-07  7:31                   ` Morten Brørup
2021-04-29 17:09                     ` Tyler Retzlaff
2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-10  7:05               ` Nick Connolly
2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-03 23:41             ` [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-07 22:22             ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-08 11:26                 ` Olivier Matz
2021-04-07 22:22               ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-08 11:45                 ` Olivier Matz
2021-04-08 19:51                   ` Dmitry Kozlyuk
2021-04-09 13:33                     ` Olivier Matz
2021-04-14 21:47                   ` Thomas Monjalon
2021-04-10 22:47               ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-14 21:33                   ` Thomas Monjalon
2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-10 22:47                 ` [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-13  4:46                 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
2021-04-13  7:00                   ` Dmitry Kozlyuk
2021-04-14 21:12                     ` Thomas Monjalon
2021-04-14 21:34                       ` Ranjit Menon
2021-04-14 21:42                         ` Thomas Monjalon
2021-04-14 21:47                           ` Ranjit Menon
2021-04-14 22:08                             ` Dmitry Kozlyuk
2021-04-14 22:58                               ` Thomas Monjalon
2021-04-14 22:06                 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-14 22:06                   ` [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-14 22:50                   ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
2021-04-14 23:57                     ` Thomas Monjalon
2021-03-17 19:19 ` [dpdk-dev] [PATCH 0/7] " Ranjit Menon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).