Date: Fri, 29 Jan 2010 15:58:12 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r203170 - in stable/7: lib/libc/gen sys/sys Message-ID: <201001291558.o0TFwCLg006978@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Fri Jan 29 15:58:12 2010 New Revision: 203170 URL: http://svn.freebsd.org/changeset/base/203170 Log: MFC 197331, 197394: Add getpagesizes(3) function that returns either the number of page sizes supported by the system or a specified subset of the supported page sizes. Approved by: re (kib) Added: stable/7/lib/libc/gen/getpagesizes.3 - copied, changed from r197331, head/lib/libc/gen/getpagesizes.3 stable/7/lib/libc/gen/getpagesizes.c - copied unchanged from r197331, head/lib/libc/gen/getpagesizes.c Modified: stable/7/lib/libc/gen/Makefile.inc stable/7/lib/libc/gen/Symbol.map stable/7/sys/sys/mman.h Directory Properties: stable/7/lib/libc/ (props changed) stable/7/lib/libc/stdtime/ (props changed) stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/lib/libc/gen/Makefile.inc ============================================================================== --- stable/7/lib/libc/gen/Makefile.inc Fri Jan 29 15:11:50 2010 (r203169) +++ stable/7/lib/libc/gen/Makefile.inc Fri Jan 29 15:58:12 2010 (r203170) @@ -16,7 +16,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 \ @@ -52,8 +52,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 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \ Modified: stable/7/lib/libc/gen/Symbol.map ============================================================================== --- stable/7/lib/libc/gen/Symbol.map Fri Jan 29 15:11:50 2010 (r203169) +++ stable/7/lib/libc/gen/Symbol.map Fri Jan 29 15:58:12 2010 (r203170) @@ -341,6 +341,10 @@ FBSD_1.1 { semctl; }; +FBSD_1.2 { + getpagesizes; +}; + FBSDprivate_1.0 { /* needed by thread libraries */ __thr_jtable; Copied and modified: stable/7/lib/libc/gen/getpagesizes.3 (from r197331, head/lib/libc/gen/getpagesizes.3) ============================================================================== --- head/lib/libc/gen/getpagesizes.3 Sat Sep 19 18:01:32 2009 (r197331, copy source) +++ stable/7/lib/libc/gen/getpagesizes.3 Fri Jan 29 15:58:12 2010 (r203170) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 19, 2009 +.Dd September 21, 2009 .Dt GETPAGESIZES 3 .Os .Sh NAME @@ -94,5 +94,6 @@ 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 +.Sh AUTHORS +This manual page was written by +.An Alan L. Cox Aq alc@cs.rice.edu . Copied: stable/7/lib/libc/gen/getpagesizes.c (from r197331, head/lib/libc/gen/getpagesizes.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/7/lib/libc/gen/getpagesizes.c Fri Jan 29 15:58:12 2010 (r203170, copy of r197331, head/lib/libc/gen/getpagesizes.c) @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2009 Alan L. Cox <alc@cs.rice.edu> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/mman.h> +#include <sys/sysctl.h> + +#include <errno.h> + +/* + * 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: stable/7/sys/sys/mman.h ============================================================================== --- stable/7/sys/sys/mman.h Fri Jan 29 15:11:50 2010 (r203169) +++ stable/7/sys/sys/mman.h Fri Jan 29 15:58:12 2010 (r203170) @@ -177,6 +177,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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001291558.o0TFwCLg006978>