From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9B082A0A0E; Thu, 29 Apr 2021 02:50:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0113F412CA; Thu, 29 Apr 2021 02:50:45 +0200 (CEST) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by mails.dpdk.org (Postfix) with ESMTP id E5756412C1 for ; Thu, 29 Apr 2021 02:50:39 +0200 (CEST) Received: by mail-lj1-f173.google.com with SMTP id u20so74393289lja.13 for ; Wed, 28 Apr 2021 17:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t8Vlj5q3aF07+xRIf/JyPx2TyXiCT8HhzTKadDOsJ+w=; b=I5E8+WEF8kbb3w2tVto3s+sxb2s3Xhc5aBl/x96pxGFdmhHWn7mRbGKkrGdgW3w20o /BxuuMG5wsLSgoK/WgVxUIz5WwbBNKeG39THHdA4gxuaOcl+bl7a8JPIYBbYJxW8/Wdq 0+7JXmU5h3vYwtKoDFgzd+vJhGqi93PEDypj8OlfLhgMHJnaWnYm1gTfLFa5jkuYR6N1 ljn7pI/mEb8L0OgQXocZKCKpNy2bt4EtZQj+ElFzPaZ3dE2YIzNklUsGgk21amDlbZ/u PitXJPj54bcLi7mVk2ukUZ7PnT0PuBEEvkaHMttnTf0JOCfsHBAsGKGpko6F9E1HwHx9 kiRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t8Vlj5q3aF07+xRIf/JyPx2TyXiCT8HhzTKadDOsJ+w=; b=jkhlYYj21v+beelC6QRBaNJuLpPy/Zcca/jCWKXitkHvDS6eWFgO2iy5+8e5rpM1Ru UFSOxIEqhDxuNjxCkc13QLH9+9dupcf+Eu7/iOkJjf9sHoiFdtZ+/nd0ncAxkA4MmcN5 9kR22h5qmqKJofpVgEuYFMnsy3sH0ivm8Msd27XrPlYIiBGAwpYOh77g/D4JZAHH61Fv 1RXkVt7as47MQe93OJJP8BZAC8ZFnyMJYeBeJJx/lc3TknWKNZLeSTkVexCKYH5IcZSS 3Wo4+yUujkUtO2jUrz0OJelwvUVG7wImGcOCwmXoUZYl3M5pS2CCGe57yAKRF7Ngmq+H K4SQ== X-Gm-Message-State: AOAM5335ccXQdFrS24lowygZTA4eHEM1VcQm633o26ySLcnKPApOoQ2E dRubNiyLtWctijbX+lbOWO8= X-Google-Smtp-Source: ABdhPJxaN5cMunvzC0LZysh+GXcSA0nZINUYQemiM3C7vvrdy4AvDAtvI7Aq2DiuAkPvK6J51QZrRw== X-Received: by 2002:a2e:5851:: with SMTP id x17mr23175513ljd.333.1619657439569; Wed, 28 Apr 2021 17:50:39 -0700 (PDT) Received: from sovereign (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id t12sm251894lfl.254.2021.04.28.17.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 17:50:39 -0700 (PDT) Date: Thu, 29 Apr 2021 03:50:38 +0300 From: Dmitry Kozlyuk To: Narcisa Ana Maria Vasile Cc: dev@dpdk.org, thomas@monjalon.net, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com, bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Message-ID: <20210429035038.40c9602f@sovereign> In-Reply-To: <1617413948-10504-4-git-send-email-navasile@linux.microsoft.com> References: <1617057640-24301-2-git-send-email-navasile@linux.microsoft.com> <1617413948-10504-1-git-send-email-navasile@linux.microsoft.com> <1617413948-10504-4-git-send-email-navasile@linux.microsoft.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v6 03/10] windows/eal: translate Windows errors to errno-style errors X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 2021-04-02 18:39 (UTC-0700), Narcisa Ana Maria Vasile: > From: Narcisa Vasile > > Add function to translate Windows error codes to > errno-style error codes. > > Signed-off-by: Narcisa Vasile Commit topic should be "eal/windows", not "windows/eal". > --- > lib/librte_eal/include/rte_thread.h | 5 +- > lib/librte_eal/windows/rte_thread.c | 75 ++++++++++++++++++++++------- > 2 files changed, 60 insertions(+), 20 deletions(-) > > diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h > index bfdd8e1b1..2d7b3bc05 100644 > --- a/lib/librte_eal/include/rte_thread.h > +++ b/lib/librte_eal/include/rte_thread.h > @@ -221,9 +221,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value); > * > * @return > * On success, value data pointer (can also be NULL). > - * On failure, NULL and an error number is set in rte_errno. > - * rte_errno can be: EINVAL - Invalid parameter passed. > - * ENOEXEC - Specific OS error. > + * On failure, NULL and a positive error number is set in rte_errno. > + * > */ > __rte_experimental > void *rte_thread_value_get(rte_thread_key key); > diff --git a/lib/librte_eal/windows/rte_thread.c b/lib/librte_eal/windows/rte_thread.c > index b29336cbd..ecd2f810f 100644 > --- a/lib/librte_eal/windows/rte_thread.c > +++ b/lib/librte_eal/windows/rte_thread.c > @@ -12,6 +12,51 @@ struct eal_tls_key { > DWORD thread_index; > }; > > +/* Translates the most common error codes related to threads */ > +static int rte_thread_translate_win32_error(void) Return type should be on a separate line. > +{ > + DWORD error = 0; > + > + error = GetLastError(); You could declare "error" and assign it in one statement. Don't initialize variables if there's no good initial value: it prevents compiler to issue a warning if the variable is not assigned a meaningful value afterwards. > + > + 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; > + > + default: > + return EINVAL; > + } Default branch is redundant at the end of function. > + > + return EINVAL; > +} > + > rte_thread_t > rte_thread_self(void) > { > @@ -87,15 +132,13 @@ rte_thread_key_create(rte_thread_key *key, > *key = malloc(sizeof(**key)); > if ((*key) == NULL) { > RTE_LOG(DEBUG, EAL, "Cannot allocate TLS key.\n"); > - rte_errno = ENOMEM; > - return -1; > + return ENOMEM; > } > (*key)->thread_index = TlsAlloc(); > if ((*key)->thread_index == TLS_OUT_OF_INDEXES) { > RTE_LOG_WIN32_ERR("TlsAlloc()"); > free(*key); > - rte_errno = ENOEXEC; > - return -1; > + return rte_thread_translate_win32_error(); Logging above can overwrite GetLastError() value. I suggest splitting rte_thread_translate_win32_error() into translation part for cases when you have error number already, and a wrapper that calls GetLastError() to shorten calling code. Same applies below in this file. [...]