1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <sys/systm.h> 31 #include <vm/page.h> 32 #include <sys/errno.h> 33 34 /* 35 * Return supported page sizes. 36 */ 37 int 38 getpagesizes(size_t *buf, int nelem) 39 { 40 int i, pagesizes = page_num_user_pagesizes(); 41 size_t *pgsza; 42 43 if (nelem < 0) { 44 return (set_errno(EINVAL)); 45 } 46 if (nelem == 0 && buf != NULL) { 47 return (set_errno(EINVAL)); 48 } 49 if (nelem == 0 && buf == NULL) { 50 return (pagesizes); 51 } 52 if (buf == NULL) { 53 return (set_errno(EINVAL)); 54 } 55 if (nelem > pagesizes) { 56 nelem = pagesizes; 57 } 58 pgsza = kmem_alloc(sizeof (*pgsza) * nelem, KM_SLEEP); 59 for (i = 0; i < nelem; i++) { 60 pgsza[i] = page_get_user_pagesize(i); 61 } 62 if (copyout(pgsza, buf, nelem * sizeof (*pgsza)) != 0) { 63 kmem_free(pgsza, sizeof (*pgsza) * nelem); 64 return (set_errno(EFAULT)); 65 } 66 kmem_free(pgsza, sizeof (*pgsza) * nelem); 67 return (nelem); 68 } 69 70 #if defined(_SYSCALL32_IMPL) 71 72 /* 73 * Some future platforms will support page sizes larger than 74 * a 32-bit address space. 75 */ 76 int 77 getpagesizes32(size32_t *buf, int nelem) 78 { 79 int i, pagesizes = page_num_user_pagesizes(); 80 size32_t *pgsza32; 81 size_t pgsz; 82 int rc; 83 84 if (nelem < 0) { 85 return (set_errno(EINVAL)); 86 } 87 if (nelem == 0 && buf != NULL) { 88 return (set_errno(EINVAL)); 89 } 90 91 pgsza32 = kmem_alloc(sizeof (*pgsza32) * pagesizes, KM_SLEEP); 92 for (i = 0; i < pagesizes; i++) { 93 pgsz = page_get_user_pagesize(i); 94 pgsza32[i] = (size32_t)pgsz; 95 if (pgsz > (size32_t)-1) { 96 pagesizes = i - 1; 97 break; 98 } 99 } 100 ASSERT(pagesizes > 0); 101 ASSERT(page_get_user_pagesize(pagesizes - 1) <= (size32_t)-1); 102 if (nelem > pagesizes) { 103 nelem = pagesizes; 104 } 105 if (nelem == 0 && buf == NULL) { 106 rc = pagesizes; 107 goto done; 108 } 109 if (buf == NULL) { 110 rc = set_errno(EINVAL); 111 goto done; 112 } 113 if (copyout(pgsza32, buf, nelem * sizeof (*pgsza32)) != 0) { 114 rc = set_errno(EFAULT); 115 goto done; 116 } 117 rc = nelem; 118 done: 119 kmem_free(pgsza32, sizeof (*pgsza32) * page_num_user_pagesizes()); 120 return (rc); 121 } 122 #endif 123