From owner-svn-src-all@FreeBSD.ORG Sat Sep 19 18:01:33 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 04BA1106566C; Sat, 19 Sep 2009 18:01:33 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E676E8FC17; Sat, 19 Sep 2009 18:01:32 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n8JI1WsY031870; Sat, 19 Sep 2009 18:01:32 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n8JI1Wq8031864; Sat, 19 Sep 2009 18:01:32 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <200909191801.n8JI1Wq8031864@svn.freebsd.org> From: Alan Cox Date: Sat, 19 Sep 2009 18:01:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197331 - in head: lib/libc/gen sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Sat, 19 Sep 2009 18:01:33 -0000 Author: alc Date: Sat Sep 19 18:01:32 2009 New Revision: 197331 URL: http://svn.freebsd.org/changeset/base/197331 Log: Add getpagesizes(3). This functions either the number of supported page sizes or some number of the sizes themselves. It is functionally compatible with a function by the same name under Solaris. Reviewed by: jhb Added: head/lib/libc/gen/getpagesizes.3 (contents, props changed) head/lib/libc/gen/getpagesizes.c (contents, props changed) Modified: head/lib/libc/gen/Makefile.inc head/lib/libc/gen/Symbol.map head/sys/sys/mman.h Modified: head/lib/libc/gen/Makefile.inc ============================================================================== --- head/lib/libc/gen/Makefile.inc Sat Sep 19 17:56:26 2009 (r197330) +++ head/lib/libc/gen/Makefile.inc Sat Sep 19 18:01:32 2009 (r197331) @@ -15,7 +15,7 @@ SRCS+= __getosreldate.c __xuname.c \ getbootfile.c getbsize.c \ getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \ - getosreldate.c getpagesize.c \ + getosreldate.c getpagesize.c getpagesizes.c \ getpeereid.c getprogname.c getpwent.c getttyent.c \ getusershell.c getvfsbyname.c glob.c \ initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \ @@ -51,8 +51,8 @@ MAN+= alarm.3 arc4random.3 \ getbootfile.3 getbsize.3 getcap.3 getcontext.3 getcwd.3 \ getdiskbyname.3 getdomainname.3 getfsent.3 \ getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ - getmntinfo.3 getnetgrent.3 getosreldate.3 \ - getpagesize.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \ + getmntinfo.3 getnetgrent.3 getosreldate.3 getpagesize.3 \ + getpagesizes.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \ getttyent.3 getusershell.3 getvfsbyname.3 \ glob.3 initgroups.3 isgreater.3 ldexp.3 lockf.3 makecontext.3 \ modf.3 \ Modified: head/lib/libc/gen/Symbol.map ============================================================================== --- head/lib/libc/gen/Symbol.map Sat Sep 19 17:56:26 2009 (r197330) +++ head/lib/libc/gen/Symbol.map Sat Sep 19 18:01:32 2009 (r197331) @@ -366,6 +366,10 @@ FBSD_1.1 { tcsetsid; }; +FBSD_1.2 { + getpagesizes; +}; + FBSDprivate_1.0 { /* needed by thread libraries */ __thr_jtable; Added: head/lib/libc/gen/getpagesizes.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/gen/getpagesizes.3 Sat Sep 19 18:01:32 2009 (r197331) @@ -0,0 +1,98 @@ +.\" Copyright (c) 2009 Alan L. Cox +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 19, 2009 +.Dt GETPAGESIZES 3 +.Os +.Sh NAME +.Nm getpagesizes +.Nd "get system page sizes" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/mman.h +.Ft int +.Fn getpagesizes "size_t pagesize[]" "int nelem" +.Sh DESCRIPTION +The +.Fn getpagesizes +function retrieves page size information from the system. +When it is called with +.Fa pagesize +specified as +.Dv NULL +and +.Fa nelem +specified as 0, it returns the number of distinct page sizes that are +supported by the system. +Otherwise, it assigns up to +.Fa nelem +of the system-supported page sizes to consecutive elements of the +array referenced by +.Fa pagesize . +These page sizes are expressed in bytes. +In this case, +.Fn getpagesizes +returns the number of such page sizes that it assigned to the array. +.Sh RETURN VALUES +If successful, the +.Fn getpagesizes +function returns either the number of page sizes that are supported by +the system or the number of supported page sizes that it assigned to +the array referenced by +.Fa pagesize . +Otherwise, it returns the value\~\-1 and sets +.Va errno +to indicate the error. +.Sh ERRORS +The +.Fn getpagesizes +function will succeed unless: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa pagesize +argument is +.Dv NULL +and the +.Fa nelem +argument is non-zero. +.It Bq Er EINVAL +The +.Fa nelem +argument is less than zero. +.El +.Sh SEE ALSO +.Xr getpagesize 3 +.Sh HISTORY +The +.Fn getpagesizes +function first appeared in Solaris 9. +This manual page was written in conjunction with a new but compatible +implementation that was first released in +.Fx 7.3 . +.Sh AUTHOR +.An Alan L. Cox Aq alc@cs.rice.edu Added: head/lib/libc/gen/getpagesizes.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/gen/getpagesizes.c Sat Sep 19 18:01:32 2009 (r197331) @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2009 Alan L. Cox + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include + +/* + * Retrieves page size information from the system. Specifically, returns the + * number of distinct page sizes that are supported by the system, if + * "pagesize" is NULL and "nelem" is 0. Otherwise, assigns up to "nelem" of + * the system-supported page sizes to consecutive elements of the array + * referenced by "pagesize", and returns the number of such page sizes that it + * assigned to the array. These page sizes are expressed in bytes. + * + * The implementation of this function does not directly or indirectly call + * malloc(3) or any other dynamic memory allocator that may itself call this + * function. + */ +int +getpagesizes(size_t pagesize[], int nelem) +{ + static u_long ps[MAXPAGESIZES]; + static int nops; + size_t size; + int i; + + if (nelem < 0 || (nelem > 0 && pagesize == NULL)) { + errno = EINVAL; + return (-1); + } + /* Cache the result of the sysctl(2). */ + if (nops == 0) { + size = sizeof(ps); + if (sysctlbyname("hw.pagesizes", ps, &size, NULL, 0) == -1) + return (-1); + /* Count the number of page sizes that are supported. */ + nops = size / sizeof(ps[0]); + while (nops > 0 && ps[nops - 1] == 0) + nops--; + } + if (pagesize == NULL) + return (nops); + /* Return up to "nelem" page sizes from the cached result. */ + if (nelem > nops) + nelem = nops; + for (i = 0; i < nelem; i++) + pagesize[i] = ps[i]; + return (nelem); +} Modified: head/sys/sys/mman.h ============================================================================== --- head/sys/sys/mman.h Sat Sep 19 17:56:26 2009 (r197330) +++ head/sys/sys/mman.h Sat Sep 19 18:01:32 2009 (r197331) @@ -208,6 +208,7 @@ __BEGIN_DECLS * posix_typed_mem_open(). */ #if __BSD_VISIBLE +int getpagesizes(size_t *, int); int madvise(void *, size_t, int); int mincore(const void *, size_t, char *); int minherit(void *, size_t, int);