1:
2:
3:
4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
39:
40: #ifndef _SYS_PROC_H_
41: #define _SYS_PROC_H_
42:
43: #include <machine/proc.h>
44: #include <sys/selinfo.h>
45: #include <sys/queue.h>
46: #include <sys/timeout.h>
47: #include <sys/event.h>
48: #include <sys/mutex.h>
49: #include <sys/resource.h>
50: #include <machine/atomic.h>
51:
52: #ifdef _KERNEL
53: #define __need_process
54: #endif
55:
56: 57: 58:
59: struct process;
60: struct session {
61: int s_count;
62: struct process *s_leader;
63: struct vnode *s_ttyvp;
64: struct tty *s_ttyp;
65: char s_login[MAXLOGNAME];
66: };
67:
68: 69: 70:
71: struct pgrp {
72: LIST_ENTRY(pgrp) pg_hash;
73: LIST_HEAD(, process) pg_members;
74: struct session *pg_session;
75: pid_t pg_id;
76: int pg_jobc;
77: };
78:
79: 80: 81:
82: struct exec_package;
83: struct proc;
84: struct ps_strings;
85: struct uvm_object;
86: union sigval;
87:
88: struct emul {
89: char e_name[8];
90: int *e_errno;
91:
92: void (*e_sendsig)(sig_t, int, int, u_long, int, union sigval);
93: int e_nosys;
94: int e_nsysent;
95: struct sysent *e_sysent;
96: char **e_syscallnames;
97: int e_arglen;
98:
99: void *(*e_copyargs)(struct exec_package *, struct ps_strings *,
100: void *, void *);
101:
102: void (*e_setregs)(struct proc *, struct exec_package *,
103: u_long, register_t *);
104: int (*e_fixup)(struct proc *, struct exec_package *);
105: int (*e_coredump)(struct proc *, void *cookie);
106: char *e_sigcode;
107: char *e_esigcode;
108: int e_flags;
109: struct uvm_object *e_sigobject;
110:
111: void (*e_proc_exec)(struct proc *, struct exec_package *);
112: void (*e_proc_fork)(struct proc *p, struct proc *parent);
113: void (*e_proc_exit)(struct proc *);
114: };
115:
116: #define EMUL_ENABLED 0x0001
117: #define EMUL_NATIVE 0x0002
118:
119: extern struct emul *emulsw[];
120: extern int nemuls;
121:
122: 123: 124: 125: 126:
127: struct tusage {
128: struct timeval tu_runtime;
129: uint64_t tu_uticks;
130: uint64_t tu_sticks;
131: uint64_t tu_iticks;
132: };
133:
134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145:
146: #ifdef __need_process
147: struct process {
148: 149: 150: 151: 152: 153: 154: 155:
156: struct proc *ps_mainproc;
157: struct pcred *ps_cred;
158:
159: TAILQ_HEAD(,proc) ps_threads;
160:
161: LIST_ENTRY(process) ps_pglist;
162: struct process *ps_pptr;
163: LIST_ENTRY(process) ps_sibling;
164: LIST_HEAD(, process) ps_children;
165:
166:
167: #define ps_startzero ps_klist
168: struct klist ps_klist;
169: int ps_flags;
170:
171: struct proc *ps_single;
172: int ps_singlecount;
173:
174: int ps_traceflag;
175: struct vnode *ps_tracevp;
176: struct ucred *ps_tracecred;
177:
178: pid_t ps_oppid;
179: int ps_ptmask;
180: struct ptrace_state *ps_ptstat;
181:
182: struct rusage *ps_ru;
183: struct tusage ps_tu;
184: struct rusage ps_cru;
185: struct itimerval ps_timer[3];
186:
187:
188: #define ps_endzero ps_startcopy
189:
190:
191: #define ps_startcopy ps_limit
192:
193: struct plimit *ps_limit;
194: struct pgrp *ps_pgrp;
195: u_int ps_rtableid;
196: char ps_nice;
197:
198: struct uprof {
199: caddr_t pr_base;
200: size_t pr_size;
201: u_long pr_off;
202: u_int pr_scale;
203: } ps_prof;
204:
205:
206: #define ps_endcopy ps_refcnt
207:
208: struct timeval ps_start;
209: struct timeout ps_realit_to;
210: struct timeout ps_virt_to;
211: struct timeout ps_prof_to;
212:
213: int ps_refcnt;
214: };
215:
216: #define ps_pid ps_mainproc->p_pid
217: #define ps_session ps_pgrp->pg_session
218: #define ps_pgid ps_pgrp->pg_id
219:
220: #endif
221:
222: 223: 224: 225: 226: 227:
228: #define PS_CONTROLT _P_CONTROLT
229: #define PS_PPWAIT _P_PPWAIT
230: #define PS_PROFIL _P_PROFIL
231: #define PS_SUGID _P_SUGID
232: #define PS_SYSTEM _P_SYSTEM
233: #define PS_TRACED _P_TRACED
234: #define PS_WAITED _P_WAITED
235: #define PS_EXEC _P_EXEC
236: #define PS_ISPWAIT _P_ISPWAIT
237: #define PS_SUGIDEXEC _P_SUGIDEXEC
238: #define PS_NOZOMBIE _P_NOZOMBIE
239: #define PS_INEXEC _P_INEXEC
240: #define PS_SYSTRACE _P_SYSTRACE
241: #define PS_CONTINUED _P_CONTINUED
242: #define PS_STOPPED _P_STOPPED
243: #define PS_SINGLEEXIT _P_SINGLEEXIT
244: #define PS_SINGLEUNWIND _P_SINGLEUNWIND
245: #define PS_EXITING _P_EXITING
246:
247: struct proc {
248: TAILQ_ENTRY(proc) p_runq;
249: LIST_ENTRY(proc) p_list;
250:
251: struct process *p_p;
252: TAILQ_ENTRY(proc) p_thr_link;
253:
254:
255: struct filedesc *p_fd;
256: struct vmspace *p_vmspace;
257: struct sigacts *p_sigacts;
258: #define p_cred p_p->ps_cred
259: #define p_ucred p_cred->pc_ucred
260: #define p_rlimit p_p->ps_limit->pl_rlimit
261:
262: int p_exitsig;
263: int p_flag;
264: u_char p_os;
265: char p_stat;
266: char p_pad1[1];
267: u_char p_descfd;
268:
269: pid_t p_pid;
270: LIST_ENTRY(proc) p_hash;
271:
272:
273: #define p_startzero p_dupfd
274:
275: int p_dupfd;
276:
277: long p_thrslpid;
278: int p_sigwait;
279:
280:
281: u_int p_estcpu;
282: int p_cpticks;
283: fixpt_t p_pctcpu;
284: const volatile void *p_wchan;
285: struct timeout p_sleep_to;
286: const char *p_wmesg;
287: u_int p_swtime;
288: u_int p_slptime;
289: struct cpu_info * __volatile p_cpu;
290:
291: struct rusage p_ru;
292: struct tusage p_tu;
293: struct timeval p_rtime;
294: u_int p_uticks;
295: u_int p_sticks;
296: u_int p_iticks;
297:
298: void *p_systrace;
299:
300: int p_siglist;
301:
302: struct vnode *p_textvp;
303:
304: void *p_emuldata;
305:
306:
307: sigset_t p_sigdivert;
308:
309:
310: #define p_endzero p_startcopy
311:
312:
313: #define p_startcopy p_sigmask
314:
315: sigset_t p_sigmask;
316:
317: u_char p_priority;
318: u_char p_usrpri;
319: char p_comm[MAXCOMLEN+1];
320:
321: #ifndef __HAVE_MD_TCB
322: void *p_tcb;
323: # define TCB_SET(p, addr) ((p)->p_tcb = (addr))
324: # define TCB_GET(p) ((p)->p_tcb)
325: #endif
326:
327: struct emul *p_emul;
328: struct sigaltstack p_sigstk;
329: vaddr_t p_sigcode;
330:
331:
332: #define p_endcopy p_addr
333:
334: struct user *p_addr;
335: struct mdproc p_md;
336:
337: sigset_t p_oldmask;
338: union sigval p_sigval;
339: int p_sisig;
340: int p_sicode;
341: long p_sitrapno;
342:
343: u_long p_prof_addr;
344: u_long p_prof_ticks;
345:
346: u_short p_xstat;
347: u_short p_acflag;
348: };
349:
350:
351: #define SIDL 1
352: #define SRUN 2
353: #define SSLEEP 3
354: #define SSTOP 4
355: #define SZOMB 5
356: #define SDEAD 6
357: #define SONPROC 7
358:
359: #define P_ZOMBIE(p) ((p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
360:
361: 362: 363: 364:
365: #define P_INKTR 0x000001
366: #define _P_CONTROLT 0x000002
367: #define P_INMEM 0x000004
368: #define P_SIGSUSPEND 0x000008
369: #define _P_PPWAIT 0x000010
370: #define P_PROFIL 0x000020
371: #define P_SELECT 0x000040
372: #define P_SINTR 0x000080
373: #define _P_SUGID 0x000100
374: #define P_SYSTEM 0x000200
375: #define P_TIMEOUT 0x000400
376: #define _P_TRACED 0x000800
377: #define P_WAITED 0x001000
378: #define P_WEXIT 0x002000
379: #define _P_EXEC 0x004000
380:
381:
382: #define P_OWEUPC 0x008000
383: #define _P_ISPWAIT 0x010000
384:
385:
386: #define P_SSTEP 0x020000
387: #define _P_SUGIDEXEC 0x040000
388:
389: #define P_SUSPSINGLE 0x080000
390: #define P_NOZOMBIE 0x100000
391: #define _P_INEXEC 0x200000
392: #define P_SYSTRACE 0x400000
393: #define P_CONTINUED 0x800000
394: #define _P_SINGLEEXIT 0x1000000
395: #define _P_SINGLEUNWIND 0x2000000
396: #define P_THREAD 0x4000000
397: #define P_SUSPSIG 0x8000000
398: #define P_SOFTDEP 0x10000000
399: #define P_STOPPED 0x20000000
400: #define P_CPUPEG 0x40000000
401: #define _P_EXITING 0x80000000
402:
403: #ifndef _KERNEL
404: #define P_CONTROLT _P_CONTROLT
405: #define P_PPWAIT _P_PPWAIT
406: #define P_SUGID _P_SUGID
407: #define P_TRACED _P_TRACED
408: #define P_EXEC _P_EXEC
409: #define P_SUGIDEXEC _P_SUGIDEXEC
410: #define P_INEXEC _P_INEXEC
411: #endif
412:
413: #define P_BITS \
414: ("\20\02CONTROLT\03INMEM\04SIGPAUSE\05PPWAIT\06PROFIL\07SELECT" \
415: "\010SINTR\011SUGID\012SYSTEM\013TIMEOUT\014TRACED\015WAITED\016WEXIT" \
416: "\017EXEC\020PWEUPC\021ISPWAIT\022SSTEP\023SUGIDEXEC\024SUSPSINGLE" \
417: "\025NOZOMBIE\026INEXEC\027SYSTRACE\030CONTINUED" \
418: "\031SINGLEEXIT\032SINGLEUNWIND" \
419: "\033THREAD\034SUSPSIG\035SOFTDEP\036STOPPED\037CPUPEG")
420:
421:
422: #define P_EXITSIG(p) \
423: (((p)->p_p->ps_flags & PS_TRACED) ? SIGCHLD : (p)->p_exitsig)
424:
425: #define THREAD_PID_OFFSET 1000000
426:
427: 428: 429: 430: 431: 432: 433:
434: struct pcred {
435: struct ucred *pc_ucred;
436: uid_t p_ruid;
437: uid_t p_svuid;
438: gid_t p_rgid;
439: gid_t p_svgid;
440: };
441:
442: #ifdef _KERNEL
443:
444: struct uidinfo {
445: LIST_ENTRY(uidinfo) ui_hash;
446: uid_t ui_uid;
447: long ui_proccnt;
448: long ui_lockcnt;
449: };
450:
451: struct uidinfo *uid_find(uid_t);
452:
453: 454: 455: 456: 457:
458: #define PID_MAX 32766
459: #define NO_PID (PID_MAX+1)
460:
461: #define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
462: #define SESSHOLD(s) ((s)->s_count++)
463: #define SESSRELE(s) do { \
464: if (--(s)->s_count == 0) \
465: pool_put(&session_pool, (s)); \
466: } while ( 0)
467:
468: 469: 470:
471: #define FORK_FORK 0x00000001
472: #define FORK_VFORK 0x00000002
473: #define FORK_RFORK 0x00000004
474: #define FORK_PPWAIT 0x00000008
475: #define FORK_SHAREFILES 0x00000010
476: #define FORK_CLEANFILES 0x00000020
477: #define FORK_NOZOMBIE 0x00000040
478: #define FORK_SHAREVM 0x00000080
479: #define FORK_TFORK 0x00000100
480: #define FORK_SIGHAND 0x00000200
481: #define FORK_PTRACE 0x00000400
482: #define FORK_THREAD 0x00000800
483:
484: #define EXIT_NORMAL 0x00000001
485: #define EXIT_THREAD 0x00000002
486:
487: #define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
488: extern LIST_HEAD(pidhashhead, proc) *pidhashtbl;
489: extern u_long pidhash;
490:
491: #define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
492: extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
493: extern u_long pgrphash;
494:
495: extern struct proc proc0;
496: extern int nprocs, maxproc;
497: extern int randompid;
498:
499: LIST_HEAD(proclist, proc);
500: extern struct proclist allproc;
501: extern struct proclist zombproc;
502:
503: extern struct proc *initproc;
504: extern struct proc *syncerproc;
505:
506: extern struct pool process_pool;
507: extern struct pool proc_pool;
508: extern struct pool rusage_pool;
509: extern struct pool ucred_pool;
510: extern struct pool session_pool;
511: extern struct pool pgrp_pool;
512: extern struct pool pcred_pool;
513:
514: struct simplelock;
515:
516: struct process *prfind(pid_t);
517: struct proc *pfind(pid_t);
518: struct pgrp *pgfind(pid_t);
519: void proc_printit(struct proc *p, const char *modif,
520: int (*pr)(const char *, ...));
521:
522: int chgproccnt(uid_t uid, int diff);
523: int enterpgrp(struct process *, pid_t, struct pgrp *, struct session *);
524: void fixjobc(struct process *, struct pgrp *, int);
525: int inferior(struct process *, struct process *);
526: void leavepgrp(struct process *);
527: void preempt(struct proc *);
528: void pgdelete(struct pgrp *);
529: void procinit(void);
530: void resetpriority(struct proc *);
531: void setrunnable(struct proc *);
532: void endtsleep(void *);
533: void unsleep(struct proc *);
534: void reaper(void);
535: void exit1(struct proc *, int, int);
536: void exit2(struct proc *);
537: void cpu_exit(struct proc *);
538: int fork1(struct proc *, int, int, void *, pid_t *, void (*)(void *),
539: void *, register_t *, struct proc **);
540: int groupmember(gid_t, struct ucred *);
541:
542: enum single_thread_mode {
543: SINGLE_SUSPEND,
544: SINGLE_UNWIND,
545: SINGLE_EXIT
546: };
547: int single_thread_set(struct proc *, enum single_thread_mode, int);
548: void single_thread_clear(struct proc *);
549: int single_thread_check(struct proc *, int);
550:
551: void child_return(void *);
552:
553: int proc_cansugid(struct proc *);
554: void proc_finish_wait(struct proc *, struct proc *);
555: void proc_zap(struct proc *);
556:
557: struct sleep_state {
558: int sls_s;
559: int sls_catch;
560: int sls_do_sleep;
561: int sls_sig;
562: };
563:
564: #if defined(MULTIPROCESSOR)
565: void proc_trampoline_mp(void);
566: #endif
567:
568: 569: 570: 571: 572: 573:
574: #define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
575: #define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
576: struct cpuset {
577: int cs_set[CPUSET_SSIZE];
578: };
579:
580: void cpuset_init_cpu(struct cpu_info *);
581:
582: void cpuset_clear(struct cpuset *);
583: void cpuset_add(struct cpuset *, struct cpu_info *);
584: void cpuset_del(struct cpuset *, struct cpu_info *);
585: int cpuset_isset(struct cpuset *, struct cpu_info *);
586: void cpuset_add_all(struct cpuset *);
587: void cpuset_copy(struct cpuset *, struct cpuset *);
588: void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
589: void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
590: void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
591: struct cpu_info *cpuset_first(struct cpuset *);
592:
593: #endif
594: #endif
595: