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-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS 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 332861F8C6 for ; Tue, 13 Jul 2021 07:43:25 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 732A239450E5 for ; Tue, 13 Jul 2021 07:43:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 732A239450E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626162204; bh=4WxWorMtteRYgYZ5LxmfEQOCqXIgz4HvrcEUhl9czKQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MXwN2g7N7MAz4p0O19GfPFMGi859RdI2vQe9XhnIu12AcMwfvjE2/huCVW2RmVQoO O6u20kjGL2KX+q3JllvHNoxvCs1LSgVoPd1SSvg7Hc5kAy1S0CpXo1Pql4t3gfHslw iGiaGneWshSu9f1q0nq7Vf8OZ4ekZ7nOyz1vfWx8= Received: from butterfly.birch.relay.mailchannels.net (butterfly.birch.relay.mailchannels.net [23.83.209.27]) by sourceware.org (Postfix) with ESMTPS id 68E9D39450E5 for ; Tue, 13 Jul 2021 07:39:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68E9D39450E5 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 0DCE422BF3; Tue, 13 Jul 2021 07:39:24 +0000 (UTC) Received: from pdx1-sub0-mail-a18.g.dreamhost.com (100-96-11-33.trex.outbound.svc.cluster.local [100.96.11.33]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6F2E0219B4; Tue, 13 Jul 2021 07:39:23 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a18.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.11.33 (trex/6.3.3); Tue, 13 Jul 2021 07:39:24 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Sponge-Macabre: 1431555f05cc2ade_1626161963724_2189578159 X-MC-Loop-Signature: 1626161963724:537224444 X-MC-Ingress-Time: 1626161963723 Received: from pdx1-sub0-mail-a18.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a18.g.dreamhost.com (Postfix) with ESMTP id 18A6C87DC6; Tue, 13 Jul 2021 00:39:23 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a18.g.dreamhost.com (Postfix) with ESMTPSA id C72D985B78; Tue, 13 Jul 2021 00:39:20 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a18 To: libc-alpha@sourceware.org Subject: [PATCH v8 06/10] Simplify __malloc_initialized Date: Tue, 13 Jul 2021 13:08:41 +0530 Message-Id: <20210713073845.504356-7-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210713073845.504356-1-siddhesh@sourceware.org> References: <20210713073845.504356-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: Siddhesh Poyarekar via Libc-alpha Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Now that mcheck no longer needs to check __malloc_initialized (and no other third party hook can since the symbol is not exported), make the variable boolean and static so that it is used strictly within malloc. --- include/malloc.h | 6 ------ malloc/arena.c | 12 ++++++------ malloc/malloc.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/include/malloc.h b/include/malloc.h index b77761f74d..f9c9610548 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -5,12 +5,6 @@ # ifndef _ISOMAC # include =20 -/* In the GNU libc we rename the global variable - `__malloc_initialized' to `__libc_malloc_initialized'. */ -#define __malloc_initialized __libc_malloc_initialized -/* Nonzero if the malloc is already initialized. */ -extern int __malloc_initialized attribute_hidden; - struct malloc_state; typedef struct malloc_state *mstate; =20 diff --git a/malloc/arena.c b/malloc/arena.c index 9111b49589..840426f9fb 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -97,7 +97,7 @@ static mstate free_list; __libc_lock_define_initialized (static, list_lock); =20 /* Already initialized? */ -int __malloc_initialized =3D -1; +static bool __malloc_initialized =3D false; =20 /***********************************************************************= ***/ =20 @@ -143,7 +143,7 @@ int __malloc_initialized =3D -1; void __malloc_fork_lock_parent (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; =20 /* We do not acquire free_list_lock here because we completely @@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void) void __malloc_fork_unlock_parent (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; =20 for (mstate ar_ptr =3D &main_arena;; ) @@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void) void __malloc_fork_unlock_child (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; =20 /* Push all arenas to the free list, except thread_arena, which is @@ -286,10 +286,10 @@ static void tcache_key_initialize (void); static void ptmalloc_init (void) { - if (__malloc_initialized >=3D 0) + if (__malloc_initialized) return; =20 - __malloc_initialized =3D 0; + __malloc_initialized =3D true; =20 #if USE_TCACHE tcache_key_initialize (); diff --git a/malloc/malloc.c b/malloc/malloc.c index cf71314b2b..ed0316e690 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes) _Static_assert (PTRDIFF_MAX <=3D SIZE_MAX / 2, "PTRDIFF_MAX is not more than half of SIZE_MAX"); =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); #if USE_TCACHE /* int_free also calls request2size, be careful to not pad twice. */ @@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes) =20 void *newp; /* chunk to return */ =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 #if REALLOC_ZERO_BYTES_FREES @@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc) void * __libc_memalign (size_t alignment, size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 void *address =3D RETURN_ADDRESS (0); @@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign) void * __libc_valloc (size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 void *address =3D RETURN_ADDRESS (0); @@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes) void * __libc_pvalloc (size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 void *address =3D RETURN_ADDRESS (0); @@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size) =20 sz =3D bytes; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 MAYBE_INIT_TCACHE (); @@ -5022,7 +5022,7 @@ __malloc_trim (size_t s) { int result =3D 0; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 mstate ar_ptr =3D &main_arena; @@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void) struct mallinfo2 m; mstate ar_ptr; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 memset (&m, 0, sizeof (m)); @@ -5208,7 +5208,7 @@ __malloc_stats (void) mstate ar_ptr; unsigned int in_use_b =3D mp_.mmapped_mem, system_b =3D in_use_b; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); _IO_flockfile (stderr); int old_flags2 =3D stderr->_flags2; @@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value) mstate av =3D &main_arena; int res =3D 1; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); __libc_lock_lock (av->mutex); =20 @@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, = size_t size) { void *mem; =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 /* Test whether the SIZE argument is valid. It must be a power of @@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp) =20 =20 =20 - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); =20 fputs ("\n", fp); --=20 2.31.1