Bug Summary

File:src/lib/libkvm/kvm_proc2.c
Warning:line 296, column 3
Assigned value is garbage or undefined

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name kvm_proc2.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/libkvm/obj -resource-dir /usr/local/lib/clang/13.0.0 -D _LIBKVM -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libkvm/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/lib/libkvm/kvm_proc2.c
1/* $OpenBSD: kvm_proc2.c,v 1.35 2021/10/06 00:42:46 deraadt Exp $ */
2/* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */
3/*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31/*-
32 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
33 * Copyright (c) 1989, 1992, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * This code is derived from software developed by the Computer Systems
37 * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
38 * BG 91-66 and contributed to Berkeley.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
63 */
64
65/*
66 * Proc traversal interface for kvm. ps and w are (probably) the exclusive
67 * users of this code, so we've factored it out into a separate module.
68 * Thus, we keep this grunge out of the other kvm applications (i.e.,
69 * most other applications are interested only in open/close/read/nlist).
70 */
71
72#define __need_process
73#include <sys/param.h> /* MAXCOMLEN NODEV */
74#include <sys/types.h>
75#include <sys/signal.h>
76#include <sys/proc.h>
77#include <sys/exec.h>
78#include <sys/stat.h>
79#include <sys/ucred.h>
80#include <sys/ioctl.h>
81#include <sys/tty.h>
82#include <sys/resource.h>
83#include <sys/resourcevar.h>
84#include <sys/signalvar.h>
85#include <sys/pledge.h>
86#include <sys/wait.h>
87#include <stddef.h>
88#include <stdlib.h>
89#include <string.h>
90#include <unistd.h>
91#include <nlist.h>
92#include <kvm.h>
93
94#include <uvm/uvm_extern.h>
95#include <uvm/uvm_amap.h>
96#include <machine/vmparam.h>
97#include <machine/pmap.h>
98
99#include <sys/sysctl.h>
100
101#include <limits.h>
102#include <errno(*__errno()).h>
103#include <db.h>
104#include <paths.h>
105
106#include "kvm_private.h"
107
108/*
109 * Read proc's from memory file into buffer bp, which has space to hold
110 * at most maxcnt procs.
111 */
112static int
113kvm_proclist(kvm_t *kd, int op, int arg, struct process *pr,
114 char *bp, int maxcnt, size_t esize)
115{
116 struct kinfo_proc kp;
117 struct session sess;
118 struct ucred ucred;
119 struct proc proc, *p;
120 struct process process, process2;
121 struct pgrp pgrp;
122 struct tty tty;
123 struct timeval elapsed, monostart, monostop, realstart, realstop;
124 struct nlist nl[3];
125 struct sigacts sa, *sap;
126 struct vmspace vm, *vmp;
127 struct plimit limits, *limp;
128 pid_t parent_pid, leader_pid;
129 int cnt = 0;
130 int dothreads = 0;
131 int i;
132
133 dothreads = op & KERN_PROC_SHOW_THREADS0x40000000;
134 op &= ~KERN_PROC_SHOW_THREADS0x40000000;
135
136 /* Anchor a time to compare process starting times from. */
137 nl[0].n_name = "_time_second";
138 nl[1].n_name = "_time_uptime";
139 nl[2].n_name = NULL((void*)0);
140 if (kvm_nlist(kd, nl) != 0) {
1
Assuming the condition is false
2
Taking false branch
141 for (i = 0; nl[i].n_type != 0; ++i)
142 continue;
143 _kvm_err(kd, kd->program, "%s: no such symbol", nl[i].n_name);
144 return (-1);
145 }
146 timerclear(&realstop)(&realstop)->tv_sec = (&realstop)->tv_usec = 0;
147 timerclear(&monostop)(&monostop)->tv_sec = (&monostop)->tv_usec = 0;
148 if (KREAD(kd, nl[0].n_value, &realstop.tv_sec)(kvm_read(kd, nl[0].n_value, (void *)(&realstop.tv_sec), sizeof
(*&realstop.tv_sec)) != sizeof(*&realstop.tv_sec))
) {
3
Assuming the condition is false
4
Taking false branch
149 _kvm_err(kd, kd->program, "cannot read time_second");
150 return (-1);
151 }
152 if (KREAD(kd, nl[1].n_value, &monostop.tv_sec)(kvm_read(kd, nl[1].n_value, (void *)(&monostop.tv_sec), sizeof
(*&monostop.tv_sec)) != sizeof(*&monostop.tv_sec))
) {
5
Assuming the condition is false
6
Taking false branch
153 _kvm_err(kd, kd->program, "cannot read time_uptime");
154 return (-1);
155 }
156
157 /*
158 * Modelled on sysctl_doproc() in sys/kern/kern_sysctl.c
159 */
160 for (; cnt < maxcnt && pr != NULL((void*)0); pr = LIST_NEXT(&process, ps_list)((&process)->ps_list.le_next)) {
7
Assuming 'cnt' is < 'maxcnt'
8
Assuming 'pr' is not equal to NULL
9
Loop condition is true. Entering loop body
161 if (KREAD(kd, (u_long)pr, &process)(kvm_read(kd, (u_long)pr, (void *)(&process), sizeof(*&
process)) != sizeof(*&process))
) {
10
Assuming the condition is false
11
Taking false branch
162 _kvm_err(kd, kd->program, "can't read process at %lx",
163 (u_long)pr);
164 return (-1);
165 }
166 if (process.ps_pgrp == NULL((void*)0))
12
Assuming field 'ps_pgrp' is not equal to NULL
13
Taking false branch
167 continue;
168 if (process.ps_flags & PS_EMBRYO0x00020000)
14
Assuming the condition is false
15
Taking false branch
169 continue;
170 if (KREAD(kd, (u_long)process.ps_ucred, &ucred)(kvm_read(kd, (u_long)process.ps_ucred, (void *)(&ucred),
sizeof(*&ucred)) != sizeof(*&ucred))
) {
16
Assuming the condition is false
17
Taking false branch
171 _kvm_err(kd, kd->program, "can't read ucred at %lx",
172 (u_long)process.ps_ucred);
173 return (-1);
174 }
175 if (KREAD(kd, (u_long)process.ps_pgrp, &pgrp)(kvm_read(kd, (u_long)process.ps_pgrp, (void *)(&pgrp), sizeof
(*&pgrp)) != sizeof(*&pgrp))
) {
18
Assuming the condition is false
19
Taking false branch
176 _kvm_err(kd, kd->program, "can't read pgrp at %lx",
177 (u_long)process.ps_pgrp);
178 return (-1);
179 }
180 if (KREAD(kd, (u_long)pgrp.pg_session, &sess)(kvm_read(kd, (u_long)pgrp.pg_session, (void *)(&sess), sizeof
(*&sess)) != sizeof(*&sess))
) {
20
Assuming the condition is false
21
Taking false branch
181 _kvm_err(kd, kd->program, "can't read session at %lx",
182 (u_long)pgrp.pg_session);
183 return (-1);
184 }
185 if ((process.ps_flags & PS_CONTROLT0x00000001) && sess.s_ttyp != NULL((void*)0) &&
22
Assuming the condition is false
186 KREAD(kd, (u_long)sess.s_ttyp, &tty)(kvm_read(kd, (u_long)sess.s_ttyp, (void *)(&tty), sizeof
(*&tty)) != sizeof(*&tty))
) {
187 _kvm_err(kd, kd->program, "can't read tty at %lx",
188 (u_long)sess.s_ttyp);
189 return (-1);
190 }
191 if (process.ps_pptr) {
23
Assuming field 'ps_pptr' is null
24
Taking false branch
192 if (KREAD(kd, (u_long)process.ps_pptr, &process2)(kvm_read(kd, (u_long)process.ps_pptr, (void *)(&process2
), sizeof(*&process2)) != sizeof(*&process2))
) {
193 _kvm_err(kd, kd->program,
194 "can't read process at %lx",
195 (u_long)process.ps_pptr);
196 return (-1);
197 }
198 parent_pid = process2.ps_pid;
199 }
200 else
201 parent_pid = 0;
202 if (sess.s_leader) {
25
Assuming field 's_leader' is null
26
Taking false branch
203 if (KREAD(kd, (u_long)sess.s_leader, &process2)(kvm_read(kd, (u_long)sess.s_leader, (void *)(&process2),
sizeof(*&process2)) != sizeof(*&process2))
) {
204 _kvm_err(kd, kd->program,
205 "can't read proc at %lx",
206 (u_long)sess.s_leader);
207 return (-1);
208 }
209 leader_pid = process2.ps_pid;
210 }
211 else
212 leader_pid = 0;
213 if (process.ps_sigacts) {
27
Assuming field 'ps_sigacts' is null
28
Taking false branch
214 if (KREAD(kd, (u_long)process.ps_sigacts, &sa)(kvm_read(kd, (u_long)process.ps_sigacts, (void *)(&sa), sizeof
(*&sa)) != sizeof(*&sa))
) {
215 _kvm_err(kd, kd->program,
216 "can't read sigacts at %lx",
217 (u_long)process.ps_sigacts);
218 return (-1);
219 }
220 sap = &sa;
221 }
222 else
223 sap = NULL((void*)0);
224
225 switch (op) {
29
Control jumps to 'case 7:' at line 264
226 case KERN_PROC_PID1:
227 if (process.ps_pid != (pid_t)arg)
228 continue;
229 break;
230
231 case KERN_PROC_PGRP2:
232 if (pgrp.pg_id != (pid_t)arg)
233 continue;
234 break;
235
236 case KERN_PROC_SESSION3:
237 if (sess.s_leader == NULL((void*)0) ||
238 leader_pid != (pid_t)arg)
239 continue;
240 break;
241
242 case KERN_PROC_TTY4:
243 if ((process.ps_flags & PS_CONTROLT0x00000001) == 0 ||
244 sess.s_ttyp == NULL((void*)0) ||
245 tty.t_dev != (dev_t)arg)
246 continue;
247 break;
248
249 case KERN_PROC_UID5:
250 if (ucred.cr_uid != (uid_t)arg)
251 continue;
252 break;
253
254 case KERN_PROC_RUID6:
255 if (ucred.cr_ruid != (uid_t)arg)
256 continue;
257 break;
258
259 case KERN_PROC_ALL0:
260 if (process.ps_flags & PS_SYSTEM0x00010000)
261 continue;
262 break;
263
264 case KERN_PROC_KTHREAD7:
265 /* no filtering */
266 break;
30
Execution continues on line 278
267
268 default:
269 _kvm_err(kd, kd->program, "invalid filter");
270 return (-1);
271 }
272
273 /*
274 * We're going to add another proc to the set. If this
275 * will overflow the buffer, assume the reason is because
276 * nthreads (or the proc list) is corrupt and declare an error.
277 */
278 if (cnt
30.1
'cnt' is < 'maxcnt'
>= maxcnt) {
31
Taking false branch
279 _kvm_err(kd, kd->program, "nthreads corrupt");
280 return (-1);
281 }
282
283 /* set up stuff that might not always be there */
284 limp = &limits;
285 if (!process.ps_limit ||
32
Assuming field 'ps_limit' is null
286 KREAD(kd, (u_long)process.ps_limit, &limits)(kvm_read(kd, (u_long)process.ps_limit, (void *)(&limits)
, sizeof(*&limits)) != sizeof(*&limits))
)
287 limp = NULL((void*)0);
288
289 vmp = NULL((void*)0);
290
291 if ((process.ps_flags & PS_ZOMBIE0x00040000) == 0 &&
33
Assuming the condition is false
292 !KREAD(kd, (u_long)process.ps_vmspace, &vm)(kvm_read(kd, (u_long)process.ps_vmspace, (void *)(&vm), sizeof
(*&vm)) != sizeof(*&vm))
)
293 vmp = &vm;
294
295#define do_copy_str(_d, _s, _l) kvm_read(kd, (u_long)(_s), (_d), (_l)-1)
296 FILL_KPROC(&kp, do_copy_str, &proc, &process,do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(process.ps_mainproc));
(&kp)->p_fd = ((u_int64_t)(u_long)((&process)->
ps_fd)); (&kp)->p_limit = ((u_int64_t)(u_long)((&process
)->ps_limit)); (&kp)->p_vmspace = ((u_int64_t)(u_long
)((&process)->ps_vmspace)); (&kp)->p_sigacts = (
(u_int64_t)(u_long)((&process)->ps_sigacts)); (&kp
)->p_sess = ((u_int64_t)(u_long)((&pgrp)->pg_session
)); (&kp)->p_ru = ((u_int64_t)(u_long)((&process)->
ps_ru)); } (&kp)->p_stats = 0; (&kp)->p_exitsig
= 0; (&kp)->p_flag = (&proc)->p_flag; (&kp
)->p_pid = (&process)->ps_pid; (&kp)->p_psflags
= (&process)->ps_flags; (&kp)->p__pgid = (&
pgrp)->pg_id; (&kp)->p_uid = (&ucred)->cr_uid
; (&kp)->p_ruid = (&ucred)->cr_ruid; (&kp)->
p_gid = (&ucred)->cr_gid; (&kp)->p_rgid = (&
ucred)->cr_rgid; (&kp)->p_svuid = (&ucred)->
cr_svuid; (&kp)->p_svgid = (&ucred)->cr_svgid; memcpy
((&kp)->p_groups, (&ucred)->cr_groups, (((sizeof
((&kp)->p_groups))<(sizeof((&ucred)->cr_groups
)))?(sizeof((&kp)->p_groups)):(sizeof((&ucred)->
cr_groups)))); (&kp)->p_ngroups = (&ucred)->cr_ngroups
; (&kp)->p_jobc = (&pgrp)->pg_jobc; (&kp)->
p_estcpu = (&proc)->p_estcpu; if (0) { (&kp)->p_rtime_sec
= (&proc)->p_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&proc)->p_tu.tu_runtime.tv_nsec/1000; (&kp)->
p_tid = (&proc)->p_tid + 100000; (&kp)->p_uticks
= (&proc)->p_tu.tu_uticks; (&kp)->p_sticks = (
&proc)->p_tu.tu_sticks; (&kp)->p_iticks = (&
proc)->p_tu.tu_iticks; } else { (&kp)->p_rtime_sec =
(&process)->ps_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&process)->ps_tu.tu_runtime.tv_nsec/1000; (&kp
)->p_tid = -1; (&kp)->p_uticks = (&process)->
ps_tu.tu_uticks; (&kp)->p_sticks = (&process)->
ps_tu.tu_sticks; (&kp)->p_iticks = (&process)->
ps_tu.tu_iticks; } (&kp)->p_cpticks = (&proc)->
p_cpticks; if (1) (&kp)->p_tracep = ((u_int64_t)(u_long
)((&process)->ps_tracevp)); (&kp)->p_traceflag =
(&process)->ps_traceflag; (&kp)->p_siglist = (
&proc)->p_siglist | (&process)->ps_siglist; (&
kp)->p_sigmask = (&proc)->p_sigmask; (&kp)->
p_sigignore = (sap) ? (sap)->ps_sigignore : 0; (&kp)->
p_sigcatch = (sap) ? (sap)->ps_sigcatch : 0; (&kp)->
p_stat = (&proc)->p_stat; (&kp)->p_nice = (&
process)->ps_nice; (&kp)->p_xstat = (((&process
)->ps_xexit) << 8 | ((&process)->ps_xsig)); (
&kp)->p_acflag = (&process)->ps_acflag; (&kp
)->p_pledge = (&process)->ps_pledge; strlcpy((&
kp)->p_emul, "native", sizeof((&kp)->p_emul)); strlcpy
((&kp)->p_comm, (&process)->ps_comm, sizeof((&
kp)->p_comm)); strlcpy((&kp)->p_login, (&sess)->
s_login, (((sizeof((&kp)->p_login))<(sizeof((&sess
)->s_login)))?(sizeof((&kp)->p_login)):(sizeof((&
sess)->s_login)))); if ((&sess)->s_ttyvp) (&kp)
->p_eflag |= 0x01; if ((&process)->ps_uvpaths) (&
kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone || (
((&process)->ps_flags & 0x00100000) && ((&
process)->ps_pledge & 0x0000001000000000ULL) == 0)) (&
kp)->p_eflag |= 0x08; if (((&process)->ps_flags &
(0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void*)0)) {
(&kp)->p_vm_rssize = (vmp)->vm_rssize; (&kp)->
p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize = (
vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
34
Taking true branch
35
Assigned value is garbage or undefined
297 &ucred, &pgrp, process.ps_mainproc, pr, &sess,do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(process.ps_mainproc));
(&kp)->p_fd = ((u_int64_t)(u_long)((&process)->
ps_fd)); (&kp)->p_limit = ((u_int64_t)(u_long)((&process
)->ps_limit)); (&kp)->p_vmspace = ((u_int64_t)(u_long
)((&process)->ps_vmspace)); (&kp)->p_sigacts = (
(u_int64_t)(u_long)((&process)->ps_sigacts)); (&kp
)->p_sess = ((u_int64_t)(u_long)((&pgrp)->pg_session
)); (&kp)->p_ru = ((u_int64_t)(u_long)((&process)->
ps_ru)); } (&kp)->p_stats = 0; (&kp)->p_exitsig
= 0; (&kp)->p_flag = (&proc)->p_flag; (&kp
)->p_pid = (&process)->ps_pid; (&kp)->p_psflags
= (&process)->ps_flags; (&kp)->p__pgid = (&
pgrp)->pg_id; (&kp)->p_uid = (&ucred)->cr_uid
; (&kp)->p_ruid = (&ucred)->cr_ruid; (&kp)->
p_gid = (&ucred)->cr_gid; (&kp)->p_rgid = (&
ucred)->cr_rgid; (&kp)->p_svuid = (&ucred)->
cr_svuid; (&kp)->p_svgid = (&ucred)->cr_svgid; memcpy
((&kp)->p_groups, (&ucred)->cr_groups, (((sizeof
((&kp)->p_groups))<(sizeof((&ucred)->cr_groups
)))?(sizeof((&kp)->p_groups)):(sizeof((&ucred)->
cr_groups)))); (&kp)->p_ngroups = (&ucred)->cr_ngroups
; (&kp)->p_jobc = (&pgrp)->pg_jobc; (&kp)->
p_estcpu = (&proc)->p_estcpu; if (0) { (&kp)->p_rtime_sec
= (&proc)->p_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&proc)->p_tu.tu_runtime.tv_nsec/1000; (&kp)->
p_tid = (&proc)->p_tid + 100000; (&kp)->p_uticks
= (&proc)->p_tu.tu_uticks; (&kp)->p_sticks = (
&proc)->p_tu.tu_sticks; (&kp)->p_iticks = (&
proc)->p_tu.tu_iticks; } else { (&kp)->p_rtime_sec =
(&process)->ps_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&process)->ps_tu.tu_runtime.tv_nsec/1000; (&kp
)->p_tid = -1; (&kp)->p_uticks = (&process)->
ps_tu.tu_uticks; (&kp)->p_sticks = (&process)->
ps_tu.tu_sticks; (&kp)->p_iticks = (&process)->
ps_tu.tu_iticks; } (&kp)->p_cpticks = (&proc)->
p_cpticks; if (1) (&kp)->p_tracep = ((u_int64_t)(u_long
)((&process)->ps_tracevp)); (&kp)->p_traceflag =
(&process)->ps_traceflag; (&kp)->p_siglist = (
&proc)->p_siglist | (&process)->ps_siglist; (&
kp)->p_sigmask = (&proc)->p_sigmask; (&kp)->
p_sigignore = (sap) ? (sap)->ps_sigignore : 0; (&kp)->
p_sigcatch = (sap) ? (sap)->ps_sigcatch : 0; (&kp)->
p_stat = (&proc)->p_stat; (&kp)->p_nice = (&
process)->ps_nice; (&kp)->p_xstat = (((&process
)->ps_xexit) << 8 | ((&process)->ps_xsig)); (
&kp)->p_acflag = (&process)->ps_acflag; (&kp
)->p_pledge = (&process)->ps_pledge; strlcpy((&
kp)->p_emul, "native", sizeof((&kp)->p_emul)); strlcpy
((&kp)->p_comm, (&process)->ps_comm, sizeof((&
kp)->p_comm)); strlcpy((&kp)->p_login, (&sess)->
s_login, (((sizeof((&kp)->p_login))<(sizeof((&sess
)->s_login)))?(sizeof((&kp)->p_login)):(sizeof((&
sess)->s_login)))); if ((&sess)->s_ttyvp) (&kp)
->p_eflag |= 0x01; if ((&process)->ps_uvpaths) (&
kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone || (
((&process)->ps_flags & 0x00100000) && ((&
process)->ps_pledge & 0x0000001000000000ULL) == 0)) (&
kp)->p_eflag |= 0x08; if (((&process)->ps_flags &
(0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void*)0)) {
(&kp)->p_vm_rssize = (vmp)->vm_rssize; (&kp)->
p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize = (
vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
298 vmp, limp, sap, 0, 1)do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(process.ps_mainproc));
(&kp)->p_fd = ((u_int64_t)(u_long)((&process)->
ps_fd)); (&kp)->p_limit = ((u_int64_t)(u_long)((&process
)->ps_limit)); (&kp)->p_vmspace = ((u_int64_t)(u_long
)((&process)->ps_vmspace)); (&kp)->p_sigacts = (
(u_int64_t)(u_long)((&process)->ps_sigacts)); (&kp
)->p_sess = ((u_int64_t)(u_long)((&pgrp)->pg_session
)); (&kp)->p_ru = ((u_int64_t)(u_long)((&process)->
ps_ru)); } (&kp)->p_stats = 0; (&kp)->p_exitsig
= 0; (&kp)->p_flag = (&proc)->p_flag; (&kp
)->p_pid = (&process)->ps_pid; (&kp)->p_psflags
= (&process)->ps_flags; (&kp)->p__pgid = (&
pgrp)->pg_id; (&kp)->p_uid = (&ucred)->cr_uid
; (&kp)->p_ruid = (&ucred)->cr_ruid; (&kp)->
p_gid = (&ucred)->cr_gid; (&kp)->p_rgid = (&
ucred)->cr_rgid; (&kp)->p_svuid = (&ucred)->
cr_svuid; (&kp)->p_svgid = (&ucred)->cr_svgid; memcpy
((&kp)->p_groups, (&ucred)->cr_groups, (((sizeof
((&kp)->p_groups))<(sizeof((&ucred)->cr_groups
)))?(sizeof((&kp)->p_groups)):(sizeof((&ucred)->
cr_groups)))); (&kp)->p_ngroups = (&ucred)->cr_ngroups
; (&kp)->p_jobc = (&pgrp)->pg_jobc; (&kp)->
p_estcpu = (&proc)->p_estcpu; if (0) { (&kp)->p_rtime_sec
= (&proc)->p_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&proc)->p_tu.tu_runtime.tv_nsec/1000; (&kp)->
p_tid = (&proc)->p_tid + 100000; (&kp)->p_uticks
= (&proc)->p_tu.tu_uticks; (&kp)->p_sticks = (
&proc)->p_tu.tu_sticks; (&kp)->p_iticks = (&
proc)->p_tu.tu_iticks; } else { (&kp)->p_rtime_sec =
(&process)->ps_tu.tu_runtime.tv_sec; (&kp)->p_rtime_usec
= (&process)->ps_tu.tu_runtime.tv_nsec/1000; (&kp
)->p_tid = -1; (&kp)->p_uticks = (&process)->
ps_tu.tu_uticks; (&kp)->p_sticks = (&process)->
ps_tu.tu_sticks; (&kp)->p_iticks = (&process)->
ps_tu.tu_iticks; } (&kp)->p_cpticks = (&proc)->
p_cpticks; if (1) (&kp)->p_tracep = ((u_int64_t)(u_long
)((&process)->ps_tracevp)); (&kp)->p_traceflag =
(&process)->ps_traceflag; (&kp)->p_siglist = (
&proc)->p_siglist | (&process)->ps_siglist; (&
kp)->p_sigmask = (&proc)->p_sigmask; (&kp)->
p_sigignore = (sap) ? (sap)->ps_sigignore : 0; (&kp)->
p_sigcatch = (sap) ? (sap)->ps_sigcatch : 0; (&kp)->
p_stat = (&proc)->p_stat; (&kp)->p_nice = (&
process)->ps_nice; (&kp)->p_xstat = (((&process
)->ps_xexit) << 8 | ((&process)->ps_xsig)); (
&kp)->p_acflag = (&process)->ps_acflag; (&kp
)->p_pledge = (&process)->ps_pledge; strlcpy((&
kp)->p_emul, "native", sizeof((&kp)->p_emul)); strlcpy
((&kp)->p_comm, (&process)->ps_comm, sizeof((&
kp)->p_comm)); strlcpy((&kp)->p_login, (&sess)->
s_login, (((sizeof((&kp)->p_login))<(sizeof((&sess
)->s_login)))?(sizeof((&kp)->p_login)):(sizeof((&
sess)->s_login)))); if ((&sess)->s_ttyvp) (&kp)
->p_eflag |= 0x01; if ((&process)->ps_uvpaths) (&
kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone || (
((&process)->ps_flags & 0x00100000) && ((&
process)->ps_pledge & 0x0000001000000000ULL) == 0)) (&
kp)->p_eflag |= 0x08; if (((&process)->ps_flags &
(0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void*)0)) {
(&kp)->p_vm_rssize = (vmp)->vm_rssize; (&kp)->
p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize = (
vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
;
299
300 /* stuff that's too painful to generalize */
301 kp.p_ppid = parent_pid;
302 kp.p_sid = leader_pid;
303 if ((process.ps_flags & PS_CONTROLT0x00000001) && sess.s_ttyp != NULL((void*)0)) {
304 kp.p_tdev = tty.t_dev;
305 if (tty.t_pgrp != NULL((void*)0) &&
306 tty.t_pgrp != process.ps_pgrp &&
307 KREAD(kd, (u_long)tty.t_pgrp, &pgrp)(kvm_read(kd, (u_long)tty.t_pgrp, (void *)(&pgrp), sizeof
(*&pgrp)) != sizeof(*&pgrp))
) {
308 _kvm_err(kd, kd->program,
309 "can't read tpgrp at %lx",
310 (u_long)tty.t_pgrp);
311 return (-1);
312 }
313 kp.p_tpgid = tty.t_pgrp ? pgrp.pg_id : -1;
314 kp.p_tsess = PTRTOINT64(tty.t_session)((u_int64_t)(u_long)(tty.t_session));
315 } else {
316 kp.p_tpgid = -1;
317 kp.p_tdev = NODEV(dev_t)(-1);
318 }
319
320 /* Convert the starting uptime to a starting UTC time. */
321 if ((process.ps_flags & PS_ZOMBIE0x00040000) == 0) {
322 monostart.tv_sec = kp.p_ustart_sec;
323 monostart.tv_usec = kp.p_ustart_usec;
324 timersub(&monostop, &monostart, &elapsed)do { (&elapsed)->tv_sec = (&monostop)->tv_sec -
(&monostart)->tv_sec; (&elapsed)->tv_usec = (&
monostop)->tv_usec - (&monostart)->tv_usec; if ((&
elapsed)->tv_usec < 0) { (&elapsed)->tv_sec--; (
&elapsed)->tv_usec += 1000000; } } while (0)
;
325 if (elapsed.tv_sec < 0)
326 timerclear(&elapsed)(&elapsed)->tv_sec = (&elapsed)->tv_usec = 0;
327 timersub(&realstop, &elapsed, &realstart)do { (&realstart)->tv_sec = (&realstop)->tv_sec
- (&elapsed)->tv_sec; (&realstart)->tv_usec = (
&realstop)->tv_usec - (&elapsed)->tv_usec; if (
(&realstart)->tv_usec < 0) { (&realstart)->tv_sec
--; (&realstart)->tv_usec += 1000000; } } while (0)
;
328 kp.p_ustart_sec = realstart.tv_sec;
329 kp.p_ustart_usec = realstart.tv_usec;
330 }
331
332 /* update %cpu for all threads */
333 if (dothreads) {
334 if (KREAD(kd, (u_long)process.ps_mainproc, &proc)(kvm_read(kd, (u_long)process.ps_mainproc, (void *)(&proc
), sizeof(*&proc)) != sizeof(*&proc))
) {
335 _kvm_err(kd, kd->program,
336 "can't read proc at %lx",
337 (u_long)process.ps_mainproc);
338 return (-1);
339 }
340 kp.p_pctcpu = proc.p_pctcpu;
341 kp.p_stat = proc.p_stat;
342 } else {
343 kp.p_pctcpu = 0;
344 kp.p_stat = (process.ps_flags & PS_ZOMBIE0x00040000) ? SDEAD6 :
345 SIDL1;
346 for (p = TAILQ_FIRST(&process.ps_threads)((&process.ps_threads)->tqh_first); p != NULL((void*)0);
347 p = TAILQ_NEXT(&proc, p_thr_link)((&proc)->p_thr_link.tqe_next)) {
348 if (KREAD(kd, (u_long)p, &proc)(kvm_read(kd, (u_long)p, (void *)(&proc), sizeof(*&proc
)) != sizeof(*&proc))
) {
349 _kvm_err(kd, kd->program,
350 "can't read proc at %lx",
351 (u_long)p);
352 return (-1);
353 }
354 kp.p_pctcpu += proc.p_pctcpu;
355 /*
356 * find best state:
357 * ONPROC > RUN > STOP > SLEEP > ...
358 */
359 if (proc.p_stat == SONPROC7 ||
360 kp.p_stat == SONPROC7)
361 kp.p_stat = SONPROC7;
362 else if (proc.p_stat == SRUN2 ||
363 kp.p_stat == SRUN2)
364 kp.p_stat = SRUN2;
365 else if (proc.p_stat == SSTOP4 ||
366 kp.p_stat == SSTOP4)
367 kp.p_stat = SSTOP4;
368 else if (proc.p_stat == SSLEEP3)
369 kp.p_stat = SSLEEP3;
370 }
371 }
372
373 memcpy(bp, &kp, esize);
374 bp += esize;
375 ++cnt;
376
377 /* Skip per-thread entries if not required by op */
378 if (!dothreads)
379 continue;
380
381 for (p = TAILQ_FIRST(&process.ps_threads)((&process.ps_threads)->tqh_first); p != NULL((void*)0);
382 p = TAILQ_NEXT(&proc, p_thr_link)((&proc)->p_thr_link.tqe_next)) {
383 if (KREAD(kd, (u_long)p, &proc)(kvm_read(kd, (u_long)p, (void *)(&proc), sizeof(*&proc
)) != sizeof(*&proc))
) {
384 _kvm_err(kd, kd->program,
385 "can't read proc at %lx",
386 (u_long)p);
387 return (-1);
388 }
389 FILL_KPROC(&kp, do_copy_str, &proc, &process,do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(p)); (&kp)->p_fd
= ((u_int64_t)(u_long)((&process)->ps_fd)); (&kp)
->p_limit = ((u_int64_t)(u_long)((&process)->ps_limit
)); (&kp)->p_vmspace = ((u_int64_t)(u_long)((&process
)->ps_vmspace)); (&kp)->p_sigacts = ((u_int64_t)(u_long
)((&process)->ps_sigacts)); (&kp)->p_sess = ((u_int64_t
)(u_long)((&pgrp)->pg_session)); (&kp)->p_ru = (
(u_int64_t)(u_long)((&process)->ps_ru)); } (&kp)->
p_stats = 0; (&kp)->p_exitsig = 0; (&kp)->p_flag
= (&proc)->p_flag; (&kp)->p_pid = (&process
)->ps_pid; (&kp)->p_psflags = (&process)->ps_flags
; (&kp)->p__pgid = (&pgrp)->pg_id; (&kp)->
p_uid = (&ucred)->cr_uid; (&kp)->p_ruid = (&
ucred)->cr_ruid; (&kp)->p_gid = (&ucred)->cr_gid
; (&kp)->p_rgid = (&ucred)->cr_rgid; (&kp)->
p_svuid = (&ucred)->cr_svuid; (&kp)->p_svgid = (
&ucred)->cr_svgid; memcpy((&kp)->p_groups, (&
ucred)->cr_groups, (((sizeof((&kp)->p_groups))<(
sizeof((&ucred)->cr_groups)))?(sizeof((&kp)->p_groups
)):(sizeof((&ucred)->cr_groups)))); (&kp)->p_ngroups
= (&ucred)->cr_ngroups; (&kp)->p_jobc = (&
pgrp)->pg_jobc; (&kp)->p_estcpu = (&proc)->p_estcpu
; if (1) { (&kp)->p_rtime_sec = (&proc)->p_tu.tu_runtime
.tv_sec; (&kp)->p_rtime_usec = (&proc)->p_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = (&proc)->p_tid + 100000
; (&kp)->p_uticks = (&proc)->p_tu.tu_uticks; (&
kp)->p_sticks = (&proc)->p_tu.tu_sticks; (&kp)->
p_iticks = (&proc)->p_tu.tu_iticks; } else { (&kp)
->p_rtime_sec = (&process)->ps_tu.tu_runtime.tv_sec
; (&kp)->p_rtime_usec = (&process)->ps_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = -1; (&kp)->p_uticks
= (&process)->ps_tu.tu_uticks; (&kp)->p_sticks
= (&process)->ps_tu.tu_sticks; (&kp)->p_iticks
= (&process)->ps_tu.tu_iticks; } (&kp)->p_cpticks
= (&proc)->p_cpticks; if (1) (&kp)->p_tracep =
((u_int64_t)(u_long)((&process)->ps_tracevp)); (&
kp)->p_traceflag = (&process)->ps_traceflag; (&
kp)->p_siglist = (&proc)->p_siglist | (&process
)->ps_siglist; (&kp)->p_sigmask = (&proc)->p_sigmask
; (&kp)->p_sigignore = (sap) ? (sap)->ps_sigignore :
0; (&kp)->p_sigcatch = (sap) ? (sap)->ps_sigcatch :
0; (&kp)->p_stat = (&proc)->p_stat; (&kp)->
p_nice = (&process)->ps_nice; (&kp)->p_xstat = (
((&process)->ps_xexit) << 8 | ((&process)->
ps_xsig)); (&kp)->p_acflag = (&process)->ps_acflag
; (&kp)->p_pledge = (&process)->ps_pledge; strlcpy
((&kp)->p_emul, "native", sizeof((&kp)->p_emul)
); strlcpy((&kp)->p_comm, (&process)->ps_comm, sizeof
((&kp)->p_comm)); strlcpy((&kp)->p_login, (&
sess)->s_login, (((sizeof((&kp)->p_login))<(sizeof
((&sess)->s_login)))?(sizeof((&kp)->p_login)):(
sizeof((&sess)->s_login)))); if ((&sess)->s_ttyvp
) (&kp)->p_eflag |= 0x01; if ((&process)->ps_uvpaths
) (&kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone
|| (((&process)->ps_flags & 0x00100000) &&
((&process)->ps_pledge & 0x0000001000000000ULL) ==
0)) (&kp)->p_eflag |= 0x08; if (((&process)->ps_flags
& (0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void
*)0)) { (&kp)->p_vm_rssize = (vmp)->vm_rssize; (&
kp)->p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize
= (vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
390 &ucred, &pgrp, p, pr, &sess, vmp, limp, sap,do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(p)); (&kp)->p_fd
= ((u_int64_t)(u_long)((&process)->ps_fd)); (&kp)
->p_limit = ((u_int64_t)(u_long)((&process)->ps_limit
)); (&kp)->p_vmspace = ((u_int64_t)(u_long)((&process
)->ps_vmspace)); (&kp)->p_sigacts = ((u_int64_t)(u_long
)((&process)->ps_sigacts)); (&kp)->p_sess = ((u_int64_t
)(u_long)((&pgrp)->pg_session)); (&kp)->p_ru = (
(u_int64_t)(u_long)((&process)->ps_ru)); } (&kp)->
p_stats = 0; (&kp)->p_exitsig = 0; (&kp)->p_flag
= (&proc)->p_flag; (&kp)->p_pid = (&process
)->ps_pid; (&kp)->p_psflags = (&process)->ps_flags
; (&kp)->p__pgid = (&pgrp)->pg_id; (&kp)->
p_uid = (&ucred)->cr_uid; (&kp)->p_ruid = (&
ucred)->cr_ruid; (&kp)->p_gid = (&ucred)->cr_gid
; (&kp)->p_rgid = (&ucred)->cr_rgid; (&kp)->
p_svuid = (&ucred)->cr_svuid; (&kp)->p_svgid = (
&ucred)->cr_svgid; memcpy((&kp)->p_groups, (&
ucred)->cr_groups, (((sizeof((&kp)->p_groups))<(
sizeof((&ucred)->cr_groups)))?(sizeof((&kp)->p_groups
)):(sizeof((&ucred)->cr_groups)))); (&kp)->p_ngroups
= (&ucred)->cr_ngroups; (&kp)->p_jobc = (&
pgrp)->pg_jobc; (&kp)->p_estcpu = (&proc)->p_estcpu
; if (1) { (&kp)->p_rtime_sec = (&proc)->p_tu.tu_runtime
.tv_sec; (&kp)->p_rtime_usec = (&proc)->p_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = (&proc)->p_tid + 100000
; (&kp)->p_uticks = (&proc)->p_tu.tu_uticks; (&
kp)->p_sticks = (&proc)->p_tu.tu_sticks; (&kp)->
p_iticks = (&proc)->p_tu.tu_iticks; } else { (&kp)
->p_rtime_sec = (&process)->ps_tu.tu_runtime.tv_sec
; (&kp)->p_rtime_usec = (&process)->ps_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = -1; (&kp)->p_uticks
= (&process)->ps_tu.tu_uticks; (&kp)->p_sticks
= (&process)->ps_tu.tu_sticks; (&kp)->p_iticks
= (&process)->ps_tu.tu_iticks; } (&kp)->p_cpticks
= (&proc)->p_cpticks; if (1) (&kp)->p_tracep =
((u_int64_t)(u_long)((&process)->ps_tracevp)); (&
kp)->p_traceflag = (&process)->ps_traceflag; (&
kp)->p_siglist = (&proc)->p_siglist | (&process
)->ps_siglist; (&kp)->p_sigmask = (&proc)->p_sigmask
; (&kp)->p_sigignore = (sap) ? (sap)->ps_sigignore :
0; (&kp)->p_sigcatch = (sap) ? (sap)->ps_sigcatch :
0; (&kp)->p_stat = (&proc)->p_stat; (&kp)->
p_nice = (&process)->ps_nice; (&kp)->p_xstat = (
((&process)->ps_xexit) << 8 | ((&process)->
ps_xsig)); (&kp)->p_acflag = (&process)->ps_acflag
; (&kp)->p_pledge = (&process)->ps_pledge; strlcpy
((&kp)->p_emul, "native", sizeof((&kp)->p_emul)
); strlcpy((&kp)->p_comm, (&process)->ps_comm, sizeof
((&kp)->p_comm)); strlcpy((&kp)->p_login, (&
sess)->s_login, (((sizeof((&kp)->p_login))<(sizeof
((&sess)->s_login)))?(sizeof((&kp)->p_login)):(
sizeof((&sess)->s_login)))); if ((&sess)->s_ttyvp
) (&kp)->p_eflag |= 0x01; if ((&process)->ps_uvpaths
) (&kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone
|| (((&process)->ps_flags & 0x00100000) &&
((&process)->ps_pledge & 0x0000001000000000ULL) ==
0)) (&kp)->p_eflag |= 0x08; if (((&process)->ps_flags
& (0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void
*)0)) { (&kp)->p_vm_rssize = (vmp)->vm_rssize; (&
kp)->p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize
= (vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
391 1, 1)do { memset((&kp), 0, sizeof(*(&kp))); if (1) { (&
kp)->p_paddr = ((u_int64_t)(u_long)(p)); (&kp)->p_fd
= ((u_int64_t)(u_long)((&process)->ps_fd)); (&kp)
->p_limit = ((u_int64_t)(u_long)((&process)->ps_limit
)); (&kp)->p_vmspace = ((u_int64_t)(u_long)((&process
)->ps_vmspace)); (&kp)->p_sigacts = ((u_int64_t)(u_long
)((&process)->ps_sigacts)); (&kp)->p_sess = ((u_int64_t
)(u_long)((&pgrp)->pg_session)); (&kp)->p_ru = (
(u_int64_t)(u_long)((&process)->ps_ru)); } (&kp)->
p_stats = 0; (&kp)->p_exitsig = 0; (&kp)->p_flag
= (&proc)->p_flag; (&kp)->p_pid = (&process
)->ps_pid; (&kp)->p_psflags = (&process)->ps_flags
; (&kp)->p__pgid = (&pgrp)->pg_id; (&kp)->
p_uid = (&ucred)->cr_uid; (&kp)->p_ruid = (&
ucred)->cr_ruid; (&kp)->p_gid = (&ucred)->cr_gid
; (&kp)->p_rgid = (&ucred)->cr_rgid; (&kp)->
p_svuid = (&ucred)->cr_svuid; (&kp)->p_svgid = (
&ucred)->cr_svgid; memcpy((&kp)->p_groups, (&
ucred)->cr_groups, (((sizeof((&kp)->p_groups))<(
sizeof((&ucred)->cr_groups)))?(sizeof((&kp)->p_groups
)):(sizeof((&ucred)->cr_groups)))); (&kp)->p_ngroups
= (&ucred)->cr_ngroups; (&kp)->p_jobc = (&
pgrp)->pg_jobc; (&kp)->p_estcpu = (&proc)->p_estcpu
; if (1) { (&kp)->p_rtime_sec = (&proc)->p_tu.tu_runtime
.tv_sec; (&kp)->p_rtime_usec = (&proc)->p_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = (&proc)->p_tid + 100000
; (&kp)->p_uticks = (&proc)->p_tu.tu_uticks; (&
kp)->p_sticks = (&proc)->p_tu.tu_sticks; (&kp)->
p_iticks = (&proc)->p_tu.tu_iticks; } else { (&kp)
->p_rtime_sec = (&process)->ps_tu.tu_runtime.tv_sec
; (&kp)->p_rtime_usec = (&process)->ps_tu.tu_runtime
.tv_nsec/1000; (&kp)->p_tid = -1; (&kp)->p_uticks
= (&process)->ps_tu.tu_uticks; (&kp)->p_sticks
= (&process)->ps_tu.tu_sticks; (&kp)->p_iticks
= (&process)->ps_tu.tu_iticks; } (&kp)->p_cpticks
= (&proc)->p_cpticks; if (1) (&kp)->p_tracep =
((u_int64_t)(u_long)((&process)->ps_tracevp)); (&
kp)->p_traceflag = (&process)->ps_traceflag; (&
kp)->p_siglist = (&proc)->p_siglist | (&process
)->ps_siglist; (&kp)->p_sigmask = (&proc)->p_sigmask
; (&kp)->p_sigignore = (sap) ? (sap)->ps_sigignore :
0; (&kp)->p_sigcatch = (sap) ? (sap)->ps_sigcatch :
0; (&kp)->p_stat = (&proc)->p_stat; (&kp)->
p_nice = (&process)->ps_nice; (&kp)->p_xstat = (
((&process)->ps_xexit) << 8 | ((&process)->
ps_xsig)); (&kp)->p_acflag = (&process)->ps_acflag
; (&kp)->p_pledge = (&process)->ps_pledge; strlcpy
((&kp)->p_emul, "native", sizeof((&kp)->p_emul)
); strlcpy((&kp)->p_comm, (&process)->ps_comm, sizeof
((&kp)->p_comm)); strlcpy((&kp)->p_login, (&
sess)->s_login, (((sizeof((&kp)->p_login))<(sizeof
((&sess)->s_login)))?(sizeof((&kp)->p_login)):(
sizeof((&sess)->s_login)))); if ((&sess)->s_ttyvp
) (&kp)->p_eflag |= 0x01; if ((&process)->ps_uvpaths
) (&kp)->p_eflag |= 0x04; if ((&process)->ps_uvdone
|| (((&process)->ps_flags & 0x00100000) &&
((&process)->ps_pledge & 0x0000001000000000ULL) ==
0)) (&kp)->p_eflag |= 0x08; if (((&process)->ps_flags
& (0x00020000 | 0x00040000)) == 0) { if ((vmp) != ((void
*)0)) { (&kp)->p_vm_rssize = (vmp)->vm_rssize; (&
kp)->p_vm_tsize = (vmp)->vm_tsize; (&kp)->p_vm_dsize
= (vmp)->vm_dused; (&kp)->p_vm_ssize = (vmp)->vm_ssize
; } (&kp)->p_addr = ((u_int64_t)(u_long)((&proc)->
p_addr)); (&kp)->p_stat = (&proc)->p_stat; (&
kp)->p_slptime = (&proc)->p_slptime; (&kp)->
p_holdcnt = 1; (&kp)->p_priority = ((&proc)->p_stat
== 2 ? (&proc)->p_runpri : ((&proc)->p_stat ==
3) ? (&proc)->p_slppri : (&proc)->p_usrpri); (
&kp)->p_usrpri = (&proc)->p_usrpri; if ((&proc
)->p_wchan && (&proc)->p_wmesg) do_copy_str
((&kp)->p_wmesg, (&proc)->p_wmesg, sizeof((&
kp)->p_wmesg)); if (1) (&kp)->p_wchan = ((u_int64_t
)(u_long)((&proc)->p_wchan)); } ; if (limp) (&kp)->
p_rlim_rss_cur = (limp)->pl_rlimit[5].rlim_cur; ; if (((&
process)->ps_flags & 0x00040000) == 0) { struct timeval
__tv; (&kp)->p_uvalid = 1; (&kp)->p_uru_maxrss
= (&proc)->p_ru.ru_maxrss; (&kp)->p_uru_ixrss =
(&proc)->p_ru.ru_ixrss; (&kp)->p_uru_idrss = (
&proc)->p_ru.ru_idrss; (&kp)->p_uru_isrss = (&
proc)->p_ru.ru_isrss; (&kp)->p_uru_minflt = (&proc
)->p_ru.ru_minflt; (&kp)->p_uru_majflt = (&proc
)->p_ru.ru_majflt; (&kp)->p_uru_nswap = (&proc)
->p_ru.ru_nswap; (&kp)->p_uru_inblock = (&proc)
->p_ru.ru_inblock; (&kp)->p_uru_oublock = (&proc
)->p_ru.ru_oublock; (&kp)->p_uru_msgsnd = (&proc
)->p_ru.ru_msgsnd; (&kp)->p_uru_msgrcv = (&proc
)->p_ru.ru_msgrcv; (&kp)->p_uru_nsignals = (&proc
)->p_ru.ru_nsignals; (&kp)->p_uru_nvcsw = (&proc
)->p_ru.ru_nvcsw; (&kp)->p_uru_nivcsw = (&proc)
->p_ru.ru_nivcsw; do { (&__tv)->tv_sec = (&(&
process)->ps_cru.ru_utime)->tv_sec + (&(&process
)->ps_cru.ru_stime)->tv_sec; (&__tv)->tv_usec = (
&(&process)->ps_cru.ru_utime)->tv_usec + (&
(&process)->ps_cru.ru_stime)->tv_usec; if ((&__tv
)->tv_usec >= 1000000) { (&__tv)->tv_sec++; (&
__tv)->tv_usec -= 1000000; } } while (0); (&kp)->p_uctime_sec
= __tv.tv_sec; (&kp)->p_uctime_usec = __tv.tv_usec; }
(&kp)->p_cpuid = (~(u_int64_t)0); (&kp)->p_rtableid
= (&process)->ps_rtableid; } while (0)
;
392
393 /* see above */
394 kp.p_ppid = parent_pid;
395 kp.p_sid = leader_pid;
396 if ((process.ps_flags & PS_CONTROLT0x00000001) &&
397 sess.s_ttyp != NULL((void*)0)) {
398 kp.p_tdev = tty.t_dev;
399 if (tty.t_pgrp != NULL((void*)0) &&
400 tty.t_pgrp != process.ps_pgrp &&
401 KREAD(kd, (u_long)tty.t_pgrp, &pgrp)(kvm_read(kd, (u_long)tty.t_pgrp, (void *)(&pgrp), sizeof
(*&pgrp)) != sizeof(*&pgrp))
) {
402 _kvm_err(kd, kd->program,
403 "can't read tpgrp at %lx",
404 (u_long)tty.t_pgrp);
405 return (-1);
406 }
407 kp.p_tpgid = tty.t_pgrp ? pgrp.pg_id : -1;
408 kp.p_tsess = PTRTOINT64(tty.t_session)((u_int64_t)(u_long)(tty.t_session));
409 } else {
410 kp.p_tpgid = -1;
411 kp.p_tdev = NODEV(dev_t)(-1);
412 }
413 }
414
415 memcpy(bp, &kp, esize);
416 bp += esize;
417 ++cnt;
418#undef do_copy_str
419 }
420 return (cnt);
421}
422
423struct kinfo_proc *
424kvm_getprocs(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
425{
426 int mib[6], st, nthreads;
427 void *procbase;
428 size_t size;
429
430 if ((ssize_t)esize < 0)
431 return (NULL((void*)0));
432
433 if (ISALIVE(kd)((kd)->alive)) {
434 size = 0;
435 mib[0] = CTL_KERN1;
436 mib[1] = KERN_PROC66;
437 mib[2] = op;
438 mib[3] = arg;
439 mib[4] = esize;
440
441 do {
442 mib[5] = 0;
443 st = sysctl(mib, 6, NULL((void*)0), &size, NULL((void*)0), 0);
444 if (st == -1) {
445 _kvm_syserr(kd, kd->program, "kvm_getprocs");
446 return (NULL((void*)0));
447 }
448
449 size += size / 8; /* add ~10% */
450
451 procbase = _kvm_realloc(kd, kd->procbase, size);
452 if (procbase == NULL((void*)0))
453 return (NULL((void*)0));
454
455 kd->procbase = procbase;
456
457 mib[5] = size / esize;
458 st = sysctl(mib, 6, kd->procbase, &size, NULL((void*)0), 0);
459 if (st == -1 && errno(*__errno()) != ENOMEM12) {
460 _kvm_syserr(kd, kd->program, "kvm_getprocs");
461 return (NULL((void*)0));
462 }
463 } while (st == -1);
464
465 nthreads = size / esize;
466 } else {
467 struct nlist nl[5];
468 int i, maxthread, maxprocess;
469 struct process *pr;
470 char *bp;
471
472 if (esize > sizeof(struct kinfo_proc)) {
473 _kvm_syserr(kd, kd->program,
474 "kvm_getprocs: unknown fields requested: libkvm out of date?");
475 return (NULL((void*)0));
476 }
477
478 memset(nl, 0, sizeof(nl));
479 nl[0].n_name = "_nthreads";
480 nl[1].n_name = "_nprocesses";
481 nl[2].n_name = "_allprocess";
482 nl[3].n_name = "_zombprocess";
483 nl[4].n_name = NULL((void*)0);
484
485 if (kvm_nlist(kd, nl) != 0) {
486 for (i = 0; nl[i].n_type != 0; ++i)
487 ;
488 _kvm_err(kd, kd->program,
489 "%s: no such symbol", nl[i].n_name);
490 return (NULL((void*)0));
491 }
492 if (KREAD(kd, nl[0].n_value, &maxthread)(kvm_read(kd, nl[0].n_value, (void *)(&maxthread), sizeof
(*&maxthread)) != sizeof(*&maxthread))
) {
493 _kvm_err(kd, kd->program, "can't read nthreads");
494 return (NULL((void*)0));
495 }
496 if (KREAD(kd, nl[1].n_value, &maxprocess)(kvm_read(kd, nl[1].n_value, (void *)(&maxprocess), sizeof
(*&maxprocess)) != sizeof(*&maxprocess))
) {
497 _kvm_err(kd, kd->program, "can't read nprocesses");
498 return (NULL((void*)0));
499 }
500 maxthread += maxprocess;
501
502 kd->procbase = _kvm_reallocarray(kd, NULL((void*)0), maxthread, esize);
503 if (kd->procbase == 0)
504 return (NULL((void*)0));
505 bp = (char *)kd->procbase;
506
507 /* allprocess */
508 if (KREAD(kd, nl[2].n_value, &pr)(kvm_read(kd, nl[2].n_value, (void *)(&pr), sizeof(*&
pr)) != sizeof(*&pr))
) {
509 _kvm_err(kd, kd->program, "cannot read allprocess");
510 return (NULL((void*)0));
511 }
512 nthreads = kvm_proclist(kd, op, arg, pr, bp, maxthread, esize);
513 if (nthreads < 0)
514 return (NULL((void*)0));
515
516 /* zombprocess */
517 if (KREAD(kd, nl[3].n_value, &pr)(kvm_read(kd, nl[3].n_value, (void *)(&pr), sizeof(*&
pr)) != sizeof(*&pr))
) {
518 _kvm_err(kd, kd->program, "cannot read zombprocess");
519 return (NULL((void*)0));
520 }
521 i = kvm_proclist(kd, op, arg, pr, bp + (esize * nthreads),
522 maxthread - nthreads, esize);
523 if (i > 0)
524 nthreads += i;
525 }
526 if (kd->procbase != NULL((void*)0))
527 *cnt = nthreads;
528 return (kd->procbase);
529}