1 /*  $NetBSD: wait.h,v 1.24 2005/12/11 12:25:21 christos Exp $ */
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989, 1993, 1994
5  *  The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *  @(#)wait.h  8.2 (Berkeley) 7/10/94
32  */
33 #ifndef _SYS_WAIT_H_
34 #define _SYS_WAIT_H_
35 
36 #include <sys/featuretest.h>
37 #include <sys/types.h>
38 
39 /*
40  * This file holds definitions relevent to the wait4 system call
41  * and the alternate interfaces that use it (wait, wait3, waitpid).
42  */
43 
44 /*
45  * Macros to test the exit status returned by wait
46  * and extract the relevant values.
47  */
48 #define _W_INT(w) (*(int *)(void *)&(w))  /* convert union wait to int */
49 
50 #define _WSTATUS(x) (_W_INT(x) & 0177)
51 #define _WSTOPPED 0177    /* _WSTATUS if process is stopped */
52 #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
53 #define WSTOPSIG(x) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
54 #define WIFSIGNALED(x)  (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
55 #define WTERMSIG(x) (_WSTATUS(x))
56 #define WIFEXITED(x)  (_WSTATUS(x) == 0)
57 #define WEXITSTATUS(x)  ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
58 #define WCOREFLAG 0200
59 #define WCOREDUMP(x)  (_W_INT(x) & WCOREFLAG)
60 
61 #define W_EXITCODE(ret, sig)  ((ret) << 8 | (sig))
62 #define W_STOPCODE(sig)   ((sig) << 8 | _WSTOPPED)
63 
64 /*
65  * Option bits for the third argument of wait4.  WNOHANG causes the
66  * wait to not hang if there are no stopped or terminated processes, rather
67  * returning an error indication in this case (pid==0).  WUNTRACED
68  * indicates that the caller should receive status about untraced children
69  * which stop due to signals.  If children are stopped and a wait without
70  * this option is done, it is as though they were still running... nothing
71  * about them is returned.
72  */
73 #define WNOHANG   0x00000001  /* don't hang in wait */
74 #define WUNTRACED 0x00000002  /* tell about stopped,
75              untraced children */
76 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
77 #define WALTSIG   0x00000004  /* wait for processes that exit
78              with an alternate signal (i.e.
79              not SIGCHLD) */
80 #define WALLSIG   0x00000008  /* wait for processes that exit
81              with any signal, i.e. SIGCHLD
82              and alternates */
83 
84 /*
85  * These are the Linux names of some of the above flags, for compatibility
86  * with Linux's clone(2) API.
87  */
88 #define __WCLONE  WALTSIG
89 #define __WALL    WALLSIG
90 
91 /*
92  * These bits are used in order to support SVR4 (etc) functionality
93  * without replicating sys_wait4 5 times.
94  */
95 #define WNOWAIT   0x00010000  /* Don't mark child 'P_WAITED' */
96 #define WNOZOMBIE 0x00020000  /* Ignore zombies */
97 #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
98 
99 /* POSIX extensions and 4.2/4.3 compatibility: */
100 
101 /*
102  * Tokens for special values of the "pid" parameter to wait4.
103  */
104 #define WAIT_ANY  (-1)  /* any process */
105 #define WAIT_MYPGRP 0 /* any process in my process group */
106 
107 /*
108  * Deprecated:
109  * Structure of the information in the status word returned by wait4.
110  * If w_stopval==WSTOPPED, then the second structure describes
111  * the information returned, else the first.
112  */
113 union wait {
114   int w_status;   /* used in syscall */
115   /*
116    * Terminated process status.
117    */
118   struct {
119 #if BYTE_ORDER == LITTLE_ENDIAN
120     unsigned int  w_Termsig:7,  /* termination signal */
121         w_Coredump:1, /* core dump indicator */
122         w_Retcode:8,  /* exit code if w_termsig==0 */
123         w_Filler:16;  /* upper bits filler */
124 #endif
125 #if BYTE_ORDER == BIG_ENDIAN
126     unsigned int  w_Filler:16,  /* upper bits filler */
127         w_Retcode:8,  /* exit code if w_termsig==0 */
128         w_Coredump:1, /* core dump indicator */
129         w_Termsig:7;  /* termination signal */
130 #endif
131   } w_T;
132   /*
133    * Stopped process status.  Returned
134    * only for traced children unless requested
135    * with the WUNTRACED option bit.
136    */
137   struct {
138 #if BYTE_ORDER == LITTLE_ENDIAN
139     unsigned int  w_Stopval:8,  /* == W_STOPPED if stopped */
140         w_Stopsig:8,  /* signal that stopped us */
141         w_Filler:16;  /* upper bits filler */
142 #endif
143 #if BYTE_ORDER == BIG_ENDIAN
144     unsigned int  w_Filler:16,  /* upper bits filler */
145         w_Stopsig:8,  /* signal that stopped us */
146         w_Stopval:8;  /* == W_STOPPED if stopped */
147 #endif
148   } w_S;
149 };
150 #define w_termsig w_T.w_Termsig
151 #define w_coredump  w_T.w_Coredump
152 #define w_retcode w_T.w_Retcode
153 #define w_stopval w_S.w_Stopval
154 #define w_stopsig w_S.w_Stopsig
155 
156 #define WSTOPPED  _WSTOPPED
157 
158 __BEGIN_DECLS
159 pid_t wait(int *);
160 
161 #if 0   /* Normally declared here but not implemented for UEFI. */
162 struct rusage;  /* forward declaration */
163 
164 pid_t waitpid(pid_t, int *, int);
165 pid_t wait3(int *, int, struct rusage *);
166 pid_t wait4(pid_t, int *, int, struct rusage *);
167 #endif
168 __END_DECLS
169 
170 #endif /* !_SYS_WAIT_H_ */
171