From patchwork Fri Jul 12 22:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1960036 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GvJ7Mds6; 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 4WLRDS0W66z1xr4 for ; Sat, 13 Jul 2024 08:32:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F533385EC54 for ; Fri, 12 Jul 2024 22:32:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by sourceware.org (Postfix) with ESMTPS id A565D3858433 for ; Fri, 12 Jul 2024 22:31:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A565D3858433 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A565D3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823516; cv=none; b=lGWnL8RrLEBXelLSYoHVzOny1jUQMeiYBjtJIOm0K23xqcKqNYDFnDsfcSmnpl5IRqJieRiIDWntfZs8viOEP/1gUnRzf07675JPwg//KFmPx0e2l4o9JCR8ZmJ+5l4FO9VFjnQp+jepRl8KXFW6e6grpd626PXmpEwct7t8Rzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823516; c=relaxed/simple; bh=FGsZyrC++GHHxKHnA/EZcn4P7e8859PQJyzH+zw55tw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XmepLV1ZTJLk02L2Nla2XOzUR1MBthzcL3DDgnQMdy1wQ0hsg9NlAn/8yZiASFYVuto4lwrtFh429W1PFwIp2fS6dNT/TpPDYcnc6atgB0op1B/K/40bTpzBHBuj/wL47RkeLstWb4gFKVgQQIaOQqYSL+ugbQrydVZJXR/9Vtg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e036105251eso2553377276.0 for ; Fri, 12 Jul 2024 15:31:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720823513; x=1721428313; 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=myFexGVoy2AKAL4T5oYuZanqraOKmWr1sfloBVgJ7Z0=; b=GvJ7Mds6l4esKu/Ib2W6Ff5ir8gDYfwESyvmadU7OChQSGNsfukyR8RpxKStxT0yST pyy+9m/+4PkZGWCow5a60przvg1fWjCRev4IFgKEzro7u1DdFP4MOU9mIXUaEcgqkSLh +EynM7FxfrVh0BCGJ7afaxTkeXPZxK6CzILwjTieyH89wmaGFk0+KkZYLinwy8c20Suq V+25XWDCPN8K/HPKapYXq24+QJe8u/1OjAWC8SsvceDQF9v4zl0I/aeA4c0qRUjHX3fF XEt8XgDhXuvIznDHj8htpR2bYlhzwZpa8BNea0rSaB2dEjFdWgUQT8sslaSjumJnxXD2 Owgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720823513; x=1721428313; 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=myFexGVoy2AKAL4T5oYuZanqraOKmWr1sfloBVgJ7Z0=; b=wTUp0YCJiBvw1IaebJtpoGOBCYvEjkCPQSoWNJI+dVN4nkkM5IAdead5FssCUF5fnB SG+yBRhij8xGyHeI1Ktm+6Y8oFpiupmF72svvtjGftdhDNbaWRH2LOP6fvIcgOKlJC75 cDqLsKcj1WTawodTEuhURy8J8s8wUdrbZRCDxqkiNIIBrPhqhs1oA370K/UuqJ5cGaai jX39NMMdApVQ2oJdNZsGhilipmQVD2KusqvgInA9r4kcwH2u4OQGxQV0Gf13TIaL+e2M wtpJHXPDB+QmsHT4hLo4+UQY+WJfzW/CXePyRCwdqRVxGlE8dv+K4c7o3YIOsArJIsWz bcCg== X-Gm-Message-State: AOJu0Yy8YfrworAEcpZZKG22zep4+h40ZSdNOc0EqfFwAw8kWgsG20Fh paQV3ppYcuNflt1OoJXvJO6Lr9jfC/KVwxPw9HhecDquLvNid1yWgjgHBGBJzcKbsA== X-Google-Smtp-Source: AGHT+IGQCcyLVHajCUDzwwWf/UNOu26ItmE0nyy/z/ABvLCZqaUNyfM72i1EZQ5H9QlPzO8RJJ0FOQ== X-Received: by 2002:a25:ac8d:0:b0:e02:bd5c:bfa9 with SMTP id 3f1490d57ef6-e041b059553mr14845539276.19.1720823513643; Fri, 12 Jul 2024 15:31:53 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.179]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e041a8f5f59sm1421547276.34.2024.07.12.15.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 15:31:53 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 98E92C020E for ; Fri, 12 Jul 2024 15:31:47 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 1/3] linux: Update the mremap C implementation [BZ #31968] Date: Fri, 12 Jul 2024 15:31:45 -0700 Message-ID: <20240712223147.1809816-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712223147.1809816-1-hjl.tools@gmail.com> References: <20240712223147.1809816-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 Update the mremap C implementation to support the optional argument for MREMAP_DONTUNMAP added in Linux 5.7 since it may not always be correct to implement a variadic function as a non-variadic function on all Linux targets. Return MAP_FAILED and set errno to EINVAL for unknown flag bits. This fixes BZ #31968. Note: A test must be added when a new flag bit is introduced. Signed-off-by: H.J. Lu --- sysdeps/unix/sysv/linux/mremap.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/mremap.c b/sysdeps/unix/sysv/linux/mremap.c index 4f770799c4..1ada5c1f40 100644 --- a/sysdeps/unix/sysv/linux/mremap.c +++ b/sysdeps/unix/sysv/linux/mremap.c @@ -20,6 +20,12 @@ #include #include #include +#include + +#define MREMAP_KNOWN_BITS \ + (MREMAP_MAYMOVE \ + | MREMAP_FIXED \ + | MREMAP_DONTUNMAP) void * __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...) @@ -27,7 +33,13 @@ __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...) va_list va; void *new_addr = NULL; - if (flags & MREMAP_FIXED) + if (flags & ~(MREMAP_KNOWN_BITS)) + { + __set_errno (EINVAL); + return MAP_FAILED; + } + + if (flags & (MREMAP_FIXED | MREMAP_DONTUNMAP)) { va_start (va, flags); new_addr = va_arg (va, void *); From patchwork Fri Jul 12 22:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1960038 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=S11AQz2i; 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 4WLRHg6F22z1xqx for ; Sat, 13 Jul 2024 08:35:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F7FA385DDF1 for ; Fri, 12 Jul 2024 22:35:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by sourceware.org (Postfix) with ESMTPS id 89443385C6CB for ; Fri, 12 Jul 2024 22:33:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89443385C6CB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 89443385C6CB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; cv=none; b=nnJR+RvK1vwidRJUim3Ruk69BqkhsBMa++mIGwPPN8Kz7lHD6VpmXUOl+nbDUR2yY0+5gjZ81LUYMnKxuxACByyGEp83Ae8X/zAhA7NEld53OZiHYAlDI1zknFFDbVdxvuh0vsUiNkbIJCU9GeF5s0B5J5HvfZsAWXSMo7ZDldo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; c=relaxed/simple; bh=dzIRQtrmL4FV6Nn52OpDiucMQJVnyl2qGld+ef0BSmk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YMxc7DlvPtezetRSyic6D2fU2fTCmdHhYgsxjdQTgc+nIGMIDeG99gjwbiJ0eQ95i4xYmt/KC2msJsZjw0nDNzEiysbNl22aVWJSYG27sArwXZrp+6l1QAySDRPxvG5C07M/TZerNxjbUf31Ns819DRnfaUgwWERkJhqVGoNNSk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-6512866fa87so26863327b3.2 for ; Fri, 12 Jul 2024 15:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720823631; x=1721428431; 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=V1PFJzq/selgIdrmZukNmxIqoIHPgifvgdt1454mTOU=; b=S11AQz2izbKDi31yeLmFoTZ+FCEw2JcG59OjrhaJkN/7wv2IVOKrylrU4dATiq+nin DWKZoiSLa5hOBNnnw3rjj+hx7Y/2rs4BANIbs5QyzMAuvrCoqBJADrWL11u+nPVCy3JQ YM0br51cNcb53HACRcyYII3tA6myJ+ECxSimHcvB4AWoeQRlTe6tPnN7+w/3iN5WgjVl CYRSLeUZBh0sUDDHBL1lDb4fxpAjEqV3Ydn/K8Sz0H60WEyXHzUQ9eX6EtnZH0kOgg0V yBKISRCiDvwsO5uHCnEnoLcVuNoHdVLIAeojikzbE/8RmOCekDGZIkWL2QRsbCLvORBe Et3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720823631; x=1721428431; 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=V1PFJzq/selgIdrmZukNmxIqoIHPgifvgdt1454mTOU=; b=wOgoxjDyhy3byMKC4jqMTGREceh0o6wFCCuJK8IdPFMto5gJ2n62Q7RBg4UC24kzhV U6E83xDaPVkOvhl6l4O7lM6TdpEtNypQ8Qcrqp3vzOjK2ZwvmIYJzt/cwYxz+4luSTmW MRnhY7qiNzDligzEpzNpUYeQgxFCgEvRgZsWrL3jyFvI9sZbeNvFw6ds9uPX6xUpkOjH VhRQQES/iHVdQXvWt34cCNhyTt/VmC4v0HIBBZuJnMaSMlTTm7MQJKVwqwKFQimQU/wT Efv64nGXJEg6qG3rs7fAkxQ2UhjACMd/JbVopxT1yKzC5vfyEFomN5LVaTjB3Sxui5cf HvDQ== X-Gm-Message-State: AOJu0YxJFgrQgTM+Aw6bL67H79sA4ITHQK2bXJLjIDolaRFEOLcXbYfD XYhE7yYGPUIzKKD5A863x9ts6Ito6BhIp8TP+tLhKv01jatzzD0I0Rqotulc1uHNVw== X-Google-Smtp-Source: AGHT+IH0Ojd/ojK7Fo7fOulpgxBLT5rbPmX079ottU/SuFsaiJVAPvbT+8S3yPUZumHG7pncpFctDA== X-Received: by 2002:a0d:e307:0:b0:651:79ee:d13f with SMTP id 00721157ae682-658eed60361mr138574547b3.20.1720823630576; Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.179]) by smtp.gmail.com with ESMTPSA id 00721157ae682-658e4a316e9sm16556017b3.17.2024.07.12.15.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id A3B3AC0227 for ; Fri, 12 Jul 2024 15:31:47 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 2/3] Support: Add linux-support.h Date: Fri, 12 Jul 2024 15:31:46 -0700 Message-ID: <20240712223147.1809816-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712223147.1809816-1-hjl.tools@gmail.com> References: <20240712223147.1809816-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 linux-support.h with /* Return an unsigned int from version, patch level and sub level of Linux kernel. */ extern unsigned int make_linux_kernel_version (unsigned int __version, unsigned int __patch, unsigned int __sub); /* Similar to make_linux_kernel_version, but version, patch level and sub level are retrieved from the uname system call. */ extern unsigned int get_linux_kernel_version (void); Signed-off-by: H.J. Lu --- sysdeps/unix/sysv/linux/Makefile | 8 +++ .../unix/sysv/linux/linux-kernel-version.c | 62 +++++++++++++++++++ sysdeps/unix/sysv/linux/linux-support.h | 38 ++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/linux-kernel-version.c create mode 100644 sysdeps/unix/sysv/linux/linux-support.h diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 097b5a26fc..7a1798f2f1 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -661,3 +661,11 @@ tests-internal += \ tst-rseq-nptl \ # tests-internal endif + +ifeq ($(subdir),support) +linux-support-routines += \ + linux-kernel-version \ +# linux-support-routines +libsupport-routines += $(linux-support-routines) +libsupport-static-only-routines += $(linux-support-routines) +endif diff --git a/sysdeps/unix/sysv/linux/linux-kernel-version.c b/sysdeps/unix/sysv/linux/linux-kernel-version.c new file mode 100644 index 0000000000..2968c528b6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/linux-kernel-version.c @@ -0,0 +1,62 @@ +/* Initialize CPU feature data. AArch64 version. + This file is part of the GNU C Library. + Copyright (C) 2017-2024 Free Software Foundation, Inc. + + 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 + +unsigned int +make_linux_kernel_version (unsigned int version, unsigned int patch, + unsigned int sub) +{ + TEST_VERIFY_EXIT (version <= 0xff); + TEST_VERIFY_EXIT (patch <= 0xff); + TEST_VERIFY_EXIT (sub <= 0xffff); + /* Return an unsigned int with VVPPSSSS. */ + return (version << 24) | (patch << 16) | sub; +} + +unsigned int +get_linux_kernel_version (void) +{ + struct utsname buf; + const char *p = &buf.release[0]; + unsigned int version; + unsigned int patch; + unsigned int sub; + + TEST_VERIFY_EXIT (uname (&buf) == 0); + + /* Get kernel version. */ + for (version = 0; *p >= '0' && *p <= '9'; p++) + version = version * 10 + *p - '0'; + TEST_VERIFY_EXIT (*p == '.'); + p++; + + /* Get kernel patch level. */ + for (patch = 0; *p >= '0' && *p <= '9'; p++) + patch = patch * 10 + *p - '0'; + TEST_VERIFY_EXIT (*p == '.'); + p++; + + /* Get kernel sub level. */ + for (sub = 0; *p >= '0' && *p <= '9'; p++) + sub = sub * 10 + *p - '0'; + + return make_linux_kernel_version (version, patch, sub); +} diff --git a/sysdeps/unix/sysv/linux/linux-support.h b/sysdeps/unix/sysv/linux/linux-support.h new file mode 100644 index 0000000000..a7c03040b1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/linux-support.h @@ -0,0 +1,38 @@ +/* Linux-specific support functions. + 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 LINUX_SUPPORT_H +#define LINUX_SUPPORT_H + +#include + +__BEGIN_DECLS + +/* Return an unsigned int from version, patch level and sub level of + Linux kernel. */ +extern unsigned int make_linux_kernel_version (unsigned int __version, + unsigned int __patch, + unsigned int __sub); + +/* Similar to make_linux_kernel_version, but version, patch level and + sub level are retrieved from the uname system call. */ +extern unsigned int get_linux_kernel_version (void); + +__END_DECLS + +#endif /* LINUX_SUPPORT_H */ From patchwork Fri Jul 12 22:31:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1960039 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ku2uA/Zt; 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 4WLRHh2Yqfz20Md for ; Sat, 13 Jul 2024 08:35:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57BC23831246 for ; Fri, 12 Jul 2024 22:35:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by sourceware.org (Postfix) with ESMTPS id 14C203858433 for ; Fri, 12 Jul 2024 22:33:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14C203858433 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14C203858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; cv=none; b=ExTgt5wDw1MmwEUs0amdWUzJOyoa8SUc6/S2OINpJ79SPHjm2TrSAXbdeCElQVRLTTuhX/OfMi/8dYrYpMbAIi85b0HqAE1MFk/TSCN2GEv0f1553fk21Xp+izNZu3+pw3/iiNPLUH5lQ8/NrqN3iVmtGpkJCVL6GcFCzmj+Ka0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; c=relaxed/simple; bh=a+B+beY2jsv4sEHhzC2ZeXWS0I+vtR0KndbJFxKkD24=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GMsfCKhZ0S/SMYbGG991TwvmuTdYDnft+5w41R/9P+9BWG7MbbtlMrzzrbYDBU8Uc6z03VXtF34ZfWvuqbjJPgR9dGmxhs5FHN5nMW0DhW5ycIGga3YpPpdjkS9MM2kunGCv/1jH0Hqhm+y5P5y/cvMYzsVFrKrwnTB9kpp8BZ8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-e035dc23a21so2590383276.0 for ; Fri, 12 Jul 2024 15:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720823630; x=1721428430; 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=U9l60l5LwnZcPy9JmoGouqwIdd/USxm0xL1No2eFIKA=; b=ku2uA/ZtGHO9zUzRahF5z2mMzTMFDcFGZLtv5gURODSI/tFvzUr/UMbQOWSdWuBYbZ Bqq0aaGOQl0URSx9swk/w1ASa3VJaQdfdGS/iyYrBT4wMBczcKUZkpZyEPfj1DhBcLAt IP/YRzjWMSoL7E9up0U4KVv6mc6KIaekVJ2IezHFz0cEEUt1QK9NA5xpgGjakYo/nS6E BIW3dCMy04vGZkohuOmQMlh4tJxdGKHXuAvZl34k+81IIomvfrlUC9hxPjaZNcsKS4+g zYm1nU7T3DOp7qI2UUMOgsYXo7DQUmSJgbZovB+USGrv965F6gETXNxyL8t9JcHl6ZiA +BXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720823630; x=1721428430; 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=U9l60l5LwnZcPy9JmoGouqwIdd/USxm0xL1No2eFIKA=; b=jWP2JjGLMudc7gYSelgYZ5Zc/eljXA+q+3NcasqqFviUF5fW4ajQWzoihTCJERIBRE 6gQGLFHDX1z93wuS6B5oZu6JoySo+xIsCMoGQutP4zI5a3GI6Dmubo7/RH3/fUGkMEsd 6SWQFmWOldEtejUIefd/taSR1RdEVbcXhcFcXklq6zuqBtUbKjs+LKx00D/4sU9omBsv T7WoZ0/gz6+SUnFafxaoHiG4LCUqKs3x8Lp7kocRZSLIiYO+qQy5mYQCSoEMjKOVkIlH aMGHkiOCZSk79Q/8EspGBBdyGmUcm8ZKaM9UMvUROvxjtxmLjG4uz42zwI1YiF/dhF0X WTKw== X-Gm-Message-State: AOJu0YyvEDC/9h2KuLTozqydL7GfIfirqbN+h9uBnVbb+R/8KMk9ONhn 50wegCVEDjHqUlZ2cP4rdrHY1uiGW2Luj4tmlp7wXFEsKm/oWNUwK2NCLkAkInjq3w== X-Google-Smtp-Source: AGHT+IGnrIz6w3t0EAT2rXstG+xmieltWwoE72D0KJFIaTF1pqDUSDKElE84m0g4cplyQwmvtIvZeA== X-Received: by 2002:a05:6902:1b0f:b0:e05:9f9c:5516 with SMTP id 3f1490d57ef6-e059f9c575fmr1154684276.19.1720823630237; Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.179]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e041a9a1695sm1481322276.62.2024.07.12.15.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id AE575C03D5 for ; Fri, 12 Jul 2024 15:31:47 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 3/3] Add mremap tests Date: Fri, 12 Jul 2024 15:31:47 -0700 Message-ID: <20240712223147.1809816-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712223147.1809816-1-hjl.tools@gmail.com> References: <20240712223147.1809816-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 tests for MREMAP_MAYMOVE, MREMAP_FIXED and MREMAP_DONTUNMAP. On Linux, enable MREMAP_FIXED test for Linux kernel 2.3.31 and above. Enable MREMAP_DONTUNMAP test for Linux kernel 5.7 and above. Signed-off-by: H.J. Lu --- misc/Makefile | 1 + misc/tst-mremap.c | 73 ++++++++++++++++++++++++++++ sysdeps/generic/tst-mremap.h | 24 +++++++++ sysdeps/unix/sysv/linux/tst-mremap.h | 67 +++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 misc/tst-mremap.c create mode 100644 sysdeps/generic/tst-mremap.h create mode 100644 sysdeps/unix/sysv/linux/tst-mremap.h diff --git a/misc/Makefile b/misc/Makefile index 5d17c562fe..96474a6886 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -257,6 +257,7 @@ tests := \ tst-mntent-blank-passno \ tst-mntent-escape \ tst-mntent2 \ + tst-mremap \ tst-preadvwritev \ tst-preadvwritev2 \ tst-preadvwritev64 \ diff --git a/misc/tst-mremap.c b/misc/tst-mremap.c new file mode 100644 index 0000000000..03e01852cb --- /dev/null +++ b/misc/tst-mremap.c @@ -0,0 +1,73 @@ +/* Basic mremap tests. + 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 + . */ + +#include +#include +#include +#include +#include +#include + +static void +test_mremap_fixed (void) +{ + size_t old_size = getpagesize (); + size_t new_size = old_size + old_size; + char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1); + old_addr[0] = 1; + old_addr[old_size - 1] = 2; + + char *fixed_addr = xmmap (NULL, new_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1); + fixed_addr[0] = 1; + fixed_addr[new_size - 1] = 2; + + /* Test MREMAP_FIXED. */ + char *new_addr = mremap (old_addr, old_size, new_size, + MREMAP_FIXED | MREMAP_MAYMOVE, + fixed_addr); + TEST_VERIFY_EXIT (new_addr == fixed_addr); + new_addr[0] = 1; + new_addr[new_size - 1] = 2; + xmunmap (new_addr, new_size); +} + +#include + +static int +do_test (void) +{ + size_t old_size = getpagesize (); + char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1); + old_addr[0] = 1; + old_addr[old_size - 1] = 2; + + /* Test MREMAP_MAYMOVE. */ + size_t new_size = old_size + old_size; + char *new_addr = mremap (old_addr, old_size, new_size, MREMAP_MAYMOVE); + TEST_VERIFY_EXIT (new_addr != MAP_FAILED); + new_addr[0] = 1; + new_addr[new_size - 1] = 2; + xmunmap (new_addr, new_size); + + return do_additonal_test (); +} + +#include diff --git a/sysdeps/generic/tst-mremap.h b/sysdeps/generic/tst-mremap.h new file mode 100644 index 0000000000..dbc760ca28 --- /dev/null +++ b/sysdeps/generic/tst-mremap.h @@ -0,0 +1,24 @@ +/* Additional mremap check. Generic 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 + . */ + +static int +do_additonal_test (void) +{ + test_mremap_fixed (); + return 0; +} diff --git a/sysdeps/unix/sysv/linux/tst-mremap.h b/sysdeps/unix/sysv/linux/tst-mremap.h new file mode 100644 index 0000000000..1c1777e23d --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-mremap.h @@ -0,0 +1,67 @@ +/* Additional mremap check. Linux 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 + . */ + +#include + +static void +test_mremap_dontunmap (void) +{ + size_t old_size = getpagesize (); + size_t new_size = old_size; + char *old_addr = xmmap (NULL, old_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1); + old_addr[0] = 1; + old_addr[old_size - 1] = 2; + + /* Create an available 64-page mmap region. */ + size_t fixed_size = old_size * 64; + char *fixed_addr = xmmap (NULL, fixed_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1); + xmunmap (fixed_addr, fixed_size); + + /* Test MREMAP_DONTUNMAP. It should return FIXED_ADDR created above. */ + char *new_addr = mremap (old_addr, old_size, new_size, + MREMAP_DONTUNMAP | MREMAP_MAYMOVE, + fixed_addr); + TEST_VERIFY_EXIT (fixed_addr == new_addr); + old_addr[0] = 3; + old_addr[old_size - 1] = 4; + new_addr[0] = 1; + new_addr[new_size - 1] = 2; + xmunmap (new_addr, new_size); + xmunmap (old_addr, old_size); +} + +static int +do_additonal_test (void) +{ + unsigned int kernel = get_linux_kernel_version (); + TEST_VERIFY_EXIT (kernel != 0); + + /* MREMAP_FIXED was added to Linux kernel 2.3.31. */ + if (kernel < make_linux_kernel_version (2, 3, 31)) + return EXIT_UNSUPPORTED; + test_mremap_fixed (); + + /* MREMAP_DONTUNMAP was added to Linux kernel 5.7. */ + if (kernel < make_linux_kernel_version (5, 7, 0)) + return EXIT_UNSUPPORTED; + test_mremap_dontunmap (); + + return 0; +}