From patchwork Tue Mar 23 00:20:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Narcisa Ana Maria Vasile X-Patchwork-Id: 89646 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6D5A7A034F; Tue, 23 Mar 2021 01:21:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E4C1E140D48; Tue, 23 Mar 2021 01:21:16 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 07972140D03 for ; Tue, 23 Mar 2021 01:21:11 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1059) id 4766120B5682; Mon, 22 Mar 2021 17:21:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4766120B5682 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1616458870; bh=YazKqFgHcH3mxxKBG/Bg2pxtKyKe0UuzLsYVDJhb3RM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xiv+1XaUqiiNfF8lEu0NPyQ1P0UjnWUxHtW+8xopWUOBuTKsSUzPoafBnKb1QS7/r jz5jCwNjpIcpuYWnjnQhQgJTbLDYTHL+Yhe+abzynseBEwKEDkvfEhPe1QID6lFkoT REXUxjBAMTy7ktjCtW2M72CXEzEe5tH1NtceUo/0= From: Narcisa Ana Maria Vasile To: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com Cc: bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Date: Mon, 22 Mar 2021 17:20:28 -0700 Message-Id: <1616458835-28502-4-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1616458835-28502-1-git-send-email-navasile@linux.microsoft.com> References: <1616029240-26588-2-git-send-email-navasile@linux.microsoft.com> <1616458835-28502-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v2 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" From: Narcisa Vasile Add function to translate Windows error codes to errno-style error codes. Signed-off-by: Narcisa Vasile --- lib/librte_eal/windows/rte_thread.c | 59 ++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/windows/rte_thread.c b/lib/librte_eal/windows/rte_thread.c index d0294d179..c948b2c5e 100644 --- a/lib/librte_eal/windows/rte_thread.c +++ b/lib/librte_eal/windows/rte_thread.c @@ -12,6 +12,47 @@ struct eal_tls_key { DWORD thread_index; }; +/* Translates the most common error codes related to threads */ +static int rte_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; + + default: + return EINVAL; + } + + return EINVAL; +} + rte_thread_t rte_thread_self(void) { @@ -87,13 +128,13 @@ rte_thread_tls_key_create(rte_tls_key *key, *key = malloc(sizeof(**key)); if ((*key) == NULL) { RTE_LOG(DEBUG, EAL, "Cannot allocate TLS key.\n"); - return -1; + return ENOMEM; } (*key)->thread_index = TlsAlloc(); if ((*key)->thread_index == TLS_OUT_OF_INDEXES) { RTE_LOG_WIN32_ERR("TlsAlloc()"); free(*key); - return -1; + return rte_thread_translate_win32_error(GetLastError()); } return 0; } @@ -101,14 +142,14 @@ rte_thread_tls_key_create(rte_tls_key *key, int rte_thread_tls_key_delete(rte_tls_key key) { - if (!key) { + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); - return -1; + return EINVAL; } if (!TlsFree(key->thread_index)) { RTE_LOG_WIN32_ERR("TlsFree()"); free(key); - return -1; + return rte_thread_translate_win32_error(GetLastError()); } free(key); return 0; @@ -119,15 +160,15 @@ rte_thread_tls_value_set(rte_tls_key key, const void *value) { char *p; - if (!key) { + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); - return -1; + return EINVAL; } /* discard const qualifier */ p = (char *) (uintptr_t) value; if (!TlsSetValue(key->thread_index, p)) { RTE_LOG_WIN32_ERR("TlsSetValue()"); - return -1; + return rte_thread_translate_win32_error(GetLastError()); } return 0; } @@ -137,7 +178,7 @@ rte_thread_tls_value_get(rte_tls_key key) { void *output; - if (!key) { + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); rte_errno = EINVAL; return NULL;