From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id A8FAEA0508;
	Wed, 13 Apr 2022 09:07:56 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 5E6C340694;
	Wed, 13 Apr 2022 09:07:56 +0200 (CEST)
Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182])
 by mails.dpdk.org (Postfix) with ESMTP id 47AE54068B
 for <dev@dpdk.org>; Wed, 13 Apr 2022 09:07:55 +0200 (CEST)
Received: by linux.microsoft.com (Postfix, from userid 1086)
 id 8A47E20C34BC; Wed, 13 Apr 2022 00:07:54 -0700 (PDT)
DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8A47E20C34BC
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;
 s=default; t=1649833674;
 bh=8dU2iMa0ePG/iVZ0nL6F1LX4yTc2l1H3ptVGIeTOqJM=;
 h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
 b=sL3Wv0E/gU03oPFBMpx8YHRgfeMbDsF7TfdXEGN6rrZPd5shxOTg3Di3lsp52Qtd4
 VyLu9qMCXAW4bqBUzY901i8sxj1ZZOddC/iCh6NXfYZrPDbH+L7ZOaS87tkncpRGV+
 s3vOgkNAJQ8BHmUnz3AV/pSQ6bABvbdzPqj9jS7o=
Date: Wed, 13 Apr 2022 00:07:54 -0700
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: "Menon, Ranjit" <ranjit.menon@intel.com>
Cc: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com,
 anatoly.burakov@intel.com, Narcisa Vasile <navasile@microsoft.com>
Subject: Re: [PATCH v2 1/4] eal/windows: translate Windows errors to
 errno-style errors
Message-ID: <20220413070754.GA792@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
References: <1648819793-18948-1-git-send-email-roretzla@linux.microsoft.com>
 <1649760220-8683-1-git-send-email-roretzla@linux.microsoft.com>
 <1649760220-8683-2-git-send-email-roretzla@linux.microsoft.com>
 <55647598-0f70-bcd4-b381-54927e160561@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <55647598-0f70-bcd4-b381-54927e160561@intel.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

On Tue, Apr 12, 2022 at 10:26:27AM -0700, Menon, Ranjit wrote:
> Hi, Tyler
> 
> On 4/12/2022 3:43 AM, Tyler Retzlaff wrote:
> >Add function to translate Windows error codes to errno-style error
> >codes. The possible return values are chosen so that we have as
> >much semantical compatibility between platforms as possible.
> >
> >Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
> >Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> >---
> >  lib/eal/windows/rte_thread.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 49 insertions(+)
> >
> >diff --git a/lib/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c
> >index 667287c..c272018 100644
> >--- a/lib/eal/windows/rte_thread.c
> >+++ b/lib/eal/windows/rte_thread.c
> >@@ -1,5 +1,6 @@
> >  /* SPDX-License-Identifier: BSD-3-Clause
> >   * Copyright 2021 Mellanox Technologies, Ltd
> >+ * Copyright (C) 2022 Microsoft Corporation
> >   */
> >  #include <rte_common.h>
> >@@ -11,6 +12,54 @@ struct eal_tls_key {
> >  	DWORD thread_index;
> >  };
> >+/* Translates the most common error codes related to threads */
> >+static int
> >+thread_translate_win32_error(DWORD error)
> >+{
> >+	switch (error) {
> >+	case ERROR_SUCCESS:
> >+		return 0;
> >+
> >+	case ERROR_INVALID_PARAMETER:
> >+		return EINVAL;
> >+
> >+	case ERROR_INVALID_HANDLE:
> >+		return EFAULT;
> >+
> >+	case ERROR_NOT_ENOUGH_MEMORY:
> >+		/* FALLTHROUGH */
> >+	case ERROR_NO_SYSTEM_RESOURCES:
> >+		return ENOMEM;
> >+
> >+	case ERROR_PRIVILEGE_NOT_HELD:
> >+		/* FALLTHROUGH */
> >+	case ERROR_ACCESS_DENIED:
> >+		return EACCES;
> >+
> >+	case ERROR_ALREADY_EXISTS:
> >+		return EEXIST;
> >+
> >+	case ERROR_POSSIBLE_DEADLOCK:
> >+		return EDEADLK;
> >+
> >+	case ERROR_INVALID_FUNCTION:
> >+		/* FALLTHROUGH */
> >+	case ERROR_CALL_NOT_IMPLEMENTED:
> >+		return ENOSYS;
> >+	}
> >+
> >+	return EINVAL;
> >+}
> >+
> 
> Shouldn't we return all these error values as negative... as in
> -EINVAL, -EFAULT etc. ?

no. since this is just a translation function it is up to the caller
what it will do with the translated value and any conversion to -errno.

since it is also used to store into rte_errno it would have been
confusing to see something like the following to reverse the sign back.

err = thread_translate_win32_error(win32err);
rte_errno = -err; // confusing

personally i don't like the -errno returns at all and this is just
another reason contributing to that opinion. you can refer to my
previous mailing list posts on the subject.

> 
> 
> ranjit m.