1
2
3
4
5 package oshi.jna.platform.unix;
6
7 import java.nio.ByteBuffer;
8
9 import com.sun.jna.Native;
10 import com.sun.jna.NativeLong;
11 import com.sun.jna.Pointer;
12 import com.sun.jna.Structure;
13 import com.sun.jna.Structure.FieldOrder;
14
15 import oshi.util.FileUtil;
16
17
18
19
20
21 public interface SolarisLibc extends CLibrary {
22
23 SolarisLibc INSTANCE = Native.load("c", SolarisLibc.class);
24
25 int UTX_USERSIZE = 32;
26 int UTX_LINESIZE = 32;
27 int UTX_IDSIZE = 4;
28 int UTX_HOSTSIZE = 257;
29
30 int PRCLSZ = 8;
31 int PRFNSZ = 16;
32 int PRLNSZ = 32;
33 int PRARGSZ = 80;
34
35
36
37
38 @FieldOrder({ "ut_user", "ut_id", "ut_line", "ut_pid", "ut_type", "ut_exit", "ut_tv", "ut_session", "pad",
39 "ut_syslen", "ut_host" })
40 class SolarisUtmpx extends Structure {
41 public byte[] ut_user = new byte[UTX_USERSIZE];
42 public byte[] ut_id = new byte[UTX_IDSIZE];
43 public byte[] ut_line = new byte[UTX_LINESIZE];
44 public int ut_pid;
45 public short ut_type;
46 public Exit_status ut_exit;
47 public Timeval ut_tv;
48 public int ut_session;
49 public int[] pad = new int[5];
50 public short ut_syslen;
51 public byte[] ut_host = new byte[UTX_HOSTSIZE];
52 }
53
54
55
56
57 @FieldOrder({ "e_termination", "e_exit" })
58 class Exit_status extends Structure {
59 public short e_termination;
60 public short e_exit;
61 }
62
63
64
65
66 @FieldOrder({ "tv_sec", "tv_usec" })
67 class Timeval extends Structure {
68 public NativeLong tv_sec;
69 public NativeLong tv_usec;
70 }
71
72
73
74
75
76
77
78
79
80 SolarisUtmpx getutxent();
81
82
83
84
85 class SolarisPsInfo {
86 public int pr_flag;
87 public int pr_nlwp;
88 public int pr_pid;
89 public int pr_ppid;
90 public int pr_pgid;
91 public int pr_sid;
92 public int pr_uid;
93 public int pr_euid;
94 public int pr_gid;
95 public int pr_egid;
96 public Pointer pr_addr;
97 public size_t pr_size;
98 public size_t pr_rssize;
99 public size_t pr_rssizepriv;
100 public NativeLong pr_ttydev;
101
102
103
104 public short pr_pctcpu;
105 public short pr_pctmem;
106 public Timestruc pr_start;
107 public Timestruc pr_time;
108 public Timestruc pr_ctime;
109 public byte[] pr_fname = new byte[PRFNSZ];
110 public byte[] pr_psargs = new byte[PRARGSZ];
111 public int pr_wstat;
112 public int pr_argc;
113 public Pointer pr_argv;
114 public Pointer pr_envp;
115 public byte pr_dmodel;
116 public byte[] pr_pad2 = new byte[3];
117 public int pr_taskid;
118 public int pr_projid;
119 public int pr_nzomb;
120 public int pr_poolid;
121 public int pr_zoneid;
122 public int pr_contract;
123 public int pr_filler;
124 public SolarisLwpsInfo pr_lwp;
125
126 public SolarisPsInfo(ByteBuffer buff) {
127 this.pr_flag = FileUtil.readIntFromBuffer(buff);
128 this.pr_nlwp = FileUtil.readIntFromBuffer(buff);
129 this.pr_pid = FileUtil.readIntFromBuffer(buff);
130 this.pr_ppid = FileUtil.readIntFromBuffer(buff);
131 this.pr_pgid = FileUtil.readIntFromBuffer(buff);
132 this.pr_sid = FileUtil.readIntFromBuffer(buff);
133 this.pr_uid = FileUtil.readIntFromBuffer(buff);
134 this.pr_euid = FileUtil.readIntFromBuffer(buff);
135 this.pr_gid = FileUtil.readIntFromBuffer(buff);
136 this.pr_egid = FileUtil.readIntFromBuffer(buff);
137 this.pr_addr = FileUtil.readPointerFromBuffer(buff);
138 this.pr_size = FileUtil.readSizeTFromBuffer(buff);
139 this.pr_rssize = FileUtil.readSizeTFromBuffer(buff);
140 this.pr_rssizepriv = FileUtil.readSizeTFromBuffer(buff);
141 this.pr_ttydev = FileUtil.readNativeLongFromBuffer(buff);
142 this.pr_pctcpu = FileUtil.readShortFromBuffer(buff);
143 this.pr_pctmem = FileUtil.readShortFromBuffer(buff);
144
145 if (Native.LONG_SIZE > 4) {
146 FileUtil.readIntFromBuffer(buff);
147 }
148 this.pr_start = new Timestruc(buff);
149 this.pr_time = new Timestruc(buff);
150 this.pr_ctime = new Timestruc(buff);
151 FileUtil.readByteArrayFromBuffer(buff, this.pr_fname);
152 FileUtil.readByteArrayFromBuffer(buff, this.pr_psargs);
153 this.pr_wstat = FileUtil.readIntFromBuffer(buff);
154 this.pr_argc = FileUtil.readIntFromBuffer(buff);
155 this.pr_argv = FileUtil.readPointerFromBuffer(buff);
156 this.pr_envp = FileUtil.readPointerFromBuffer(buff);
157 this.pr_dmodel = FileUtil.readByteFromBuffer(buff);
158 FileUtil.readByteArrayFromBuffer(buff, this.pr_pad2);
159 this.pr_taskid = FileUtil.readIntFromBuffer(buff);
160 this.pr_projid = FileUtil.readIntFromBuffer(buff);
161 this.pr_nzomb = FileUtil.readIntFromBuffer(buff);
162 this.pr_poolid = FileUtil.readIntFromBuffer(buff);
163 this.pr_zoneid = FileUtil.readIntFromBuffer(buff);
164 this.pr_contract = FileUtil.readIntFromBuffer(buff);
165 this.pr_filler = FileUtil.readIntFromBuffer(buff);
166 this.pr_lwp = new SolarisLwpsInfo(buff);
167 }
168 }
169
170
171
172
173 class SolarisLwpsInfo {
174 public int pr_flag;
175 public int pr_lwpid;
176 public Pointer pr_addr;
177 public Pointer pr_wchan;
178 public byte pr_stype;
179 public byte pr_state;
180 public byte pr_sname;
181 public byte pr_nice;
182 public short pr_syscall;
183 public byte pr_oldpri;
184 public byte pr_cpu;
185 public int pr_pri;
186
187
188
189 public short pr_pctcpu;
190 public short pr_pad;
191 public Timestruc pr_start;
192 public Timestruc pr_time;
193 public byte[] pr_clname = new byte[PRCLSZ];
194 public byte[] pr_oldname = new byte[PRFNSZ];
195 public int pr_onpro;
196 public int pr_bindpro;
197 public int pr_bindpset;
198 public int pr_lgrp;
199 public long pr_last_onproc;
200 public byte[] pr_name = new byte[PRLNSZ];
201
202 public SolarisLwpsInfo(ByteBuffer buff) {
203 this.pr_flag = FileUtil.readIntFromBuffer(buff);
204 this.pr_lwpid = FileUtil.readIntFromBuffer(buff);
205 this.pr_addr = FileUtil.readPointerFromBuffer(buff);
206 this.pr_wchan = FileUtil.readPointerFromBuffer(buff);
207 this.pr_stype = FileUtil.readByteFromBuffer(buff);
208 this.pr_state = FileUtil.readByteFromBuffer(buff);
209 this.pr_sname = FileUtil.readByteFromBuffer(buff);
210 this.pr_nice = FileUtil.readByteFromBuffer(buff);
211 this.pr_syscall = FileUtil.readShortFromBuffer(buff);
212 this.pr_oldpri = FileUtil.readByteFromBuffer(buff);
213 this.pr_cpu = FileUtil.readByteFromBuffer(buff);
214 this.pr_pri = FileUtil.readIntFromBuffer(buff);
215 this.pr_pctcpu = FileUtil.readShortFromBuffer(buff);
216 this.pr_pad = FileUtil.readShortFromBuffer(buff);
217 this.pr_start = new Timestruc(buff);
218 this.pr_time = new Timestruc(buff);
219 FileUtil.readByteArrayFromBuffer(buff, this.pr_clname);
220 FileUtil.readByteArrayFromBuffer(buff, this.pr_oldname);
221 this.pr_onpro = FileUtil.readIntFromBuffer(buff);
222 this.pr_bindpro = FileUtil.readIntFromBuffer(buff);
223 this.pr_bindpset = FileUtil.readIntFromBuffer(buff);
224 this.pr_lgrp = FileUtil.readIntFromBuffer(buff);
225 this.pr_last_onproc = FileUtil.readLongFromBuffer(buff);
226 FileUtil.readByteArrayFromBuffer(buff, this.pr_name);
227 }
228 }
229
230
231
232
233 class SolarisPrUsage {
234 public int pr_lwpid;
235 public int pr_count;
236 public Timestruc pr_tstamp;
237 public Timestruc pr_create;
238 public Timestruc pr_term;
239 public Timestruc pr_rtime;
240 public Timestruc pr_utime;
241 public Timestruc pr_stime;
242 public Timestruc pr_ttime;
243 public Timestruc pr_tftime;
244 public Timestruc pr_dftime;
245 public Timestruc pr_kftime;
246 public Timestruc pr_ltime;
247 public Timestruc pr_slptime;
248 public Timestruc pr_wtime;
249 public Timestruc pr_stoptime;
250 public Timestruc[] filltime = new Timestruc[6];
251 public NativeLong pr_minf;
252 public NativeLong pr_majf;
253 public NativeLong pr_nswap;
254 public NativeLong pr_inblk;
255 public NativeLong pr_oublk;
256 public NativeLong pr_msnd;
257 public NativeLong pr_mrcv;
258 public NativeLong pr_sigs;
259 public NativeLong pr_vctx;
260 public NativeLong pr_ictx;
261 public NativeLong pr_sysc;
262 public NativeLong pr_ioch;
263 public NativeLong[] filler = new NativeLong[10];
264
265 public SolarisPrUsage(ByteBuffer buff) {
266 this.pr_lwpid = FileUtil.readIntFromBuffer(buff);
267 this.pr_count = FileUtil.readIntFromBuffer(buff);
268 this.pr_tstamp = new Timestruc(buff);
269 this.pr_create = new Timestruc(buff);
270 this.pr_term = new Timestruc(buff);
271 this.pr_rtime = new Timestruc(buff);
272 this.pr_utime = new Timestruc(buff);
273 this.pr_stime = new Timestruc(buff);
274 this.pr_ttime = new Timestruc(buff);
275 this.pr_tftime = new Timestruc(buff);
276 this.pr_dftime = new Timestruc(buff);
277 this.pr_kftime = new Timestruc(buff);
278 this.pr_ltime = new Timestruc(buff);
279 this.pr_slptime = new Timestruc(buff);
280 this.pr_wtime = new Timestruc(buff);
281 this.pr_stoptime = new Timestruc(buff);
282 for (int i = 0; i < filltime.length; i++) {
283 this.filltime[i] = new Timestruc(buff);
284 }
285 this.pr_minf = FileUtil.readNativeLongFromBuffer(buff);
286 this.pr_majf = FileUtil.readNativeLongFromBuffer(buff);
287 this.pr_nswap = FileUtil.readNativeLongFromBuffer(buff);
288 this.pr_inblk = FileUtil.readNativeLongFromBuffer(buff);
289 this.pr_oublk = FileUtil.readNativeLongFromBuffer(buff);
290 this.pr_msnd = FileUtil.readNativeLongFromBuffer(buff);
291 this.pr_mrcv = FileUtil.readNativeLongFromBuffer(buff);
292 this.pr_sigs = FileUtil.readNativeLongFromBuffer(buff);
293 this.pr_vctx = FileUtil.readNativeLongFromBuffer(buff);
294 this.pr_ictx = FileUtil.readNativeLongFromBuffer(buff);
295 this.pr_sysc = FileUtil.readNativeLongFromBuffer(buff);
296 this.pr_ioch = FileUtil.readNativeLongFromBuffer(buff);
297 for (int i = 0; i < filler.length; i++) {
298 this.filler[i] = FileUtil.readNativeLongFromBuffer(buff);
299 }
300 }
301 }
302
303
304
305
306 class Timestruc {
307 public NativeLong tv_sec;
308 public NativeLong tv_nsec;
309
310 public Timestruc(ByteBuffer buff) {
311 this.tv_sec = FileUtil.readNativeLongFromBuffer(buff);
312 this.tv_nsec = FileUtil.readNativeLongFromBuffer(buff);
313 }
314 }
315
316
317
318
319
320
321 int thr_self();
322 }