From owner-svn-src-all@freebsd.org Wed Sep 2 18:17:09 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6E1CD3C3C0F; Wed, 2 Sep 2020 18:17:09 +0000 (UTC) (envelope-from markj@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BhXGF2D6Wz40jY; Wed, 2 Sep 2020 18:17:09 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2FAE2E830; Wed, 2 Sep 2020 18:17:09 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 082IH9L7005601; Wed, 2 Sep 2020 18:17:09 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 082IH8nM005599; Wed, 2 Sep 2020 18:17:08 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202009021817.082IH8nM005599@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Wed, 2 Sep 2020 18:17:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365268 - in head: sbin/sysctl sys/kern X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in head: sbin/sysctl sys/kern X-SVN-Commit-Revision: 365268 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2020 18:17:09 -0000 Author: markj Date: Wed Sep 2 18:17:08 2020 New Revision: 365268 URL: https://svnweb.freebsd.org/changeset/base/365268 Log: Add sysctl(8) formatting for hw.pagesizes. - Change the type of hw.pagesizes to OPAQUE, since it returns an array. - Modify the handler to only truncate the returned length if the caller supplied an output buffer. This allows use of the trick of passing a NULL output buffer to fetch the output size, while preserving compatibility if MAXPAGESIZES is increased. - Add a "S,pagesize" formatter to sysctl(8). Reviewed by: alc, kib MFC after: 2 weeks Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D26239 Modified: head/sbin/sysctl/sysctl.c head/sys/kern/kern_mib.c Modified: head/sbin/sysctl/sysctl.c ============================================================================== --- head/sbin/sysctl/sysctl.c Wed Sep 2 18:16:43 2020 (r365267) +++ head/sbin/sysctl/sysctl.c Wed Sep 2 18:17:08 2020 (r365268) @@ -697,6 +697,29 @@ S_input_id(size_t l2, void *p) return (0); } +static int +S_pagesizes(size_t l2, void *p) +{ + char buf[256]; + u_long *ps; + size_t l; + int i; + + l = snprintf(buf, sizeof(buf), "{ "); + ps = p; + for (i = 0; i * sizeof(*ps) < l2 && ps[i] != 0 && l < sizeof(buf); + i++) { + l += snprintf(&buf[l], sizeof(buf) - l, + "%s%lu", i == 0 ? "" : ", ", ps[i]); + } + if (l < sizeof(buf)) + (void)snprintf(&buf[l], sizeof(buf) - l, " }"); + + printf("%s", buf); + + return (0); +} + #ifdef __amd64__ static int S_efi_map(size_t l2, void *p) @@ -1002,6 +1025,8 @@ show_var(int *oid, int nlen) func = S_vmtotal; else if (strcmp(fmt, "S,input_id") == 0) func = S_input_id; + else if (strcmp(fmt, "S,pagesizes") == 0) + func = S_pagesizes; #ifdef __amd64__ else if (strcmp(fmt, "S,efi_map_header") == 0) func = S_efi_map; Modified: head/sys/kern/kern_mib.c ============================================================================== --- head/sys/kern/kern_mib.c Wed Sep 2 18:16:43 2020 (r365267) +++ head/sys/kern/kern_mib.c Wed Sep 2 18:17:08 2020 (r365268) @@ -246,22 +246,22 @@ sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS) pagesizes32[i] = (uint32_t)pagesizes[i]; len = sizeof(pagesizes32); - if (len > req->oldlen) + if (len > req->oldlen && req->oldptr != NULL) len = req->oldlen; error = SYSCTL_OUT(req, pagesizes32, len); } else #endif { len = sizeof(pagesizes); - if (len > req->oldlen) + if (len > req->oldlen && req->oldptr != NULL) len = req->oldlen; error = SYSCTL_OUT(req, pagesizes, len); } return (error); } SYSCTL_PROC(_hw, OID_AUTO, pagesizes, - CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, - sysctl_hw_pagesizes, "LU", + CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, + sysctl_hw_pagesizes, "S,pagesizes", "Supported page sizes"); int adaptive_machine_arch = 1;