From patchwork Wed Nov 1 12:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1857945 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=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=B8w5a/px; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4SL6TN5clmz1yQm for ; Wed, 1 Nov 2023 23:56:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D10F43857806 for ; Wed, 1 Nov 2023 12:56:38 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by sourceware.org (Postfix) with ESMTPS id F02F3385840F for ; Wed, 1 Nov 2023 12:56:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F02F3385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F02F3385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; cv=none; b=tKcNHSYq0F+ugpNtR7CSQlXJ3ZayWi87ZhI0pbtcFcC6LsMgMhBDQtzxJkj9XJZ/UOyE1YIhv3DQocQR6OTURzCP6+wulne1xEjS+cahd0Vi99xT/B/UAgSdBvhc8xbOXKRAejiyBPotL995PqjvVZkVLE5UbH8L9q2NlY9M/Rw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; c=relaxed/simple; bh=WG53seEKpuXvBhS6R/4bsY7sK1gYeZpD7QzufqQ+Lj4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fiv5oEBfEsNiW/oimwxp/bG3nKpdasrDBE4PoGoLSLg6aBME9MBsTn3dh2JpDM05lLnxIGs+KfiJA7lvZeyHCUWB+0bwKmaOdJmUkLNDh8Em+W558GEpLfDlX4WbOyOzCJJJe20POPkj4hrJO5p4AurwAnuLCLVeop1BW4NZENI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-d865854ef96so6198113276.2 for ; Wed, 01 Nov 2023 05:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843382; x=1699448182; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3a7I+lue/0gnA5BTyHrSEIRxoZIlLTWh+LPA0Yf1gsg=; b=B8w5a/pxfWiwRwDRo0lCr0Z8IEPhBksQdOvDlwY1uCPBiQOWmXMzSM0hAGiUl6I5ps /VZdFgsweXyGdbc7O2C8e81anybGvCzHeJ6nrPsP35Xl0hGZtXMS0WguDO7fqg2lK7q3 OHprOq8vXizm8KxDShjjTgo8Txnd90pfrzhJaR62wVPKswxbcl9MAq4hCdNisKUpFUf9 DTNZSFMz5DZkHr2Tei/rb4ZraLiej4BWtsQGdjzHxzM3CDv/cbJPu5ehdcm3vwuyxjuj Thwvrnzg+asjiYtqpo8iXQXY5pRXG4cHsCnwpLT4CRWlysJqPuNx9U6veGh8vOlfFwqd ALKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843382; x=1699448182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3a7I+lue/0gnA5BTyHrSEIRxoZIlLTWh+LPA0Yf1gsg=; b=TgibRKO8EjEJEz3jArOKjW5uK5XZ4kbJ1W0UXJm0y6Bskol87u8OrUHgsDrvMcbb8R xDmgMUzyMKSgxxf9f5Sgww4b0hHzhuFnanoELKecQIw9xBLwIQMMBKvGq9GcVvkVPyr3 afxTQ5Z4X34VG69VRPfwhGYr35eZYJpK4QURbIOvZ7dm/8pmnsaoJRiGpMf0gebrfBeR b7LeeCIoqXOIi0fvRDLeeKKKfspskTmnAATH6Pcvor8PckaLrBrw3Gb8kO6JXrxADskk z0N30edK0ht/OK7ODPuv9kulL0pDfVVT6KQnOqZkeqjKM4WdpAcXa9f2jF8MFHrRRPaF rHKQ== X-Gm-Message-State: AOJu0YyZWsThItoWqw6IBH2VP2BTAc/LsXMkJDlYVSKZVdWgmcZ1sw+D 06NkFvRmXDeuIOtmdnvjdN4oRg92kQYBDa8cgPp9Tw== X-Google-Smtp-Source: AGHT+IG/667P7Twed3Fl1OluNs+RqfDGxU7HvKJIAhbtxEH3jGkOUXun3EZ2zo/R6QiKmYW/a3TF9g== X-Received: by 2002:a25:804f:0:b0:d9a:3d70:db36 with SMTP id a15-20020a25804f000000b00d9a3d70db36mr13380088ybn.42.1698843381801; Wed, 01 Nov 2023 05:56:21 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:21 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 2/7] support: Add support_set_vma_name Date: Wed, 1 Nov 2023 09:56:06 -0300 Message-Id: <20231101125611.208544-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 Check if kernel supports prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, ...). Reviewed-by: DJ Delorie --- support/Makefile | 1 + support/support.h | 4 ++ support/support_set_vma_name_supported.c | 49 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 support/support_set_vma_name_supported.c diff --git a/support/Makefile b/support/Makefile index 917a858bd1..9aa7f23a6e 100644 --- a/support/Makefile +++ b/support/Makefile @@ -80,6 +80,7 @@ libsupport-routines = \ support_select_modifies_timeout \ support_select_normalizes_timeout \ support_set_small_thread_stack_size \ + support_set_vma_name_supported \ support_shared_allocate \ support_small_stack_thread_attribute \ support_socket_so_timestamp_time64 \ diff --git a/support/support.h b/support/support.h index b7f76bf080..4a068d3aee 100644 --- a/support/support.h +++ b/support/support.h @@ -235,6 +235,10 @@ void support_stack_free (struct support_stack *stack); The returned value is the lowest file descriptor number. */ int support_open_dev_null_range (int num, int flags, mode_t mode); + +/* Check if kernel supports set VMA range name. */ +extern bool support_set_vma_name_supported (void); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/support_set_vma_name_supported.c b/support/support_set_vma_name_supported.c new file mode 100644 index 0000000000..712caa9b9b --- /dev/null +++ b/support/support_set_vma_name_supported.c @@ -0,0 +1,49 @@ +/* Check if kernel supports set VMA range name. + Copyright (C) 2023 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 + . */ + +#include +#include +#include +#include +#ifdef __linux__ +# include +#endif + +bool +support_set_vma_name_supported (void) +{ +#ifdef __linux__ + size_t size = sysconf (_SC_PAGESIZE); + if (size == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n"); + + void *vma = xmmap (0, + size, + PROT_NONE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, + -1); + + int r = prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, vma, size, "vmaname"); + + xmunmap (vma, size); + + return r == 0; +#else + return false; +#endif +}