From patchwork Mon Jun 9 13:47:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 114044 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 B14D3382D469 for ; Mon, 9 Jun 2025 13:48:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B14D3382D469 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 6CE16382D475 for ; Mon, 9 Jun 2025 13:47:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CE16382D475 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6CE16382D475 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749476863; cv=none; b=Vxo5d5wWa0R9MWfDTfWFqSh/y/XPbU8jsBHka/csXgytTtM/84d1oQXAUjLhUhiO7f3dzMXL5d+0siDNJqtfYtL9YC/nAH7gE80vrwEbXhBFgF25QXKyiPVglobeULPnq7tuGmlfkvDxt76JCyWgerIKdhFKv/XwTpn7BvPD75o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749476863; c=relaxed/simple; bh=SCOxgJQoU9UHjFIKZuUBVugmLUtUmPj3XK0+pubuf+I=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZR/N7688Dh215yEhmdWE5xB/JIcWii/ugmileuCLVeDJyRrrO8B1F3B8TmZH5XWl9QT5QV/6YNnX4cTE6jAoOAfU1dpFv1T+ss9J2hXN3ErQg4jPk1kVqS9GzGXCa8XGzu1qNiC0Fdp7IhHPojw2SIR04GmxjMI31sFnuyTnVz4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CE16382D475 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 55C47A1C1E; Mon, 9 Jun 2025 15:47:42 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xf_HATo24tEK; Mon, 9 Jun 2025 15:47:42 +0200 (CEST) Received: from begin (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 220A8A01C3; Mon, 9 Jun 2025 15:47:42 +0200 (CEST) Received: from samy by begin with local (Exim 4.98.2) (envelope-from ) id 1uOcqj-00000005NX4-22m5; Mon, 09 Jun 2025 15:47:41 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Make __getrandom_early_init call __mach_init Date: Mon, 9 Jun 2025 15:47:41 +0200 Message-ID: <20250609134741.1282091-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org 25d37948c9f3 ("malloc: Improve malloc initialization") moved calling malloc initialization earlier, within _dl_sysdep_start's call to dl_main, before __mach_init is called by _dl_init_first. But malloc initialization uses getrandom, which needs to make RPCs. This adds __getrandom_early_init on hurd to express that getrandom needs __mach_init too. This also adds a guard to avoid making it create several task and host ports. Fixes: 25d37948c9f3 ("malloc: Improve malloc initialization") Signed-off-by: Samuel Thibault --- mach/mach_init.c | 4 ++++ sysdeps/mach/hurd/getrandom-internal.h | 30 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 sysdeps/mach/hurd/getrandom-internal.h diff --git a/mach/mach_init.c b/mach/mach_init.c index 9b05e4e175..6237e9c8e4 100644 --- a/mach/mach_init.c +++ b/mach/mach_init.c @@ -35,6 +35,10 @@ __mach_init (void) { kern_return_t err; + if (__mach_host_self_) + /* Already initialized. */ + return; + __mach_task_self_ = (__mach_task_self) (); __mach_host_self_ = (__mach_host_self) (); __mig_init (0); diff --git a/sysdeps/mach/hurd/getrandom-internal.h b/sysdeps/mach/hurd/getrandom-internal.h new file mode 100644 index 0000000000..8bd718b7c1 --- /dev/null +++ b/sysdeps/mach/hurd/getrandom-internal.h @@ -0,0 +1,30 @@ +/* Internal definitions for Hurd getrandom implementation. + Copyright (C) 2024-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _GETRANDOM_INTERNAL_H +#define _GETRANDOM_INTERNAL_H + +extern void __mach_init (void); + +static inline void __getrandom_early_init (_Bool initial) +{ + /* getrandom needs RPCs for time etc. */ + __mach_init (); +} + +#endif