From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS,UNWANTED_LANGUAGE_BODY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 80A4E1F55B for ; Tue, 19 May 2020 18:06:06 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F25D33954807; Tue, 19 May 2020 18:05:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F25D33954807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1589911550; bh=zm7V/YtPo+LL5V+BMocTtIqbDdJW3g+nNEWYNBi+F58=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=qzJnnSL78moOvQ1jt/+lGoaplfPW4YWOYbOoW2fjQiZrdcmm3yra8dF96Zw/wKsBf owBk+Yk12875K3UxR4yEMlSNOaP7VMwRY7ZVwsQtjhoIfzM8DKtzlkC2Mp6beZibP1 Y6srwkj17jPobdhmhZVHqAf22mMW1CF9BazCJ1ow= Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id D14913954807 for ; Tue, 19 May 2020 18:05:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D14913954807 Received: by mail-qk1-x743.google.com with SMTP id z80so523366qka.0 for ; Tue, 19 May 2020 11:05:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zm7V/YtPo+LL5V+BMocTtIqbDdJW3g+nNEWYNBi+F58=; b=Fpt/hxud0PxvtP41KNgOXiBtXSCt37KqTExqKl4jL2QjZheL9iUmwjFk9LPbv2pEAV PlBjszXW3COFNbtKT5LhXJTfVU4eoBXSokWH0wi23ouGnHarSEljfL2z5g539Mg0WhjO 6VBB14rmRU6jAXZaX87evIZEZCb5cD/mb6F7JZCXaUnieUSE8uTJGAhy2a27SyMr/RxN cumUGDy5yN56uyTnhYb9iTuPRkknxGT6BDr1LfAuCLCzEJB6joMq+FRQzF4ZycdDoJ1B Hww1SrU4RIGB8IWBYKfmrhPxhCal1BxvGTIz2w+Pjf4XVeBj1irKLeQ5AycFmzkDRKCG AIFQ== X-Gm-Message-State: AOAM533i/H0uFh+UctLZsWwnLBpcS8p/IHgNkL90Xb0sLodKnPelcM/j Mfmn4mUCHt42vTCGynzSc3b9AmRF2lw= X-Google-Smtp-Source: ABdhPJyU88WgZYLT4hokh68K4g1vWlPT4Rs2zmnWc9Tw3tmYAvpfzPQbpfOQAR2t5whpAK3Aa9Hpfg== X-Received: by 2002:a37:4243:: with SMTP id p64mr665655qka.438.1589911546918; Tue, 19 May 2020 11:05:46 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id m6sm230091qkc.4.2020.05.19.11.05.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 11:05:46 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 07/13] string: Use tls-internal on strerror_l Date: Tue, 19 May 2020 15:05:12 -0300 Message-Id: <20200519180518.318733-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200519180518.318733-1-adhemerval.zanella@linaro.org> References: <20200519180518.318733-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The buffer allocation uses the same strategy of strsignal. Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, and s390x-linux-gnu. --- string/strerror_l.c | 16 +++++++-------- sysdeps/generic/tls-internal-struct.h | 1 + sysdeps/mach/strerror_l.c | 28 +++++++++++++-------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/string/strerror_l.c b/string/strerror_l.c index cb656b5d54..dcbf605560 100644 --- a/string/strerror_l.c +++ b/string/strerror_l.c @@ -18,11 +18,8 @@ #include #include #include -#include #include -#include - -static __thread char *last_value; +#include static const char * @@ -45,12 +42,13 @@ __strerror_l (int errnum, locale_t loc) if (__glibc_unlikely (errnum < 0 || errnum >= _sys_nerr_internal || _sys_errlist_internal[errnum] == NULL)) { - free (last_value); - if (__asprintf (&last_value, "%s%d", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%d", translate ("Unknown error ", loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - r = last_value; + r = tls_internal->strerror_l_buf; } else r = (char *) translate (_sys_errlist_internal[errnum], loc); @@ -64,6 +62,6 @@ libc_hidden_def (__strerror_l) void __strerror_thread_freeres (void) { - free (last_value); + free (__glibc_tls_internal ()->strerror_l_buf); } text_set_element (__libc_subfreeres, __strerror_thread_freeres); diff --git a/sysdeps/generic/tls-internal-struct.h b/sysdeps/generic/tls-internal-struct.h index 33a9079ee9..156e722bd8 100644 --- a/sysdeps/generic/tls-internal-struct.h +++ b/sysdeps/generic/tls-internal-struct.h @@ -22,6 +22,7 @@ struct tls_internal_t { char *strsignal_buf; + char *strerror_l_buf; }; #endif diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c index b6c9fdbe80..1e97496e77 100644 --- a/sysdeps/mach/strerror_l.c +++ b/sysdeps/mach/strerror_l.c @@ -23,11 +23,7 @@ #include #include #include -#include -#include - - -static __thread char *last_value; +#include static const char * @@ -58,13 +54,14 @@ __strerror_l (int errnum, locale_t loc) if (system > err_max_system || ! __mach_error_systems[system].bad_sub) { - free (last_value); - if (__asprintf (&last_value, "%s%X", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%X", translate ("Error in unknown error system: ", loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } es = &__mach_error_systems[system]; @@ -74,14 +71,15 @@ __strerror_l (int errnum, locale_t loc) if (code >= es->subsystem[sub].max_code) { - free (last_value); - if (__asprintf (&last_value, "%s%s %d", + struct tls_internal_t *tls_internal = __glibc_tls_internal (); + free (tls_internal->strerror_l_buf); + if (__asprintf (&tls_internal->strerror_l_buf, "%s%s %d", translate ("Unknown error ", loc), translate (es->subsystem[sub].subsys_name, loc), errnum) == -1) - last_value = NULL; + tls_internal->strerror_l_buf = NULL; - return last_value; + return tls_internal->strerror_l_buf; } return (char *) translate (es->subsystem[sub].codes[code], loc); @@ -89,10 +87,10 @@ __strerror_l (int errnum, locale_t loc) weak_alias (__strerror_l, strerror_l) libc_hidden_def (__strerror_l) -/* This is called when a thread is exiting to free the last_value string. */ +/* This is called when a thread is exiting to free the allocated string. */ void __strerror_thread_freeres (void) { - free (last_value); + free (__glibc_tls_internal ()->strerror_l_buf); } text_set_element (__libc_subfreeres, __strerror_thread_freeres); -- 2.25.1