From patchwork Wed Aug 30 09:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pekka_Sepp=C3=A4nen?= X-Patchwork-Id: 74965 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A1A13857347 for ; Wed, 30 Aug 2023 09:17:03 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by sourceware.org (Postfix) with ESMTPS id 145FC38582A3 for ; Wed, 30 Aug 2023 09:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 145FC38582A3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sourceware.mail.kapsi.fi Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kapsi.fi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Subject:Content-Transfer-Encoding:Content-Type:Message-ID:To: From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VJqxbeYU/nlpuGUe7nJ/ZMCNkfhju4sjLFpnwE2MW8k=; b=klppmzbv3csvUMzyZccaRIEWJZ KUpzCczt0o/pgBknbneM0KibN8DR9v3uft4GkD87mkdlSl6FGYiHrobhXfmhSoQ34jpKf/K7TZfuv 9QOq4PLF+WMJBRe4alpEe/IsI51A0QsPqWUQmHwcsfsBGFgcwQNRQSZTpv9QEXZR774sd8Rob7yOI 7wNurlEe95O18aWf479Blf3NkXnbKIXkoF+ZmIXW6ZwgxwqFTqFRQw+PHIv5KebQkg+7jZ+H8NEV4 3ag51wL/ojK1j1WVHPArzRQTmVwqc1LuZ4rcRG43/vGslj9exJtZTevvXNQY0XN1TAbKDvCAyCF8+ ZAD1jICg==; Received: from [2001:67c:1be8::200] (helo=roundcube.kapsi.fi) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qbHJL-00D1CJ-11 for newlib@sourceware.org; Wed, 30 Aug 2023 12:16:27 +0300 MIME-Version: 1.0 Date: Wed, 30 Aug 2023 12:16:26 +0300 From: =?utf-8?q?Pekka_Sepp=C3=A4nen?= To: newlib@sourceware.org Message-ID: X-Sender: pexu@sourceware.mail.kapsi.fi X-SA-Exim-Connect-IP: 2001:67c:1be8::200 X-SA-Exim-Mail-From: pexu@sourceware.mail.kapsi.fi X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 1/3] Reentrancy, use _REENT_ERRNO() X-SA-Exim-Version: 4.2.1 (built Wed, 06 Jul 2022 17:57:39 +0000) X-SA-Exim-Scanned: Yes (on mail.kapsi.fi) X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org Sender: "Newlib" Use _REENT_ERRNO() macro to access errno. This encapsulation is required, as errno might be either _errno member of struct _reent, _tls_errno or any such implementation detail. --- newlib/libc/locale/locale.c | 18 +++++++++--------- newlib/libc/locale/newlocale.c | 6 +++--- newlib/libc/stdlib/_mallocr.c | 2 +- newlib/libc/stdlib/nano-mallocr.c | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c index 3772106e3..b16ec1511 100644 --- a/newlib/libc/locale/locale.c +++ b/newlib/libc/locale/locale.c @@ -317,7 +317,7 @@ _setlocale_r (struct _reent *p, if (category < LC_ALL || category >= _LC_LAST) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } @@ -343,7 +343,7 @@ _setlocale_r (struct _reent *p, env = __get_locale_env (p, i); if (strlen (env) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[i], env); @@ -354,7 +354,7 @@ _setlocale_r (struct _reent *p, env = __get_locale_env (p, category); if (strlen (env) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[category], env); @@ -364,7 +364,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[category], locale); @@ -375,7 +375,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } for (i = 1; i < _LC_LAST; ++i) @@ -387,7 +387,7 @@ _setlocale_r (struct _reent *p, ; if (!r[1]) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; /* Hmm, just slashes... */ } do @@ -396,7 +396,7 @@ _setlocale_r (struct _reent *p, break; /* Too many slashes... */ if ((len = r - locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strlcpy (new_categories[i], locale, len + 1); @@ -429,7 +429,7 @@ _setlocale_r (struct _reent *p, strcpy (saved_categories[i], __get_global_locale ()->categories[i]); if (__loadlocale (__get_global_locale (), i, new_categories[i]) == NULL) { - saverr = p->_errno; + saverr = _REENT_ERRNO(p); for (j = 1; j < i; j++) { strcpy (new_categories[j], saved_categories[j]); @@ -440,7 +440,7 @@ _setlocale_r (struct _reent *p, __loadlocale (__get_global_locale (), j, new_categories[j]); } } - p->_errno = saverr; + _REENT_ERRNO(p) = saverr; return NULL; } } diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c index 278f78ed2..92f9e0a9c 100644 --- a/newlib/libc/locale/newlocale.c +++ b/newlib/libc/locale/newlocale.c @@ -103,7 +103,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, /* Check for invalid mask values and valid locale ptr. */ if ((category_mask & ~LC_VALID_MASK) || !locale) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } /* If the new locale is supposed to be all default locale, just return @@ -125,7 +125,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, : locale; if (strlen (cat) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[i], cat); @@ -172,7 +172,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, /* Otherwise load locale data. */ else if (!__loadlocale (&tmp_locale, i, new_categories[i])) { - p->_errno = ENOENT; + _REENT_ERRNO(p) = ENOENT; goto error; } } diff --git a/newlib/libc/stdlib/_mallocr.c b/newlib/libc/stdlib/_mallocr.c index 1997b6db1..c73982c18 100644 --- a/newlib/libc/stdlib/_mallocr.c +++ b/newlib/libc/stdlib/_mallocr.c @@ -346,7 +346,7 @@ extern void __malloc_unlock(); #define RDECL struct _reent *reent_ptr; #endif -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) #define RCALL reent_ptr, #define RONECALL reent_ptr diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c index 41e69abb0..030be44ad 100644 --- a/newlib/libc/stdlib/nano-mallocr.c +++ b/newlib/libc/stdlib/nano-mallocr.c @@ -64,7 +64,7 @@ #define MALLOC_LOCK __malloc_lock(reent_ptr) #define MALLOC_UNLOCK __malloc_unlock(reent_ptr) -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) #define nano_malloc _malloc_r #define nano_free _free_r From patchwork Wed Aug 30 09:16:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pekka_Sepp=C3=A4nen?= X-Patchwork-Id: 74966 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3723385C6D5 for ; Wed, 30 Aug 2023 09:17:06 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by sourceware.org (Postfix) with ESMTPS id 9A0F8385840A for ; Wed, 30 Aug 2023 09:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A0F8385840A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sourceware.mail.kapsi.fi Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kapsi.fi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Subject:Content-Transfer-Encoding:Content-Type:Message-ID:To: From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=c4mNbHeB9SZPNl4C/pLlKfO6fCHbcxTE6irjRCCfdjs=; b=FaXFtRZ3gERzsxw2parUK2Gl0T RDowyyiEva/8tMy2v3Rbkb/653jwHl7F33nOiGoKQtxTCHDglK58PeVm0ciFJlYKbuqW/Hfrtf81/ xx4D8xHy3YN82ovoYqC54y52xpqJ+C9MiTC2dCR8424TIv+7YTfrY02FjuBrylFm11W0okFOGRV76 FOwl6GmLhjaWAd9upqQ0EbgbntbhKawPzZRY7s36FjnXcid2X+shPGtb/uuLykZyU3ARoZB2VmQ7t nFb02u2hGs58iTf8zBBTTmFgE4UKstwVlNAfihWUhfPTmWHRy2nXi/t+2nlqkd+kmn7yjlwTmwsRO azl5a9jw==; Received: from [2001:67c:1be8::200] (helo=roundcube.kapsi.fi) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qbHJQ-00D1EC-0e for newlib@sourceware.org; Wed, 30 Aug 2023 12:16:32 +0300 MIME-Version: 1.0 Date: Wed, 30 Aug 2023 12:16:32 +0300 From: =?utf-8?q?Pekka_Sepp=C3=A4nen?= To: newlib@sourceware.org Message-ID: <482bc37e7c7cdb7830996d6ae52fe8ca@sourceware.mail.kapsi.fi> X-Sender: pexu@sourceware.mail.kapsi.fi X-SA-Exim-Connect-IP: 2001:67c:1be8::200 X-SA-Exim-Mail-From: pexu@sourceware.mail.kapsi.fi X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 2/3] Reentrancy, conditionally provide default __getreent() implementation X-SA-Exim-Version: 4.2.1 (built Wed, 06 Jul 2022 17:57:39 +0000) X-SA-Exim-Scanned: Yes (on mail.kapsi.fi) X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org Sender: "Newlib" Conditionally provide default __getreent() implementation only if _REENT_THREAD_LOCAL is not defined. If struct _reent is replaced by dedicated thread-local objects neither the structure nor _impure_ptr is available. --- newlib/libc/reent/getreent.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/newlib/libc/reent/getreent.c b/newlib/libc/reent/getreent.c index 5fa98e96b..86bb04fb9 100644 --- a/newlib/libc/reent/getreent.c +++ b/newlib/libc/reent/getreent.c @@ -9,6 +9,8 @@ int _dummy_getreent; #include <_ansi.h> #include +#ifndef _REENT_THREAD_LOCAL + #ifdef __getreent #undef __getreent #endif @@ -19,4 +21,6 @@ __getreent (void) return _impure_ptr; } +#endif /* !_REENT_THREAD_LOCAL */ + #endif From patchwork Wed Aug 30 09:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Pekka_Sepp=C3=A4nen?= X-Patchwork-Id: 74964 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC3193856972 for ; Wed, 30 Aug 2023 09:16:50 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by sourceware.org (Postfix) with ESMTPS id 7CBBB3857016 for ; Wed, 30 Aug 2023 09:16:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CBBB3857016 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sourceware.mail.kapsi.fi Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kapsi.fi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Subject:Content-Transfer-Encoding:Content-Type:Message-ID:To: From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=oyKQ1mCl0YN5+6qfem4kzbfASXQ0BGJ8MZt4fP7TXBs=; b=egFqxcB1NOdSiPxJ5B7VXRMfE2 WBJbLnzNNyiH6B6zdOwQ+vYC1oRC6Z6/fRr6+K5dTV0hYoE2hkl3TPe2KE8kO2KgA4YDqsnNxL8JI jCvhvCioN6ndb4UziP/xI5pGwGfJAs6G951g0F9iTEtkid+6dghFU/nuqtm5q4gTUmBtG9Yr7qRaa /EdEPHEdFoi8UYS08JMVcKnk68xEVVQ6QltFqnp5IzHbk7e95bIfDOGQJdmSG5eH5lrqbXcSWzy+r peq1uKr8oLrVOjiLqHIRctLn0TreBTsvQaiTE45zUFpEhTrL/lua0rDUvCp9ADHOOUehZuN+bXXeB bB5b0wxQ==; Received: from [2001:67c:1be8::200] (helo=roundcube.kapsi.fi) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qbHJU-00D1F5-0t for newlib@sourceware.org; Wed, 30 Aug 2023 12:16:36 +0300 MIME-Version: 1.0 Date: Wed, 30 Aug 2023 12:16:36 +0300 From: =?utf-8?q?Pekka_Sepp=C3=A4nen?= To: newlib@sourceware.org Message-ID: <78a10e66535350a46e694ff7484279eb@sourceware.mail.kapsi.fi> X-Sender: pexu@sourceware.mail.kapsi.fi X-SA-Exim-Connect-IP: 2001:67c:1be8::200 X-SA-Exim-Mail-From: pexu@sourceware.mail.kapsi.fi X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 3/3] Reentrancy, attempt to always provide _Thread_local in X-SA-Exim-Version: 4.2.1 (built Wed, 06 Jul 2022 17:57:39 +0000) X-SA-Exim-Scanned: Yes (on mail.kapsi.fi) X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org Sender: "Newlib" Attempt to always provide _Thread_local in by including . The C specific keyword _Thread_local is not available unless targetting a suitable C version. --- newlib/libc/include/sys/reent.h | 1 + 1 file changed, 1 insertion(+) diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index a6c923f1c..a02e7c2bd 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -12,6 +12,7 @@ extern "C" { #include <_ansi.h> #include +#include #include #define _NULL 0