From patchwork Mon Jan 30 12:52:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 63912 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 641B83858C2C for ; Mon, 30 Jan 2023 12:54:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 641B83858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675083269; bh=TbIU87j+4LnwfJuq6FFSKQBAndPRIeaJpY8k/nFX9Ug=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=SKOY3uVuVPjDhwMvMOZppLExm7x/o0NZPHFxgEGjTxftULR0saBn/gR4O4drituGC kNrJVWecXqh78brmLPj2PCtD97UThalL7RBTttYVQiq8Vj6t5+ED/s+NdIfrcCPZ0B 5gU50mk4v8NnIuXVhhi8sHB20AmEw7hE4IfEeKyw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id E75213858C1F for ; Mon, 30 Jan 2023 12:52:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E75213858C1F Received: by mail-lf1-x135.google.com with SMTP id cf42so18861113lfb.1 for ; Mon, 30 Jan 2023 04:52:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TbIU87j+4LnwfJuq6FFSKQBAndPRIeaJpY8k/nFX9Ug=; b=qL5Zxm1iW1lpt98AzSPafTuOIGTCiW24EwUZDDFGkHWrcXUlKDwlXnk+z3jQcoMPIz gAiY/yZbG6vrtMKI9X5oHbJN0GA0277tYKDp2Y8dLC3S4/Lb2N1OnYUQbAUqmMmobeVy 6sct8xdrk3bS2UpE/MMzR5OOmsilZiCQZdE0tByy9HEznmaAufr7ytqPSDjm6NrOV/Te PougGbkZLnqN/dBcQM+TrefpnKIJM8LprmhR7dxt5Xa1/a4BdgqOap1bqdvyxMizfuux MoES0fa6yvXcv6W3CaHd0i5k2Eu/rawWbI+aJtjIrAT4hGtxcRllnk4QfLAt4pAls1s5 joiA== X-Gm-Message-State: AFqh2krQDNU2wYua29QkAXi7Zn0CaF/Ez7aVVTrEyBRfb7vT8zmOYeNb s8GLzoirwx6iry9DMWu8O0c= X-Google-Smtp-Source: AMrXdXuHTdWcfIYdbmDt04G0CBnGOI7RtocijWsEiRvISoXlnueBUpPZ/obP2e2Xjj1aZ6dqXr2htQ== X-Received: by 2002:a05:6512:358a:b0:4cb:1189:285c with SMTP id m10-20020a056512358a00b004cb1189285cmr11541975lfr.10.1675083167341; Mon, 30 Jan 2023 04:52:47 -0800 (PST) Received: from surface-pro-6.. ([194.190.106.50]) by smtp.gmail.com with ESMTPSA id m4-20020a05651202e400b004d35fea344dsm847233lfq.202.2023.01.30.04.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 04:52:46 -0800 (PST) To: bug-hurd@gnu.org, libc-alpha@sourceware.org, samuel.thibault@gnu.org Cc: Sergey Bugaev Subject: [PATCH v2 3/3] hurd: Implement SHM_ANON Date: Mon, 30 Jan 2023 15:52:16 +0300 Message-Id: <20230130125216.6254-4-bugaevc@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130095907.mlvp3pbmtarkhhql@begin> References: <20230130095907.mlvp3pbmtarkhhql@begin> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This adds a special SHM_ANON value that can be passed into shm_open () in place of a name. When called in this way, shm_open () will create a new anonymous shared memory file. The file will be created in the same way that other shared memory files are created (i.e., under /dev/shm/), except that it is not given a name and therefore cannot be reached from the file system, nor by other calls to shm_open (). This is accomplished by utilizing O_TMPFILE. This is intended to be compatible with FreeBSD's API of the same name. Signed-off-by: Sergey Bugaev --- posix/shm-directory.c | 25 +++++++++++++++++++++---- rt/shm_open.c | 5 +++++ sysdeps/mach/hurd/bits/mman_ext.h | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 sysdeps/mach/hurd/bits/mman_ext.h diff --git a/posix/shm-directory.c b/posix/shm-directory.c index 47e2355d..86d9fd8e 100644 --- a/posix/shm-directory.c +++ b/posix/shm-directory.c @@ -23,17 +23,34 @@ #include #include #include +#include +#include int __shm_get_name (struct shmdir_name *result, const char *name, bool sem_prefix) { + struct alloc_buffer buffer; + size_t namelen; + + buffer = alloc_buffer_create (result->name, sizeof (result->name)); + alloc_buffer_copy_bytes (&buffer, SHMDIR, strlen (SHMDIR)); + +#if defined (SHM_ANON) && defined (O_TMPFILE) + if (name == SHM_ANON) + { + /* For SHM_ANON, we want shm_open () to pass O_TMPFILE to open (), + with SHMDIR itself as the path. So, leave it at that. */ + alloc_buffer_add_byte (&buffer, 0); + if (alloc_buffer_has_failed (&buffer)) + return -1; + return 0; + } +#endif + while (name[0] == '/') ++name; - size_t namelen = strlen (name); + namelen = strlen (name); - struct alloc_buffer buffer - = alloc_buffer_create (result->name, sizeof (result->name)); - alloc_buffer_copy_bytes (&buffer, SHMDIR, strlen (SHMDIR)); if (sem_prefix) alloc_buffer_copy_bytes (&buffer, "sem.", strlen ("sem.")); alloc_buffer_copy_bytes (&buffer, name, namelen + 1); diff --git a/rt/shm_open.c b/rt/shm_open.c index 48970bbc..6c1f4d60 100644 --- a/rt/shm_open.c +++ b/rt/shm_open.c @@ -23,6 +23,7 @@ #include #include #include +#include /* Open shared memory object. */ int @@ -36,6 +37,10 @@ __shm_open (const char *name, int oflag, mode_t mode) } oflag |= O_NOFOLLOW | O_CLOEXEC; +#if defined (SHM_ANON) && defined (O_TMPFILE) + if (name == SHM_ANON) + oflag |= O_TMPFILE; +#endif int fd = __open64_nocancel (dirname.name, oflag, mode); if (fd == -1 && __glibc_unlikely (errno == EISDIR)) diff --git a/sysdeps/mach/hurd/bits/mman_ext.h b/sysdeps/mach/hurd/bits/mman_ext.h new file mode 100644 index 00000000..f022826e --- /dev/null +++ b/sysdeps/mach/hurd/bits/mman_ext.h @@ -0,0 +1,25 @@ +/* System-specific extensions of , Hurd version. + Copyright (C) 2022 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 _SYS_MMAN_H +# error "Never include directly; use instead." +#endif + +#ifdef __USE_GNU +# define SHM_ANON ((const char *) 1) +#endif /* __USE_GNU */