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 BC3D4A0C40; Tue, 3 Aug 2021 21:01:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1710541210; Tue, 3 Aug 2021 21:01:39 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id C6752411FB for ; Tue, 3 Aug 2021 21:01:33 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 270D220B36ED; Tue, 3 Aug 2021 12:01:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 270D220B36ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1628017293; bh=LF1D8eN+wBAeduli9A3YQUhlSeXFC+kfXFxFmQlfZSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmNg9+aS8BS6KCqA065ZYC0wxHO1wAMzvghLtx0hdnYc+qMWKfDqsaF4K0pLgqiUj MpHaQfrKVVMJMKCALlvSl5OQrJuX2aiI5gk7gSIiYIWhC+UoZuipgAH8beI2/m12We O8okiOEseWmbPlCXukyK0ulHnDGZsfTpRGIeK2GM= 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: Tue, 3 Aug 2021 12:01:24 -0700 Message-Id: <1628017291-3756-4-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1628017291-3756-1-git-send-email-navasile@linux.microsoft.com> References: <1627925546-29982-1-git-send-email-navasile@linux.microsoft.com> <1628017291-3756-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v13 03/10] eal/windows: 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. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible. Signed-off-by: Narcisa Vasile --- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-) diff --git a/lib/eal/common/rte_thread.c b/lib/eal/common/rte_thread.c index e1a4d7eae4..27ad1c7eb0 100644 --- a/lib/eal/common/rte_thread.c +++ b/lib/eal/common/rte_thread.c @@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr) int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, - rte_cpuset_t *cpuset) + rte_cpuset_t *cpuset) { RTE_VERIFY(thread_attr != NULL); RTE_VERIFY(cpuset != NULL); @@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, - rte_cpuset_t *cpuset) + rte_cpuset_t *cpuset) { RTE_VERIFY(thread_attr != NULL); RTE_VERIFY(cpuset != NULL); @@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, - enum rte_thread_priority priority) + enum rte_thread_priority priority) { RTE_VERIFY(thread_attr != NULL); diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 032ff73b36..bf649c2fe6 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -235,9 +235,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/eal/windows/rte_thread.c b/lib/eal/windows/rte_thread.c index 01966e7745..c1ecfbd6ae 100644 --- a/lib/eal/windows/rte_thread.c +++ b/lib/eal/windows/rte_thread.c @@ -13,6 +13,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; +} + +static int +thread_log_last_error(const char *message) +{ + DWORD error = GetLastError(); + RTE_LOG(DEBUG, EAL, "GetLastError()=%lu: %s\n", error, message); + + return thread_translate_win32_error(error); +} + rte_thread_t rte_thread_self(void) { @@ -42,7 +90,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr) int rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, - rte_cpuset_t *cpuset) + rte_cpuset_t *cpuset) { RTE_VERIFY(thread_attr != NULL); thread_attr->cpuset = *cpuset; @@ -52,7 +100,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr, int rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, - rte_cpuset_t *cpuset) + rte_cpuset_t *cpuset) { RTE_VERIFY(thread_attr != NULL); @@ -63,7 +111,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, int rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr, - enum rte_thread_priority priority) + enum rte_thread_priority priority) { RTE_VERIFY(thread_attr != NULL); @@ -76,18 +124,18 @@ int rte_thread_key_create(rte_thread_key *key, __rte_unused void (*destructor)(void *)) { + int ret; + *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()"); + ret = thread_log_last_error("TlsAlloc()"); free(*key); - rte_errno = ENOEXEC; - return -1; + return ret; } return 0; } @@ -95,16 +143,16 @@ rte_thread_key_create(rte_thread_key *key, int rte_thread_key_delete(rte_thread_key key) { - if (!key) { + int ret; + + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); - rte_errno = EINVAL; - return -1; + return EINVAL; } if (!TlsFree(key->thread_index)) { - RTE_LOG_WIN32_ERR("TlsFree()"); + ret = thread_log_last_error("TlsFree()"); free(key); - rte_errno = ENOEXEC; - return -1; + return ret; } free(key); return 0; @@ -115,17 +163,14 @@ rte_thread_value_set(rte_thread_key key, const void *value) { char *p; - if (!key) { + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); - rte_errno = EINVAL; - return -1; + return EINVAL; } /* discard const qualifier */ p = (char *) (uintptr_t) value; if (!TlsSetValue(key->thread_index, p)) { - RTE_LOG_WIN32_ERR("TlsSetValue()"); - rte_errno = ENOEXEC; - return -1; + return thread_log_last_error("TlsSetValue()"); } return 0; } @@ -134,16 +179,18 @@ void * rte_thread_value_get(rte_thread_key key) { void *output; + DWORD ret = 0; - if (!key) { + if (key == NULL) { RTE_LOG(DEBUG, EAL, "Invalid TLS key.\n"); rte_errno = EINVAL; return NULL; } output = TlsGetValue(key->thread_index); - if (GetLastError() != ERROR_SUCCESS) { - RTE_LOG_WIN32_ERR("TlsGetValue()"); - rte_errno = ENOEXEC; + ret = GetLastError(); + if (ret != 0) { + RTE_LOG(DEBUG, EAL, "GetLastError()=%lu: TlsGetValue()\n", ret); + rte_errno = thread_translate_win32_error(ret); return NULL; } return output; -- 2.31.0.vfs.0.1