8828 udapl: value computed is not used
[unleashed.git] / usr / src / lib / libproc / common / pr_meminfo.c
blob475c7282674625631b843f25ada4e99fcd76142b
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include "libproc.h"
35 #include "Pcontrol.h"
36 #include "Putil.h"
39 int
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)
46 int error;
47 sysret_t rval;
48 argdes_t argd[7];
49 argdes_t *adp = &argd[0];
50 struct meminfo m;
51 #ifdef _LP64
52 struct meminfo32 m32;
53 int model;
54 #endif
55 int retval = -1;
56 uintptr_t inaddr, infoaddr, outaddr, validityaddr;
57 size_t outarraysize, infoarraysize;
58 size_t inarraysize, validityarraysize;
59 size_t totalsize;
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 +
69 validityarraysize;
71 if ((totalmap = pr_zmap(Pr, 0, totalsize, PROT_READ | PROT_WRITE,
72 MAP_PRIVATE)) == MAP_FAILED) {
73 dprintf("pr_meminfo: mmap failed\n");
74 goto out;
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");
87 goto out;
90 if (Pwrite(Pr, info, infoarraysize, infoaddr) !=
91 infoarraysize) {
92 dprintf("pr_meminfo: Pwrite info failed \n");
93 goto out;
96 #ifdef _LP64
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;
104 } else
105 #endif
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;
116 * initial command
119 adp->arg_value = MISYS_MEMINFO;
120 adp->arg_object = NULL;
121 adp->arg_type = AT_BYVAL;
122 adp->arg_inout = AI_INPUT;
123 adp->arg_size = 0;
124 adp++;
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;
134 adp->arg_size = 0;
135 adp++;
138 * information wanted vector
141 adp->arg_value = 0;
142 #ifdef _LP64
143 if (model == PR_MODEL_ILP32) {
144 adp->arg_object = &m32;
145 adp->arg_size = sizeof (struct meminfo32);
146 } else
147 #endif
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]);
158 if (error) {
159 errno = (error > 0) ? error: ENOSYS;
160 goto out;
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");
167 goto out;
170 if (Pread(Pr, validity, validityarraysize, validityaddr)
171 != validityarraysize) {
172 dprintf("pr_meminfo: Pread of validity array failed\n");
173 goto out;
176 retval = rval.sys_rval1;
178 out:
180 if (totalmap != MAP_FAILED &&
181 pr_munmap(Pr, totalmap, totalsize) == -1) {
182 dprintf("pr_meminfo: munmap failed\n");
183 retval = -1;
186 return (retval);