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