1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
28*7c478bd9Sstevel@tonic-gate #include <unistd.h>
29*7c478bd9Sstevel@tonic-gate #include <errno.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/mman.h>
32*7c478bd9Sstevel@tonic-gate #include "libproc.h"
33*7c478bd9Sstevel@tonic-gate #include "Pcontrol.h"
34*7c478bd9Sstevel@tonic-gate #include "Putil.h"
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate int
pr_meminfo(struct ps_prochandle * Pr,const uint64_t * addrs,int addr_count,const uint_t * info,int info_count,uint64_t * outdata,uint_t * validity)38*7c478bd9Sstevel@tonic-gate pr_meminfo(struct ps_prochandle *Pr, const uint64_t *addrs,
39*7c478bd9Sstevel@tonic-gate int addr_count, const uint_t *info, int info_count,
40*7c478bd9Sstevel@tonic-gate uint64_t *outdata, uint_t *validity)
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate int error;
45*7c478bd9Sstevel@tonic-gate sysret_t rval;
46*7c478bd9Sstevel@tonic-gate argdes_t argd[7];
47*7c478bd9Sstevel@tonic-gate argdes_t *adp = &argd[0];
48*7c478bd9Sstevel@tonic-gate struct meminfo m;
49*7c478bd9Sstevel@tonic-gate #ifdef _LP64
50*7c478bd9Sstevel@tonic-gate struct meminfo32 m32;
51*7c478bd9Sstevel@tonic-gate int model;
52*7c478bd9Sstevel@tonic-gate #endif
53*7c478bd9Sstevel@tonic-gate int retval = -1;
54*7c478bd9Sstevel@tonic-gate uintptr_t inaddr, infoaddr, outaddr, validityaddr;
55*7c478bd9Sstevel@tonic-gate size_t outarraysize, infoarraysize;
56*7c478bd9Sstevel@tonic-gate size_t inarraysize, validityarraysize;
57*7c478bd9Sstevel@tonic-gate size_t totalsize;
58*7c478bd9Sstevel@tonic-gate char *totalmap = MAP_FAILED;
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate inarraysize = addr_count * sizeof (uint64_t);
61*7c478bd9Sstevel@tonic-gate outarraysize = sizeof (uint64_t) * addr_count * info_count;
62*7c478bd9Sstevel@tonic-gate infoarraysize = info_count * sizeof (uint_t);
63*7c478bd9Sstevel@tonic-gate validityarraysize = sizeof (uint_t) * addr_count;
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate totalsize = inarraysize + outarraysize + infoarraysize +
67*7c478bd9Sstevel@tonic-gate validityarraysize;
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate if ((totalmap = pr_zmap(Pr, 0, totalsize, PROT_READ | PROT_WRITE,
70*7c478bd9Sstevel@tonic-gate MAP_PRIVATE)) == MAP_FAILED) {
71*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: mmap failed\n");
72*7c478bd9Sstevel@tonic-gate goto out;
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate inaddr = (uintptr_t)totalmap;
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate outaddr = inaddr + inarraysize;
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate infoaddr = outaddr + outarraysize;
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate validityaddr = infoaddr + infoarraysize;
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate if (Pwrite(Pr, addrs, inarraysize, inaddr) != inarraysize) {
84*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: Pwrite inaddr failed \n");
85*7c478bd9Sstevel@tonic-gate goto out;
86*7c478bd9Sstevel@tonic-gate }
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate if (Pwrite(Pr, info, infoarraysize, infoaddr) !=
89*7c478bd9Sstevel@tonic-gate infoarraysize) {
90*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: Pwrite info failed \n");
91*7c478bd9Sstevel@tonic-gate goto out;
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate #ifdef _LP64
95*7c478bd9Sstevel@tonic-gate model = Pr->status.pr_dmodel;
96*7c478bd9Sstevel@tonic-gate if (model == PR_MODEL_ILP32) {
97*7c478bd9Sstevel@tonic-gate m32.mi_info_count = info_count;
98*7c478bd9Sstevel@tonic-gate m32.mi_inaddr = (caddr32_t)inaddr;
99*7c478bd9Sstevel@tonic-gate m32.mi_outdata = (caddr32_t)outaddr;
100*7c478bd9Sstevel@tonic-gate m32.mi_info_req = (caddr32_t)infoaddr;
101*7c478bd9Sstevel@tonic-gate m32.mi_validity = (caddr32_t)validityaddr;
102*7c478bd9Sstevel@tonic-gate } else
103*7c478bd9Sstevel@tonic-gate #endif
104*7c478bd9Sstevel@tonic-gate {
105*7c478bd9Sstevel@tonic-gate m.mi_info_count = info_count;
106*7c478bd9Sstevel@tonic-gate m.mi_inaddr = (uint64_t *)inaddr;
107*7c478bd9Sstevel@tonic-gate m.mi_outdata = (uint64_t *)outaddr;
108*7c478bd9Sstevel@tonic-gate m.mi_info_req = (uint_t *)infoaddr;
109*7c478bd9Sstevel@tonic-gate m.mi_validity = (uint_t *)validityaddr;
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate * initial command
115*7c478bd9Sstevel@tonic-gate */
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate adp->arg_value = MISYS_MEMINFO;
118*7c478bd9Sstevel@tonic-gate adp->arg_object = NULL;
119*7c478bd9Sstevel@tonic-gate adp->arg_type = AT_BYVAL;
120*7c478bd9Sstevel@tonic-gate adp->arg_inout = AI_INPUT;
121*7c478bd9Sstevel@tonic-gate adp->arg_size = 0;
122*7c478bd9Sstevel@tonic-gate adp++;
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate /*
125*7c478bd9Sstevel@tonic-gate * length of input address vector
126*7c478bd9Sstevel@tonic-gate */
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate adp->arg_value = addr_count;
129*7c478bd9Sstevel@tonic-gate adp->arg_object = NULL;
130*7c478bd9Sstevel@tonic-gate adp->arg_type = AT_BYVAL;
131*7c478bd9Sstevel@tonic-gate adp->arg_inout = AI_INPUT;
132*7c478bd9Sstevel@tonic-gate adp->arg_size = 0;
133*7c478bd9Sstevel@tonic-gate adp++;
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate * information wanted vector
137*7c478bd9Sstevel@tonic-gate */
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate adp->arg_value = 0;
140*7c478bd9Sstevel@tonic-gate #ifdef _LP64
141*7c478bd9Sstevel@tonic-gate if (model == PR_MODEL_ILP32) {
142*7c478bd9Sstevel@tonic-gate adp->arg_object = &m32;
143*7c478bd9Sstevel@tonic-gate adp->arg_size = sizeof (struct meminfo32);
144*7c478bd9Sstevel@tonic-gate } else
145*7c478bd9Sstevel@tonic-gate #endif
146*7c478bd9Sstevel@tonic-gate {
147*7c478bd9Sstevel@tonic-gate adp->arg_object = &m;
148*7c478bd9Sstevel@tonic-gate adp->arg_size = sizeof (struct meminfo);
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate adp->arg_type = AT_BYREF;
151*7c478bd9Sstevel@tonic-gate adp->arg_inout = AI_INPUT;
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate error = Psyscall(Pr, &rval, SYS_meminfosys, 3, &argd[0]);
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate if (error) {
157*7c478bd9Sstevel@tonic-gate errno = (error > 0) ? error: ENOSYS;
158*7c478bd9Sstevel@tonic-gate goto out;
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate /* syscall was successful, copy out the data */
162*7c478bd9Sstevel@tonic-gate
163*7c478bd9Sstevel@tonic-gate if ((Pread(Pr, outdata, outarraysize, outaddr)) != outarraysize) {
164*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: Pread of outarray failed\n");
165*7c478bd9Sstevel@tonic-gate goto out;
166*7c478bd9Sstevel@tonic-gate }
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gate if (Pread(Pr, validity, validityarraysize, validityaddr)
169*7c478bd9Sstevel@tonic-gate != validityarraysize) {
170*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: Pread of validity array failed\n");
171*7c478bd9Sstevel@tonic-gate goto out;
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate retval = rval.sys_rval1;
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate out:
177*7c478bd9Sstevel@tonic-gate
178*7c478bd9Sstevel@tonic-gate if (totalmap != MAP_FAILED &&
179*7c478bd9Sstevel@tonic-gate pr_munmap(Pr, totalmap, totalsize) == -1) {
180*7c478bd9Sstevel@tonic-gate dprintf("pr_meminfo: munmap failed\n");
181*7c478bd9Sstevel@tonic-gate retval = -1;
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate return (retval);
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate }
187