From patchwork Mon Aug 5 20:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 1969202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=QurzEg+w; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wd7qs4Jfsz1ydt for ; Tue, 6 Aug 2024 06:50:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CCA4385DDE4 for ; Mon, 5 Aug 2024 20:50:31 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [IPv6:2607:5300:203:b2ee::31e5]) by sourceware.org (Postfix) with ESMTPS id B4BB6385842A for ; Mon, 5 Aug 2024 20:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4BB6385842A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4BB6385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:5300:203:b2ee::31e5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722890943; cv=none; b=ADjFy70MlCi2qQdkkeVEKMxMH5+6RKPlCzg5yuEh1u0Px05UeZphlmAymrc61EwKSxUZIw08TdUR084fM049Dg8I+V/JOtrgu/Qrop2AnXzreeqpjQWeSVw8KFrXZyDgf+GgYdvc9QDybnTbUzWXCbVPuSSj4ooyXO/4UKW8ej4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722890943; c=relaxed/simple; bh=mZWp3yQu7X4pjjtu112NGh0JYRD8/8ExasO5xs1X+Q4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=XieN/ki/0z4cmjzE/K1AfUOB4t6dCzgiH+52uNx5bXLIjP01Q3815nl2S95B2YmUig2Wuw0YoDzLe5OyBCMVAcMbJNqv138FEO5J5FbIqizeOjrtPrmjNPNqBWdnZJy6oeXU6BVOjIvX5vIZ9B9xb28MyonhPaoV5P8bUTt0N4I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1722890940; bh=mZWp3yQu7X4pjjtu112NGh0JYRD8/8ExasO5xs1X+Q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QurzEg+wtOXZ0GVbVypVD/wqPYrb5fkAF6yvelzE2g3pU3g9e5xyYfkACKaoFutY6 Xm3pQ2/8P0j4YeXb67QK6PrZ2f2C8OmtJCg64iz4AUD3t4bGQNEmEK0Kes5WZpNY6o Vy7ehUKBhCXZLzpcgeIvGnShkh6fWfvevQFClDysTnxTSZdCRMsOACmlmjjxTQocCr YWBmpWhlmZ4uI51bB90+8XoB5zYIjHr3WsziuUPRbeVAvGMLyq88CO7FzrRyFPrP4u KK2R2BHkTOb2NTXIQNhjgfItXWlUUWNHXMSF7BtqRdmtzau4SyIax4ts/xQ84KC9mp xyZko1wuh3uMw== Received: from mj-deb12-aarch64-glibc.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Wd7p42N5xz1GY8; Mon, 5 Aug 2024 16:49:00 -0400 (EDT) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Florian Weimer , Carlos O'Donell , DJ Delorie , Mathieu Desnoyers Subject: [PATCH v12 03/17] Add Linux 'extra TLS' Date: Mon, 5 Aug 2024 16:48:25 -0400 Message-Id: <20240801-rseq-abi-v11-split-v12-3-0e87479dddc0@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240801-rseq-abi-v11-split-v12-0-0e87479dddc0@efficios.com> References: <20240801-rseq-abi-v11-split-v12-0-0e87479dddc0@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, 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~incoming=patchwork.ozlabs.org@sourceware.org Add the Linux implementation of 'extra TLS' which will allocate space for the rseq area at the end of the TLS blocks in allocation order. Signed-off-by: Michael Jeanson --- sysdeps/unix/sysv/linux/dl-extra_tls.h | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/sysdeps/unix/sysv/linux/dl-extra_tls.h b/sysdeps/unix/sysv/linux/dl-extra_tls.h new file mode 100644 index 0000000000..d00207a76e --- /dev/null +++ b/sysdeps/unix/sysv/linux/dl-extra_tls.h @@ -0,0 +1,76 @@ +/* extra tls block utils for the dynamic linker. Generic stub version. + Copyright (C) 2024 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 _DL_EXTRA_TLS_H +#define _DL_EXTRA_TLS_H 1 + +#include +#include +#include +#include + +/* Returns the size of the extra TLS block. */ +static inline size_t +_dl_extra_tls_get_size (void) +{ + bool do_rseq = true; + do_rseq = TUNABLE_GET_FULL (glibc, pthread, rseq, int, NULL); + if (do_rseq) + { + /* Make sure the rseq area size is at least the minimum ABI size and a + multiple of the requested aligment. */ + return roundup (MAX (_rseq_size, RSEQ_AREA_SIZE_INITIAL), _rseq_align); + } + + /* Even when disabled by tunable, an rseq area will be allocated to allow + application code to test the registration status with 'rseq->cpu_id >= 0'. + Default to the rseq ABI minimum size, this will ensure we don't use more + TLS than necessary. */ + return RSEQ_AREA_SIZE_INITIAL; +} + +/* Returns the alignment requirements of the extra TLS block. */ +static inline size_t +_dl_extra_tls_get_align (void) +{ + bool do_rseq = true; + do_rseq = TUNABLE_GET_FULL (glibc, pthread, rseq, int, NULL); + if (do_rseq) + { + return _rseq_align; + } + + /* Even when disabled by tunable, an rseq area will be allocated to allow + application code to test the registration status with 'rseq->cpu_id >= 0'. + Default to the rseq ABI minimum alignment, this will ensure we don't use + more TLS than necessary. */ + return RSEQ_MIN_ALIGN; +} + +/* Record the offset of the extra TLS block from the thread pointer. */ +static inline void +_dl_extra_tls_set_offset (ptrdiff_t tls_offset) +{ +#ifdef RSEQ_SIG + /* Not all targets support __thread_pointer, so set __rseq_offset only if + the rseq registration may have happened because RSEQ_SIG is defined. */ + _rseq_offset = tls_offset; +#endif +} + +#endif