From nobody Tue Nov 28 17:16:11 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SfpyN1ZByz52FmP; Tue, 28 Nov 2023 17:16:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SfpyN0fCKz3dFb; Tue, 28 Nov 2023 17:16:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701191772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gpg82+uh40JbqOrVNvt56XDOJzX+iQemcGWVQjUU8zA=; b=EmW+6LBkFg5Fm7wFiWGdGMCMW6nnydlEdaGC7jhmdTTn/3Wk0ImQjHZYS+o/4Ulw3EKqvZ 1q9YpuNpxR/hUFAV0lHwTegpT98JO/D17wrH23BCiC+gOQd/ot9GAFJPALPjRdpeVhKT1g 1BRY/l5LPJe0rc4URgwIzu6eGlxs+LKKgDjUZraWTX6HpkHxHNYb4+FqUDrZNTy6+V/QW3 W6Nf7gJ3TC0YVkAnS+lsFx07O32jbd8nax2BlDcH90OzXLwy98yqh1IQD7Zxr2W1NYiwy/ GBlJRLMvZQ3PueRKLFYHanluiYm7ayxThZk3Hw2Lcw8Pdt/29Kqf4kCP+Lm4qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701191772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gpg82+uh40JbqOrVNvt56XDOJzX+iQemcGWVQjUU8zA=; b=D+Dm2ycmXC3av3tC30fvOCD2nTpElf1/0gVKTUrzPv+WaJ1yZVUzWVS9getSBdxY7CcX9F IHINOsTOV9vYWJKUMjtcTjqUxN1/HJTVvzVYD1QU1NhiVvSZ+uep1Ak1V2WEmTTQpNZzgD 1TOZTCE49NmaBvnmS+5QY5YUVqVTV6AdvqGzIST0EcRQVhhfkUdZMcsO0Tiq+3MTFmntUN i4/BVEK4pS0eVdcaL6u82Yj3GK1Iph62DFsyyITCF51y7IQ8dpYdMA2Q0LjfDYoJN53yoz QBOcXvtPq11WVqp9zX9Zrja4BLH9/JdRy7NN++fN0LN34kxAY5LN+FPkNUI0hg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701191772; a=rsa-sha256; cv=none; b=TZLjebrP0pdVcSR1djW1/AS5AbJ5RETPz2GzkxrKnNoIyu5UcejuwFLkkbNT/Jap1chISx WL/a+BqcWFOwdPSxlcccFlGjAk7KAvOGLszTvrGjAM449pfJ3ZyY5BYzHeBKkzQMDAPliy 9v2w2fLp2eOrJL7DRwMEMzsTqIiz5COR00EYUWXD/S66JtHFH8Lq1K0pgpTb1sLlIokq9t Q/QYf4ljXEIEPPhpTDrh/YPthrXfW8jghYlq+eBXL/t+ujKHkJ5WX0OtJ+SuSIuLxJVDbH wehGMKIQapTwzTqgMG/XVxvREMBhleNgX/U5fGfIEis/gDeGRtRXbMhcED3xNw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SfpyM6nzSzWfC; Tue, 28 Nov 2023 17:16:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ASHGBmn095410; Tue, 28 Nov 2023 17:16:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ASHGBQ6095407; Tue, 28 Nov 2023 17:16:11 GMT (envelope-from git) Date: Tue, 28 Nov 2023 17:16:11 GMT Message-Id: <202311281716.3ASHGBQ6095407@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: c96772227b7d - main - memfd_create: don't allocate heap memory List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c96772227b7dfcaf4eec4d07acb5c916643aca3a Auto-Submitted: auto-generated The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=c96772227b7dfcaf4eec4d07acb5c916643aca3a commit c96772227b7dfcaf4eec4d07acb5c916643aca3a Author: Brooks Davis AuthorDate: 2023-11-27 17:07:06 +0000 Commit: Brooks Davis CommitDate: 2023-11-28 17:09:27 +0000 memfd_create: don't allocate heap memory Rather than calling calloc() to allocate space for a page size array to pass to getpagesizes(), just follow the getpagesizes() implementation and allocate MAXPAGESIZES elements on the stack. This avoids the need for the allocation. While this does mean that a new libc is required to take advantage of a new huge page size, that was already true due to getpagesizes() using a static buffer of MAXPAGESIZES elements. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42710 --- lib/libc/gen/memfd_create.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/libc/gen/memfd_create.c b/lib/libc/gen/memfd_create.c index b26d638656a4..78131f46d7b1 100644 --- a/lib/libc/gen/memfd_create.c +++ b/lib/libc/gen/memfd_create.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -52,7 +51,8 @@ int memfd_create(const char *name, unsigned int flags) { char memfd_name[NAME_MAX + 1]; - size_t namelen, *pgs, pgsize; + size_t pgs[MAXPAGESIZES]; + size_t namelen, pgsize; struct shm_largepage_conf slc; int error, fd, npgs, oflags, pgidx, saved_errno, shmflags; @@ -92,16 +92,9 @@ memfd_create(const char *name, unsigned int flags) if (fd == -1 || (flags & MFD_HUGETLB) == 0) return (fd); - pgs = NULL; - npgs = getpagesizes(NULL, 0); + npgs = getpagesizes(pgs, nitems(pgs)); if (npgs == -1) goto clean; - pgs = calloc(npgs, sizeof(size_t)); - if (pgs == NULL) - goto clean; - error = getpagesizes(pgs, npgs); - if (error == -1) - goto clean; pgsize = (size_t)1 << ((flags & MFD_HUGE_MASK) >> MFD_HUGE_SHIFT); for (pgidx = 0; pgidx < npgs; pgidx++) { if (pgsize == pgs[pgidx]) @@ -111,8 +104,6 @@ memfd_create(const char *name, unsigned int flags) errno = EOPNOTSUPP; goto clean; } - free(pgs); - pgs = NULL; memset(&slc, 0, sizeof(slc)); slc.psind = pgidx; @@ -125,7 +116,6 @@ memfd_create(const char *name, unsigned int flags) clean: saved_errno = errno; close(fd); - free(pgs); errno = saved_errno; return (-1); }