From patchwork Tue Jul 16 22:43:19 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: 1961348 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=BXDPnnhW; 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 4WNvHp6lyNz20B2 for ; Wed, 17 Jul 2024 08:43:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2164B387088B for ; Tue, 16 Jul 2024 22:43:49 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by sourceware.org (Postfix) with ESMTPS id 1CE5A385DDE6 for ; Tue, 16 Jul 2024 22:43:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CE5A385DDE6 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 1CE5A385DDE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169808; cv=none; b=VBxx+Sna5/iwMX2zPk3mam0GTGihqCvz1MyXv95CX67d7lcuKktO3Dx+JII+S59cZan9eaC/Fv8L/JFUHkcpXy9hH63Uwk4D6v6laRH7CHyVTt13QeiatGkiiGFiDvKv/NDqMleLaZnl+ht93IeIG+v2NAsM4TNGlAPK5Gi8pmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169808; c=relaxed/simple; bh=FGsZyrC++GHHxKHnA/EZcn4P7e8859PQJyzH+zw55tw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KkW1tYTL/E7GWo2r++Z4CdcvXP6BhOm42osxoZojkELbWIiZKafacanfUBsYjjbMFzGt3WgQQBHGuntGPs39wjJadswXcPWdwpFb58gA3BFmFKtA6aHY4HzxpXn2Kj82+wx7P5DD6+unTrCrjx/Z0AV+eyz5ZRBHB471IRrL8+I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-64f4fd64773so69140717b3.0 for ; Tue, 16 Jul 2024 15:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721169806; x=1721774606; 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=BXDPnnhWIwDT9Bmot9Cl4pY67TkD3n+msr5Js52OXYBxkO8iOtVbIwAJPAlePF1gEB gbwvFWsNJRu1WSTh/pvcsYsdPSYxK7jpTZEfyatt2bzpXpFBT+WptYHnCV+KRifLeiEy k6hJ5MbhRxNZooApBN7JeNOmk/3WRxY8mQxM9PedPQo9SGEXxkGIezdoHws1uGVd3N1a 7xpkrLA44Du12YPzPslM3X4AYebecwvzjZsP6g62xd+JmgrmsY45iMSMiaK4e7DFr2Z/ F56FGzJvhear67SpX7rHKqakVOpCcLKwDauEnBPCpX1SIb3dof9s16b4Sp7sAHxocpln N52g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721169806; x=1721774606; 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=i6i33Vxeyc0hfIuNaqyYl1rgsx1jUVNd4bJAo/cAS+mpousxYPjDMCsqKzDZPZ9gPC Y6QwcyHcmjrRsMBPz92D8Bjlizp8NJDLLMvMYfailrPmOiCSmI/Im/2kXBVLTWS14Syt QyIOnb71bvXKGUojygXsvzAygGRBTKMbZ5+q7nmfpp05jDKtSh+oouqmBayYW/Q5jy9u AGhymQAla4w4hDSXLEj0E6Cr9ZFiVQ/ZgjzrCnt6Y+EkgGCFs+CAAFYlhlvtVzlZiQib kvs61zpna1oUm1E0WqjLGQB398OkqnldrW2uA4IZFXtykV4ZMkfVDbAkQd+yrXHtcO/4 hIaQ== X-Gm-Message-State: AOJu0YzsPEsPh3YNgK3eAt2BuR1EOq2HBub9m0dGmIpK9safYhqZ5H6l PIgx9ViykPHK90yRM+b1gNp30o+OdPISJi/JcORU6gxeb+uaMVuxnEFns30wMk58aQ== X-Google-Smtp-Source: AGHT+IHUXSdM1Y4sD9AeYxFED3IFTQbDh/Jutct97a7AEgKw1hq/9MzYhpGIaSFXE4dyxJKKjndaqQ== X-Received: by 2002:a05:690c:61c2:b0:664:6532:bd46 with SMTP id 00721157ae682-664fe25eee3mr70407b3.19.1721169806234; Tue, 16 Jul 2024 15:43:26 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.139.74]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc212bbeasm13265997b3.2.2024.07.16.15.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 15:43:25 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id AC8FAC01AA for ; Tue, 16 Jul 2024 15:43:21 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v2 1/3] linux: Update the mremap C implementation [BZ #31968] Date: Tue, 16 Jul 2024 15:43:19 -0700 Message-ID: <20240716224321.2352246-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716224321.2352246-1-hjl.tools@gmail.com> References: <20240716224321.2352246-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3020.9 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 Tue Jul 16 22:43:20 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: 1961349 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=iZ1o0zxm; 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 4WNvHs0G15z1ySl for ; Wed, 17 Jul 2024 08:43:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA301384A05B for ; Tue, 16 Jul 2024 22:43:50 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by sourceware.org (Postfix) with ESMTPS id 43AD2386102F for ; Tue, 16 Jul 2024 22:43:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43AD2386102F 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 43AD2386102F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169808; cv=none; b=rIaVuOnHUNcd26IM2bJohPvDVW1wO6TN8wyWH4dS9Bid9yJ8beFuw7lgJp+2UqA7x49Bec34BA8CqNIZIoqYCcG9VPrx1Qisg/ZIOfLx86HlYPZ7SXTA0HRTAuokVJFMKrdxXZTYmeJ5fRTYAUKXlpkkR/9lf/7u2MIaV8QF0BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169808; c=relaxed/simple; bh=089WUDnNwGUENRAwEwtYwh7cyUzzIuQlOMEiZT2Ir1I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J3H6Qv2UoLVnTkL9BPorHvgm52my1GO2W6HHKKC+dXb43B/Ui8dEfswWaHCqvuCgjXoHUHYIT6OoWTvmVxeo3wEIGF12VHw2PWf9xG0q4Sdee+NulEiecb3fZg1MgptWIvNeX7MbKkX2G1nFiXpfg2P+y0ASvV0LicZHVB4GtRQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-65f8b0df1f0so35250647b3.2 for ; Tue, 16 Jul 2024 15:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721169806; x=1721774606; 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=MYSTc1vRVmD9HF5t/D7rT07o8wpHENQRFWQ1vT5Le3I=; b=iZ1o0zxmLneyZbjKT4zegk3WeMpMccbRSQUeH/Fyd7SC83xyBHPoIuSD7iXb16RD4B ahyrKi3IuKqik1feLJ1X1dH95OM2U0W8v68HGXY1o493uJhIVVY7BAyrH2bsIxqG+GIm xGyxiHQ9sy0pk3SYg9ejk1gUPBdY5fQzz7UaoKU37eaVUx5Kp01xac/+XXhNxNSZvTcR dMNeoN1oa1vFl/x6gCAU54o4L0otbfHo8zGgN3i8qOiw0wtXv4VARxG+ZBOgz3giUVOj 25HwVyABAFllr7b6d3rg5oGCfacWTiSrnx0Pk1stcCBRsPFC6UHXOy7zUYgXg+9JrhYz 8cBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721169806; x=1721774606; 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=MYSTc1vRVmD9HF5t/D7rT07o8wpHENQRFWQ1vT5Le3I=; b=c7uIVo3cHklbBlELiLc8l98q1tYdGGj7jGWRnmm9Tu1oGuyRsdXM1pmpE0ZFD84vIa QAw3LHvRKDGrv68+AZ+A2dErDIaioYbdsQtP5vXQ3n6C2aG30/h0Ul83bA+Ky/n6sSww IGOkdJGqVO+8YkiLPWUbREKTjbYgKtsQAX7GGcGQwpOl3/XdlhbVpbA7pZKvSeDOA03P hMoxDUUmJHTJvvBtqtyl67CH0RSKsGb5h4F5z8uK1ktfs2mzkoqNMT2HPJSC68xLXtPM pLhuBnOOkQ98C4WA9++Z+1oBziBmmc8cfrxTKBO6/hxkPyXI3X3JBVy49IE4k3KCCfet 8z4w== X-Gm-Message-State: AOJu0YxCZiRBucWw4qC9jUd8N3mRApdJes6t75pn5KGYZCXKDqXMs1qe rxZ5zVlYEiU7mcTOH9dcuMQ7EkxQQN7Xw8n5P3lU4oUAgG7D74bi8YPVHO1dwWzPIw== X-Google-Smtp-Source: AGHT+IGJRgTFYKcljfC1a6+Gi/5/flYyiwnfGpmzgcWmhlxg8StMg47tEooN1jUK6wwy0FbZvHlEaw== X-Received: by 2002:a05:690c:f15:b0:620:2cfb:7a0e with SMTP id 00721157ae682-663817d8469mr44320917b3.40.1721169806343; Tue, 16 Jul 2024 15:43:26 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.139.74]) by smtp.gmail.com with ESMTPSA id 00721157ae682-65fc26111ddsm13130977b3.41.2024.07.16.15.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 15:43:25 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id B7228C02F4 for ; Tue, 16 Jul 2024 15:43:21 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] mremap: Update manual entry Date: Tue, 16 Jul 2024 15:43:20 -0700 Message-ID: <20240716224321.2352246-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716224321.2352246-1-hjl.tools@gmail.com> References: <20240716224321.2352246-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, 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 mremap manual entry: 1. Change mremap to variadic. 2. Document MREMAP_FIXED and MREMAP_DONTUNMAP. Signed-off-by: H.J. Lu --- manual/llio.texi | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/manual/llio.texi b/manual/llio.texi index 6f0a48609b..c6f65089ee 100644 --- a/manual/llio.texi +++ b/manual/llio.texi @@ -1892,7 +1892,7 @@ There is no existing mapping in at least part of the given region. @end deftypefun -@deftypefun {void *} mremap (void *@var{address}, size_t @var{length}, size_t @var{new_length}, int @var{flag}) +@deftypefun {void *} mremap (void *@var{address}, size_t @var{length}, size_t @var{new_length}, int @var{flag}, ... /* void *@var{new_address} */) @standards{GNU, sys/mman.h} @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} @@ -1901,12 +1901,39 @@ area. @var{address} and @var{length} must cover a region entirely mapped in the same @code{mmap} statement. A new mapping with the same characteristics will be returned with the length @var{new_length}. -One option is possible, @code{MREMAP_MAYMOVE}. If it is given in -@var{flags}, the system may remove the existing mapping and create a new -one of the desired length in another location. +Possible flags are -The address of the resulting mapping is returned, or @math{-1}. Possible -error codes include: +@table @code + +@item MREMAP_MAYMOVE +If it is given in @var{flags}, the system may remove the existing mapping +and create a new one of the desired length in another location. + +@item MREMAP_FIXED +If it is given in @var{flags}, @code{mremap} accepts a fifth argument, +@code{void *new_address}, which specifies a page-aligned address to +which the mapping must be moved. Any previous mapping at the address +range specified by @var{new_address} and @var{new_size} is unmapped. + +@code{MREMAP_FIXED} must be used together with @code{MREMAP_MAYMOVE}. + +@item MREMAP_DONTUNMAP +If it is given in @var{flags}, @code{mremap} accepts a fifth argument, +@code{void *new_address}, which specifies a page-aligned address. Any +previous mapping at the address range specified by @var{new_address} and +@var{new_size} is unmapped. If @var{new_address} is @code{NULL}, the +kernel chooses the page-aligned address at which to create the mapping. +Otherwise, the kernel takes it as a hint about where to place the mapping. +The mapping at the address range specified by @var{old_address} and +@var{old_size} isn't unmapped. + +@code{MREMAP_DONTUNMAP} must be used together with @code{MREMAP_MAYMOVE}. +@var{old_size} must be the same as @var{new_size}. + +@end table + +The address of the resulting mapping is returned, or @code{MAP_FAILED}. +Possible error codes include: @table @code @@ -1915,7 +1942,7 @@ There is no existing mapping in at least part of the original region, or the region covers two or more distinct mappings. @item EINVAL -The address given is misaligned or inappropriate. +Any arguments are inappropriate, including unknown @var{flags} values. @item EAGAIN The region has pages locked, and if extended it would exceed the From patchwork Tue Jul 16 22:43:21 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: 1961350 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=Nox5d0wK; 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 4WNvJf33h4z1ySl for ; Wed, 17 Jul 2024 08:44:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4153C3858401 for ; Tue, 16 Jul 2024 22:44:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by sourceware.org (Postfix) with ESMTPS id 050AC3858C78 for ; Tue, 16 Jul 2024 22:43:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 050AC3858C78 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 050AC3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169809; cv=none; b=Ig6IOcnfstKaHwFTnCFGzDl9abSy+wG3jU47H5UID3muX2QIW4dgx3W0yjvPVEK69CxClyTPYV85emSHH0pkNrRaycb+Jhbj3iqkrGn6jr6BP5tBa56iAZ1vYxgMnpr41HHlIXnzRYJyF+2EsSJbzNVsWo6Rj2I/ooVO8gQ2jJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721169809; c=relaxed/simple; bh=7ZCXvABcSy/QaVCIRMknfRYpFmL6Frdgcyy9TbxlndU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AjBm1R6OeuX0/VS+M35//gcdkv6rApqZx/zxUd0BdJA7XzoSfTe4vk8qCfz+wyYq97Nc2yhhwjAfM8S0yfRAuMfpabgirbVvj5t2lfkvOSkUmZpH68h49jk7UZoYpHeqG1PC1Zdrdhg4Z3Jq+8ymjHk5pHZwi1akGXnb3I5ir/I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-e0354459844so6103304276.3 for ; Tue, 16 Jul 2024 15:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721169806; x=1721774606; 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=SD5K6V8ZzUWewVaOZI5d2dNurMC7+MVePUYh9TSmcDc=; b=Nox5d0wKdz9DRZA5SN6TyUFBA7H63QZorFw4xOsJLMfmnrRSvU8InmMlppAewJ+WJq +vH6s2CQJuhvFoNtY7MoSurQ3V0Gl2UFVYPcekz1pXREChOYQ6zqP1IrJxmeVJsXLBNT Wf1NAgYU6eaPYi1XmR9HJo4VVkpy4oBJsxsSgiyC5vFoUzmfewcVFDiRkvFdF9UEnApd W/F4ZASRLVadWyreqNqGpZ1WfzSIuOcpYarr5arjzATOCyCED3M8rRlKfnKOjq9VG4AI 8Xs3HZFBUFOd8Fq2RVlQicJckUb8PL3bMQeZSjOuKY1ykDN9q0hqTPCJexpaQEhec9Pj iXug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721169806; x=1721774606; 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=SD5K6V8ZzUWewVaOZI5d2dNurMC7+MVePUYh9TSmcDc=; b=IhlnYXe7tspKbcKsARVM/+R9IpzVPWQXjJADls082XoA0BJb/o9fRwnAahNGVRJLQ9 sAe0ptHLQ/gBzt18mH8U8xq5+9L2Y4Tyx2L/KrSkwNomJGyXtCEkNZgIlMbZOjPyQvp0 4sKDB4AzTEFQ+9tDcsU2necjKrx/37ssyeCL9wtQCrDM4DBCSgFgHBmSovphxNgoS6mS rwZFXolU4G+2r3KJLHY9DUnht8SiVDloQB3nupaMF9LVr0mPKqxjYJNCOcl5aNobnfY7 MIFGQQjmDPw1vZzoZBT4Y9Rbx6+/c1STfV/gZhtFnXG+I6zu/KScCEfw3ftmTuFWdhAP RQHw== X-Gm-Message-State: AOJu0YwrdzPyLqj1tbbMeGIit3daG9CbNdXs854P6ajaYkvuDIdzr/tF Ycp/CBTFbghk/aJvVBXTj/5Pbbllh8zl7Ormds7C8Waqrs6rNZCpF8nrlizwPamOHg== X-Google-Smtp-Source: AGHT+IE5AugcfMYQwK3iNOaKsJhgEjMIZWWc+RHIA/RcmOHcduZZmY5i7kHE/vkyAQtrRcEIOMwo/g== X-Received: by 2002:a05:6902:18c5:b0:e05:674f:fad6 with SMTP id 3f1490d57ef6-e05d565c759mr4786110276.5.1721169806014; Tue, 16 Jul 2024 15:43:26 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.139.74]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e05a4614b8bsm1373938276.23.2024.07.16.15.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 15:43:25 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id C1ECBC044B for ; Tue, 16 Jul 2024 15:43:21 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH v2 3/3] Add mremap tests Date: Tue, 16 Jul 2024 15:43:21 -0700 Message-ID: <20240716224321.2352246-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716224321.2352246-1-hjl.tools@gmail.com> References: <20240716224321.2352246-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.2 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 and MREMAP_FIXED. On Linux, also test MREMAP_DONTUNMAP. Signed-off-by: H.J. Lu --- misc/Makefile | 2 + misc/tst-mremap1.c | 46 +++++++++++++++ misc/tst-mremap2.c | 53 ++++++++++++++++++ sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-linux-mremap1.c | 62 +++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 misc/tst-mremap1.c create mode 100644 misc/tst-mremap2.c create mode 100644 sysdeps/unix/sysv/linux/tst-linux-mremap1.c diff --git a/misc/Makefile b/misc/Makefile index 5d17c562fe..7b7f8351bf 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -257,6 +257,8 @@ tests := \ tst-mntent-blank-passno \ tst-mntent-escape \ tst-mntent2 \ + tst-mremap1 \ + tst-mremap2 \ tst-preadvwritev \ tst-preadvwritev2 \ tst-preadvwritev64 \ diff --git a/misc/tst-mremap1.c b/misc/tst-mremap1.c new file mode 100644 index 0000000000..0469991a6c --- /dev/null +++ b/misc/tst-mremap1.c @@ -0,0 +1,46 @@ +/* Test mremap with MREMAP_MAYMOVE. + 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 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 0; +} + +#include diff --git a/misc/tst-mremap2.c b/misc/tst-mremap2.c new file mode 100644 index 0000000000..9e226eb90e --- /dev/null +++ b/misc/tst-mremap2.c @@ -0,0 +1,53 @@ +/* Test mremap with MREMAP_FIXED. + 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 + +static int +do_test (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); + if (new_addr == MAP_FAILED) + return errno == EINVAL ? EXIT_UNSUPPORTED : EXIT_FAILURE; + new_addr[0] = 1; + new_addr[new_size - 1] = 2; + xmunmap (new_addr, new_size); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 097b5a26fc..59998c7af4 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -206,6 +206,7 @@ tests += \ tst-getauxval \ tst-gettid \ tst-gettid-kill \ + tst-linux-mremap1 \ tst-memfd_create \ tst-misalign-clone \ tst-mlock2 \ diff --git a/sysdeps/unix/sysv/linux/tst-linux-mremap1.c b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c new file mode 100644 index 0000000000..0d484377bd --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-linux-mremap1.c @@ -0,0 +1,62 @@ +/* Test mremap with MREMAP_DONTUNMAP. + 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 int +do_test (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); + + /* Add 3 * pagesize. */ + fixed_size += 3 * old_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); + if (new_addr == MAP_FAILED) + return errno == EINVAL ? EXIT_UNSUPPORTED : EXIT_FAILURE; + 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); + + return 0; +} + +#include