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
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.
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]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
40 pr_meminfo(struct ps_prochandle
*Pr
, const uint64_t *addrs
,
41 int addr_count
, const uint_t
*info
, int info_count
,
42 uint64_t *outdata
, uint_t
*validity
)
49 argdes_t
*adp
= &argd
[0];
56 uintptr_t inaddr
, infoaddr
, outaddr
, validityaddr
;
57 size_t outarraysize
, infoarraysize
;
58 size_t inarraysize
, validityarraysize
;
60 char *totalmap
= MAP_FAILED
;
62 inarraysize
= addr_count
* sizeof (uint64_t);
63 outarraysize
= sizeof (uint64_t) * addr_count
* info_count
;
64 infoarraysize
= info_count
* sizeof (uint_t
);
65 validityarraysize
= sizeof (uint_t
) * addr_count
;
68 totalsize
= inarraysize
+ outarraysize
+ infoarraysize
+
71 if ((totalmap
= pr_zmap(Pr
, 0, totalsize
, PROT_READ
| PROT_WRITE
,
72 MAP_PRIVATE
)) == MAP_FAILED
) {
73 dprintf("pr_meminfo: mmap failed\n");
77 inaddr
= (uintptr_t)totalmap
;
79 outaddr
= inaddr
+ inarraysize
;
81 infoaddr
= outaddr
+ outarraysize
;
83 validityaddr
= infoaddr
+ infoarraysize
;
85 if (Pwrite(Pr
, addrs
, inarraysize
, inaddr
) != inarraysize
) {
86 dprintf("pr_meminfo: Pwrite inaddr failed \n");
90 if (Pwrite(Pr
, info
, infoarraysize
, infoaddr
) !=
92 dprintf("pr_meminfo: Pwrite info failed \n");
97 model
= Pr
->status
.pr_dmodel
;
98 if (model
== PR_MODEL_ILP32
) {
99 m32
.mi_info_count
= info_count
;
100 m32
.mi_inaddr
= (caddr32_t
)inaddr
;
101 m32
.mi_outdata
= (caddr32_t
)outaddr
;
102 m32
.mi_info_req
= (caddr32_t
)infoaddr
;
103 m32
.mi_validity
= (caddr32_t
)validityaddr
;
107 m
.mi_info_count
= info_count
;
108 m
.mi_inaddr
= (uint64_t *)inaddr
;
109 m
.mi_outdata
= (uint64_t *)outaddr
;
110 m
.mi_info_req
= (uint_t
*)infoaddr
;
111 m
.mi_validity
= (uint_t
*)validityaddr
;
119 adp
->arg_value
= MISYS_MEMINFO
;
120 adp
->arg_object
= NULL
;
121 adp
->arg_type
= AT_BYVAL
;
122 adp
->arg_inout
= AI_INPUT
;
127 * length of input address vector
130 adp
->arg_value
= addr_count
;
131 adp
->arg_object
= NULL
;
132 adp
->arg_type
= AT_BYVAL
;
133 adp
->arg_inout
= AI_INPUT
;
138 * information wanted vector
143 if (model
== PR_MODEL_ILP32
) {
144 adp
->arg_object
= &m32
;
145 adp
->arg_size
= sizeof (struct meminfo32
);
149 adp
->arg_object
= &m
;
150 adp
->arg_size
= sizeof (struct meminfo
);
152 adp
->arg_type
= AT_BYREF
;
153 adp
->arg_inout
= AI_INPUT
;
156 error
= Psyscall(Pr
, &rval
, SYS_meminfosys
, 3, &argd
[0]);
159 errno
= (error
> 0) ? error
: ENOSYS
;
163 /* syscall was successful, copy out the data */
165 if ((Pread(Pr
, outdata
, outarraysize
, outaddr
)) != outarraysize
) {
166 dprintf("pr_meminfo: Pread of outarray failed\n");
170 if (Pread(Pr
, validity
, validityarraysize
, validityaddr
)
171 != validityarraysize
) {
172 dprintf("pr_meminfo: Pread of validity array failed\n");
176 retval
= rval
.sys_rval1
;
180 if (totalmap
!= MAP_FAILED
&&
181 pr_munmap(Pr
, totalmap
, totalsize
) == -1) {
182 dprintf("pr_meminfo: munmap failed\n");