1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1989, 1991, 1993
5 * The Regents of the University of California.
6 * Copyright (c) 2007 Robert N. M. Watson
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef _SYS_USER_H_
35#define _SYS_USER_H_
36
37#include <machine/pcb.h>
38#ifndef _KERNEL
39/* stuff that *used* to be included by user.h, or is now needed */
40#include <sys/errno.h>
41#include <sys/event.h>
42#include <sys/time.h>
43#include <sys/resource.h>
44#include <sys/ucred.h>
45#include <sys/uio.h>
46#include <sys/queue.h>
47#include <sys/_lock.h>
48#include <sys/_mutex.h>
49#include <sys/proc.h>
50#include <vm/vm.h> /* XXX */
51#include <vm/vm_param.h> /* XXX */
52#include <vm/pmap.h> /* XXX */
53#include <vm/vm_map.h> /* XXX */
54#endif /* !_KERNEL */
55#ifndef _SYS_RESOURCEVAR_H_
56#include <sys/resourcevar.h>
57#endif
58#ifndef _SYS_SIGNALVAR_H_
59#include <sys/signalvar.h>
60#endif
61#ifndef _SYS_SOCKET_VAR_H_
62#include <sys/socket.h>
63#endif
64#include <sys/caprights.h>
65
66/*
67 * KERN_PROC subtype ops return arrays of selected proc structure entries:
68 *
69 * This struct includes several arrays of spare space, with different arrays
70 * for different standard C-types. When adding new variables to this struct,
71 * the space for byte-aligned data should be taken from the ki_sparestring,
72 * pointers from ki_spareptrs, word-aligned data from ki_spareints, and
73 * doubleword-aligned data from ki_sparelongs. Make sure the space for new
74 * variables come from the array which matches the size and alignment of
75 * those variables on ALL hardware platforms, and then adjust the appropriate
76 * KI_NSPARE_* value(s) to match.
77 *
78 * Always verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE on all
79 * platforms after you have added new variables. Note that if you change
80 * the value of KINFO_PROC_SIZE, then many userland programs will stop
81 * working until they are recompiled!
82 *
83 * Once you have added the new field, you will need to add code to initialize
84 * it in two places: function fill_kinfo_proc in sys/kern/kern_proc.c and
85 * function kvm_proclist in lib/libkvm/kvm_proc.c .
86 */
87#define KI_NSPARE_INT 2
88#define KI_NSPARE_LONG 12
89#define KI_NSPARE_PTR 4
90
91#ifndef _KERNEL
92#ifndef KINFO_PROC_SIZE
93#error "Unknown architecture"
94#endif
95#endif /* !_KERNEL */
96
97#define WMESGLEN 8 /* size of returned wchan message */
98#define LOCKNAMELEN 8 /* size of returned lock name */
99#define TDNAMLEN 16 /* size of returned thread name */
100#define COMMLEN 19 /* size of returned ki_comm name */
101#define KI_EMULNAMELEN 16 /* size of returned ki_emul */
102#define KI_NGROUPS 16 /* number of groups in ki_groups */
103#define LOGNAMELEN 17 /* size of returned ki_login */
104#define LOGINCLASSLEN 17 /* size of returned ki_loginclass */
105
106#ifndef BURN_BRIDGES
107#define OCOMMLEN TDNAMLEN
108#define ki_ocomm ki_tdname
109#endif
110
111/* Flags for the process credential. */
112#define KI_CRF_CAPABILITY_MODE 0x00000001
113/*
114 * Steal a bit from ki_cr_flags to indicate that the cred had more than
115 * KI_NGROUPS groups.
116 */
117#define KI_CRF_GRP_OVERFLOW 0x80000000
118
119struct kinfo_proc {
120 int ki_structsize; /* size of this structure */
121 int ki_layout; /* reserved: layout identifier */
122 struct pargs *ki_args; /* address of command arguments */
123 struct proc *ki_paddr; /* address of proc */
124 struct user *ki_addr; /* kernel virtual addr of u-area */
125 struct vnode *ki_tracep; /* pointer to trace file */
126 struct vnode *ki_textvp; /* pointer to executable file */
127 struct filedesc *ki_fd; /* pointer to open file info */
128 struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */
129 const void *ki_wchan; /* sleep address */
130 pid_t ki_pid; /* Process identifier */
131 pid_t ki_ppid; /* parent process id */
132 pid_t ki_pgid; /* process group id */
133 pid_t ki_tpgid; /* tty process group id */
134 pid_t ki_sid; /* Process session ID */
135 pid_t ki_tsid; /* Terminal session ID */
136 short ki_jobc; /* job control counter */
137 short ki_spare_short1; /* unused (just here for alignment) */
138 uint32_t ki_tdev_freebsd11; /* controlling tty dev */
139 sigset_t ki_siglist; /* Signals arrived but not delivered */
140 sigset_t ki_sigmask; /* Current signal mask */
141 sigset_t ki_sigignore; /* Signals being ignored */
142 sigset_t ki_sigcatch; /* Signals being caught by user */
143 uid_t ki_uid; /* effective user id */
144 uid_t ki_ruid; /* Real user id */
145 uid_t ki_svuid; /* Saved effective user id */
146 gid_t ki_rgid; /* Real group id */
147 gid_t ki_svgid; /* Saved effective group id */
148 short ki_ngroups; /* number of groups */
149 short ki_spare_short2; /* unused (just here for alignment) */
150 gid_t ki_groups[KI_NGROUPS]; /* groups */
151 vm_size_t ki_size; /* virtual size */
152 segsz_t ki_rssize; /* current resident set size in pages */
153 segsz_t ki_swrss; /* resident set size before last swap */
154 segsz_t ki_tsize; /* text size (pages) XXX */
155 segsz_t ki_dsize; /* data size (pages) XXX */
156 segsz_t ki_ssize; /* stack size (pages) */
157 u_short ki_xstat; /* Exit status for wait & stop signal */
158 u_short ki_acflag; /* Accounting flags */
159 fixpt_t ki_pctcpu; /* %cpu for process during ki_swtime */
160 u_int ki_estcpu; /* Time averaged value of ki_cpticks */
161 u_int ki_slptime; /* Time since last blocked */
162 u_int ki_swtime; /* Time swapped in or out */
163 u_int ki_cow; /* number of copy-on-write faults */
164 u_int64_t ki_runtime; /* Real time in microsec */
165 struct timeval ki_start; /* starting time */
166 struct timeval ki_childtime; /* time used by process children */
167 long ki_flag; /* P_* flags */
168 long ki_kiflag; /* KI_* flags (below) */
169 int ki_traceflag; /* Kernel trace points */
170 char ki_stat; /* S* process status */
171 signed char ki_nice; /* Process "nice" value */
172 char ki_lock; /* Process lock (prevent swap) count */
173 char ki_rqindex; /* Run queue index */
174 u_char ki_oncpu_old; /* Which cpu we are on (legacy) */
175 u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */
176 char ki_tdname[TDNAMLEN+1]; /* thread name */
177 char ki_wmesg[WMESGLEN+1]; /* wchan message */
178 char ki_login[LOGNAMELEN+1]; /* setlogin name */
179 char ki_lockname[LOCKNAMELEN+1]; /* lock name */
180 char ki_comm[COMMLEN+1]; /* command name */
181 char ki_emul[KI_EMULNAMELEN+1]; /* emulation name */
182 char ki_loginclass[LOGINCLASSLEN+1]; /* login class */
183 char ki_moretdname[MAXCOMLEN-TDNAMLEN+1]; /* more thread name */
184 /*
185 * When adding new variables, take space for char-strings from the
186 * front of ki_sparestrings, and ints from the end of ki_spareints.
187 * That way the spare room from both arrays will remain contiguous.
188 */
189 char ki_sparestrings[46]; /* spare string space */
190 int ki_spareints[KI_NSPARE_INT]; /* spare room for growth */
191 uint64_t ki_tdev; /* controlling tty dev */
192 int ki_oncpu; /* Which cpu we are on */
193 int ki_lastcpu; /* Last cpu we were on */
194 int ki_tracer; /* Pid of tracing process */
195 int ki_flag2; /* P2_* flags */
196 int ki_fibnum; /* Default FIB number */
197 u_int ki_cr_flags; /* Credential flags */
198 int ki_jid; /* Process jail ID */
199 int ki_numthreads; /* XXXKSE number of threads in total */
200 lwpid_t ki_tid; /* XXXKSE thread id */
201 struct priority ki_pri; /* process priority */
202 struct rusage ki_rusage; /* process rusage statistics */
203 /* XXX - most fields in ki_rusage_ch are not (yet) filled in */
204 struct rusage ki_rusage_ch; /* rusage of children processes */
205 struct pcb *ki_pcb; /* kernel virtual addr of pcb */
206 void *ki_kstack; /* kernel virtual addr of stack */
207 void *ki_udata; /* User convenience pointer */
208 struct thread *ki_tdaddr; /* address of thread */
209 /*
210 * When adding new variables, take space for pointers from the
211 * front of ki_spareptrs, and longs from the end of ki_sparelongs.
212 * That way the spare room from both arrays will remain contiguous.
213 */
214 struct pwddesc *ki_pd; /* pointer to process paths info */
215 void *ki_uerrmsg; /* address of the ext err msg place */
216 void *ki_spareptrs[KI_NSPARE_PTR]; /* spare room for growth */
217 long ki_sparelongs[KI_NSPARE_LONG]; /* spare room for growth */
218 long ki_sflag; /* PS_* flags */
219 long ki_tdflags; /* XXXKSE kthread flag */
220};
221void fill_kinfo_proc(struct proc *, struct kinfo_proc *);
222/* XXX - the following two defines are temporary */
223#define ki_childstime ki_rusage_ch.ru_stime
224#define ki_childutime ki_rusage_ch.ru_utime
225
226/*
227 * Legacy PS_ flag. This moved to p_flag but is maintained for
228 * compatibility.
229 */
230#define PS_INMEM 0x00001 /* Loaded into memory, always true. */
231
232/* ki_sessflag values */
233#define KI_CTTY 0x00000001 /* controlling tty vnode active */
234#define KI_SLEADER 0x00000002 /* session leader */
235#define KI_LOCKBLOCK 0x00000004 /* proc blocked on lock ki_lockname */
236
237/*
238 * This used to be the per-process structure containing data that
239 * isn't needed in core when the process is swapped out, but now it
240 * remains only for the benefit of a.out core dumps.
241 */
242struct user {
243 struct pstats u_stats; /* *p_stats */
244 struct kinfo_proc u_kproc; /* eproc */
245};
246
247/*
248 * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor
249 * array of another process.
250 */
251#define KF_ATTR_VALID 0x0001
252
253#define KF_TYPE_NONE 0
254#define KF_TYPE_VNODE 1
255#define KF_TYPE_SOCKET 2
256#define KF_TYPE_PIPE 3
257#define KF_TYPE_FIFO 4
258#define KF_TYPE_KQUEUE 5
259/* was KF_TYPE_CRYPTO 6 */
260#define KF_TYPE_MQUEUE 7
261#define KF_TYPE_SHM 8
262#define KF_TYPE_SEM 9
263#define KF_TYPE_PTS 10
264#define KF_TYPE_PROCDESC 11
265#define KF_TYPE_DEV 12
266#define KF_TYPE_EVENTFD 13
267#define KF_TYPE_TIMERFD 14
268#define KF_TYPE_INOTIFY 15
269#define KF_TYPE_JAILDESC 16
270#define KF_TYPE_UNKNOWN 255
271
272#define KF_VTYPE_VNON 0
273#define KF_VTYPE_VREG 1
274#define KF_VTYPE_VDIR 2
275#define KF_VTYPE_VBLK 3
276#define KF_VTYPE_VCHR 4
277#define KF_VTYPE_VLNK 5
278#define KF_VTYPE_VSOCK 6
279#define KF_VTYPE_VFIFO 7
280#define KF_VTYPE_VBAD 8
281#define KF_VTYPE_UNKNOWN 255
282
283#define KF_FD_TYPE_CWD -1 /* Current working directory */
284#define KF_FD_TYPE_ROOT -2 /* Root directory */
285#define KF_FD_TYPE_JAIL -3 /* Jail directory */
286#define KF_FD_TYPE_TRACE -4 /* Ktrace vnode */
287#define KF_FD_TYPE_TEXT -5 /* Text vnode */
288#define KF_FD_TYPE_CTTY -6 /* Controlling terminal */
289
290#define KF_FLAG_READ 0x00000001
291#define KF_FLAG_WRITE 0x00000002
292#define KF_FLAG_APPEND 0x00000004
293#define KF_FLAG_ASYNC 0x00000008
294#define KF_FLAG_FSYNC 0x00000010
295#define KF_FLAG_NONBLOCK 0x00000020
296#define KF_FLAG_DIRECT 0x00000040
297#define KF_FLAG_HASLOCK 0x00000080
298#define KF_FLAG_SHLOCK 0x00000100
299#define KF_FLAG_EXLOCK 0x00000200
300#define KF_FLAG_NOFOLLOW 0x00000400
301#define KF_FLAG_CREAT 0x00000800
302#define KF_FLAG_TRUNC 0x00001000
303#define KF_FLAG_EXCL 0x00002000
304#define KF_FLAG_EXEC 0x00004000
305
306/*
307 * Old format. Has variable hidden padding due to alignment.
308 * This is a compatibility hack for pre-build 7.1 packages.
309 */
310#if defined(__amd64__)
311#define KINFO_OFILE_SIZE 1328
312#endif
313#if defined(__i386__)
314#define KINFO_OFILE_SIZE 1324
315#endif
316
317struct kinfo_ofile {
318 int kf_structsize; /* Size of kinfo_file. */
319 int kf_type; /* Descriptor type. */
320 int kf_fd; /* Array index. */
321 int kf_ref_count; /* Reference count. */
322 int kf_flags; /* Flags. */
323 /* XXX Hidden alignment padding here on amd64 */
324 off_t kf_offset; /* Seek location. */
325 int kf_vnode_type; /* Vnode type. */
326 int kf_sock_domain; /* Socket domain. */
327 int kf_sock_type; /* Socket type. */
328 int kf_sock_protocol; /* Socket protocol. */
329 char kf_path[PATH_MAX]; /* Path to file, if any. */
330 struct sockaddr_storage kf_sa_local; /* Socket address. */
331 struct sockaddr_storage kf_sa_peer; /* Peer address. */
332};
333
334#if defined(__amd64__) || defined(__i386__)
335/*
336 * This size should never be changed. If you really need to, you must provide
337 * backward ABI compatibility by allocating a new sysctl MIB that will return
338 * the new structure. The current structure has to be returned by the current
339 * sysctl MIB. See how it is done for the kinfo_ofile structure.
340 */
341#define KINFO_FILE_SIZE 1392
342#endif
343
344struct kinfo_file {
345 int kf_structsize; /* Variable size of record. */
346 int kf_type; /* Descriptor type. */
347 int kf_fd; /* Array index. */
348 int kf_ref_count; /* Reference count. */
349 int kf_flags; /* Flags. */
350 int kf_pad0; /* Round to 64 bit alignment. */
351 int64_t kf_offset; /* Seek location. */
352 union {
353 struct {
354 /* API compatibility with FreeBSD < 12. */
355 int kf_vnode_type;
356 int kf_sock_domain;
357 int kf_sock_type;
358 int kf_sock_protocol;
359 struct sockaddr_storage kf_sa_local;
360 struct sockaddr_storage kf_sa_peer;
361 };
362 union {
363 struct {
364 /* Sendq size */
365 uint32_t kf_sock_sendq;
366 /* Socket domain. */
367 int kf_sock_domain0;
368 /* Socket type. */
369 int kf_sock_type0;
370 /* Socket protocol. */
371 int kf_sock_protocol0;
372 /* Socket address. */
373 struct sockaddr_storage kf_sa_local;
374 /* Peer address. */
375 struct sockaddr_storage kf_sa_peer;
376 /* Address of so_pcb. */
377 uint64_t kf_sock_pcb;
378 /* Obsolete! May be reused as a spare. */
379 uint64_t kf_sock_inpcb;
380 /* Address of unp_conn. */
381 uint64_t kf_sock_unpconn;
382 /* Send buffer state. */
383 uint16_t kf_sock_snd_sb_state;
384 /* Receive buffer state. */
385 uint16_t kf_sock_rcv_sb_state;
386 /* Recvq size. */
387 uint32_t kf_sock_recvq;
388 } kf_sock;
389 struct {
390 /* Vnode type. */
391 int kf_file_type;
392 /* Space for future use */
393 int kf_spareint[3];
394 uint64_t kf_spareint64[29];
395 /* Number of references to file. */
396 uint64_t kf_file_nlink;
397 /* Vnode filesystem id. */
398 uint64_t kf_file_fsid;
399 /* File device. */
400 uint64_t kf_file_rdev;
401 /* Global file id. */
402 uint64_t kf_file_fileid;
403 /* File size. */
404 uint64_t kf_file_size;
405 /* Vnode filesystem id, FreeBSD 11 compat. */
406 uint32_t kf_file_fsid_freebsd11;
407 /* File device, FreeBSD 11 compat. */
408 uint32_t kf_file_rdev_freebsd11;
409 /* File mode. */
410 uint16_t kf_file_mode;
411 /* Round to 64 bit alignment. */
412 uint16_t kf_file_pad0;
413 uint32_t kf_file_pad1;
414 } kf_file;
415 struct {
416 uint32_t kf_spareint[4];
417 uint64_t kf_spareint64[32];
418 uint32_t kf_sem_value;
419 uint16_t kf_sem_mode;
420 } kf_sem;
421 struct {
422 uint32_t kf_spareint[4];
423 uint64_t kf_spareint64[32];
424 uint64_t kf_pipe_addr;
425 uint64_t kf_pipe_peer;
426 uint32_t kf_pipe_buffer_cnt;
427 uint32_t kf_pipe_buffer_in;
428 uint32_t kf_pipe_buffer_out;
429 uint32_t kf_pipe_buffer_size;
430 } kf_pipe;
431 struct {
432 uint32_t kf_spareint[4];
433 uint64_t kf_spareint64[32];
434 uint32_t kf_pts_dev_freebsd11;
435 uint32_t kf_pts_pad0;
436 uint64_t kf_pts_dev;
437 /* Round to 64 bit alignment. */
438 uint32_t kf_pts_pad1[4];
439 } kf_pts;
440 struct {
441 uint32_t kf_spareint[4];
442 uint64_t kf_spareint64[32];
443 pid_t kf_pid;
444 } kf_proc;
445 struct {
446 uint64_t kf_eventfd_value;
447 uint32_t kf_eventfd_flags;
448 uint32_t kf_eventfd_spareint[3];
449 uint64_t kf_eventfd_addr;
450 } kf_eventfd;
451 struct {
452 uint32_t kf_timerfd_clockid;
453 uint32_t kf_timerfd_flags;
454 uint64_t kf_timerfd_addr;
455 } kf_timerfd;
456 struct {
457 int32_t kf_jid;
458 } kf_jail;
459 struct {
460 uint64_t kf_kqueue_addr;
461 int32_t kf_kqueue_count;
462 int32_t kf_kqueue_state;
463 } kf_kqueue;
464 struct {
465 uint64_t kf_inotify_npending;
466 uint64_t kf_inotify_nbpending;
467 } kf_inotify;
468 } kf_un;
469 };
470 uint16_t kf_status; /* Status flags. */
471 uint16_t kf_pad1; /* Round to 32 bit alignment. */
472 int _kf_ispare0; /* Space for more stuff. */
473 cap_rights_t kf_cap_rights; /* Capability rights. */
474 uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */
475 /* Truncated before copyout in sysctl */
476 char kf_path[PATH_MAX]; /* Path to file, if any. */
477};
478
479struct kinfo_lockf {
480 int kl_structsize; /* Variable size of record. */
481 int kl_rw;
482 int kl_type;
483 int kl_pid;
484 int kl_sysid;
485 int kl_pad0;
486 uint64_t kl_file_fsid;
487 uint64_t kl_file_rdev;
488 uint64_t kl_file_fileid;
489 off_t kl_start;
490 off_t kl_len; /* len == 0 till the EOF */
491 char kl_path[PATH_MAX];
492};
493
494#define KLOCKF_RW_READ 0x01
495#define KLOCKF_RW_WRITE 0x02
496
497#define KLOCKF_TYPE_FLOCK 0x01
498#define KLOCKF_TYPE_PID 0x02
499#define KLOCKF_TYPE_REMOTE 0x03
500
501/*
502 * The KERN_PROC_VMMAP sysctl allows a process to dump the VM layout of
503 * another process as a series of entries.
504 */
505#define KVME_TYPE_NONE 0
506#define KVME_TYPE_DEFAULT 1 /* no longer returned */
507#define KVME_TYPE_VNODE 2
508#define KVME_TYPE_SWAP 3
509#define KVME_TYPE_DEVICE 4
510#define KVME_TYPE_PHYS 5
511#define KVME_TYPE_DEAD 6
512#define KVME_TYPE_SG 7
513#define KVME_TYPE_MGTDEVICE 8
514#define KVME_TYPE_GUARD 9
515#define KVME_TYPE_UNKNOWN 255
516
517#define KVME_PROT_READ 0x00000001
518#define KVME_PROT_WRITE 0x00000002
519#define KVME_PROT_EXEC 0x00000004
520#define KVME_MAX_PROT_READ 0x00010000
521#define KVME_MAX_PROT_WRITE 0x00020000
522#define KVME_MAX_PROT_EXEC 0x00040000
523
524#define KVME_FLAG_COW 0x00000001
525#define KVME_FLAG_NEEDS_COPY 0x00000002
526#define KVME_FLAG_NOCOREDUMP 0x00000004
527#define KVME_FLAG_SUPER 0x00000008
528#define KVME_FLAG_GROWS_UP 0x00000010
529#define KVME_FLAG_GROWS_DOWN 0x00000020
530#define KVME_FLAG_USER_WIRED 0x00000040
531#define KVME_FLAG_SYSVSHM 0x00000080
532#define KVME_FLAG_POSIXSHM 0x00000100
533
534#if defined(__amd64__)
535#define KINFO_OVMENTRY_SIZE 1168
536#endif
537#if defined(__i386__)
538#define KINFO_OVMENTRY_SIZE 1128
539#endif
540
541struct kinfo_ovmentry {
542 int kve_structsize; /* Size of kinfo_vmmapentry. */
543 int kve_type; /* Type of map entry. */
544 void *kve_start; /* Starting address. */
545 void *kve_end; /* Finishing address. */
546 int kve_flags; /* Flags on map entry. */
547 int kve_resident; /* Number of resident pages. */
548 int kve_private_resident; /* Number of private pages. */
549 int kve_protection; /* Protection bitmask. */
550 int kve_ref_count; /* VM obj ref count. */
551 int kve_shadow_count; /* VM obj shadow count. */
552 char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
553 void *_kve_pspare[8]; /* Space for more stuff. */
554 off_t kve_offset; /* Mapping offset in object */
555 uint64_t kve_fileid; /* inode number if vnode */
556 uint32_t kve_fsid; /* dev_t of vnode location */
557 int _kve_ispare[3]; /* Space for more stuff. */
558};
559
560#if defined(__amd64__) || defined(__i386__)
561#define KINFO_VMENTRY_SIZE 1160
562#endif
563
564struct kinfo_vmentry {
565 int kve_structsize; /* Variable size of record. */
566 int kve_type; /* Type of map entry. */
567 uint64_t kve_start; /* Starting address. */
568 uint64_t kve_end; /* Finishing address. */
569 uint64_t kve_offset; /* Mapping offset in object */
570 uint64_t kve_vn_fileid; /* inode number if vnode */
571 uint32_t kve_vn_fsid_freebsd11; /* dev_t of vnode location */
572 int kve_flags; /* Flags on map entry. */
573 int kve_resident; /* Number of resident pages. */
574 int kve_private_resident; /* Number of private pages. */
575 int kve_protection; /* Protection bitmask. */
576 int kve_ref_count; /* VM obj ref count. */
577 int kve_shadow_count; /* VM obj shadow count. */
578 int kve_vn_type; /* Vnode type. */
579 uint64_t kve_vn_size; /* File size. */
580 uint32_t kve_vn_rdev_freebsd11; /* Device id if device. */
581 uint16_t kve_vn_mode; /* File mode. */
582 uint16_t kve_status; /* Status flags. */
583 union {
584 uint64_t _kve_vn_fsid; /* dev_t of vnode location */
585 uint64_t _kve_obj; /* handle of anon obj */
586 } kve_type_spec;
587 uint64_t kve_vn_rdev; /* Device id if device. */
588 int _kve_ispare[8]; /* Space for more stuff. */
589 /* Truncated before copyout in sysctl */
590 char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
591};
592#define kve_vn_fsid kve_type_spec._kve_vn_fsid
593#define kve_obj kve_type_spec._kve_obj
594
595#define KVMO_FLAG_SYSVSHM 0x0001
596#define KVMO_FLAG_POSIXSHM 0x0002
597
598/*
599 * The "vm.objects" sysctl provides a list of all VM objects in the system
600 * via an array of these entries.
601 */
602struct kinfo_vmobject {
603 int kvo_structsize; /* Variable size of record. */
604 int kvo_type; /* Object type: KVME_TYPE_*. */
605 uint64_t kvo_size; /* Object size in pages. */
606 uint64_t kvo_vn_fileid; /* inode number if vnode. */
607 uint32_t kvo_vn_fsid_freebsd11; /* dev_t of vnode location. */
608 int kvo_ref_count; /* Reference count. */
609 int kvo_shadow_count; /* Shadow count. */
610 int kvo_memattr; /* Memory attribute. */
611 uint64_t kvo_resident; /* Number of resident pages. */
612 uint64_t kvo_active; /* Number of active pages. */
613 uint64_t kvo_inactive; /* Number of inactive pages. */
614 union {
615 uint64_t _kvo_vn_fsid;
616 uint64_t _kvo_backing_obj; /* Handle for the backing obj */
617 } kvo_type_spec; /* Type-specific union */
618 uint64_t kvo_me; /* Uniq handle for anon obj */
619 uint64_t kvo_laundry; /* Number of laundry pages. */
620 uint64_t kvo_wired; /* Number of wired pages. */
621 uint64_t _kvo_qspare[4];
622 uint32_t kvo_swapped; /* Number of swapped pages */
623 uint32_t kvo_flags;
624 uint32_t _kvo_ispare[6];
625 char kvo_path[PATH_MAX]; /* Pathname, if any. */
626};
627#define kvo_vn_fsid kvo_type_spec._kvo_vn_fsid
628#define kvo_backing_obj kvo_type_spec._kvo_backing_obj
629
630/*
631 * The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
632 * another process as a series of entries. Each stack is represented by a
633 * series of symbol names and offsets as generated by stack_sbuf_print(9).
634 */
635#define KKST_MAXLEN 1024
636
637#define KKST_STATE_STACKOK 0 /* Stack is valid. */
638#define KKST_STATE_SWAPPED 1 /* Stack swapped out, obsolete. */
639#define KKST_STATE_RUNNING 2 /* Stack ephemeral. */
640
641#if defined(__amd64__) || defined(__i386__)
642#define KINFO_KSTACK_SIZE 1096
643#endif
644
645struct kinfo_kstack {
646 lwpid_t kkst_tid; /* ID of thread. */
647 int kkst_state; /* Validity of stack. */
648 char kkst_trace[KKST_MAXLEN]; /* String representing stack. */
649 int _kkst_ispare[16]; /* Space for more stuff. */
650};
651
652struct kinfo_sigtramp {
653 void *ksigtramp_start;
654 void *ksigtramp_end;
655 void *ksigtramp_spare[4];
656};
657
658#define KMAP_FLAG_WIREFUTURE 0x01 /* all future mappings wil be wired */
659#define KMAP_FLAG_ASLR 0x02 /* ASLR is applied to mappings */
660#define KMAP_FLAG_ASLR_IGNSTART 0x04 /* ASLR may map into sbrk grow region */
661#define KMAP_FLAG_WXORX 0x08 /* W^X mapping policy is enforced */
662#define KMAP_FLAG_ASLR_STACK 0x10 /* the stack location is randomized */
663#define KMAP_FLAG_ASLR_SHARED_PAGE 0x20 /* the shared page location is randomized */
664
665struct kinfo_vm_layout {
666 uintptr_t kvm_min_user_addr;
667 uintptr_t kvm_max_user_addr;
668 uintptr_t kvm_text_addr;
669 size_t kvm_text_size;
670 uintptr_t kvm_data_addr;
671 size_t kvm_data_size;
672 uintptr_t kvm_stack_addr;
673 size_t kvm_stack_size;
674 int kvm_map_flags;
675 uintptr_t kvm_shp_addr;
676 size_t kvm_shp_size;
677 uintptr_t kvm_spare[12];
678};
679
680#define KNOTE_STATUS_ACTIVE 0x00000001
681#define KNOTE_STATUS_QUEUED 0x00000002
682#define KNOTE_STATUS_DISABLED 0x00000004
683#define KNOTE_STATUS_DETACHED 0x00000008
684#define KNOTE_STATUS_KQUEUE 0x00000010
685
686#define KNOTE_EXTDATA_NONE 0
687#define KNOTE_EXTDATA_VNODE 1
688#define KNOTE_EXTDATA_PIPE 2
689
690struct kinfo_knote {
691 int knt_kq_fd;
692 struct kevent knt_event;
693 int knt_status;
694 int knt_extdata;
695 uint64_t knt_spare0[4];
696 union {
697 struct {
698 int knt_vnode_type;
699 uint64_t knt_vnode_fsid;
700 uint64_t knt_vnode_fileid;
701 char knt_vnode_fullpath[PATH_MAX];
702 } knt_vnode;
703 struct {
704 ino_t knt_pipe_ino;
705 } knt_pipe;
706 };
707};
708
709#ifdef _KERNEL
710/* Flags for kern_proc_out function. */
711#define KERN_PROC_NOTHREADS 0x1
712#define KERN_PROC_MASK32 0x2
713
714/* Flags for kern_proc_filedesc_out. */
715#define KERN_FILEDESC_PACK_KINFO 0x00000001U
716
717/* Flags for kern_proc_vmmap_out. */
718#define KERN_VMMAP_PACK_KINFO 0x00000001U
719struct sbuf;
720
721/*
722 * The kern_proc out functions are helper functions to dump process
723 * miscellaneous kinfo structures to sbuf. The main consumers are KERN_PROC
724 * sysctls but they may also be used by other kernel subsystems.
725 *
726 * The functions manipulate the process locking state and expect the process
727 * to be locked on enter. On return the process is unlocked.
728 */
729
730int kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
731 int flags);
732int kern_proc_cwd_out(struct proc *p, struct sbuf *sb, ssize_t maxlen);
733int kern_proc_out(struct proc *p, struct sbuf *sb, int flags);
734int kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
735 int flags);
736int kern_proc_kqueues_out(struct proc *p, struct sbuf *s, size_t maxlen,
737 bool compat32);
738
739int vntype_to_kinfo(int vtype);
740void pack_kinfo(struct kinfo_file *kif);
741#endif /* !_KERNEL */
742
743#endif