17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*02bc52beSkchow  * Common Development and Distribution License (the "License").
6*02bc52beSkchow  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*02bc52beSkchow  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/systm.h>
287c478bd9Sstevel@tonic-gate #include <vm/page.h>
297c478bd9Sstevel@tonic-gate #include <sys/errno.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Return supported page sizes.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate int
getpagesizes(int legacy,size_t * buf,int nelem)35*02bc52beSkchow getpagesizes(int legacy, size_t *buf, int nelem)
367c478bd9Sstevel@tonic-gate {
37*02bc52beSkchow 	int i, pagesizes = page_num_user_pagesizes(legacy);
387c478bd9Sstevel@tonic-gate 	size_t *pgsza;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 	if (nelem < 0) {
417c478bd9Sstevel@tonic-gate 		return (set_errno(EINVAL));
427c478bd9Sstevel@tonic-gate 	}
437c478bd9Sstevel@tonic-gate 	if (nelem == 0 && buf != NULL) {
447c478bd9Sstevel@tonic-gate 		return (set_errno(EINVAL));
457c478bd9Sstevel@tonic-gate 	}
467c478bd9Sstevel@tonic-gate 	if (nelem == 0 && buf == NULL) {
477c478bd9Sstevel@tonic-gate 		return (pagesizes);
487c478bd9Sstevel@tonic-gate 	}
497c478bd9Sstevel@tonic-gate 	if (buf == NULL) {
507c478bd9Sstevel@tonic-gate 		return (set_errno(EINVAL));
517c478bd9Sstevel@tonic-gate 	}
527c478bd9Sstevel@tonic-gate 	if (nelem > pagesizes) {
537c478bd9Sstevel@tonic-gate 		nelem = pagesizes;
547c478bd9Sstevel@tonic-gate 	}
557c478bd9Sstevel@tonic-gate 	pgsza = kmem_alloc(sizeof (*pgsza) * nelem, KM_SLEEP);
567c478bd9Sstevel@tonic-gate 	for (i = 0; i < nelem; i++) {
577c478bd9Sstevel@tonic-gate 		pgsza[i] = page_get_user_pagesize(i);
587c478bd9Sstevel@tonic-gate 	}
597c478bd9Sstevel@tonic-gate 	if (copyout(pgsza, buf, nelem * sizeof (*pgsza)) != 0) {
607c478bd9Sstevel@tonic-gate 		kmem_free(pgsza, sizeof (*pgsza) * nelem);
617c478bd9Sstevel@tonic-gate 		return (set_errno(EFAULT));
627c478bd9Sstevel@tonic-gate 	}
637c478bd9Sstevel@tonic-gate 	kmem_free(pgsza, sizeof (*pgsza) * nelem);
647c478bd9Sstevel@tonic-gate 	return (nelem);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * Some future platforms will support page sizes larger than
717c478bd9Sstevel@tonic-gate  * a 32-bit address space.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate int
getpagesizes32(int legacy,size32_t * buf,int nelem)74*02bc52beSkchow getpagesizes32(int legacy, size32_t *buf, int nelem)
757c478bd9Sstevel@tonic-gate {
76*02bc52beSkchow 	int i, pagesizes = page_num_user_pagesizes(legacy);
777c478bd9Sstevel@tonic-gate 	size32_t *pgsza32;
787c478bd9Sstevel@tonic-gate 	size_t pgsz;
797c478bd9Sstevel@tonic-gate 	int rc;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	if (nelem < 0) {
827c478bd9Sstevel@tonic-gate 		return (set_errno(EINVAL));
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 	if (nelem == 0 && buf != NULL) {
857c478bd9Sstevel@tonic-gate 		return (set_errno(EINVAL));
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	pgsza32 = kmem_alloc(sizeof (*pgsza32) * pagesizes, KM_SLEEP);
897c478bd9Sstevel@tonic-gate 	for (i = 0; i < pagesizes; i++) {
907c478bd9Sstevel@tonic-gate 		pgsz = page_get_user_pagesize(i);
917c478bd9Sstevel@tonic-gate 		pgsza32[i] = (size32_t)pgsz;
927c478bd9Sstevel@tonic-gate 		if (pgsz > (size32_t)-1) {
937c478bd9Sstevel@tonic-gate 			pagesizes = i - 1;
947c478bd9Sstevel@tonic-gate 			break;
957c478bd9Sstevel@tonic-gate 		}
967c478bd9Sstevel@tonic-gate 	}
977c478bd9Sstevel@tonic-gate 	ASSERT(pagesizes > 0);
987c478bd9Sstevel@tonic-gate 	ASSERT(page_get_user_pagesize(pagesizes - 1) <= (size32_t)-1);
997c478bd9Sstevel@tonic-gate 	if (nelem > pagesizes) {
1007c478bd9Sstevel@tonic-gate 		nelem = pagesizes;
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 	if (nelem == 0 && buf == NULL) {
1037c478bd9Sstevel@tonic-gate 		rc = pagesizes;
1047c478bd9Sstevel@tonic-gate 		goto done;
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 	if (buf == NULL) {
1077c478bd9Sstevel@tonic-gate 		rc = set_errno(EINVAL);
1087c478bd9Sstevel@tonic-gate 		goto done;
1097c478bd9Sstevel@tonic-gate 	}
1107c478bd9Sstevel@tonic-gate 	if (copyout(pgsza32, buf, nelem * sizeof (*pgsza32)) != 0) {
1117c478bd9Sstevel@tonic-gate 		rc = set_errno(EFAULT);
1127c478bd9Sstevel@tonic-gate 		goto done;
1137c478bd9Sstevel@tonic-gate 	}
1147c478bd9Sstevel@tonic-gate 	rc = nelem;
1157c478bd9Sstevel@tonic-gate done:
116*02bc52beSkchow 	kmem_free(pgsza32, sizeof (*pgsza32) *
117*02bc52beSkchow 	    page_num_user_pagesizes(legacy));
1187c478bd9Sstevel@tonic-gate 	return (rc);
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate #endif
121