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 #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/systm.h> 307c478bd9Sstevel@tonic-gate #include <vm/page.h> 317c478bd9Sstevel@tonic-gate #include <sys/errno.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* 347c478bd9Sstevel@tonic-gate * Return supported page sizes. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate int 37*02bc52beSkchow getpagesizes(int legacy, size_t *buf, int nelem) 387c478bd9Sstevel@tonic-gate { 39*02bc52beSkchow int i, pagesizes = page_num_user_pagesizes(legacy); 407c478bd9Sstevel@tonic-gate size_t *pgsza; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate if (nelem < 0) { 437c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 447c478bd9Sstevel@tonic-gate } 457c478bd9Sstevel@tonic-gate if (nelem == 0 && buf != NULL) { 467c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 477c478bd9Sstevel@tonic-gate } 487c478bd9Sstevel@tonic-gate if (nelem == 0 && buf == NULL) { 497c478bd9Sstevel@tonic-gate return (pagesizes); 507c478bd9Sstevel@tonic-gate } 517c478bd9Sstevel@tonic-gate if (buf == NULL) { 527c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 537c478bd9Sstevel@tonic-gate } 547c478bd9Sstevel@tonic-gate if (nelem > pagesizes) { 557c478bd9Sstevel@tonic-gate nelem = pagesizes; 567c478bd9Sstevel@tonic-gate } 577c478bd9Sstevel@tonic-gate pgsza = kmem_alloc(sizeof (*pgsza) * nelem, KM_SLEEP); 587c478bd9Sstevel@tonic-gate for (i = 0; i < nelem; i++) { 597c478bd9Sstevel@tonic-gate pgsza[i] = page_get_user_pagesize(i); 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate if (copyout(pgsza, buf, nelem * sizeof (*pgsza)) != 0) { 627c478bd9Sstevel@tonic-gate kmem_free(pgsza, sizeof (*pgsza) * nelem); 637c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate kmem_free(pgsza, sizeof (*pgsza) * nelem); 667c478bd9Sstevel@tonic-gate return (nelem); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL) 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Some future platforms will support page sizes larger than 737c478bd9Sstevel@tonic-gate * a 32-bit address space. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate int 76*02bc52beSkchow getpagesizes32(int legacy, size32_t *buf, int nelem) 777c478bd9Sstevel@tonic-gate { 78*02bc52beSkchow int i, pagesizes = page_num_user_pagesizes(legacy); 797c478bd9Sstevel@tonic-gate size32_t *pgsza32; 807c478bd9Sstevel@tonic-gate size_t pgsz; 817c478bd9Sstevel@tonic-gate int rc; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate if (nelem < 0) { 847c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate if (nelem == 0 && buf != NULL) { 877c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate pgsza32 = kmem_alloc(sizeof (*pgsza32) * pagesizes, KM_SLEEP); 917c478bd9Sstevel@tonic-gate for (i = 0; i < pagesizes; i++) { 927c478bd9Sstevel@tonic-gate pgsz = page_get_user_pagesize(i); 937c478bd9Sstevel@tonic-gate pgsza32[i] = (size32_t)pgsz; 947c478bd9Sstevel@tonic-gate if (pgsz > (size32_t)-1) { 957c478bd9Sstevel@tonic-gate pagesizes = i - 1; 967c478bd9Sstevel@tonic-gate break; 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate ASSERT(pagesizes > 0); 1007c478bd9Sstevel@tonic-gate ASSERT(page_get_user_pagesize(pagesizes - 1) <= (size32_t)-1); 1017c478bd9Sstevel@tonic-gate if (nelem > pagesizes) { 1027c478bd9Sstevel@tonic-gate nelem = pagesizes; 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate if (nelem == 0 && buf == NULL) { 1057c478bd9Sstevel@tonic-gate rc = pagesizes; 1067c478bd9Sstevel@tonic-gate goto done; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate if (buf == NULL) { 1097c478bd9Sstevel@tonic-gate rc = set_errno(EINVAL); 1107c478bd9Sstevel@tonic-gate goto done; 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate if (copyout(pgsza32, buf, nelem * sizeof (*pgsza32)) != 0) { 1137c478bd9Sstevel@tonic-gate rc = set_errno(EFAULT); 1147c478bd9Sstevel@tonic-gate goto done; 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate rc = nelem; 1177c478bd9Sstevel@tonic-gate done: 118*02bc52beSkchow kmem_free(pgsza32, sizeof (*pgsza32) * 119*02bc52beSkchow page_num_user_pagesizes(legacy)); 1207c478bd9Sstevel@tonic-gate return (rc); 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate #endif 123