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]
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>
31 #include <sys/errno.h>
34 * Return supported page sizes.
37 getpagesizes(int legacy
, size_t *buf
, int nelem
)
39 int i
, pagesizes
= page_num_user_pagesizes(legacy
);
43 return (set_errno(EINVAL
));
45 if (nelem
== 0 && buf
!= NULL
) {
46 return (set_errno(EINVAL
));
48 if (nelem
== 0 && buf
== NULL
) {
52 return (set_errno(EINVAL
));
54 if (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
);
69 #if defined(_SYSCALL32_IMPL)
72 * Some future platforms will support page sizes larger than
73 * a 32-bit address space.
76 getpagesizes32(int legacy
, size32_t
*buf
, int nelem
)
78 int i
, pagesizes
= page_num_user_pagesizes(legacy
);
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) {
99 ASSERT(pagesizes
> 0);
100 ASSERT(page_get_user_pagesize(pagesizes
- 1) <= (size32_t
)-1);
101 if (nelem
> pagesizes
) {
104 if (nelem
== 0 && buf
== NULL
) {
109 rc
= set_errno(EINVAL
);
112 if (copyout(pgsza32
, buf
, nelem
* sizeof (*pgsza32
)) != 0) {
113 rc
= set_errno(EFAULT
);
118 kmem_free(pgsza32
, sizeof (*pgsza32
) *
119 page_num_user_pagesizes(legacy
));